Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtest results with Tick replay VERY different from Market replay

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

    Backtest results with Tick replay VERY different from Market replay

    Hi,

    I'm running a strategy on a 5 min bars but calculated on each tick with Tick replay enabled.

    The results that I get from BackTesting are so wrong. Exits have nothing to do with reality. Despite trades should be filled based on ticks, I get exit fills at the next 5 min bar.

    E.g. Image, From Backtest, the 11 October at 11:44.06 in ES. Entry at 3627.50, and exit at 11:45:00 at 3622.50 despite that price never existed at that time (It seems it's taking exits with ticks previous to the entry).

    In Market replay, I'd have stopped out at 11:44:33 at 3629.25. This is correct.

    Any idea why? How can I change the strategy to have a real exits based on ticks, so have the exit at 11:44:36.


    Click image for larger version

Name:	example.jpg
Views:	1209
Size:	46.7 KB
ID:	1219660

    Code:
        Calculate = Calculate.OnEachTick;
                    IncludeCommission = true;
                    RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;
                    IsExitOnSessionCloseStrategy = false;
    
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(BarsPeriodType.Tick, 1);​
    
    ...........
    
    protected override void OnBarUpdate()
            {
    
                if (BarsInProgress != 0) return;
                if (CurrentBar < BarsRequiredToTrade) return;
                if (_lastBar == CurrentBar) return;
                if (Position.MarketPosition == MarketPosition.Flat)
                {
                    var support = _sr.SupportPrice[0];
                    if (Low[0] <= support && Close[0] >= support + ExtraRetracementTicks * TickSize)
                    {
                        if (_sr.SupportTouches[0] >= MinTouches)
                        {
                            if (_lastLevel.ApproxCompare(support) != 0)
                            {
                                EnterLong(1, 1, "buy");
                                _lastBar = CurrentBar;
                                _lastLevel = support;
                                SetProfitTarget(CalculationMode.Ticks, TakeProfit);
    
                                var ticks = (Close[0] - Low[0]) / TickSize;
                                if (ticks < 4) ticks = 4;
                                ticks += ExtraSLTicks;
                                SetStopLoss(CalculationMode.Ticks, ticks);
    
                                return;
                            }​

    #2
    Hello jrtrading251,

    Thanks for your post.

    Please review the help guide document on the differences on real-time vs backtest (historical).
    http://ninjatrader.com/support/helpG...ime_vs_bac.htm

    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 script and the following Help Guide links for more information.

    SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity' - https://ninjatrader.com/support/helpGuides/nt8/backtesting_ninjascript_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

    Ultimately, to fully understand how the strategy is processing logic and placing trades, debugging prints should be added to the strategy. Below is a link to a forum post that demonstrates how to use prints to understand behavior.

    https://ninjatrader.com/support/foru...121#post791121

    Please let us know if we may be of further assistance to you.​​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hi Brandon,

      Thanks for the information.

      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.
      I already did that. As you can see from the code in my previous message, I already "AddDataSeries(BarsPeriodType.Tick, 1) with tick replay"

      Despite that, EXIT orders in Backtest are NOT filled intrabar.

      What am I doing wrong?​

      Comment


        #4
        Hello jrtrading251,

        Thanks for your note.

        If the strategy is not placing orders as expected, you would need to add debugging prints to the script to determine exactly how the script is processing the logic and placing trades.

        In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

        Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

        Also, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.

        https://ninjatrader.com/support/foru...121#post791121

        Let us know if we may assist further.​
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          JR trading - did you get to know what was wrong.

          Originally posted by jrtrading251 View Post
          Hi Brandon,

          Thanks for the information.



          I already did that. As you can see from the code in my previous message, I already "AddDataSeries(BarsPeriodType.Tick, 1) with tick replay"

          Despite that, EXIT orders in Backtest are NOT filled intrabar.

          What am I doing wrong?​

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          51 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          127 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          69 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          42 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          46 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X