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

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 MarianApalaghiei, Today, 10:49 PM
    2 responses
    8 views
    0 likes
    Last Post MarianApalaghiei  
    Started by love2code2trade, Yesterday, 01:45 PM
    4 responses
    28 views
    0 likes
    Last Post love2code2trade  
    Started by funk10101, Today, 09:43 PM
    0 responses
    8 views
    0 likes
    Last Post funk10101  
    Started by pkefal, 04-11-2024, 07:39 AM
    11 responses
    37 views
    0 likes
    Last Post jeronymite  
    Started by bill2023, Yesterday, 08:51 AM
    8 responses
    46 views
    0 likes
    Last Post bill2023  
    Working...
    X