Writing a reversal strategy
To detect a reversal, we need to write an algorithm for any of the following three components:
- Existing trend, where we are going to use the simple moving average
- Volatility compression, where we are going to use a VoltyRatio indicator
- Final trend, where we are going to use a breakout
Existing trend
To catch the existing trend, according to what we presented in Chapter 3, we know that we can use the simple moving average. So, to catch a downtrend, we can write the following condition:
close<average(close,PullLen)
Here, PullLen
represents the length to calculate the simple moving average.
Adding such a condition to the long entry strategy’s rules will allow long trades only when the price is below the simple moving average selected. Conversely, to detect an existing uptrend, we can write this condition:
close>average(close,PullLen)
Adding this condition to the short entry strategy’s rules will allow...