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

Tick Replay, Order fill Resolution = High, and intrabar granular fill

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

    Tick Replay, Order fill Resolution = High, and intrabar granular fill

    I have a working on a strategy which utilizes intrabar granular fill (based on https://ninjatrader.com/support/foru...ularity?t=6652) and now I am at point where I want to compare the backtesting results (order fill resolution using Historical data) with either:
    • Live NinjaTrader Continuum (connecting to Phillip Capital clearing firm) connection using RealTime data or
    • Playback connection using Market Replay data (a special RealTime data form which allows to control the speed in which the RealTime data is processed)
    At multiple places in the NinjaTrader 8 Help Guide, it is mentioned that there will always be a difference between historical order fill resolution and RealTime order fill resolution. The help guide also clarifies that even within the RealTime order fill resolution, there is a difference in the results based on the account associated to the Live connection. If using a simulation account, the NinjaTrader trade simulation engine will be used. If using a Live Trading account, on the order is submitted to the exchange, the filled will be in accordance to market dynamics. (Source: https://ninjatrader.com/support/help...ime_vs_bac.htm)

    When trying to compare the results between orders filled with RealTime data and Historical data, there is nothing I can due to alter the behavior of order filled with RealTime data. If trading with a Live account, the order is subject to market dynamics. If trading with a simulated account, the order fill is subject to NinjaTrader's trade simulation engine https://ninjatrader.com/support/help...simulation.htm. The only way to close the gap between the results of RealTime data and Historical data lays in the techniques that NinjaTrader offers to do fill with Historical data.

    To attempt to get closer results when doing order fill resolution with Historical data, one must use techniques which allow you fills based on intrabar data. By default, NinjaTrader ignores intrabar data when fill order using Historical data. (Source: https://ninjatrader.com/support/help...ical_fill_.htm and https://ninjatrader.com/support/help...fill_logic.htm)

    These are three techniques which alter the way orders are filled when processing Historical fills by allowing intrabar order fills:
    • Tick Replay (new technique in NinjaTrader 8)allows
      • Although Tick Replay allow access to 1 tick (intrabar data) historical data, this technique should NOT be used to order fill resolution on Historical data.
    • Order fill Resolution (new technique in NinjaTrader 8)
      • At the strategy level, there is the Order Fill resolution parameter (https://ninjatrader.com/support/help...ical_fill_.htm section "Understanding order fill resolution". When set to High, 1 Tick, it uses a 1 Tick data series of the LAST price. It does not give you access to the BID and ASK data series.
        • When working with Market orders, LONG orders tend to filled at ASK price and SHORT orders tend to be filled at the BID price. This is just one reason one would like to have access to the BID and ASK 1 tick data series instead of just the LAST 1 tick data series.
    • Intrabar granular fill using NinjaScript (source: https://ninjatrader.com/support/foru...ularity?t=6652)
      • This technique allows the developer to add the LAST, ASK and BID 1 tick data series and pick & chose which data series to use based on the order type by using an order method overload (source: https://ninjatrader.com/support/help...rumentStrategy section "Working with a Multi-Instrument strategy")
        • Using the order method overload provides access to the barInProgressIndex method parameter which can be use to set the data series which will be use for the order fill resolution.
      • This technique also can be altered by the "Fill limit orders on touch" strategy parameter when using limit orders
    ISSUE / CONCERN:
    When comparing the results between order fill resolution using Historical data vs RealTime, there is a significant discrepancy. The discrepancy is so large, that I don't see a reason why one would go through the trouble of backtesting (order fill resolution using Historical data). One runs backtest or the optimizer and finds the ideal parameters for a set of backtesting data. Then I download the Market Replay data for the backtesting period, and I set the Playback connection using the Market Replay to replay the same period of the backtesting.

    When I examine trade by trade, I see the discrepancies between NinjaTrader's trade simulation engine and the intraday granular fill.

    QUESTIONS:
    • Is there a technique I am not aware of which allows me to get closer between the two results?
    • Does unmanaged approach gives me other tools that can help improve the order fill resolution using Historical data? I am currently using Advance Order Handling approach
    • Source: https://ninjatrader.com/support/help...ick_replay.htm
      • In the first sentence "Tick Replay is used to playback 1 tick historical data to build the bars as if they had been build live, this means that tick data will be thrown as Market Data events in historical and subsequently OnMarketData and OnBarUpdate events will be called as if it was live", I am confuse by Market Data events and OnMarketData and OnBarUpdate event. When I read it, it sounds like there are Market Data events, followed by OnMarketData and then by OnBarUpdate events. Please help me clarify this.
      • On the screenshot which I have included as an attachment, when looking at the legend (right side), should I be reading this graph from right to left? If so, what happened to the orange zero bar which should be the first "Actual Tick Event". I have been reading this chart from left to right for the longest time. Click image for larger version

Name:	2020-02-11_14-29-26 (3).png
Views:	897
Size:	66.8 KB
ID:	1086976
    • Tick Replay relays on the OnMarketData() event (https://ninjatrader.com/support/help...marketdata.htm). Could you provide with a better sample than one provided on the help guide. The one of the help guide only displays BID, the ASK and LAST. What else can one do in this event which one cannot do in the OnBarUpdate(). I am trying to understand the Tick Replay potential.
    • If "Intrabar granular fill using NinjaScript" is the way to go, could you provide a simple snippet which demonstrates how I test for a certain LAST volume after the trigger has occurred? I want to fill when using the LAST at a certain price point (example limit order) but ONLY if there has been sufficient (hard coded) volume at a certain level. Sometime I get fills because the price touched the limit price. I would like to make it more complex by saying that price has touched after the order trigger and that it has a certain volume.. "Fill limit orders on touch" parameter will be enabled in this particular scenario.
    • Do ASK and BID 1 tick data series have volume? if so, what does the volume represent?

    Lots of information, but before writing this post I have tried to do as much research as possible.

    #2
    Hello GARZONJ,

    Thanks for your post.

    I'll summarize a few items and then answer your questions directly.

    Tick Replay is used for intrabar logical processing. It does not change how the orders fill. (Historical orders fill according to the OHLC values of the data series the orders are submitted to.)

    Tick Replay allows for historical Calculate.OnEachTick and Calculate.OnPriceChange. If using OnMarketData, we will see historical MarketDataType.Last events as well.

    OnBarUpdate happens before OnMarketData.

    • Is there a technique I am not aware of which allows me to get closer between the two results?
    If you would like to have logic processed historically with the advantages of Tick Replay, orders can be submitted to a single tick data series. (This follow SampleIntrabarBacktest example.) This would provide the closest to market simulations for historical orders since the orders will be filled with single tick data.

    • Does unmanaged approach gives me other tools that can help improve the order fill resolution using Historical data? I am currently using Advance Order Handling approach
    No, the concept for filling historical orders is the same: the data series in which the order is placed to will fill the order.

    • Source: https://ninjatrader.com/support/help...ick_replay.htm
      • In the first sentence "Tick Replay is used to playback 1 tick historical data to build the bars as if they had been build live, this means that tick data will be thrown as Market Data events in historical and subsequently OnMarketData and OnBarUpdate events will be called as if it was live", I am confuse by Market Data events and OnMarketData and OnBarUpdate event. When I read it, it sounds like there are Market Data events, followed by OnMarketData and then by OnBarUpdate events. Please help me clarify this.
      • On the screenshot which I have included as an attachment, when looking at the legend (right side), should I be reading this graph from right to left? If so, what happened to the orange zero bar which should be the first "Actual Tick Event". I have been reading this chart from left to right for the longest time. Click image for larger version  Name:	2020-02-11_14-29-26 (3).png Views:	0 Size:	66.8 KB ID:	1086976
    The chart should be read from left to right. Please note the color used in the grid. While MarketData events are seen first here, we see the color green for the CurrentBar = 1 OnBarUpdate event, and then the OnMarketData events associated with that update. The BuySellPressure and BuySellVolume indicators demonstrate a Calculate.OnEachTick scenario where the current plot values are calculated from buys and sells set in OnMarketData, and then when the bar changes, the previous plot value is assigned with the calculated values. Since OnMArketData happens after OnBarUpdate, it will always technically be one tick behind.

    • Tick Replay relays on the OnMarketData() event (https://ninjatrader.com/support/help...marketdata.htm). Could you provide with a better sample than one provided on the help guide. The one of the help guide only displays BID, the ASK and LAST. What else can one do in this event which one cannot do in the OnBarUpdate(). I am trying to understand the Tick Replay potential.
    I'd suggest looking at the BuySellPressure/BuySellVolume indicators. If you use Tick Replay with these indicators, we can see the historical OnMarketData events for MarketDataType.Last. The indicators compare where where the price of the Last tick is in comparison to the Bid and Ask to track buys and sells.

    • If "Intrabar granular fill using NinjaScript" is the way to go, could you provide a simple snippet which demonstrates how I test for a certain LAST volume after the trigger has occurred? I want to fill when using the LAST at a certain price point (example limit order) but ONLY if there has been sufficient (hard coded) volume at a certain level. Sometime I get fills because the price touched the limit price. I would like to make it more complex by saying that price has touched after the order trigger and that it has a certain volume.. "Fill limit orders on touch" parameter will be enabled in this particular scenario.
    This is minded in realtime order simulations and can be tested with the Playback Connection. Historical fill processing is hard coded into NinjaTrader and cannot be customized with your own fill algorithm. This is something that we are tracking interest behind with the feature request ticket ID SFT-1137. I have submitted a vote on your behalf. Since this is not exposed in NinjaScript, we could not offer a sample to customize the fill algorithm.

    • Do ASK and BID 1 tick data series have volume? if so, what does the volume represent?
    Yes, there is volume here. It would represent the number of contracts being offered or bidded at that price level, or price levels if we are building a bar from that data. Actual trades occur on the last. A publicly available resource that may be helpful is included below.



    I'll be happy to answer any additional questions, but I may ask that we transition to more concise questions so if a teammate needs to step in, it will be easy for that technician to assist as well.

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Shansen, 08-30-2019, 10:18 PM
    24 responses
    938 views
    0 likes
    Last Post spwizard  
    Started by Max238, Today, 01:28 AM
    0 responses
    3 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by rocketman7, Today, 01:00 AM
    0 responses
    2 views
    0 likes
    Last Post rocketman7  
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    27 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    32 views
    0 likes
    Last Post wzgy0920  
    Working...
    X