Name
双重移动平均线反转交易策略Dual-Moving-Average-Reversal-Trading-Strategy
Author
ChaoZhang
Strategy Description
[trans]
这是一个基于双重移动平均线指标的反转交易策略。该策略通过计算两组不同参数设置的移动平均线,根据其方向变化来判断价格趋势,并设定方向变化的灵敏度参数,从而产生交易信号。
该策略的核心指标是双重移动平均线。策略允许选择移动平均线的类型(SMA、EMA等)、长度和价格源(收盘价、典型价格等)。计算出两组移动平均线之后,通过定义参数reaction判断其方向。当快线上穿慢线时产生买入信号,下穿时产生卖出信号。reaction参数用来调整识别转折点的灵敏度。
此外,策略还设定了变化方向和持续上涨/下跌的条件判定,避免产生错误信号。并用不同颜色可视化表示价格的涨跌状态。当价格持续上涨时,movavg线显示为绿色,下跌时为红色。
这种双重movavg策略结合不同参数设定的快慢线,可以有效滤波交易市场的噪声,识别较强势的趋势。相比单一movavg策略,它减少了错误信号,可以在趋势更加明确时入场,从而获得更高的胜率。
灵敏度参数reaction让该策略可以灵活适应不同周期和品种。策略过程直观简单,容易理解和优化。
该策略最大的风险在于错过转折点而亏损或反向建仓。这与参数reaction设定有关。如果reaction太小,则容易产生错误信号;如果reaction太大,则可能错过较好的入场点。
另一个风险是无法有效控制亏损。当价格出现剧烈波动时,无法快速止损,导致亏损扩大。这需要配合止损策略来控制。
该策略的优化方向主要集中在参数reaction、移动平均线类型及长度的选择。reaction可适当增加来减少错误信号。移动平均线参数可据不同周期和品种进行测试,选择产生信号最佳的组合。
另外,结合其他辅助指标如RSI、KD等来确认交易信号也是优化思路。或使用机器学习方法自动优选参数。
本策略整体来说较简单实用,通过双重移动平均线滤波并产生交易信号,可有效识别趋势反转,是一种典型的趋势跟踪策略。优化参数组合后,其顺市捕捉能力和抗市持仓能力都会得到提高。与止损和位置管理机制配合使用效果更佳。
||
This is a reversal trading strategy based on dual moving average indicators. By calculating two groups of moving averages with different parameter settings and judging the price trend according to their directional changes, trading signals can be generated by setting the sensitivity parameter for directional changes.
The core indicator of this strategy is the dual moving average. The strategy allows selecting the type (SMA, EMA, etc.), length and price source (close price, typical price, etc.) of the moving average. After calculating two groups of moving averages, their directions are determined by defining the reaction parameter. A buy signal is generated when the fast line crosses above the slow line, and a sell signal is generated when it crosses below. The reaction parameter is used to adjust the sensitivity to identify turning points.
In addition, the strategy also sets the conditions to determine the change of direction and continued rise/fall to avoid generating wrong signals. And it visualizes the rise and fall of prices in different colors. When prices continue to rise, the movavg line is displayed in green, and in red when prices fall.
The dual movavg strategy combines fast and slow lines with different parameter settings, which can effectively filter the noise in the trading market and identify stronger trends. Compared with a single movavg strategy, it reduces wrong signals and allows entering the market when the trend is more distinct, thereby obtaining a higher win rate.
The reaction parameter allows the strategy to be flexible and adaptable to different cycles and varieties. The strategic process is intuitive and simple, easy to understand and optimize.
The biggest risk of this strategy is missing the turning point and losing money or taking a reverse position. This relates to the reaction parameter setting. If the reaction is too small, wrong signals are prone to occur. If the reaction is too large, it may miss better entry points.
Another risk is the inability to effectively control losses. When prices fluctuate violently, it cannot quickly stop losses, leading to enlarged losses. This requires the use of stop-loss strategies to control risks.
The main optimization directions of this strategy focus on selecting reaction parameters, types and lengths of moving averages. Increasing reaction appropriately can reduce wrong signals. Moving average parameters can be tested according to different cycles and varieties to select the best combination for generating signals.
In addition, confirming trading signals with other auxiliary indicators such as RSI and KD is also an optimization idea. Or use machine learning methods to automatically optimize parameters.
Overall, this strategy is relatively simple and practical. By filtering with dual moving averages and generating trading signals, it can effectively identify trend reversals and is a typical trend-following strategy. After optimizing the parameter portfolio, its ability to capture trends and hold positions against the market will be improved. Using it with stop loss and position management mechanisms works better.
[/trans]
Strategy Arguments
Argument | Default | Description |
---|---|---|
v_input_1 | 0 | MA Type: : HullMA |
v_input_2 | 32 | MA Lenght |
v_input_3_close | 0 | MA Source: close |
v_input_4 | 2 | MA Reaction |
Source (PineScript)
/*backtest
start: 2023-11-03 00:00:00
end: 2023-12-03 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy(shorttitle="MA_color strategy", title="Moving Average Color", overlay=true)
// === INPUTS
ma_type = input(defval="HullMA", title="MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"])
ma_len = input(defval=32, title="MA Lenght", minval=1)
ma_src = input(close, title="MA Source")
reaction = input(defval=2, title="MA Reaction", minval=1)
// SuperSmoother filter
// © 2013 John F. Ehlers
variant_supersmoother(src,len) =>
a1 = exp(-1.414*3.14159 / len)
b1 = 2*a1*cos(1.414*3.14159 / len)
c2 = b1
c3 = (-a1)*a1
c1 = 1 - c2 - c3
v9 = 0.0
v9 := c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
v9
variant_smoothed(src,len) =>
v5 = 0.0
v5 := na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len
v5
variant_zerolagema(src,len) =>
ema1 = ema(src, len)
ema2 = ema(ema1, len)
v10 = ema1+(ema1-ema2)
v10
variant_doubleema(src,len) =>
v2 = ema(src, len)
v6 = 2 * v2 - ema(v2, len)
v6
variant_tripleema(src,len) =>
v2 = ema(src, len)
v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len)
v7
variant(type, src, len) =>
type=="EMA" ? ema(src,len) :
type=="WMA" ? wma(src,len):
type=="VWMA" ? vwma(src,len) :
type=="SMMA" ? variant_smoothed(src,len) :
type=="DEMA" ? variant_doubleema(src,len):
type=="TEMA" ? variant_tripleema(src,len):
type=="HullMA"? wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) :
type=="SSMA" ? variant_supersmoother(src,len) :
type=="ZEMA" ? variant_zerolagema(src,len) :
type=="TMA" ? sma(sma(src,len),len) : sma(src,len)
// === Moving Average
ma_series = variant(ma_type,ma_src,ma_len)
direction = 0
direction := rising(ma_series,reaction) ? 1 : falling(ma_series,reaction) ? -1 : nz(direction[1])
change_direction= change(direction,1)
change_direction1= change(direction,1)
pcol = direction>0 ? lime : direction<0 ? red : na
plot(ma_series, color=pcol,style=line,join=true,linewidth=3,transp=10,title="MA PLOT")
/////// Alerts ///////
alertcondition(change_direction,title="Change Direction MA",message="Change Direction MA")
longCondition = direction>0
shortCondition = direction<0
if (longCondition)
strategy.entry("BUY", strategy.long)
if (shortCondition)
strategy.entry("SELL", strategy.short)
Detail
https://www.fmz.com/strategy/434196
Last Modified
2023-12-04 16:39:13