Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CHange of RSI calculation

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

    #16
    I guess I'm close to resolution.

    Here is one other issue I'm seeing. May be the way I'm accessing 60 min RSI value in lower time frame chart. What I observed is that when I access RSI60[0], I'm seeing the value from previous hour candle not the current hour value. The 60 min RSI plot looks fine in lower time frame chart(in this case 5 min chart). I do see the RSI value plotted properly but when I print the values I'm seeing previous hour candle value.

    Wondering if there is different way to access the current value of higher time frame RSI.
    Attached are the values what I'm seeing -

    Appreciate your help.
    Attached Files

    Comment


      #17
      Hi ark,

      The hourly bar has not closed yet, so you are getting the value from the bar that closed last. Try experimenting with different Calculate settings like OnEachTick/OnPriceChange:



      Kind regards,
      -ChrisL

      Comment


        #18
        I will try these. The plot shows correctly though

        Comment


          #19
          Does this below statement returns the price of the current bar in multi time frame scenario? Looks like it is not

          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          // Calculate on the close of each bar
          Calculate = Calculate.OnEachTick;
          }
          }

          As per this reference https://ninjatrader.com/support/help...?calculate.htm (under How Bars Data is referenced), I should be seeing the current bar value of the higher time frame but I'm still seeing previous bar close value.

          Below is the sample code for RSI value for 60 min time frame (higher time frame) insider a lower time frame chart.

          if (State == State.DataLoaded)
          {

          RSI60 = RSI(BarsArray[1], 14, 3);
          rsi2_ma = EMA(RSI60, 50);

          }
          Last edited by ark321; 09-15-2021, 09:53 AM.

          Comment


            #20
            Hi ark,

            Please see the attached test script demonstrating OnEachTick values from the 60M RSI.

            Kind regards.
            Attached Files

            Comment


              #21
              Thank you.

              Just wanted to make sure, this code has OnBarClose setting. Shouldnt this be OnEachTick ?

              Calculate = Calculate.OnBarClose;

              Comment


                #22
                Hi ark. Correct, I was changing from the indicator settings. To set OnEachTick as the default set Calculate = Calculate.OnEachTick in State.SetDefaults.

                Kind regards,
                -ChrisL

                Comment


                  #23
                  Thanks for confirming

                  I'm calling the indicator like this (renamed the sample)


                  _RSI60 = RSI60();
                  rsi2_ma = EMA(_RSI60, 50);

                  Print(_RSI60[0]) <---- error here

                  Error on calling 'OnBarUpdate' method on bar 20: Index was outside the bounds of the array.

                  Am I missing any step?

                  Comment


                    #24
                    Hi ark,

                    It looks like you need to wait until there are at least 50 bars in each series before processing the command. See my example above how I check for CurrentBars[0] and CurrentBars[1] for at least 14 bars (the period of the RSI).

                    Kind regards,
                    -ChrisL

                    Comment


                      #25
                      I loaded the chart with 1 year of data. What do you mean need to wait for 50 bars?

                      Comment


                        #26
                        Hi Ark,

                        The sample I uploaded does:

                        if(CurrentBars[0] < 14 || CurrentBars[1] < 14)

                        to check for at least 14 bars on the chart before processing. The EMA needs at least 50 60 minute bars on the chart before it can produce a value.

                        Kind regards,
                        -ChrisL

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        649 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        370 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        109 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        573 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        576 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X