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 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 bortz, 11-06-2023, 08:04 AM
      47 responses
      1,603 views
      0 likes
      Last Post aligator  
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      8 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      4 views
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      12 views
      0 likes
      Last Post Javierw.ok  
      Working...
      X