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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      574 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      332 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      553 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X