Case study: Moving average crossover
The moving average crossover system is a classic trend-following method. Two popular variations of this strategy are the dual-moving-average system and the triple-moving-average crossover.
Here’s the code for a simple dual-moving-average crossover system:
Sub DualMACrossover(SLen As Integer,LLen As Integer)
Dim ShortAve As BarArray
Dim LongAve As BarArray
ShortAve = Average(Close, SLen,0)
LongAve = Average(Close, LLen,0)
If ShortAve > LongAve Then
If ShortAve <LongAve Then
This is a simple trend-following system that has some problems. First, if the short-term moving average is half of the dominant cycle, and the long-term moving average is a full dominant cycle, basic cycle theory says we are 180% out of phase, meaning regardless of how well the system does at other times, we will buy every top and will sell every bottom. This is why a dual-moving-average approach is flawed. It will catch big trends, but it will lose badly when trends are shorter term.