Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using historical data with tick replay

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

    Using historical data with tick replay

    I'm trying to replicate the example provided in NT8 docs: Educational Resources: Developing for Tick Replay: Accessing the current best bid and ask at the time of a trade. I am getting correct results for real time data, but very wrong results for historical data. I do not believe this is a problem with the historical data itself (Continuum/CQG) because I have a similar third party indicator running on the same chart and it appears to be working properly. Tick replay is enabled, of course, as is Calculate.OnEachTick. Here is the pertinent snippet of code:

    protected override void OnMarketData(MarketDataEventArgs data)
    {
    if (data.MarketDataType == MarketDataType.Last)
    {
    if (data.Last >= data.Ask)
    {
    buys += data.Volume;
    if (State == State.Historical)
    Print(string.Format("buys {0} {1} {2}", data.Last, data.Bid, data.Ask));
    }
    if (data.Last <= data.Bid)
    {
    sells += data.Volume;
    if (State == State.Historical)
    Print(string.Format("sells {0} {1} {2}", data.Last, data.Bid, data.Ask));
    }
    }
    }

    The problem appears to be with data.Last. The data.Bid and data.Ask values appear to be appropriate, but data.Last sticks on values outside the bid/ask range for large periods of time. Here is an example from the print output:

    sells 4576.5 4578.75 4579
    sells 4576.5 4578.5 4578.75
    sells 4576.5 4578.5 4578.75
    sells 4576.5 4578.5 4578.75
    sells 4576.5 4578.75 4579
    sells 4576.5 4578.75 4579
    sells 4576.5 4578.75 4579
    sells 4576.5 4578.75 4579
    sells 4576.5 4578.75 4579

    Any ideas or suggestions would be greatly appreciated.

    #2
    Hi jvanelli, thanks for posting.

    One application of this concept is implemented in the BuySellVolume indicator. You may review the source code for this indicator and make the same comparison with that script. It can be found under NinjaScript Editor>Indicators list. If you see the same issue please let me know.

    Best regards,
    -ChrisL

    Comment


      #3
      Thanks Chris. This was, as usual, pilot error. For reference, historical tick replay does not understand data.Last in same context as real time processing. Need to use data.Price as opposed to data.Last for the historical tick replay.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      580 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      336 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X