A simple demonstration of moving averages using the curve.

Author: Goodness, Created: 2019-07-04 14:05:46, Updated: 2023-10-25 19:57:53

img

Double moving average strategy, by establishing m-day and n-day moving averages, the two moving averages must have a crossing point during the price movement. If m>n, then the n-day moving average is the upward crossing point. The m-day moving average is the buy point, and vice versa. The strategy is based on the intersection of different cyclical moving averages, capturing the strong weak moments of the trade mark, and executing the trade.

We will now use the Commodity Futures Screw Steel Index over the past year as a daily K-line data source. Let's see the strength of the moving average.

如果交易标的是数字货币,以下代码基本不用改动任何地方,只需要把交易标的在发明者量化平台设置成你想要交易的数字货币交易对,然后选好交易所即可。

The single moving average strategy

A single moving average can also be used as a trading strategy. In fact, it is a variant of a double moving average. The current price will be treated as another moving average.

MA5^^MA(C, 5);
CROSS(C, MA5), BK;
CROSSDOWN(C, MA5), SP;
AUTOFILTER;

The above is a simple open and close strategy based on a single-root equation. The results of the retest are shown below. Although it looks good, the results are bad when you consider the slippage and commission fees.

img img

The double moving average 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;

This simple strategy, with no optimization, results in the following:

img img

Slight improvement in the double moving average strategy

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;

Confirmation conditions are added here compared to the original strategy. For example, if the strategy wants to do more, ask for MA10 and MA5 to be in an uptrend in the last two periods, filter out some recurring short-term signals and raise the median rate.

The final results of the retest were good.

img

Moving average deviation strategy

MA1:=EMA(C,33)-EMA(C,60);//计算33周期和60周期指数之间的平均差值为MA1
MA2:=EMA(MA1,9);//计算9周期MA1指数的平均值
MA3:=MA1-MA2;//计算MA1和MA2之间的差异为MA3
MA4:=(MA(MA3,3)*3-MA3)/2;//计算MA3的3周期和MA3的一半的平均值的3倍的差值
MA3>MA4&&C>=REF(C,1),BPK;//当MA3大于MA4且收盘价不低于前一K线的收盘价时,平仓和开仓多头。
MA3<MA4&&C<=REF(C,1),SPK;//当MA3小于MA4且收盘价不大于前一K线的收盘价时,平仓和开仓空头。
AUTOFILTER;

What is the result of long-short-term averages decreasing in moving averages? Strategic research relies on this continuous attempt. MA4 is actually the average of the first two periods of MA3.

When the current value of the MA3 is greater than the average of the previous two periods, do more, which increases the filtering conditions for the current price to be greater than the previous K-line closing price, which increases the median quotation rate.

The effect of eliminating this condition was almost nonexistent. Specific retest results were as follows:

img

Three strategies for moving averages

Using double moving averages, we naturally think of the results of three moving averages, three moving averages with 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 following is the source code of the simplest three-line moving average strategies, short, medium and long-term averages, which are used to satisfy the following conditions: short > medium, medium > long term.

img

By introducing these five strategies, we can see how the straight-line strategy has evolved. A single moving average strategy is easily triggered repeatedly. It is necessary to add filtering conditions. Different conditions produce different strategies, but the nature of the moving average strategy does not change.

Using these strategies as examples, it is estimated that readers can easily motivate themselves to improve their own mobile average strategies.


Related

More