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 helpwanted, Today, 03:06 AM
      1 response
      7 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      7 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      5 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      242 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      384 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X