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

RSI with Range bars

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

    RSI with Range bars

    Hello all,
    on every new bar I can determine two possible positions of close prices of this bar. Lower close is at (High-Range Value), higher close is at (Low+Range Value). I use the ranage 6 for this example. In the same chart I have RSI inidcator displayed. I would like to do 2 RSI predictions on both positions - lower and higher close.
    I supposed a can use dataseries with Close values and for the latest Close value I can use
    High-Range value for higher and Low+Range Value for lower and then calculate RSI on these dataseries. But It does not work properly
    The prediciton done this way is not accurate. Calculated value of RSI is little bit different then final value of real RSI according to price close value.
    Would anybody be so king and help me.
    Thank you very much.
    Alex

    Just simply code:
    Period = period for RSI (14 default)

    in Initialize:
    closeUP = new DataSeries(this);
    closeDN = new DataSeries(this);


    protected override void OnBarUpdate()
    {
    closeUP.Set( Close[0] );
    closeDN.Set( Close[0] );

    // calculate just for last bar
    if (CurrentBar<=(Bars.Count-2)) return;

    // not necessary, just for sure - copy values
    for(int i=0; i<=Period; i++) {
    closeUP.Set(i,Close[i]);
    closeDN.Set(i,Close[i]);
    }

    closeShort = Bars.Instrument.MasterInstrument.Round2TickSize( High[0] - ((Bars.Period.Value) * Bars.Instrument.MasterInstrument.TickSize) );

    // for short
    closeDN.Set(0,closeShort);

    // this value does not equal to real RSI value on real bar close value
    rsiValueShort = RSI(closeDN, Period, 3)[0];
    }

    #2
    Alexik30, thanks for the post - the issue here likely is that the RSI would internally use the SMA method - which would be using a recursive calculation, which works fine if the past values of the past series would not change which is not the case for your scenario.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hello Bertrand, thank you for you replay.
      As I examined RSI code, SMA is only in one section and if I get it right, it is calculated just one time:
      if ((CurrentBar + 1) == Period)
      {
      avgDown.Set(SMA(down, Period)[0]);
      avgUp.Set(SMA(up, Period)[0]);
      }
      and next thing is that I dont use smoothed RSI AVG..just simple RSI.
      I dont really understand why it doesnt work right
      Alex

      Comment


        #4
        Correct, the SMA call is one time there only, however SMA internal using a recursive calculation - which give you the issue here. So what would be needed is an alternative custom SMA implementation for this scenario.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          OK, thank you so much Bertrand, I will give it a try
          Alex

          Comment


            #6
            The problem here is that you need to create two artificial data series, on which you want to perform the RSI calculations.

            -> first data series = N closes + projected high of range bar
            -> second data series = N closes + projected low of range bar

            You have already introduced them and called then closeUP and closeDN. Internally the RSI uses exponential smoothing and needs a significantly larger lookback than the period of the indicator, because the EMA is an IIR filter.

            Your project is not difficult to achieve, here is a code snippet with a few explanations

            Code:
            protected override void OnBarUpdate()
            {
                if (CurrentBar < period)
                {
                     closeUP.Set(Close[0]);
                     closeDN.Set(Close[0]);
                     Values[0].Reset();  // no prediction
                     Values[1].Reset();  // no prediction
                     return;
                }
            
                if (FirstTickOfBar)
                {
                         closeUP.Set(1, Close[1]);  // update prior value of closeUP
                         closeDN.Set(1, Close[1]);  // update  prior value of closeDN 
                }
                // with every incoming tick recalculate projected high and low
                // also you should calculate the value of BarsPeriod.Value * TickSize in OnStartUp() and not here
               closeUP.Set(Low[0] + BarsPeriod.Value * TickSize);
               closeDN.Set(High[0] - BarsPeriod.Value * TickSize);
               Values[0].Set(RSI(closeUP, period, 3)[0]);
               Values[1].Set(RSI(closeDN, period, 3)[0]);
            }
            The code should produce the result you look for. NOT tested.

            Comment


              #7
              Harry, thank you soooooooooooo much !! I achieved that but in more complicated way. Your way looks great ! The power is in simply codes I will try it. Thank you very much again !
              Have a great time !
              Alex

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Barry Milan, Yesterday, 10:35 PM
              5 responses
              16 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Started by DanielSanMartin, Yesterday, 02:37 PM
              2 responses
              13 views
              0 likes
              Last Post DanielSanMartin  
              Started by DJ888, 04-16-2024, 06:09 PM
              4 responses
              12 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by terofs, Today, 04:18 PM
              0 responses
              11 views
              0 likes
              Last Post terofs
              by terofs
               
              Started by nandhumca, Today, 03:41 PM
              0 responses
              8 views
              0 likes
              Last Post nandhumca  
              Working...
              X