Moving Average Crossover Backtests

I have been running some numbers. I am a computer programmer and I have written a little program to crunch numbers.

Currency Pairs.
The chosen currency pairs are the combinations of the following currencies (“AUD”, “CAD”, “CHF”, “EUR”, “GBP”, “JPY”, “NZD”, “SGD”, “USD”).

The strategy is a Moving Average Crossover. Orders are opened when the short average crosses the long average. An upward cross means buy and a downwards cross means sell. The stop loss is placed at the lowest low or highest high of the past two candles and the take profit is placed at twice the distance of the stop loss in the other direction. If an order is open on that currency pair and another signal occurs then the order will remain open and will not be replaced.

The assumption is that each order risks the same dollar amount each time regardless of the number of pips the stop loss is away from the order price. More pips means a smaller position size to compensate. This is VERY important.

The data.
The backtest consists of 500 historical daily candles covering approximately 2 years worth of data.

The runs.
The moving average lengths go from 5 to 50 and cover every combination (5,10 5,15 … 40,50 45,50) in both EMA/SMA combinations.

The results.
There results are split into portfolios of one currency pair, two currency pairs and three currency pairs. The idea is that if you only want one trade open at any time then use the one currency portfolio, two open trades at a time use the two currency portfolio and three trades use the three currency portfolio. The portfolios are grouped by parameters so that there are no issues with using the wrong MA’s with the wrong pairs (for convenience).

The portfolios.
The currencies were chosen as follows…
Each individual currency pair makes a profit.
The currency pairs do not share any individual currency.
The currency pairs have a correlation between -50 and +50 with each other so that they do not generally move in the same direction. The correlation calculation is based on the last 6 months worth of data.

The results table is as follows…
It is sorted according to “total profit”.
Parameters - The parameters of the run.
The pair followed by its win percentage and its “profit”.
The other pairs as described above.
The average win percentage for the pairs.
The “total profit” for the pairs.
“Profit” is calculated as if the run risked just $1 per order and it is calculated on a per year basis. So a total profit of 6.5 means that if you risked $1 per trade you would make $6.50 in the course of a year. If you risk $10 per trade you would make $65 per year if you took all the trades. The “total profit” is the same but you would take all of the trades in all of the currencies in the portfolio.
The important thing is that the profit is based on dollar risk and not on pip risk. Every order must risk the same dollar amount no matter how many pips, adjust the position size to make this happen.

Have a look at the results, I hope they prove useful.

I will see if I can attach the spreadsheets.Portfolio1.csv (272.1 KB) Portfolio2.csv (459.1 KB) Portfolio3.csv (1.2 MB)


I did the same runs but using the MACD lines for crossover.Portfolio1.csv (1.8 KB) Portfolio2.csv (4.5 KB) Portfolio3.csv (15.5 KB)

1 Like

Hi and welcome to Babypips. When members discuss such programs, they normally present the data as a graphic with the x-axis being date or number of trades, and the y-axis being profit and loss either as a $ value or as a %. It would help greatly if you prepare such graphs from your .csv files.

Also, did the algorithm take into account the two way spread of a broker on the buy/sell sides, or any slippage that would occur in a live account between when the algo says “buy” and the market order is placed immediately?

Very cool. Much thanks for the data.

Can you please clarify some questions?:

  1. Is it safe to assume that where parameters aren’t available for a specific currency pair (Portfolio 1 for example) that you weren’t able to find observations for the duration? Like a 10EMA - 15EMA & 10EMA - 20SMA crossovers against the AUD/CAD

  1. No negative value observations were present against TotalProfit in atleast 2 of the files (Portfolio1 & Portfolio2). Were they ommitted or did you not observe any?

  2. Since there’s no demarcation b/w longs and shorts is it safe to assume that TotalProfit is a cumulative value of absolute values? Basically if a currency pairs registers both a short and long profit has the TotalProfit registered them without one subtracting the other. If this doesn’t make sense I can give an example I guess.

This is pretty awesome. Haven’t looked at the data in more detail yet tbh. A bit bz with something else.

