Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Instrument.MasterInstrument.Name

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

    Instrument.MasterInstrument.Name

    I often use instructions like
    if (Instrument.MasterInstrument.Name = ".....")
    or
    if (Instrument.FullName = ".....")
    in order to identify specific instruments.
    There is no problem with stocks or currency pairs, while how may I avoid to necessarily change my codes every month when using futures, whose symbol is (for istance) "ES 03-15" ?

    #2
    Hello Mauripasto,

    Thank you for your post.

    There are a couple different ways to do this however I believe the setup I have provided below will meet your needs here
    Code:
    string instrumentName = Instrument.FullName.Substring(0, Instrument.MasterInstrument.Name.Length + 1);
    string fullInstrument = string.Concat(instrumentName, ContractMonth);
    
    if(Instrument.FullName == fullInstrument)
    	Print("HIT");
    We are getting the ES naming convention string and adding an additional space which will serve for between ES and the Contract Month

    We then use string.Concat() to combine the two strings, ContractMonth being a public string that can be set from the properties of the indicator

    I then added the if statement to test the string name and printed Hit to confirm that it was working as expected.


    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Perfect. Thank you

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      81 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      41 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      66 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X