Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

RSI working with other data series (BarsArray)?

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

    RSI working with other data series (BarsArray)?

    I've looked through this forum and can't find an answer to my question. Is there something about the NT8 RSI indicator that demands special treatment when using an added data series (for a Multi Time Frame strategy)? I don't need the RSI to display on the chart, I just want to perform calculations using the indicator. I ask because I can't get a simple instantiation of the RSI to compile, next to an SMA and an EMA and an ADX compiling just fine. Here's what I mean:

    Code:
    public class CWCODE9 : Strategy
    {
         private SMA SMA1;
         private EMA EMA1;
         private RSI RSI1;
         private ADX ADX1;
    
         protected override void OnStateChange()
         {
              if (State == State.SetDefaults)
              {
                   Name = "CWCODE9";
                   Calculate = Calculate.OnBarClose;
              }
              else if (State == State.Configure)
              {
                   AddDataSeries(Data.BarsPeriodType.Minute, 60);
              }
              else if (State == State.DataLoaded)
              {
              }
         }
    
         protected override void OnBarUpdate()
         {
              if (SMA1 == null || EMA1 == null || RSI1 == null || ADX1 == null)
              {
                   SMA1 = SMA(BarsArray[1],5); // Compiles just fine
                   EMA1 = EMA(BarsArray[1],50); // Compiles just fine
                   RSI1 = RSI(BarsArray[1],20); // WILL NOT COMPILE
                   ADX1 = ADX(BarsArray[1],14); // Compiles just fine
              }
         }
    }
    If I comment out the RSI line in OnBarUpdate everything compiles just fine, but if I leave it in as written, I get a couple of errors:

    "The best overloaded method match for 'NinjaTrader.NinjaScript.Strategies.Strategy.RSI(i nt,int)' has some invalid arguments"
    "Argument 1: cannot convert from 'NinjaTrader.Data.Bars' to 'int'"

    Any ideas?
    Thanks,
    Chris

    #2
    Hello Chris,
    RSI needs 2 parameters wherein you've given only 1, use RSI as below:-

    Code:
    RSI1 = RSI(BarsArray[1],20, 3);
    Here 3 is the RSI Average Period which is required, you can give input as you wish.
    Hope it helps!

    Comment


      #3
      Okay, rats...I was afraid I'd forget something when I simplified the code in testing, and I did. I originally DID have the smoothing parameter, and I was using a variable for the the RSI period. I.E.,

      Code:
      RSI1 = RSI(Close, Convert.ToInt32(RSIperiod), 3);
      Which worked. When I implemented the added Data Series, I put the extra parentheses bracket where I thought it should go, after the smoothing variable.

      Code:
      RSI1 = RSI(BarsArray[1],(Convert.ToInt32(RSIperiod), 3));
      Which does NOT work. However, then I simplified, thought the smoothing parameter was optional, and shot myself in the foot. But thank you s.kinra for making me look at it again, as when I put the extra parentheses where I did NOT think it should go (and had never tried), it worked, so now I'm good. And for anybody else who may run into this, here's what works:

      Code:
      RSI1 = RSI(BarsArray[1],(Convert.ToInt32(RSIperiod)), 3);
      Thanks again,
      Chris


      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by vrewoises, Today, 04:31 AM
      0 responses
      4 views
      0 likes
      Last Post vrewoises  
      Started by butt_toast, Yesterday, 09:47 PM
      1 response
      6 views
      0 likes
      Last Post Leeroy_Jenkins  
      Started by vrewoises, Today, 03:33 AM
      0 responses
      5 views
      0 likes
      Last Post vrewoises  
      Started by devonburto, Today, 03:11 AM
      0 responses
      2 views
      0 likes
      Last Post devonburto  
      Started by ziemany, Today, 02:54 AM
      0 responses
      2 views
      0 likes
      Last Post ziemany
      by ziemany
       
      Working...
      X