Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
      Chris L.NinjaTrader Customer Service

      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
            Chris L.NinjaTrader Customer Service

            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
                Chris L.NinjaTrader Customer Service

                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
                    Chris L.NinjaTrader Customer Service

                    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
                        Chris L.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Mestor, 03-10-2023, 01:50 AM
                        16 responses
                        387 views
                        0 likes
                        Last Post z.franck  
                        Started by rtwave, 04-12-2024, 09:30 AM
                        4 responses
                        31 views
                        0 likes
                        Last Post rtwave
                        by rtwave
                         
                        Started by yertle, Yesterday, 08:38 AM
                        7 responses
                        29 views
                        0 likes
                        Last Post yertle
                        by yertle
                         
                        Started by bmartz, 03-12-2024, 06:12 AM
                        2 responses
                        22 views
                        0 likes
                        Last Post bmartz
                        by bmartz
                         
                        Started by funk10101, Today, 12:02 AM
                        0 responses
                        7 views
                        0 likes
                        Last Post funk10101  
                        Working...
                        X