1) The strategy trades in the premarket and after hours, when the Bid/Ask will frequently move around a lot with no fills. Then there is a small order of 100 or so shares that all executes at one price, with a significant gap between this execution price and the close of the last bar. No other orders fill within the bar time, so it creates a bar with Open, High, Low, and Close all at the same price.
2) If my strategy had a limit entry order between the Close of the prior bar and the price of the new bar, backtesting fills the limit order at the price of the new bar, because (if I understand it correctly) the historical fill algo follows its steps, skips over the large price gap, and chooses to fill my order at the only price available in the newest bar.
3) Then over the next hour or longer, the bid/ask prices of that stock move back the other direction without any fills. Eventually there is a small fill with another large gap in price between the newest bar and the prior bar. Usually taking the stock back to where it started, because whoever placed that random lot order was an idiot. And now the backtest thinks I entered a position at an incredible price, and have a large profit.
In real life, this would almost never, if ever, happen. If a stock had a last bar close price of 100, and its 4am and I have a live buy limit order in at 99, and the CEO gets caught smuggling a pangolin out of Vietnam, and the bid/ask prices RACE down to 90, it will fill my order on the way. Then say at 90 someone else buys 100 shares, creating a small bar. Then lets say my strategy puts a profit target $1 above the fill price, so now in live trading I am down 10% with an average price around 99, an exit limit order waiting at 100, and the current price at 90. Then time passes and the bid/ask prices move back up to 95 where someone else buys 100 shares. In live trading I'm still very negative.
BUT if I then ran the same strategy backtested on that same time period (without me in it), the historical fill algo does this:
Bar 1 Close at 100, Enter Limit Long at 99. (bid/ask moves prices down to 90, where there is a 1 lot fill) --> Bar 2 has Open = High = Low = Close = 90. So the fill algorithm fills my Enter Limit Order at 90 instead of 99. (bid/ask prices move back up to 95 where there is a 1 lot fill) --> Bar 3 has Open = High = Low = Close = 95, so the fill algo fills my Exit limit order at 95.
Its a HUGE difference, where the back test reports a large unrealistic gain, but live trading would have resulted in a large loss. This situation occurs every day in premarket and after hours, all across the market. SO I have a few questions, if you wouldn't mind.
- Would it be at all possible to not allow Limit orders to fill at prices better than the limit price? Or at least restrict how extreme it can be? I know limit orders can technically fill at a better price, but in the situation that happens every day in the after hours markets, with bid/ask prices moving all around but few or no fills occurring, they don't just jump over your limit order and hook you up with a great price... They give you the ****ty price and move the market on down. Is there a way to code this, or could this feature be added?
- Is there a way to have a strategy or a backtest ignore tiny ticks way off of the prior close price? I know you can filter live ticks, but any chance this is coming to back testing?
- And finally, one other kind of annoying thing is the lack of partial fills in back testing. If I am trying to write a strategy for a large amount of $, and trying to backtest it on a basket of instruments, the results can very unrealistic in thin markets as the fill algo fills my 200,000 share order on a bar with a volume of 100. Is there any way to at least limit my historical fills to something realistic? Like limited by the volume of the bar, or sum of a few recent bars, or anything to make it anywhere close to reality?
Thanks so much! I always appreciate you help.
Comment