The double moving average line strategy, by establishing the m-day and n-day moving average line, which these two moving average lines must have intersections during the price moves. If m>n, the n-day moving average line “up cross” m-day moving average is the buying point, and vice versa. This strategy is based on the intersection of different days of moving averages, grasping the strong and weak moments of the trading pairs, and execute trading. The short-period moving average up cross long-period moving average is called “Buying Point” and vice versa. Ok, now we can build a simple strategy: buying when up cross, selling when down cross.
Now we will use the Chinese commodity future rebar index 15 minutes K line as the data source for backtesting. let’s take a look of the power of the moving average.
Single moving average strategy The single moving average can also engage in strategy. In fact, it is a variant of the double moving average. The current price will be treat as one of the moving averages.
MA5:MA(C,5); CROSS(C,MA5),BK; CROSSDOWN(C,MA5),SP; AUTOFILTER;
The simple one open position and one close position model backtest performance is shown in the figure. although it seems not bad, as long as the slippage and commission fees are taken into consideration, the result will be terrible. 1.Simple double moving average line strategy
MA5:=MA(CLOSE,5); MA10:=MA(CLOSE,10); CROSS(MA5,MA10),BK; CROSSDOWN(MA5,MA10),BP; CROSS(MA10,MA5),SK; CROSSDOWN(MA10,MA5),SP; AUTOFILTER;
With such a simple strategy, without optimization, the results are not ideal, and the profit are as follows: 2.Small improvement of the double moving average
MA5:=MA(CLOSE,5); MA10:=MA(CLOSE,10); CROSS(MA5,MA10)&&MA10>REF(MA10,1)&&REF(MA10,1)>REF(MA10,2)&&MA5>REF(MA5,1)&&REF(MA5,1)>REF(MA5,2),BK; CROSSDOWN(MA5,MA10),BP; CROSS(MA10,MA5)&&MA10<REF(MA10,1)&&REF(MA10,1)<REF(MA10,2)&&MA5<REF(MA5,1)&&REF(MA5,1)<REF(MA5,2),SK; CROSSDOWN(MA10,MA5),SP; AUTOFILTER;
Compared with the original strategy, the confirmation condition is increased. Such as if the strategy want to buy long, requiring MA10 and MA5 are both in an upward trend for the past two periods, filtering out some recurring short-period signals and improving the winning rate. The final backtest results performed well: 3.Moving average line difference strategy
MA1:=EMA(C,33)-EMA(C,60);//Calculate the average difference between the 33-cycle and 60-cycle exponentials as MA1 MA2:=EMA(MA1,9);//Calculate the average of the 9-cycle MA1 index MA3:=MA1-MA2;//Calculate the difference between MA1 and MA2 as MA3 MA4:=(MA(MA3,3)*3-MA3)/2;//Calculate difference of 3 times the average of 3 cycles of MA3 and half of the MA3 MA3>MA4&&C>=REF(C,1),BPK;//When MA3 is greater than MA4 and the closing price is not less than the closing price of the previous K-line, close position and open long position MA3<MA4&&C<=REF(C,1),SPK;//When MA3 is smaller than MA4 and the closing price is not greater than the closing price of the previous K line, close position and open short position. AUTOFILTER;
What is the result of the long-and-short-period moving average subtraction in the moving average? Strategy research relies on this constant attempt. MA4 is actually the average of the first two periods of MA3. When the current value of MA3 is greater than the average of the previous two periods, buy long, here added a filter condition that the current price is greater than the previous K-line closing price, which improves the winning rate. You can try it yourself. The effect of removing this condition has little effect. The specific backtest results are as follows: 4.Three moving average line strategy
With the double moving average line, we will naturally think of the results of the three moving averages, and the three moving averages have more filtering conditions.
MA1: MA(C, 10); MA2: MA (C, 30); MA3: MA (C, 90); MA1>MA2&&MA2>MA3, BPK; MA1<MA2&&MA2<MA3, SPK; AUTOFILTER;
The above is the simplest three moving averages strategy source code, short-period, medium-period and long-period moving averages, opening long position to meet short-period > medium-period, medium-period > long-period. The idea is still the idea of the two moving averages. The backtest results are as follows: Through the introduction of the previous five strategies, we can see how the average line strategy evolves. The single moving average strategy is easy to trigger repeatedly. It is necessary to increase the filtering conditions. Different conditions produce different strategies, but the nature of the moving average strategy has not changed. The short-period represents the short-period trends, long period represent long-period trends, and crossing represents a breakthrough in trends.
With these strategies as examples, it is estimated that readers can easily inspire their own moving average improvements.