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

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 :

      BertrandNinjaTrader Customer Service

      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.
          BertrandNinjaTrader Customer Service

          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 llanqui, Today, 10:32 AM
            0 responses
            1 view
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by StockTrader88, 03-06-2021, 08:58 AM
            45 responses
            3,992 views
            3 likes
            Last Post johntraderuser2  
            Started by TAJTrades, Today, 09:46 AM
            0 responses
            7 views
            0 likes
            Last Post TAJTrades  
            Started by rhyminkevin, Yesterday, 04:58 PM
            5 responses
            62 views
            0 likes
            Last Post dp8282
            by dp8282
             
            Started by realblubb, Today, 09:28 AM
            0 responses
            8 views
            0 likes
            Last Post realblubb  
            Working...
            X