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 sjsj2732, 03-23-2026, 04:31 AM
    0 responses
    78 views
    0 likes
    Last Post sjsj2732  
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    313 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    315 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    149 views
    1 like
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    115 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Working...
    X