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

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:



    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 Barry Milan, Yesterday, 10:35 PM
            5 responses
            16 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by DanielSanMartin, Yesterday, 02:37 PM
            2 responses
            13 views
            0 likes
            Last Post DanielSanMartin  
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            11 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            8 views
            0 likes
            Last Post nandhumca  
            Working...
            X