Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Instrument.MasterInstrument.Name in Initialize()

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

    Instrument.MasterInstrument.Name in Initialize()

    Howdy--

    I am attempting to test the following if statement within Initialize():

    string name;

    if(Instrument.MasterInstrument.Name == "GC")
    name = "GC";

    However, I cannot get this if statement to evaluate. By creating the string name variable and leaving it undefined, I'm getting a compiler error saying that name is not defined (i.e., the if statement isn't true, so name remains undefined).

    So I then change the if statement to:

    if(Instrument.MasterInstrument.Name != "GC")
    name = "GC";

    However name still remains undefined (i.e., the if statement is still not being properly evaluated).

    In the NT notes on Instrument.MasterInstrument.Name, I see that it says something about OnBarUpdate():

    This property can be accessed without a null reference check in the OnBarUpdate() event handler. When the OnBarUpdate() event is triggered, there will always be an Instrument object. Should you wish to access this property elsewhere, check for null reference first. e.g. if (Instrument != null)

    Does that somehow mean that my issue is caused because I am trying to test I.MI.Name within Initialize()?

    Do you have any thoughts on how I can successfully test for the instrument name?

    I'm using this within a WebRequest url pull. I am able to successfully use I.MI.Name in the url string--so I know that the I.MI.Name call works...but I'm having the above problem when testing if I.MI.Name equals something to assign a generic name variable for the url string.

    I'm having to use the string variable name instead of the I.MI.Name in the url path, as the WebRequest destination uses different names than NT for instruments. For instance, GC and ES are GC and ES (so they work fine), but 6E, ZW, 6A, etc use different names for the url pulls...so I am needing to test I.MI.Name to pass the correct url path to the WebRequest. So in the case of the 6C, I need to pass "CD" instead of "6C", which begets the above I.MI.Name test...in the case of I.MI.Name == 6C, I would then assign name = "CD" and then make the WebRequest.

    Hopefully that backstory helps.

    Thanks,

    Aventeren
    Last edited by aventeren; 09-05-2014, 09:02 AM.

    #2
    Nevermind...I just figured out that I needed to defined

    string name = "";

    This allowed the if statement to evaluate successfully.

    Move along, nothing to see here.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    173 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    90 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    129 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    208 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    186 views
    0 likes
    Last Post CarlTrading  
    Working...
    X