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 MacDad, 02-25-2024, 11:48 PM
            7 responses
            157 views
            0 likes
            Last Post loganjarosz123  
            Started by Belfortbucks, Today, 09:29 PM
            0 responses
            6 views
            0 likes
            Last Post Belfortbucks  
            Started by zstheorist, Today, 07:52 PM
            0 responses
            7 views
            0 likes
            Last Post zstheorist  
            Started by pmachiraju, 11-01-2023, 04:46 AM
            8 responses
            151 views
            0 likes
            Last Post rehmans
            by rehmans
             
            Started by mattbsea, Today, 05:44 PM
            0 responses
            6 views
            0 likes
            Last Post mattbsea  
            Working...
            X