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

Why would I be getting unrealistic fills on backtesting versus forwardtesting?

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

    Why would I be getting unrealistic fills on backtesting versus forwardtesting?

    Hi,

    The attached strategy(TurtleSystem1OnPriceChange.zip) uses the 20 period Donchian channel indicator (a built-in indicator) to go long or short. It's always in the market, and flips long or short.
    I'm having an issue with unrealistic simulated fills and want to understand why this is happening in my backtest.


    Settings:
    Click image for larger version  Name:	image.png Views:	0 Size:	63.9 KB ID:	1297651


    Notice that the fills are regularly happening at the open of each candle (at the red arrows) whereas the expected fill would be around the red circle, where the donchian channel has been touched.

    Click image for larger version  Name:	image.png Views:	0 Size:	83.3 KB ID:	1297650


    other examples below:
    Click image for larger version  Name:	image.png Views:	0 Size:	100.4 KB ID:	1297652

    These fills are clearly unrealistic.


    Below is the same strategy when forward tested on live data.The fills look correct here.

    Click image for larger version  Name:	image.png Views:	0 Size:	82.3 KB ID:	1297653

    What could be causing this? I've tried calcing on each tick and on price change, there is no difference.

    thanks in advance.
    Last edited by Conall; 03-29-2024, 01:35 AM.

    #2
    Hello Conall,

    Thanks for your post.

    Please review the help guide document on the differences on real-time vs backtest (historical).



    It is expected that a strategy running real-time (live brokerage account, live market simulation, Playback connection etc...) will produce different results than the performance results generated during a backtest.

    When in historical data, only the Open, High, Low, and Close will be available 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.

    Because of this, 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' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.

    Below is a link to the help guide on Calculate.


    To improve the accuracy of a backtest, you may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar.

    Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.

    High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

    Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

    SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/help...ipt_strate.htm

    TickReplay — https://ninjatrader.com/support/help...ick_replay.htm

    Developing for Tick Replay - https://ninjatrader.com/support/helpGuides/nt8/developing_for__tick_replay.htm?zoom_highlightsub= developing+for+tick+replay

    Additional information may be found in this NinjaTrader Forum post — https://ninjatrader.com/support/foru...mance?t=102504
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Brandon, makes sense, and I've got things working as intended now.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by DJ888, Today, 10:57 PM
      0 responses
      6 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      158 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Today, 09:29 PM
      0 responses
      7 views
      0 likes
      Last Post Belfortbucks  
      Started by zstheorist, Today, 07:52 PM
      0 responses
      7 views
      0 likes
      Last Post zstheorist  
      Started by pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      151 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Working...
      X