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

GetCurrentBID and GetCurrentASK gives wrong data

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

    GetCurrentBID and GetCurrentASK gives wrong data

    Hi!

    It's strange cause when I open a chart with ZN and ZB instruments I can see the right price displayed on the right right axis, but when I develop an indicator trying to obtain the close, bid or ask data from these instruments it's different that one displayed for each instrument.

    I've put some displays and i get wrong values, all variables were defined as double:

    Close[0]: 120,3125
    Inputs[0][0]: 120,3125
    Inputs[1][0]: 120,171875
    Bid(0): 120,3125
    Ask(1): 120,1875

    Please, see the attached chart, at bottom there's the values of the spread indicator, with last, bid and ask prices of the spread, with other instruments like YC and YW the values shown by the indicator are right.

    Which could be the problem?

    Thank you
    Attached Files

    #2
    Hello JoanNT,

    There are a couple items here that may explain what you are seeing.

    GetCurrentAsk() and GetCurrentBid() are real time values. When called historically they will use close prices rather than historical bid / ask.

    To get the most accuracy for bid/ ask data, you must work in OnMarketData() method. If you are accessing from OBU, it is only updated when there has been a trade. This can be less frequent than changes in level I data, like OnMarketData is used for.

    Viewing changes in bid / ask data aligned with a bar through charting is challenging because of this. You're comparing two different thing as bid / ask can be updated much more often than trades.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks RyanM

      but I'm working with real data and not historical one, I've just copied the example method

      protected override void OnMarketData(MarketDataEventArgs e)
      {
      // Print some data to the Output window
      if (e.MarketDataType == MarketDataType.Last)
      Print("Last = " + e.Price + " " + e.Volume);

      else if (e.MarketDataType == MarketDataType.Ask)
      Print("Ask = " + e.Price + " " + e.Volume);
      else if (e.MarketDataType == MarketDataType.Bid)
      Print("Bid = " + e.Price + " " + e.Volume);
      }

      and I got this results:
      Bid = 120,40625 918
      Ask = 120,421875 629
      Last = 120,421875 20
      Close[0]: 120,421875
      Inputs[0][0]: 120,71875
      Inputs[1][0]: 120,421875
      Bid(0): 120,71875
      Ask(1): 120,421875

      both prices for Ask are the same and both are wrong, I've tried the same with other instruments and this don't happens

      Comment


        #4
        How are you determining they're wrong? Who is your data provider?
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I work with IB, simply looking to their IB ask and bid data, the ones i get from NT are far from ones i get from IB

          Comment


            #6
            It's working OK here. I'm getting the same values in TWS for ZN.

            I would make sure you're looking at the same instrument / exchange within both applications.

            Are you aware of the different formatting between Ninja's output and TWS?

            Ninja - Decimal
            TWS - Tick
            Attached Files
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              I don't see the same values in your attached image, this could be "the different formatting between Ninja's output and TWS", what do you mean?

              is there any thread or document about this?

              thanks!

              Comment


                #8
                You'll want to check contract specifications for more info on price formatting.


                Points ($1,000) and halves of 1/32 of a point. For example, 126-16 represents 126 16/32 and 126-165 represents 126 16.5/32. Par is on the basis of 100 points.

                ZN 120^170 = 120.53125
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Ryan Thank you very much, I didn't know about that.

                  Have a nice day

                  Comment


                    #10
                    My pleasure, Joan. Glad we were able to get it sorted.
                    Ryan M.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by aa731, Today, 02:54 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by BarzTrading, Today, 07:25 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post BarzTrading  
                    Started by i019945nj, 12-14-2023, 06:41 AM
                    5 responses
                    65 views
                    0 likes
                    Last Post i019945nj  
                    Started by ruudawakening, Today, 12:58 AM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by thread, Yesterday, 11:58 PM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Working...
                    X