Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limit Orders Filling before price is touched on backtest

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

    Limit Orders Filling before price is touched on backtest

    Hi, I have made a strategy that implements different long and short limit orders. However, in backtesting they are not filling at the correct prices. For example, in a backtest if I have a short limit order at 5210, the order fills at 5214. The price never went below 5214. I have put in print statements to make sure it is placing the limit orders at the correct points and it is. I'm not sure why this is happening.

    #2
    8.1.2.1 64-bit
    MES 06-24
    5 minute
    I have tried filled on touch enabled and disabled.
    I am using OnEachTick and have tried OnBarClose

    Here's some logic from the code. This part is supposed to place a short limit order at a 10s place value above the VWAP. It is also supposed to adjust the limit order if the conditions have changed.

    double vwapValue = vwap.VWAP[0];
    double upperTensPlace = Math.Ceiling(vwapValue / 10) * 10;

    if (Open[0] > upperTensPlace && (shortLimitOrder == null || shortLimitOrder.LimitPrice != upperTensPlace))
    {
    CancelOrder(shortLimitOrder);
    shortLimitOrder = EnterShortLimit(0, upperTensPlace, "ShortLimitVWAP");
    SetProfitTarget("ShortLimitVWAP", CalculationMode.Ticks, ProfitTicks);
    SetStopLoss("ShortLimitVWAP", CalculationMode.Ticks, StopLossTicks, false);
    Print($"Short limit order placed at {upperTensPlace}");
    }

    The print statements I have now tell me the proper vwap price, open price, and limit order price in the output window. Just the orders don't seem to fill right on the backtests
    I'll try adding your suggestions to see if anything is wrong​​

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    47 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    23 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    33 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    51 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X