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

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:	396
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.​​
    Brandon H.NinjaTrader Customer Service

    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.​
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by smartromain, Today, 02:52 AM
        0 responses
        4 views
        0 likes
        Last Post smartromain  
        Started by Marklhc1988, 04-19-2023, 11:11 AM
        12 responses
        569 views
        1 like
        Last Post victor68133  
        Started by nicthe, Yesterday, 02:58 PM
        1 response
        9 views
        0 likes
        Last Post nicthe
        by nicthe
         
        Started by percy3687, 05-17-2024, 12:28 AM
        3 responses
        30 views
        0 likes
        Last Post percy3687  
        Started by SilverSurfer1, Yesterday, 01:33 PM
        0 responses
        13 views
        0 likes
        Last Post SilverSurfer1  
        Working...
        X