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

Call different indicator based on instrument

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

    Call different indicator based on instrument

    Hi,

    Is it possible to call a different indicator based on the Instrument.MasterInstrument.Name?

    For example if Instrument is ES then use this.PFRES().Last or if
    Instrument is TF then use this.PFRTF().Last etc.

    Is there a way that this can be done?

    I need to just do this once as I would be calling this specific indicator more then a few times across many lines of code?

    Appreciate the help.
    suprsnipes

    #2
    Hello,

    Thank you for the question.

    Instrument.MasterInstrument.Name is a string so you could do an if statement or a switch case statement to call an indicator based on the instrument.

    A simple statement like the following could be used:

    Code:
    double value = 0;
    if(Instrument.MasterInstrument.Name == "ES")
    {
    value = SMA(12)[0];
    } else if(Instrument.MasterInstrument.Name == "NQ")
    {
    value = EMA(12)[0];
    }
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Originally posted by suprsnipes View Post
      Hi,

      Is it possible to call a different indicator based on the Instrument.MasterInstrument.Name?

      For example if Instrument is ES then use this.PFRES().Last or if
      Instrument is TF then use this.PFRTF().Last etc.

      Is there a way that this can be done?

      I need to just do this once as I would be calling this specific indicator more then a few times across many lines of code?

      Appreciate the help.
      suprsnipes
      Code:
      //declare the indicators as class objects of the relevant type
      private RSI theRSI;
      private SMA theSMA;
      private int Period = 21;
      Code:
      //Assign them in OnStartUp(), based on conditions
      if(Instrument.MasterInstrument.Name == "ES")
      {
      theRSI= RSI(Period, 1);
      } 
      else if(Instrument.MasterInstrument.Name == "NQ")
      {
      theSMA = SMA(Close, Period);
      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,221 views
      0 likes
      Last Post xiinteractive  
      Started by andrewtrades, Today, 04:57 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      7 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      438 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      9 views
      0 likes
      Last Post FAQtrader  
      Working...
      X