双均线跟踪趋势策略是一个利用快速移动平均线和慢速移动平均线组合来判断市场趋势,并在趋势方向发生转折时发出交易信号的策略。该策略同时结合了均线指标和价格通道指标来识别趋势,可以有效过滤市场噪音,判断趋势方向。
双均线跟踪趋势策略使用两个移动平均线指标——快速移动平均线(5周期)和慢速移动平均线(21周期)。快速均线用于生成交易信号,慢速均线用于判断市场趋势方向。当快速均线从下向上穿过慢速均线时,产生买入信号;当快速均线从上向下穿过慢速均线时,产生卖出信号。
该策略还同时使用价格通道指标辅助判断趋势。价格通道由最高价和最低价的移动平均线确定。当价格突破通道时,表示趋势发生反转。该策略使用两个价格通道,第一个价格通道周期为21,第二个价格通道周期为5,与均线周期相匹配。
在判断买入和卖出信号时,该策略要求红柱连续出现(用户可设置柱子数量),作为额外的过滤条件。这可以避免在盘整区域发出错误信号。
总的来说,双均线跟踪趋势策略判断趋势的逻辑是:
通过多级别的趋势判断,可以有效过滤噪音,确定趋势方向。
双均线跟踪趋势策略有以下优势:
综上,该策略整体稳定性较好,在大幅趋势市中表现较为出色。
双均线跟踪趋势策略也存在一些风险,主要有:
对应地,可以通过以下方法降低策略风险:
双均线跟踪趋势策略还有进一步优化的空间,主要方向有:
这些优化方向可以进一步提高策略的稳定性、适应性和智能化水平。
双均线跟踪趋势策略整体来说是一个较为稳健的趋势跟踪策略。它同时结合均线指标和价格通道判断趋势方向和强度,并以快速均线发出交易信号。额外增加的柱形过滤条件也可以进一步避免错误信号。该策略参数可调整,可以很好适应不同市场环境。同时也留有较大的优化空间,有潜力打造成一个可靠、智能的自动交易策略。
/*backtest start: 2023-12-24 00:00:00 end: 2024-01-23 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=2 strategy(title = "Noro's Trend MAs Strategy v1.8", shorttitle = "Trend MAs str 1.8", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100.0, pyramiding=0) //Settings needlong = input(true, "long") needshort = input(true, "short") needstops = input(false, "stops") stoppercent = input(5, defval = 5, minval = 1, maxval = 50, title = "Stop, %") useohlc4 = input(false, defval = false, title = "Use OHLC4") usefastsma = input(true, "Use fast MA Filter") fastlen = input(5, defval = 5, minval = 1, maxval = 50, title = "fast MA Period") slowlen = input(21, defval = 20, minval = 2, maxval = 200, title = "slow MA Period") bars = input(2, defval = 2, minval = 0, maxval = 3, title = "Bars Q") needbg = input(false, defval = false, title = "Need trend Background?") needarr = input(false, defval = false, title = "Need entry arrows?") src = useohlc4 == true ? ohlc4 : close fastsma = ema(src, 5) //PriceChannel 1 lasthigh = highest(src, slowlen) lastlow = lowest(src, slowlen) center = (lasthigh + lastlow) / 2 //PriceChannel 2 lasthigh2 = highest(src, fastlen) lastlow2 = lowest(src, fastlen) center2 = (lasthigh2 + lastlow2) / 2 //Trend //ma = type == 1 ? sma(src, len) : type == 2 ? ema(src, len) : type == 3 ? vwma(src, len) : type == 4 ? dema : type == 5 ? tema : type == 6 ? kama : type == 7 ? center : 0 //trend = low > ma and low[1] > ma[1] and low[2] > ma[2] ? 1 : high < ma and high[1] < ma[1] ? -1 : trend[1] trend1 = low > center and low[1] > center[1] ? 1 : high < center and high[1] < center[1] ? -1 : trend1[1] trend2 = low > center2 and low[1] > center2[1] ? 1 : high < center2 and high[1] < center2[1] ? -1 : trend1[1] trend = trend1 == 1 and trend2 == 1 ? 1 : trend2 == -1 and trend2 == -1 ? -1 : trend[1] //Bars bar = close > open ? 1 : close < open ? -1 : 0 redbars = bars == 0 ? 1 : bars == 1 and bar == -1 ? 1 : bars == 2 and bar == -1 and bar[1] == -1 ? 1 : bars == 3 and bar == -1 and bar[1] == -1 and bar[2] == -1 ? 1 : 0 greenbars = bars == 0 ? 1 : bars == 1 and bar == 1 ? 1 : bars == 2 and bar == 1 and bar[1] == 1 ? 1 : bars == 3 and bar == 1 and bar[1] == 1 and bar[2] == 1 ? 1 : 0 //Signals up = trend == 1 and (low < center2 or usefastsma == false) and (redbars == 1) ? 1 : 0 dn = trend == -1 and (high > center2 or usefastsma == false) and (greenbars == 1) ? 1 : 0 //Lines colorfastsma = usefastsma == true ? red : na plot(fastsma, color = colorfastsma, title = "Fast MA") plot(center, color = blue, linewidth = 3, transp = 0, title = "Slow MA") plot(center2, color = red, linewidth = 3, transp = 0, title = "PriceChannel 2") //Arrows plotarrow(up == 1 and needarr == true ? 1 : 0, colorup = black, colordown = black, transp = 0) plotarrow(dn == 1 and needarr == true ? -1 : 0, colorup = black, colordown = black, transp = 0) //Background col = needbg == false ? na : trend == 1 ? lime : red bgcolor(col, transp = 90) //Alerts alertcondition(up == 1, title='buy', message='Uptrend') alertcondition(dn == 1, title='sell', message='Downtrend') //Trading stoplong = up == 1 and needstops == true ? close - (close / 100 * stoppercent) : stoplong[1] stopshort = dn == 1 and needstops == true ? close + (close / 100 * stoppercent) : stopshort[1] longCondition = up == 1 if (longCondition) strategy.entry("Long", strategy.long, needlong == false ? 0 : na) strategy.exit("Stop Long", "Long", stop = stoplong) shortCondition = dn == 1 if (shortCondition) strategy.entry("Short", strategy.short, needshort == false ? 0 : na) strategy.exit("Stop Short", "Short", stop = stopshort)