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


correct processing of historical and real-time L1 tick data

  • Filter
  • Time
  • Show
Clear All
new posts

    correct processing of historical and real-time L1 tick data


    I want to make sure I understand the correct processing of historical & real-time Level 1 tick data (Datetime, Price, Volume, Bid/Ask Prices at time of trade).

    The main use cases I'm interested in:

    a. Historical back-fill of charts, indicators and SuperDOM columns for trading setups

    b. Real-time updating of charts, indicators and SuperDOM columns while trading

    c. Accessing more data than is currently displayed within either a chart range or the DOM price ladder

    d. Using Tick Replay

    As far as I understand, there are 3 approaches:

    1. A multi-series approach:

    - using AddDataSeries(xxx,BarsPeriodType.Tick) within OnStateChange() and State == State.Configure

    - using GetClose(), GetVolume(), GetBid() and GetAsk() in OnBarUpdate() with Calculate == Calculate.OnEachTick in State == State.SetDefaults

    - there could be is a synchronising problem with backfill as historical data is stored as separate data series for Last/Bid/Ask

    - this synchronisation problem maybe overcome if historical L1 tick data is available/loaded from your data provider

    - dependent on how much historical L1 tick has either been downloaded or is available from your data provider

    2. Tick Replay approach (uses Market Replay data)

    - with the Tick Replay option set, accessing Last,Volume, Bid/Ask Price data within OnMarketData() for MarketDataType.Last​MarketDataType.Last

    - there is no synchronisation problem with this approach

    - this approach handles be more CPU intensive as higher-level bars would also be build from tick data

    - dependent on how much Market Replay has been downloaded

    3. Using BarsRequest

    - creating a BarsRequest for a desired start/end datetime and a BarsPeriodType.Tick

    - using OnBarUpdate() and BarsUpdateEventArgs to process real-time updates

    - using OnRender() to display data (in either a chart or a SuperDOM column)

    - dependent on how much historical L1 tick has either been downloaded or is available from your data provider

    My questions:

    1. Is my understanding in general correct? Or have I missed something?

    2. If historical L1 tick data is available from your data provider (I'm using Continuum), will the L1 tick data always be provided & processed correctly ie synchronised ?

    3. Are there any further requirements to make sure this works correctly - eg within the various OnStateChange() states?

    4. When using BarsRequest, where should you perform an initial load of data ? I'm thinking State.Configure...

    Many thanks.

    Hello pmbi00,

    Thanks for your post.

    It seems that most of your general understanding is correct.

    That said, Tick Replay is an option that allows you to ensure that the market data (bid/ask/last) that went into building a bar is loaded in the exact sequence of market data events. It is not dependent on the Market Replay data you have downloaded.

    Please see the forum post from my colleague Manfred linked below detailing the differences between Market Replay data, Historical Data, and the Tick Replay option to fully understand each of these.

    This help guide page details the use of AddDataSeries() to add additional bars objects to a script:

    See the help guide documentation below for more information about Tick Replay and developing scripts for Tick Repaly.

    TickReplay —
    Developing for Tick Replay -

    You could view this forum thread for more information about using BarsRequest in a custom NinjaScript:

    And, see this help guide page about BarsRequest:

    Let me know if I may assist further.
    Brandon H.NinjaTrader Customer Service



      Thank you for your reply.

      Actually, I understand that Tick Replay throws either downloaded market replay data or historical data from your data provider in the same way as real-time ticks are received - consequently OnMarketData() and OnBarUpdate() events are in effect in sync.

      This means you can use either OnMarketData() or AddDataSeries(BarsPeriodType.Tick, 1) to process L1 tick data - but, if using AddDataSeries(), you need to provide additional code/logic in OnBarUpdate() to handle the differences between real-time / historical processing and Calculate.OnBarClose / OnEachTick.

      I found this link to your BuySellVolumeOneTick example which I'm working through to develop a script that can handle Tick Replay, real-time or historical data:

      I think I'm on track now, right?

      Many thanks


        Hello pmbi00,

        Thanks for your note.

        The BuySellVolumeOneTick reference sample would use the 1-Tick data series to calculate logic and it is not recommended to use the script with TickReplay.

        Tick Replay shouldn't alter the result for a time-based historical bar. We are aware there are discrepancies between the OneTick approach and tick-based historical bars, but time-based bars should be consistent when compared to the default BuySellVolume indicator.

        Please let me know if I may assist further.
        Brandon H.NinjaTrader Customer Service



          Ok, if we exclude TickReplay, what is the recommended way to process real-time and historical L1 tick data ? Is there a best practice sample script to do this?

          Many thanks.


            Hello pmbi00,

            Thanks for your note.

            After further reviewing the version of BuySellVolumeOneTick that you linked in post # 3, I see that the script is already programmed to support Tick Replay so this script may be used with Tick Replay enabled.

            Note that this script will calculate historical and real-time tick data by default and does not require Tick Replay to be enabled since it calculates from a one-tick series. This could be seen by enabling the script onto a chart and testing this script with Tick Replay disabled. Then you could enable Tick Replay and view the indicator on a chart to see that the historical and real-time values are the same.

            Let me know if I may assist further.

            Brandon H.NinjaTrader Customer Service



              Thank you for your note and clarification.

              I have this sample script working now for real-time, historical and Tick Replay data. :-)

              Though I will probably have a few questions about the logic shortly...

              Many thanks.


              Latest Posts


              Topics Statistics Last Post
              Started by Stevenastleberry, Today, 01:13 AM
              0 responses
              Last Post Stevenastleberry  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              95 responses
              Last Post sidlercom80  
              Started by kevinenergy, 02-17-2023, 12:42 PM
              48 responses
              1 like
              Last Post TradeSaber  
              Started by FatCanary, 06-11-2021, 09:11 AM
              17 responses
              Last Post Laurentvan  
              Started by csrkkalyan, 11-18-2023, 08:38 PM
              4 responses
              Last Post csrkkalyan