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 argusthome, 03-08-2026, 10:06 AM
    0 responses
    113 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    60 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    40 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    43 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    81 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X