该策略结合了移动平均线(MA)、相对强弱指数(RSI)和平均真实波幅(ATR)等技术分析工具,旨在捕捉市场的趋势性机会。策略通过双均线交叉来判断趋势方向,并利用RSI指标对交易信号进行动量过滤,同时采用ATR作为止损依据,以控制风险。
该策略的核心是利用两条不同周期的移动平均线(快线和慢线)的交叉来判断市场趋势。当快线上穿慢线时,表明上升趋势,策略将产生做多信号;反之,当快线下穿慢线时,表明下降趋势,策略将产生做空信号。
为了提高交易信号的可靠性,策略引入了RSI指标作为动量过滤器。当RSI高于某一阈值(如50)时,才允许开多仓;当RSI低于该阈值时,才允许开空仓。这样可以避免在横盘市或动量不足时交易,提高信号质量。
此外,策略采用ATR作为止损依据,根据最近一段时间内价格的波动幅度来动态调整止损位,以适应不同的市场状态。这种自适应的止损方式可以在趋势不明朗时快速止损,控制回撤;在趋势强劲时给予更大的盈利空间,提高策略收益。
该策略通过趋势跟随和动量过滤的有机结合,在捕捉市场趋势性机会的同时,较好地控制了风险。策略逻辑清晰,易于实现和优化。但在实际应用中,仍需注意震荡市风险和参数风险,并根据市场特点和自身需求,灵活调整和优化策略。总的来说,这是一个兼顾趋势把握和风险控制的balanced策略,值得进一步探索和实践。
/*backtest
start: 2023-05-28 00:00:00
end: 2024-06-02 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Trend-Following Strategy with MACD and RSI Filter", overlay=true)
// Input variables
fastLength = input(12, title="Fast MA Length")
slowLength = input(26, title="Slow MA Length")
signalLength = input(9, title="Signal Line Length")
stopLossPct = input(1.0, title="Stop Loss %") / 100
rsiLength = input(14, title="RSI Length")
rsiThreshold = input(50, title="RSI Threshold")
// Moving averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)
// MACD
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalLength)
// RSI
rsi = ta.rsi(close, rsiLength)
// Entry conditions with RSI filter
bullishSignal = ta.crossover(macdLine, signalLine) and rsi > rsiThreshold
bearishSignal = ta.crossunder(macdLine, signalLine) and rsi < rsiThreshold
// Calculate stop loss levels
longStopLoss = ta.highest(close, 10)[1] * (1 - stopLossPct)
shortStopLoss = ta.lowest(close, 10)[1] * (1 + stopLossPct)
// Execute trades
strategy.entry("Long", strategy.long, when=bullishSignal)
strategy.entry("Short", strategy.short, when=bearishSignal)
strategy.exit("Exit Long", "Long", stop=longStopLoss)
strategy.exit("Exit Short", "Short", stop=shortStopLoss)
// Plotting signals
plotshape(bullishSignal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Bullish Signal")
plotshape(bearishSignal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Bearish Signal")
// Plot MACD
plot(macdLine, color=color.blue, title="MACD Line")
plot(signalLine, color=color.orange, title="Signal Line")
// Plot RSI
hline(rsiThreshold, "RSI Threshold", color=color.gray)
plot(rsi, color=color.purple, title="RSI")