该策略使用多个移动平均线(MA)作为主要的交易信号,并结合平均方向指数(ADX)作为过滤器。策略的主要思路是通过比较快速MA、慢速MA和平均MA的关系,识别潜在的多头和空头机会。同时,使用ADX指标过滤出趋势强度足够的市场环境,以提高交易信号的可靠性。
基于平均方向指数过滤器的均线拒绝策略利用多个MA和ADX指标,识别潜在的交易机会并过滤掉低质量的交易信号。该策略逻辑清晰,易于理解和实现,但在实际应用中需要注意市场环境的变化,并结合其他技术指标和风险管理措施进行优化。
/*backtest start: 2024-04-01 00:00:00 end: 2024-04-30 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © gavinc745 //@version=5 strategy("MA Rejection Strategy with ADX Filter", overlay=true) // Input parameters fastMALength = input.int(10, title="Fast MA Length", minval=1) slowMALength = input.int(50, title="Slow MA Length", minval=1) averageMALength = input.int(20, title="Average MA Length", minval=1) adxLength = input.int(14, title="ADX Length", minval=1) adxThreshold = input.int(20, title="ADX Threshold", minval=1) // Calculate moving averages fastMA = ta.wma(close, fastMALength) slowMA = ta.wma(close, slowMALength) averageMA = ta.wma(close, averageMALength) // Calculate ADX manually dmPlus = high - high[1] dmMinus = low[1] - low trueRange = ta.tr dmPlusSmoothed = ta.wma(dmPlus > 0 and dmPlus > dmMinus ? dmPlus : 0, adxLength) dmMinusSmoothed = ta.wma(dmMinus > 0 and dmMinus > dmPlus ? dmMinus : 0, adxLength) trSmoothed = ta.wma(trueRange, adxLength) diPlus = dmPlusSmoothed / trSmoothed * 100 diMinus = dmMinusSmoothed / trSmoothed * 100 adx = ta.wma(math.abs(diPlus - diMinus) / (diPlus + diMinus) * 100, adxLength) // Identify potential levels potentialLongLevel = low < slowMA and close > slowMA potentialShortLevel = high > slowMA and close < slowMA // Confirm levels confirmedLongLevel = potentialLongLevel and close > fastMA confirmedShortLevel = potentialShortLevel and close < fastMA // Entry signals longEntry = confirmedLongLevel and ta.crossover(fastMA, averageMA) and adx > adxThreshold shortEntry = confirmedShortLevel and ta.crossunder(fastMA, averageMA) and adx > adxThreshold // Exit signals longExit = ta.crossunder(close, slowMA) shortExit = ta.crossover(close, slowMA) // Plot signals plotshape(longEntry, title="Long Entry", location=location.belowbar, style=shape.triangleup, size=size.small, color=color.green) plotshape(shortEntry, title="Short Entry", location=location.abovebar, style=shape.triangledown, size=size.small, color=color.red) // Plot moving averages and ADX plot(fastMA, title="Fast MA", color=color.blue) plot(slowMA, title="Slow MA", color=color.red) plot(averageMA, title="Average MA", color=color.orange) // plot(adx, title="ADX", color=color.purple) // hline(adxThreshold, title="ADX Threshold", color=color.gray, linestyle=hline.style_dashed) // Execute trades if longEntry strategy.entry("Long", strategy.long) else if longExit strategy.close("Long") if shortEntry strategy.entry("Short", strategy.short) else if shortExit strategy.close("Short")