Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set indicator in OnStartUp using the MasterInstrument.Name

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

    Set indicator in OnStartUp using the MasterInstrument.Name

    Hi,

    I would like to know how I can point to a different indicator based on the instrument in OnStartUp.

    Because I need to point to different indicators based on the instrument which all share the same name except ending in the MasterInstrument.Name it would be easier to have one script that allows for each instrument instead of creating one for each instrument.

    For example instead of using the indicator like so from within the code.
    Code:
    this.IndicatorES().Value
    I would like to be able to set the MasterInstrument.Name in OnStartUp. Then within the code I can use a generic name instead. If anyone could provide an example as to how I could achieve this it would be much appreciated.

    I guess the question is how do I combine the this.Indicator+Instrument.MasterInstrument.Name+() .Value in OnStartUp and then refer to it within the code later?

    Hopefully this is clear.
    Regards,
    suprsnipes

    #2
    Hello suprsnipes,

    You can use a switch or if statement checking the Instrument.MasterInstrument.Name or Instrument.FullName.
    http://ninjatrader.com/support/helpG...instrument.htm

    Code:
    int Period = 14;
    double indicatorValue = 0;
    
    switch (Instrument.MasterInstrument.Name)
    {
    case "ES":
    indicatorValue = EMA(Period)[0]);
    break;
    
    case "NQ":
    indicatorValue = SMA(Period)[0]);
    break;
    }
    
    Print(indicatorValue);
    Below is a link to the Moving Average Cross Builder indicator which would provide a good example of how something like this could be created.


    You can also save the Instrument.MasterInstrument name to a string and modify this however you would like.

    Code:
    string myInstrumentName = string.Format("{0} {1} {2}", Instrument.MasterInstrument.Name, BarsPeriod.Value, BarsPeriod.Id);
    Last edited by NinjaTrader_ChelseaB; 07-11-2016, 07:29 AM.
    Chelsea B.NinjaTrader Customer Service

    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
    333 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