Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RSA(Close, 2, 3)[1] doesn't seem to work

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

    RSA(Close, 2, 3)[1] doesn't seem to work

    I am trying to set up an indicator that plots a line and plays a sound when the current RSI[0] is above say, 30 and the previous candle RSI (RSI[1] correct?) is at 1 or less.
    This code looks like it should work to me according to the manual and the tutorials, but when I add the RSI[1] the graph is blank. If I remark that out, then the RSI[0] works just fine. I've tried porting the values to the output window, but when I include RSI[1] I get the following output regardless of the RSI value...

    The current RSI value is 1.3983
    Error on calling 'OnBarUpdate' method for indicator 'PrintRSI' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    Again, if I remove RSI[1] then the value of RSI[0] prints fine. Here is the code I am trying to get to work:

    Code:
                ///  Just debug code here
                Print ("RSI currently is " + RSI(Close, 2, 3)[0]);
                Print ("RSI 1 currently is " + RSI(Close, 2, 3)[1]);
                
                if (RSI(Close, 2, 3)[1] <= 1)
                    && RSI(Close, 2, 3)[0] >= 30)
                {
                    PlotHigh.Set(1);
                    PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\Connected.wav");
                }
                
                if (RSI(Close, 2, 3)[1] >= 99)
                    && RSI(Close, 2, 3)[0] <=70)
                {
                    PlotLow.Set(1);
                    PlaySound(@"C:\Program Files (x86)\NinjaTrader 7\sounds\Connected.wav");
                }

    #2
    This should help:

    Comment


      #3
      Welcome to our forums bchirhart, this is a common situation newer coders run into which can be resolved easily with the concepts from this tip :

      Comment


        #4
        Yep - that got it! Thanks. One step closer.

        I did find however that RSI[0] and RSI[1] were displaying the same number - so I changed it to RSI[2]. Not sure if I am seeing the correct results or not, but it seems to be "mostly" working. Sometimes the bars double fire and the RSI[2] output is the same for the second bar as it was for the first. I would think that RSI[2] would be the old RSI[0], correct? OR - should I really be using RSI[1] and I just read my initial results incorrectly?

        Comment


          #5
          Glad to hear that - would RSI[0] would give you depends on the CalculateOnBarClose setting you use for your script : http://www.ninjatrader.com/support/h...onbarclose.htm

          With this set to 'true' - index 0 is the value of last completed bar, on 'false' the value for the currently developing bar, so updated on each incoming tick.

          Comment


            #6
            Thanks! That is showing what I would suspect. I really appreciate it Bertrand and Sludge.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by cmoran13, 04-16-2026, 01:02 PM
            0 responses
            46 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            28 views
            0 likes
            Last Post PaulMohn  
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            163 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            98 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            158 views
            2 likes
            Last Post CaptainJack  
            Working...
            X