1 Like

I don’t doubt that mathematically, MA crossovers will make a long-run profit. But studies find that running a typical MA crossover strategy produces painful draw-down and offers a poor return.

I am pretty sure they only work because they get the trader long into uptrends and short into downtrends. They tend to work better if the entry signal only is a MA crossover, and the exit is a more sensitive TA feature or a fixed pip or trailing stop-loss.

But at the individual chart level, for every MA crossover there will be 3 or 4 or 5 alternative rational trend entry signals. And these will have greater correlation with more recent price action; the point in time at which the MA crossover occurs is random in comparison with price action.

I also agree with this. MA crossovers would be very effective if all trends were smooth sinewaves with the same frequency but that is not the case.

Very often the gradual entry of traders into a new trend is much slower than their combined exit when things change. And we often see this kind of move:

In this type of situation, the MA crossover pair may get you in reasonably soon but when the price reverses so much quicker, the same MA pair crossover will be too late to save much (or any) of the profit.

As @tommor says, there are ways to overcome this by using a different exit strategy. For example, in addition to those he mentions, one could also use an MA crossover on a lower timeframe to identify when a pullback turns critical to the overall trend and is worth closing out.

Also, MA crossovers can be extremely damaging in periods when a particular pair is drifting without any trend. Whipsawing can eat away profits faster than we expect even when the market is not actually doing anything much at all! Therefore, it is useful to also include some other kind of filter such as a momentum indicator to weed out the weak crossovers. Afterall, simply by definition, the shorter MA will always be on one side or the other of the longer term MA even though price is just drifting around.

1 Like

If I understood the OP right only the entry is based on the MA crossover. I don’t think the exit is crossover based. On the long-side the SL is based on the LL of the previous 2 candles and the TP is 1 x SL (Edited from 2 x SL to 1 x SL)

He’s also noted that the SL/TP levels aren’t overwritten if another signal is generated while a previous order is open for the currency pair.

1 Like

@darthdimsky You are correct, the TP is SL*2 and an order is only closed when one of those two levels is hit and not because another signal has been generated.

@darthdimsky - Anything that ended up with a loss was not reported so you can assume that no data present means it ended up as a loss. The total profit is both long and short profits, basically a profit is a profit regardless of direction.

1 Like

That is indeed the point here. This is an example of the kind of distinctive exit strategy that can work with an MA crossover based approach - and it is important (I think) that the reasons for such an exit strategy are understood.

Whether or not this particular approach is optimal or not is a different issue. It seems the key principle here is a pre-set (and adequate) R:R relationship that matches with the success rate of the MA pair used in reaching the pre-set target levels.

Maybe this suits well with a mechanical, programmed system, but a discretionary approach may well produce better results based on placing stops and targets at PA-based levels rather than a strict R:R ratio - especially if combined with a filter of some kind.

I ran the backtest as two individual years instead of one two year period and the results showed what I expected them to show. They showed that the best currency/periods combination is different for each year thus proving that backtesting can only give you so much information.

Just because I could I went back 4 years and each year was a different set of currency/periods that made the best profit. I will see if there is any sort of pattern but I doubt it.

I tend to agree with you. As you adjust parameters in backtesting you tend to optimize the backtest, but that optimization leads to misleading results. Now if you found parameters that resulted in:
1 Gain in each year tested, or most of them
2 Gain over the entire four year period

at least you could say that the algorithm - both the strategy and the plan - has got some merit. From there, it would be a useful tool via which to start forward testing, with far less probability than random that it would result in losses. Furthermore if you backtested for years t-1 to t-4 years, then ran a forward test on year t-1 to t-0, that would give you even greater confidence in the usefulness of the EA.

The 4 year test was useful to see that the differences in profits each year do not show a smooth transition but are a bit wild. This means there is no way to tell if your currency pair and parameters are “going out of fashion” as it were. They could give you large profits one year and a loss the next year with no warning. Some combinations give profits for every year of the 4 year period and others give losses over all 4 years but based on the current evidence there is no way to predict if it will give a profit or loss next year.

1 Like