• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 ralett, Today, 06:20 PM
    0 responses
    4 views
    0 likes
    Last Post ralett
    by ralett
     
    Started by grizzlytrader, Today, 06:24 AM
    1 response
    20 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by andrewtrades, Today, 01:43 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by FuturesRon, Today, 03:09 AM
    1 response
    18 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Ivantr, Today, 05:24 PM
    0 responses
    7 views
    0 likes
    Last Post Ivantr
    by Ivantr
     
    Working...
    X