Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RSI in the condition

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    RSI in the condition

    Hello!

    When the RSI is below the oversold zone, I save its value in the Series RSILow. I also save the value of the Low of the corresponding bar in the series BarLow.

    The print function gives me the expected values on the output window.

    The obtained values are then compared as shown in the line (a), but the print function is failing to pup up the result of the multiplication used to test if this condition is working. But when I comment the following section of the line ​(a)
    HTML Code:
    && BarLow[0] > BarLow[1];
    ,
    I obtain 2000.

    For the line (a), why the comparison
    HTML Code:
    RSILow[0] > RSILow[1]
    is working alone and when combined with
    HTML Code:
    && BarLow[0] > BarLow[1];
    it fails?
    I have the following code in OnBarUpdate()

    HTML Code:
    myRSI[0]     = RSI(Close, Amplitude,  3)[0];
    if(myRSI[0] < Oversold)
    {
        RSILow[0] = MIN(myRSI, barBackwards)[0];
        BarLow[0]  = MIN(Low, barBackwards)[0];
    
        Print("RSILow" + " Size " + ":  " + RSILow[0] + " : " + Time[0]);
        Print("BarLow" + " Size " + ":  " + BarLow[0] + " : " + Time[0]);
    
      if(RSILow[0] > RSILow[1] && BarLow[0] > BarLow[1])   // (a)
      {
         Print("Product" + " Size " + ":  " + 1000*2 + " : " + Time[0]);
      }
    }
    ​
    I would appreciate any help.

    Thanks in advance!
    Last edited by Stanfillirenfro; 10-28-2024, 11:49 AM.

    #2
    Hello Stanfillirenfro,

    From just the code I can't tell how this may have evaluated, do you have the prints that go with this code that show how the condition evaluated when run?

    Comment


      #3
      Hello NinjaTrader_Jesse and many thanks for your reply.

      I have attached the prints.

      Thanks!
      Attached Files

      Comment


        #4
        Hello Stanfillirenfro,

        It looks like you are not printing the 1 bar ago value, it would be helpful to just print all 4 values used in the condition along with the bar time so you can see why the condition is not becoming true.


        Print(RSILow[0] + " > " + RSILow[1] + " " + BarLow[0] + " > " + BarLow[1]);

        Comment


          #5
          Many thanks NinjaTrader_Jesse for your reply.

          The prints are showing that all Value[1] are turned to zero (see attached file).

          I am using the Series to save the values, but why are these Series saving only the Value[0]?

          Thanks!
          Attached Files

          Comment


            #6
            Hello Stanfillirenfro,

            Did you add dashes to the print or modify it? I am unsure how to read this as printed.

            Comment


              #7
              Hello NinjaTrader_Jesse and thank for your reply.

              Did you add dashes to the print or modify it? I am unsure how to read this as printed.
              I have added dashes to the print to.

              Thanks!

              Comment


                #8
                Hello Stanfillirenfro,

                Can you provide a copy of the updated code showing the print as you added it so I can compare that to the output?

                Comment


                  #9
                  Hello NinjaTrader_Jesse and many thanks for your reply.

                  Below is the update of the code:

                  HTML Code:
                  myRSI[0] = RSI(Close, Amplitude, 3)[0];
                  
                  if(myRSI[0] < Oversold)
                  {
                     RSILow[0] = MIN(myRSI, barBackwards)[0];
                     BarLow[0] = MIN(Low, barBackwards)[0];
                  
                     Print(RSILow[0] + " > " + RSILow[1] + "--------" + BarLow[0] + " > " + BarLow[1] + "--------" + " : " + Time[0]);
                  }​
                  Thanks!

                  Comment


                    #10
                    Hello Stanfillirenfro,

                    If the myRSI[0] value is greater than oversold that condition wont be true for some bars meaning the plot value is not set for every bar. I would suggest adding a print outside that condition so you can see how often that condition is true in contrast to when it is not. If the plot is not set for 2 bars in a row the previous bar value will be 0.

                    Comment


                      #11
                      Many thanks NinjaTrader_Jesse for your reply.

                      Lookig back at the post#1, my probelm is located on the line (a) of the code.
                      below is the pat of the code with the problem:

                      HTML Code:
                      if(RSILow[0] > RSILow[1] && BarLow[0] > BarLow[1]) // (a)
                      {
                          Print("Product" + " Size " + ": " + 1000*2 + " : " + Time[0]);
                      }​
                      FIRST CASE:
                      I comment or remove the part of code with BarLow on the line (a) and I have the following modification:

                      HTML Code:
                      if(RSILow[0] > RSILow[1]) // (a)
                      {
                           Print("Product" + " Size " + ": " + 1000*2 + " : " + Time[0]);
                      }​
                      RESULT: On the output window, I have 2000 from the top to the bottom of the window.
                      CONCLUSION. RSILow is not the problem!

                      SECOND CASE:

                      I add the part of the code with BarLow to have:

                      HTML Code:
                      if(RSILow[0] > RSILow[1] && BarLow[0] > BarLow[1]) // (a)
                      {
                          Print("Product" + " Size " + ": " + 1000*2 + " : " + Time[0]);
                      }​
                      RRESULT: There is nothing on the output window, so that I am suspecting the Series BarLow to be causing the problem.

                      THIRD CASE: I remove the Series RSILow from the code to have:
                      HTML Code:
                      if(BarLow[0] > BarLow[1]) // (a)
                      {
                         Print("Product" + " Size " + ": " + 1000*2 + " : " + Time[0]);
                      }​
                      RESULT: Nothing on the output window.
                      CONCLUSION: The Series BarLow is the problem.

                      I am just not understanding why! I am just failing to combine RSILow and BarLow in the same condition.

                      RSI is plotted on another panel than the chart. Could that be the problem? If yes, is there a line to ba added somewhere to prevent the proplem?

                      Thanks!
                      Last edited by Stanfillirenfro; 10-28-2024, 03:27 PM.

                      Comment


                        #12
                        Hello Stanfillirenfro,

                        It was clear from your previous comment that adding the additional condition caused the overall condition to be false. To know why that is you need to explore how the series is being set before that point. Did you try printing the value on every bar rather than inside the condition? If you are not setting a value on every bar the 1 bars ago value will be not set and invalid which will print as 0.

                        The panel is not a problem,the RSI is being called in code so that part is irrelevant.

                        Comment


                          #13
                          Hello NinjaTrader_Jesse and thanks for your reply.

                          I have printed the values outside of the condition and they are different from zero on each bar as shwon on the attached file.

                          Thanks!
                          Attached Files

                          Comment


                            #14
                            Hello Stanfillirenfro,

                            Please try the print you originally had which was showing 0's in that use case. The print should happen for every bar and then we can check all 4 values being used. For the condition to work you need to have a value set on every bar, if you see output where some 0's are showing up we could explore that further if you provide an updated sample. If a value is being set on every bar you should see that all 4 values are always populated.

                            Print(RSILow[0] + " > " + RSILow[1] + "--------" + BarLow[0] + " > " + BarLow[1] + "--------" + " : " + Time[0]);

                            Comment


                              #15
                              Hello NinjaTrader_Jesse and many thanks for your reply.

                              The prints outside of the condition are as expected due to the amplitude used, as shown on the attached file.

                              How to get the correct values in the condition?


                              Thanks!
                              Attached Files
                              Last edited by Stanfillirenfro; 10-30-2024, 01:14 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              636 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              366 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              107 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              569 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              571 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X