Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Received wrong best Bid and Ask price in historical data

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

    Received wrong best Bid and Ask price in historical data

    Hi I am using orderflow indicator. I face some issues regards bid and ask price data. Once market opens, new data comes without any problem. My chart looks perfect. Once try to change time frame or reload historical data, ask volume becomes 0. I used to debug the bid and ask data in live market as well historical , It shows different result.

    Example :

    Recorded in live :

    Bid price - 43220.2, Price - 43270, Ask price - 43270, Time - 05/10/23 9:15:01 AM
    Bid price - 43232.3, Price - 43232.3, Ask price - 43250, Time - 05/10/23 9:15:02 AM
    Bid price - 43236.35, Price - 43236.35, Ask price - 43262.25, Time - 05/10/23 9:15:04 AM
    Bid price - 43250.15, Price - 43273, Ask price - 43273, Time - 05/10/23 9:15:05 AM
    Bid price - 43271.9, Price - 43287.25, Ask price - 43287.25, Time - 05/10/23 9:15:07 AM
    Bid price - 43265.15, Price - 43265.15, Ask price - 43285.75, Time - 05/10/23 9:15:09 AM
    Bid price - 43267.75, Price - 43271, Ask price - 43277.75, Time - 05/10/23 9:15:10 AM
    Bid price - 43268.35, Price - 43269.95, Ask price - 43277.05, Time - 05/10/23 9:15:12 AM
    Bid price - 43264, Price - 43265.15, Ask price - 43269.95, Time - 05/10/23 9:15:13 AM
    Bid price - 43256.95, Price - 43264.9, Ask price - 43268.2, Time - 05/10/23 9:15:15 AM
    Bid price - 43252.45, Price - 43264.6, Ask price - 43264.6, Time - 05/10/23 9:15:16 AM

    Recorded in Historical :​

    Bid price - 43270, Price - 43270, Ask price - 43270.05, Time - 05/10/23 9:15:01 AM
    Bid price - 43232.3, Price - 43232.3, Ask price - 43232.35, Time - 05/10/23 9:15:02 AM
    Bid price - 43236.35, Price - 43236.35, Ask price - 43236.4, Time - 05/10/23 9:15:04 AM
    Bid price - 43273, Price - 43273, Ask price - 43273.05, Time - 05/10/23 9:15:05 AM
    Bid price - 43287.25, Price - 43287.25, Ask price - 43287.3, Time - 05/10/23 9:15:07 AM
    Bid price - 43265.15, Price - 43265.15, Ask price - 43265.2, Time - 05/10/23 9:15:09 AM
    Bid price - 43271, Price - 43271, Ask price - 43271.05, Time - 05/10/23 9:15:10 AM
    Bid price - 43269.95, Price - 43269.95, Ask price - 43270, Time - 05/10/23 9:15:12 AM
    Bid price - 43265.15, Price - 43265.15, Ask price - 43265.2, Time - 05/10/23 9:15:13 AM
    Bid price - 43264.9, Price - 43264.9, Ask price - 43264.95, Time - 05/10/23 9:15:15 AM
    Bid price - 43264.6, Price - 43264.6, Ask price - 43264.65, Time - 05/10/23 9:15:16 AM​

    And also i checked my incoming data, I receive bid and ask price via Market data method in Ninja script.
    And I enable tick reply as well.
    And also enable "Record live data as historical " in Tools->Options -> Market data I am using ninja trader 8.0.27.1 64-bit Version.

    Kindly help me to resolve this issue, Thank you.
    Attached Files

    #2
    Hello Code Breaker,

    Thanks for your post.

    I see that you are using an old version of NinjaTrader. Please update NinjaTrader to either 8.0.28.0 or 8.1.1.5 by following the steps below.

    Updates to NinjaTrader will contain the latest security updates and bug fixes, as well as occasional new features and instruments.

    To update NinjaTrader
    • Shutdown all programs including NinjaTrader *important
    • Download NinjaTrader from the link below
    • Double click the downloaded file to execute it
    • Follow the on screen instructions
    • Restart NinjaTrader
    You can read about changes to this release in the release notes linked below.
    https://ninjatrader.com/support/help...ease_notes.htm

    That said, I am not able to reproduce the behavior on my end when testing this on the most recent release of NinjaTrader Desktop (8.1.1.5). First, I opened a 1-Minute Volumetric chart for the ES 06-23 instrument while connected to a live data feed connection and took a screenshot of the values on the chart.

    Then, I downloaded the Market Replay data for today's date and connected to the Playback connection. I compared the screenshot of the live chart to the Market Replay/Playback chart and see the values do match.

    I disconnected from the Playback connection and reconnected to a live data feed connection. The OF Volumetric Bars Ask volume and Bid volume are displayed on the chart. I right-clicked on the chart, selected 'Reload all historical data' and the Volumetric Bars Ask and Bid values remained on the chart. The Ask volume did not change to 0 for historical data.

    Next, I changed the interval to a 30-second Volumetric chart and saw the Volumetric Bars Ask and Bid values showed as expected. The Ask volume was not changed to 0 for historical data.

    Finally, I reloaded all historical data again and the Ask and Bid values were unchanged.

    See this demonstration video: https://brandonh-ninjatrader.tinytak...NF8yMTQyNTk5Mg

    After upgrading to either 8.0.28.0 or 8.1.1.5, retest to see if you are able to reproduce the behavior. If you are able to reproduce the behavior on one of these versions of NinjaTrader Desktop, please send me the exact steps and settings you used to reproduce the behavior so that I may try to reproduce it on my end using the same exact steps and settings.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hello BrandonH,

      Thanks for your reply,

      I am not using OF Volumetric indicator. I try to develop own indicator for myself.

      I update the new version of ninja Trader even though i got same issues to get wrong bid and ask price in historical data..

      Sorry to mention 0. I show in the format of 0 volume if current tick price not match with Ask price.
      Once try to change time frame or reload historical data, ask volume becomes 0
      And also i spoke with my data provider, he said bid and ask data only send in live market not in historical data.

      I tested with another orderflow software ( MarketBalance ), it works fine using same data . So my code is wrong, Please guide me to get bid and ask volume to find delta in each tick and also guide me if i misunderstand any of the concepts

      My code to store time and price based bid and ask volume:

      This code written inside OnMarketData

      Code:
      if (Bars.IsTickReplay)
      {​
      double price = marketDataEventArgs.Price;
      double askPrice = marketDataEventArgs.Ask;
      double bidPrice = marketDataEventArgs.Bid;
      long volume = marketDataEventArgs.Volume;
      ​
      var queryModel = orderFlowMinuteBarsTypeTickData.
      Where(x =&gt; x.SesssionStartDate == sessionDetails.SessionStartDate &amp;&amp; x.Price == price);
      
      if (queryModel.Count() &lt;= 0)
      {
      double askVolume = 0;
      double bidVolume = 0;
      
      if (price &gt;= askPrice)
      {
      askVolume = volume;
      }
      else if (price &lt;= bidPrice)
      {
      bidVolume = volume;
      }
      orderFlowMinuteBarsTypeTickData.Add(new OrderFlowMinuteBarsTypeTickDataListModel(sessionDe tails.SessionStartDate, DateTimeHelperFP.GetOnlyDate(sessionDetails.Sessio nStartDate), volume, bidVolume, askVolume, price));
      }
      else
      {
      
      var model = queryModel.FirstOrDefault();
      
      if (price &gt;= askPrice)
      {
      model.AskVolume += volume;
      }
      else if (price &lt;= bidPrice)
      {
      model.BidVolume += volume;
      }
      model.Volume += volume;
      
      }​
      }
      I have some queries also,

      1. Where ninja trader store best bid and ask price.
      2. When i reload all data i got difference in Bid and Ask price.

      Example see this record

      During Live Feed :
      Bid price - 43252.45, Price - 43264.6, Ask price - 43264.6, Time - 05/10/23 9:15:16 AM

      After Reload All Historical Data :
      Bid price - 43264.6, Price - 43264.6, Ask price - 43264.65, Time - 05/10/23 9:15:16 AM

      In above ask price move to bid price. How it's happen.
      I back tracked historical tick data, Each price match with only bid price,

      #Mentioned in first post
      ​​​​​​​
      Bid price - 43270, Price - 43270, Ask price - 43270.05, Time - 05/10/23 9:15:01 AM
      Bid price - 43232.3, Price - 43232.3, Ask price - 43232.35, Time - 05/10/23 9:15:02 AM
      Bid price - 43236.35, Price - 43236.35, Ask price - 43236.4, Time - 05/10/23 9:15:04 AM
      Bid price - 43273, Price - 43273, Ask price - 43273.05, Time - 05/10/23 9:15:05 AM
      Bid price - 43287.25, Price - 43287.25, Ask price - 43287.3, Time - 05/10/23 9:15:07 AM
      Bid price - 43265.15, Price - 43265.15, Ask price - 43265.2, Time - 05/10/23 9:15:09 AM


      Kindly help me to resolve this issue, Thank you.

      Comment


        #4
        In your OnMarketData are you checking that these are trade ticks and not just bid/ask updates? Try adding this line at the top of OnMarketData:
        Code:
        if (marketDataEventArgs.MarketDataType != MarketDataType.Last) return;
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Thanks for your reply,

          Yes i already added this condition. Kindly correct any mistake i done in my code.

          Comment


            #6
            What market data connection are you using? Is this the NinjaTrader connection type with multi-provider turned on, or off? Or, is it CQG/Continuum for NinjaTrader? Or, is it Kinetick/IQFeed? Or, is it interactive brokers? Or, is it Rithmic?

            The symptoms you are describing make it seem as if when the chart is reloaded bid/ask are not available so it is assigning all the trades to the bid price.

            You may want to try the example code at Developing for Tick Replay https://ninjatrader.com/support/help...ick_replay.htm to see if you still have this problem with the example code and then work from there back towards what you have here. If you still have the problem with the example code, that narrows it down to a platform bug or the data feed.
            Bruce DeVault
            QuantKey Trading Vendor Services
            NinjaTrader Ecosystem Vendor - QuantKey

            Comment


              #7
              Hello Code Breaker,

              The code you have posted in post # 3 does not check the marketDataType is .Last and then compare to the ask and bid as demonstrated in the help guide.

              From the help guide:


              Code:
              protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
              {
              // TickReplay events only occur on the "Last" market data type
              if (marketDataUpdate.MarketDataType == MarketDataType.Last)
              {
              if (marketDataUpdate.Price >= marketDataUpdate.Ask)
              {
              Print(marketDataUpdate.Volume + " contracts traded at asking price " + marketDataUpdate.Ask);
              }
              
              else if (marketDataUpdate.Price <= marketDataUpdate.Bid)
              {
              Print(marketDataUpdate.Volume + " Contracts Traded at bidding price " + marketDataUpdate.Bid);
              }
              }
              }
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              639 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              366 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              107 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              569 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              572 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X