Announcement

Collapse
No announcement yet.

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.

    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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      160 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      307 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      244 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      348 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      178 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X