该策略是一个结合了双均线交叉、RSI超买超卖和ATR波动率过滤的复合型交易系统。系统采用短期和长期移动平均线产生交易信号,通过RSI指标过滤市场状态,利用ATR指标进行波动率判断,并结合百分比止损和风险收益比来进行仓位管理和风险控制。该策略具有较强的适应性,可以根据市场环境灵活调整参数。
策略的核心逻辑基于以下几个方面: 1. 信号生成:利用9日和21日简单移动平均线的交叉来捕捉趋势变化。当短期均线上穿长期均线时产生做多信号,下穿时产生做空信号。 2. 条件过滤:通过RSI指标过滤超买超卖状态,避免在极端市场条件下入场。同时使用ATR指标确保市场波动率满足交易条件。 3. 风险管理:采用基于账户净值的百分比止损,通过设定风险收益比来确定止盈位置,实现对冲风险的同时获取合理收益。
该策略通过组合多个技术指标,构建了一个相对完整的交易系统。策略在趋势市场中表现优异,具有良好的风险控制能力。通过合理设置参数和添加必要的过滤条件,策略可以适应不同的市场环境。建议在实盘使用前进行充分的回测和参数优化。
/*backtest
start: 2025-01-21 00:00:00
end: 2025-02-20 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("Simplified MA Crossover Strategy with Disable Options", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Inputs
shortLength = input.int(9, title="Short MA Length", minval=1)
longLength = input.int(21, title="Long MA Length", minval=1)
// RSI Filter
enableRSI = input.bool(true, title="Enable RSI Filter")
rsiLength = input.int(14, title="RSI Length", minval=1)
rsiOverbought = input.int(70, title="RSI Overbought Level", minval=50, maxval=100)
rsiOversold = input.int(30, title="RSI Oversold Level", minval=0, maxval=50)
// ATR Filter
enableATR = input.bool(true, title="Enable ATR Filter")
atrLength = input.int(14, title="ATR Length", minval=1)
minATR = input.float(0.005, title="Minimum ATR Threshold", minval=0)
// Risk Management
stopLossPerc = input.float(0.5, title="Stop Loss (%)", minval=0.1) / 100
riskRewardRatio = input.float(2, title="Risk-Reward Ratio", minval=1)
riskPercentage = input.float(2, title="Risk Percentage", minval=0.1) / 100
// Indicators
shortMA = ta.sma(close, shortLength)
longMA = ta.sma(close, longLength)
rsi = ta.rsi(close, rsiLength)
atr = ta.atr(atrLength)
// Conditions
longCondition = ta.crossover(shortMA, longMA)
shortCondition = ta.crossunder(shortMA, longMA)
// Apply RSI Filter (if enabled)
if (enableRSI)
longCondition := longCondition and rsi < rsiOverbought
shortCondition := shortCondition and rsi > rsiOversold
// Apply ATR Filter (if enabled)
if (enableATR)
longCondition := longCondition and atr > minATR
shortCondition := shortCondition and atr > minATR
// Risk Management
positionSize = strategy.equity * riskPercentage / (stopLossPerc * close)
takeProfitLevel = strategy.position_avg_price * (1 + stopLossPerc * riskRewardRatio)
stopLossLevel = strategy.position_avg_price * (1 - stopLossPerc)
// Execute Trades
if (longCondition)
strategy.entry("Long", strategy.long, qty=positionSize)
strategy.exit("Take Profit/Stop Loss", "Long", limit=takeProfitLevel, stop=stopLossLevel)
if (shortCondition)
strategy.entry("Short", strategy.short, qty=positionSize)
strategy.exit("Take Profit/Stop Loss", "Short", limit=strategy.position_avg_price * (1 - stopLossPerc * riskRewardRatio), stop=strategy.position_avg_price * (1 + stopLossPerc))
// Plotting
plot(shortMA, color=color.blue, title="Short MA")
plot(longMA, color=color.red, title="Long MA")
hline(rsiOverbought, "Overbought", color=color.red)
hline(rsiOversold, "Oversold", color=color.green)
plot(atr, color=color.orange, title="ATR")
plotshape(series=longCondition, title="Long Entry", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=shortCondition, title="Short Entry", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")