Hi all - Currently running a day-trading backtest over a number of years where the main strategy is to enter short positions under certain circumstances. I'm using a consolidator to run over 5min bars. Exit is either take-profit at some decrease in price (related to a moving average) or stop-loss if price climbs too high (sorry, need to be a bit vague).
Naturally, some big gains and big losses are expected. However, I am observing some unexpected prices when the exit/buy orders are filled - in particular the buy price appears to be much higher than expected. I understand market orders may not be filled immediately, but checking the 5m charts, I do not see that the stocks in question ever reach the fill price during the time period in question! This is very odd to me - is it possible the historical data has some large errors?
Note that I use `self.MarketOrder(symbol, -quantity)` to enter the short position and `self.Liquidate(symbol)` to exit the short position.
Here are two examples:
- I short SOBR on 9/21/22 at $3.31. Exit short 20m later, but its filled at $10! If we check chart for SOBR on this date, the price never goes above $3.50 on this date!

I also do some logging for the trades - we can see that the `tradebar.Close` value (argument to my `OnConsolidatedData` consolidator function) shows current price at $2.76, which my algorithm logic considers a take-profit signal.

2. Here's a more dramatic one: I short CVNA on 12/9/22 for $5.58. Order filled 10m later at $350 (lol). Can check CVNA never goes above $6 on this date. Unfortunately I don't have my logs for this example, but I am sure it would be similar to the first example.

If someone could please help me on this would be much appreciated! Implementing the strategy correctly is hard enough already. And please let me know if I can provide any other info that would help. Thanks!
Sam Bald
As per suggesting in discord, I'm attaching some code to make it easier to help debug. Note that I have removed some sensitive portions related to selecting stocks each day and conditions for entering/exiting positions, but I'm fairly sure those aren't contributing to the issue I'm seeing (the stock selection is certainly irrelevant, and the take-profit and stop-loss conditions are fairly innocuous signals that typically trigger within 10-30m after the initial short).
Again, thanks in advance for any help here!
Sam Bald
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!