Creating a Contrarian Indicator Using Moving Averages in Python.
By: Sofien Kaabar
Tags: Machine Learning, Investing, Trading, Finance, Data Science

Creating the Strategy

Now we can create a simple contrarian strategy based on the MACI(100, 10). This nomenclature means that it is a 100-period moving average with a normalization period of 10. The strategy is already obvious. We will use:

The 0 level of the MACI to trigger a long (buy) order and hold it until getting another signal or exiting following the Simplified ATR.

The 100 level of the MACI to trigger a short (sell) order and hold it until getting another signal or exiting following the Simplified ATR.

Signal chart on the EURUSD. We can notice the abundance of signals. (Image by Author)

The signal chart shows an abundance of signals with an unclear view on whether they are of quality or not although they seem to be catching local tops and bottoms quite well. By continuing the back-test on the rest of the major currency pairs, we can get the below performance summary table.

Performance Summary Table. (Image by Author)

The back-testing results below are on the 3H time frame since 2000 with a target at 1x Simplified-ATR and a stop at 2x Simplified-ATR. This is not very optimal but as I always mention in my articles, I prefer giving systematic strategies time to breathe before forcing the orders to be stopped out. In other words, the theoretical risk-reward ratio we are using is 0.50 as opposed to the recommended 2.00.

Equity Curves of the MACI Strategy. (Image by Author)

I think it is important now to also understand the performance metrics that we use to evaluate our strategies, here is a quick refresher:

Hit Ratio

As I have mentioned in my previous articles, the hit ratio does not mean anything without the risk-reward ratio. As mentioned above, the theoretical risk-reward ratio is 0.50, and thus, to get a profitable strategy we need at least 67.00% hit ratio. However, we can see that the above table shows an average hit ratio of 58%. How are we profitable?

Image by Author.

The answer to this lies with the word theoretical that we have used above. Indeed, we have set a 0.50 risk-reward ratio by targeting half of what we are risking, but in reality we have other exit rules based on the trading conditions above and thus, the average realized risk-reward ratio was around 0.81. This explains the profitability, because with 0.81 risk-reward ratio, we need 55.25% to break-even.

To compute the required hit ratio to break even, you can use the following formula:

Image by Author.

Profit Factor

This is a relatively quick and straightforward method to compute the profitability of the strategy. It is calculated as the total gross profit over the total gross loss in absolute values, hence, the interpretation of the profit factor (also referred to as profitability index in the jargon of corporate finance) is how much profit is generated per $1 of loss. The formula for the profit factor is:

Image by Author.

Expectancy

Expectancy is a flexible measure that is composed of the average win/loss and the hit ratio. It provides the expected profit or loss on a dollar figure weighted by the hit ratio.

Image by Author.

Conclusion

The MACI is a very interesting indicator as it is one of the few that present consistent upward sloping equity curves. In simpler terms, it is a profitable indicator. But the reality is that a lot more back-testing, research, and stress-testing should be done before we can employ it in a systematic way. Another thing to mention is that we need to optimize the risk management process so that it works well with the indicator. In a future article, I will be presenting an enhanced and more complicated version of the MACI.