• 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

MarketData.Opening always null

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

    MarketData.Opening always null

    Hello,

    I am trying to fetch snapshot data from an instrument which I create in code by invoking:

    SPXInstrument = NinjaTrader.Cbi.Instrument.GetInstrument("^SP500") ;

    I then am able to use the instrument, albeit the MarketData does only refresh if I add it to e,g. a Market Analyzer (until then all Market Data is null.)

    Once the instrument starts getting its Market Data refreshed, I am able to access most pricepoints in the Market Data object, but MarketData.Opening is always null. I am attaching a screenshot.

    Could you please help me understand how:

    1) I can refresh the MarketData object without using a workaround such as the Market Analyzer
    2) how do I get the opening price of the day from the MarketData Object?

    Many thanks,


    Libor
    Attached Files

    #2
    Hello,

    Thank you for the post.

    I wanted to check, are you actually subscribing to the market data or just calling GetInstrument? GetInstrument is simply used to look up an instrument definition but does not subscribe to data or do anything else data related. This would be useful to get an instance to an Instrument object when one is needed for a method.

    If you are not subscribing, then I would not expect the data to be available. Also, I would generally not suggest using the instrument object directly but instead use the MarketData object.

    We have a sample of accessing market data from an addon here:

    http://ninjatrader.com/support/helpG...ghtsub=opening

    You could use the Instrument you have from the GetInsturment method to supply to the MarketData constructor which subscribes the add-on to its data.

    The values could then be saved as they come in or retrieved from the marketData variable.

    Code:
    Print(marketData.Opening.Price);
    Please keep in mind subscribing is event driven you would not be able to request the data until it is sent from the provider in that case.

    Code:
    double opening; 
    private void OnMarketData(object sender, MarketDataEventArgs e)
    {
    	if(e.MarketDataType == MarketDataType.Opening)
    	    opening = e.Price;
    }
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      thank you for your swift response. I forgot to mention I am using the Addon Framework code as basis for my addon, and hence the instrument does get its attached MarketData object subscribed to automatically at the creation of the Instrument object.

      Nonetheless, I did change my code to subscribe to OnMarketData via a dedicated MarketData object, but the result is exactly the same as you see in the screenshot I posted initially: the Opening value is null, while most of the other price points do get populated.

      Any ideas what could be wrong?

      Many thanks,

      Libor

      Comment


        #4
        Hello,

        Are you able to retrieve values using the help guide example or the following:

        Code:
        if(State == State.Realtime)
        if(!doOnce)
        {
        	marketData = new MarketData(Instrument.GetInstrument("ES 12-17"));
        	Print(marketData.Opening.Price);
        	doOnce = true;
        }
        Also, does your data provider offer these values for the instrument you are using? Some providers do not offer this level of information which would be another reason why the value may be null.

        I just tried the above and see that I am able to retrieve the values when I correctly subscribe and use Kinetick.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hello,

          I use the Interactive Brokers data service.

          Many of the other price points are there (Ask, Bid, DailyHigh, DailyLow, Last, LastClose), but Opening is null. I hence cannot print Opening.Price...

          Have you seen this behaviour before?

          Thanks,

          LIbor

          Comment


            #6
            Hello,

            Thank you for the reply.

            In the case that your data provider does not offer this value, it would be null. I can see that this is populated using Kinetick, if you are seeing null otherwise this is likely that your provider does not provide this value.

            Can you tell me, do you see this value in TWS being populated (if possible)?

            To confirm if you should be able to see this value, you would need to inquire with the broker to see if this value is included with the data you have subscribed to. In the case you can see this value updating in TWS but not in NinjaTrader, I would like to further explore that situation.

            please let me know if I may be of further assistance.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NinjaCustomer, Today, 10:06 AM
            3 responses
            6 views
            0 likes
            Last Post NinjaTrader_JoshG  
            Started by crabman777, Today, 09:52 AM
            3 responses
            12 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by Arkadiy_B, Today, 06:43 AM
            0 responses
            4 views
            0 likes
            Last Post Arkadiy_B  
            Started by leontancfa, Today, 06:09 AM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_PatrickG  
            Started by soulfx, 12-01-2017, 08:44 AM
            3 responses
            1,023 views
            0 likes
            Last Post NinjaTrader_EricB  
            Working...
            X