Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simulator delay

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

    Simulator delay

    Why execution in strategy analyzer is delayed?

    Time frame in sample: 12 minutes.


    Sample strategy:
    protected override void Initialize()
    {
    SMA(Fast).Plots[0].Pen.Color = Color.Orange;
    SMA(Slow).Plots[0].Pen.Color = Color.Green;

    Add(SMA(Fast));
    Add(SMA(Slow));

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick).
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (CrossAbove(SMA(Fast), SMA(Slow), 1))
    {
    this.Print( string.Format( "EnterLong ON {0}", Time[0] ) );
    EnterLong();
    }
    else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
    {
    this.Print( string.Format( "EnterShort ON {0}", Time[0] ) );
    EnterShort();
    }
    }
    ----

    Debug results:
    EnterShort ON 23.09.2010 10:00:00
    EnterLong ON 23.09.2010 15:24:00
    EnterShort ON 23.09.2010 17:24:00
    EnterLong ON 23.09.2010 18:12:00

    Trades list in simulator is attached.

    Time in strategy is Time[0] = 10:00 and execute EnterShort.
    But Simulator wait one bar - 12 minutes for execution, start position at 10:12:00.
    MarketReplay work correctly, execute trade on 10:00:08

    Does someone know, why simulator delay order execution after one bar?
    Thank you.
    Attached Files

    #2
    Bob, this is expected as in backtesting the earliest trade location is the next bar open after your condition for entry is triggered, i.e. entering at the close of a bar really means being at the open the following one.

    Comment


      #3
      But MarketReplay doesn't have this shift, I think that live trading doesn't have this shift too.
      If Strategy analyzer have Time[0] = 10:00:00 and Enter position on this time, I think that this position shouldn't start at close time of next bar.
      This give different results in strategy analyzer backtest compared to MarketReplay - indicators give slightly different signals because of this shift.

      Comment


        #4
        Bob, for an explanation of what discrepancies between backtesting, Market Replay and live trading are routinely observed please review this link - http://www.ninjatrader-support.com/H...sBacktest.html

        If you with CalculateOnBarClose = true, the trade would be entered on the next bar open in Market Replay testing as well.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        71 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        39 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        63 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X