# Strategy "Maximum deviation from the average" or looking for a trend reversal

*In the 63rd issue of ForTrader.org we explore the trading strategy "Maximum deviation from the mean."which uses in its arsenal only, as the name suggests, the moving average and the history of quotes. *

So, as already mentioned, to work on the strategy we need a moving average and candlestick closing prices (see Fig. 1).

Fig. 1. Trading strategy template "Maximum deviation from the average".

The idea of the proposed review trading strategy is based on the notion **market cyclicality **- We know that the price cannot rise or fall forever (although no one has canceled long-term trends), there always comes a turning point, especially if we are talking about volatile pairs and low timeframes. In this study we will try to "catch" reversal moments, i.e. price points when the reversal is most likely to occur.

To be more precise, we will take historical data for a certain period of time, for example, for a month, and look at how many points the price deviated from the moving average. The obtained figure will have to be memorized, and in case of repeated deviation by the same number of points, we will enter the deal.

### In the study, I propose to try two options:

1. Using the tester **MetaTrader 5 **we will select the most optimal deviation for sell and buy trades.

2. Let's select the optimal value of the average deviation based on the time range specified in advance. For example, we will search for the parameter we need for the last 100 bars, while the strategy tester will search for the number of bars.

In Figure 1 you can clearly see those places on the chart where the price deviates from the average as much as possible and then immediately changes its direction. In the next few issues of the magazine we will try to finalize the strategy based on this idea, but for now we will try the initial version in action.

Fig. 2. The "Deviation from the average" indicator in action.

For ease of analysis, it was written **MaDEv trading indicator**with the help of which it is possible to quickly determine the size of maximum price deviations from the average (see Fig. 2). The first maximum deviations from the average line were chosen as signal lines. Note that in all the signals we received, the reversal occurred either on the same bar or even a little later than the signal appeared.

### Rules for entering and exiting the deal:

So, let's try to formulate the basic rules for entering and exiting a trading strategy.

**Long position (see Figure 3):**

Fig. 3. Buy signal on the trading strategy.

It's pretty simple: we wait for the price to deviate as much as possible from the moving average downwards after the crossing. As soon as the MaDEv indicator crosses the signal line, we open a buy at the close of the candle. We exit the position as soon as the price touches the moving average.

**Short position (see Figure 4):**

Fig. 4. Sell signal on the trading strategy.

The situation is similar: we wait for the price to deviate from the moving average upwards as much as possible after the crossover. As soon as the MaDEv indicator crosses the signal line from above, at the close of the candle we will **open a sale**. Exit the position as soon as the price touches the moving average.

### Testing a trading strategy

From the programming point of view, the strategy turned out to be quite simple. Having implemented its rules and set the maximum deviation of 30 points, we try the idea on price charts. The most volatile currency pair is considered to be the following** EURUSD**We choose a small timeframe - M15, we will test starting from 2009 (see Fig. 5).

Fig. 5. Testing the trading strategy on EURUSD. Download the report

As we can see, the potential for our idea is there. The balance graph is like a cardiogram, which means that there are market moments when the strategy works well, and those when things are not so good. As always, let's turn to optimization to find good parameters to smooth out the rough edges.

### Optimizing your trading strategy

Optimization will be performed on the same EURUSD pair, on the 15-minute chart. We are looking for **successful deviation parameters** from 2009.01.01 to 2010.01.01. In addition, as a forward test let's see how the parameters will work on the section outside the optimization until 2010.09.10 (see Fig. 6).

Fig. 6. Optimization of the trading Expert Advisor on EURUSD using the forward test.

Download the report

I don't know about you, but I like the picture in Figure 6 very much. We do not observe negative periods, although the period "at zero" is also quite long. Judging by the fact that the main earnings occur at the beginning of the year, when the markets are unstable, we conclude that the most relevant for the given expert times when the market is at its most volatile. There will be something to build on in the next issues.....

### To summarize

As we can see, the idea we have proposed for consideration has the right to exist. Although the performance statistics does not look very impressive, let's discount the fact that we did not try to improve the strategy itself by adding additional parameters and indicators. Perhaps Fibonacci and its levels can help us quite well.

For now, our main task is to find a method that will allow the Expert Advisor to adapt to a particular market - whether it is volatile or not. Therefore, we will continue our research in the next issue.

### Description of the parameters of the obtained advisor

- InpStopLoss - StopLoss size;

- InpTakeProfit - TakeProfit size;

- InpLots - volume of deals made;

- InpMaDevPeriod - period of the moving average indicator;

- Maxdevbuy, maxdevsell - the size of maximum deviations from the average in points for buying and selling respectively.

Continued: Part II