After supporting auto trading for one year now, it seems to be that understanding the difference between backtesting and real-time trading might be the biggest struggle. If your backtesting results do not match your real trading results, using the close instead of the next bar's open is the culprit nine times out of ten.
This is a very simple moving average crossover system designed to create many trades to demonstrate the problem. If moving average A crosses moving average B, it fires a trade on the close of the bar. After just ten trades, the backtesting result (upper histogram) makes you believe you made 3375€, but after running this in auto trade, you actually lost 1175€ (lower histogram)! So the difference of more than 4000€ in just ten trades is not a bug – it is a design error in this trading system.
Let’s have a look at an open candle and two moving averages on a one-minute chart.
A few seconds after the open of this candle, it appears to be a positive candle and the blue moving average has crossed above the pink moving average. If the trading system is set to auto execution using the close price of the bar, it would immediately fire in a long trade.
In this case, a WRONG TRADE!
A few seconds before the close of the candle, the signal had disappeared again as the pink moving average is back on top of the blue moving average. As the system already fired in the trade in real time, that does not match the backtesting view anymore.
This is how it looked after the candle was closed and we have a valid signal on the right side of the third candle.
The backtesting is just looking at historical data, and would not add a trade here, but in reality the auto trade was already long.
It is very easy to avoid these situations. The only way to guarantee that the candle does not change anymore is firing in the trade after the next candle has opened.
For the formula toolbox, you are looking for the signal of the moving average one bar prior to the bar on which you want to trade.
On the price top, you need to set the price to Open(@).
There is still a small difference in the results between backtesting (upper histogram) and the ATS study that records the real trading in auto trade mode.
The backtesting calculation assumes that every trade would be filled exactly on the open price in the next candle. In reality, the order gets fired in the second the new candle opens and gets filled usually with a few ticks slippage. We did trade ten times (twenty executions) with three lots each. That’s twenty executions, multiplied by three lots, multiplied by one-point slippage at the DAX future that is 25€. This would sum to 1500€. The difference between backtesting and ATS is actually a little bit below 1500€. You can also see the blue trades from backtesting versus the green arrows from ATS in the upper portion of the chart.
In most cases the idea of backtesting is to get an idea how a certain strategy would perform over a period of time. If you are happy with the backtesting results and you start putting it into auto trading mode, it will almost never match 100%, but it should be close to the backtesting results. The difference between the two should be explainable, such as slippage.
I also want to mention that sometimes traders actually DO WANT their systems to execute halfway into the bar to get a hopefully “better” execution than waiting for the next bar to open. This is basically front-running your own trading system. Some systems might perform better in reality than on the backtest; however, you need to monitor that very closely in real time as backtesting results are almost meaningless in these situations.