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

Real-Time vs backtest

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

    Real-Time vs backtest

    Hello everybody,

    online support page Discrepancies: Real-Time vs Backtest says:

    The Fill Price of Orders

    During a backtest assumptions are made on the fill price of an order is based on the OHLC of a bar and the price of the order itself. You can also have differences depending on which fill algorithm you choose.

    During simulation using real-time market data or Playback, the fill price is based on incoming market data and volume, you may receive better or worse fill prices dependant on where the bid or ask price is and what volume is available at this market prices.

    During real-time brokerage trading, orders are filled according to market dynamics.


    As you can see, there are three different models on what price an order can be filled at.
    Question 1)
    I do not understand the last sentence "As you can see, there are three different models on what price an order can be filled at." In my understanding point 3 is the same as point 2. When Real-Time data is being recorded and used as feed for point 2 than point 2 will be exactly the same when played back. What is the difference?

    Question 2)
    When set "Calculate = on each tick" does that mean that this setting can only take effect when used in real-time market or playing back recorded data? Let's say I use "calculate on each tick" and I do a backtest on historical data (OHLC can be used only), this will result in the backtest to use CLOSE for each bar independent of that tick-by-tick setting? Let's say I use "calculate on each tick" and I do a backtest through market replay, then and only then this setting can take effect?

    Question 3)
    The option in stragegy builder, condition configuration, price = ask or bid can only take effect when "Calculate = on each tick" so this is useless when running historical backtest based on OHLC data, right?
    Last edited by patricia70; 12-11-2020, 05:28 AM.

    #2
    Hello patricia70,

    Thank you for your post.

    Question 1)
    I do not understand the last sentence "As you can see, there are three different models on what price an order can be filled at." In my understanding point 3 is the same as point 2. When Real-Time data is being recorded and used as feed for point 2 than point 2 will be exactly the same when played back. What is the difference?
    That's not correct. When you are using Market Replay data with the playback connection, orders are filled by the simulator. This can vary from where you might be in the queue and whether you get filled at a certain price when the order is filled via a live order with your broker. Likely they would be very similar, but they may vary.

    Question 2)
    When set "Calculate = on each tick" does that mean that this setting can only take effect when used in real-time market or playing back recorded data? Let's say I use "calculate on each tick" and I do a backtest on historical data (OHLC can be used only), this will result in the backtest to use CLOSE for each bar independent of that tick-by-tick setting? Let's say I use "calculate on each tick" and I do a backtest through market replay, then and only then this setting can take effect?
    This is essentially correct. In a backtest, Fills are determined based on 4 data points, the OHLC of a bar since that is the only information that is known during a backtest and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known, so OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick'.

    Adding intra-bar granularity can help with this.

    Here's a link to another post that goes into using High Order Fill Resolution and Tick Replay to assist in making your backtests as close to real time as possible:

    https://ninjatrader.com/support/foru...mance?t=102504

    High Fill Order Resolution and TickReplay cannot be used together. If it is necessary to have both, it is still possible to add intra-bar granularity to a script in the code itself for order fill accuracy and use TickReplay to update indicators with Calculate set to OnPriceChange or OnEachTick historically. For example, add a single tick data series and submit your orders on that series. Note that this cannot be done in the Strategy Builder, the code would need to be unlocked and logic manually added to submit orders to a secondary data series.

    Question 3)
    The option in stragegy builder, condition configuration, price = ask or bid can only take effect when "Calculate = on each tick" so this is useless when running historical backtest based on OHLC data, right?
    That's correct, when accessed during State.Historical, the Close price of the evaluated bar is substituted. In order to be able to access historical bid/ask prices, you would need to unlock the code. An example of accessing historical bid/ask prices may be found in our help guide here:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by samish18, 04-17-2024, 08:57 AM
    17 responses
    64 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by rocketman7, Today, 02:12 AM
    2 responses
    16 views
    0 likes
    Last Post rocketman7  
    Started by briansaul, Today, 05:31 AM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by PaulMohn, Today, 03:49 AM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by frslvr, 04-11-2024, 07:26 AM
    6 responses
    106 views
    1 like
    Last Post NinjaTrader_BrandonH  
    Working...
    X