本策略结合了趋势跟踪和动量分析两种方法,利用简单移动平均线(SMA)和移动平均收敛散度(MACD)指标来识别潜在的交易机会。策略通过Trendilo指标(一种基于SMA的趋势指示器)来确定整体市场趋势,同时使用MACD的零线交叉来捕捉短期动量变化。此外,策略还运用了平均真实范围(ATR)来动态设置止损和获利水平,以适应市场波动性的变化。
策略的核心逻辑基于以下几个关键元素:
具体而言,当MACD线从下方穿过零线(上穿),且收盘价高于Trendilo线时,触发做多信号。相反,当MACD线从上方穿过零线(下穿),且收盘价低于Trendilo线时,触发做空信号。入场后,策略使用基于ATR的止损和获利水平来管理风险和锁定利润。
该策略巧妙地结合了趋势跟踪和动量分析,通过Trendilo和MACD的协同作用,为交易者提供了一个相对全面的市场分析框架。动态的风险管理方法增强了策略的适应性,使其能够在不同的市场环境中保持稳定性。然而,交易者在使用此策略时仍需谨慎,特别是在参数优化和风险控制方面。通过持续的监控和优化,该策略有潜力成为一个可靠的交易工具,特别适合那些希望在趋势市场中捕捉机会的投资者。
/*backtest start: 2019-12-23 08:00:00 end: 2024-09-24 08:00:00 period: 1d basePeriod: 1d exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("NNFX Trendilo + Zero MACD Strategy", overlay=true) // --- Inputs --- atrPeriod = input.int(14, title="ATR Period") stopLossMultiplier = input.float(1.5, minval=0.0, maxval = 20.0, step = 0.1 ,title="Stop Loss Multiplier") takeProfitMultiplier = input.float(2.0, minval=0.0 , maxval = 20.0, step = 0.1,title="Take Profit Multiplier") // --- Trendilo --- trendiloPeriod = input.int(50, title="Trendilo Period") trendilo = ta.sma(close, trendiloPeriod) // --- MACD --- [macdLine, signalLine, _] = ta.macd(close, 12, 26, 9) macdZeroCrossUp = ta.crossover(macdLine, 0) macdZeroCrossDown = ta.crossunder(macdLine, 0) // --- ATR for Stop Loss and Take Profit --- atr = ta.atr(atrPeriod) stopLoss = atr * stopLossMultiplier takeProfit = atr * takeProfitMultiplier // --- Trading Logic --- longCondition = macdZeroCrossUp and close > trendilo shortCondition = macdZeroCrossDown and close < trendilo // --- Execute Long Trades --- if (longCondition) strategy.entry("Buy", strategy.long) strategy.exit("Take Profit/Stop Loss", "Buy", limit=close + takeProfit, stop=close - stopLoss) // --- Execute Short Trades --- if (shortCondition) strategy.entry("Sell", strategy.short) strategy.exit("Take Profit/Stop Loss", "Sell", limit=close - takeProfit, stop=close + stopLoss) // --- Plot Signals --- plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, text="Buy") plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell") // --- Plot Trendilo --- plot(trendilo, color=color.blue, linewidth=2)