这是一个结合了动量和趋势的交易策略,通过多条指数移动平均线(EMA)、相对强弱指数(RSI)和随机指标(Stochastic)来识别市场趋势和动量。该策略还整合了基于平均真实波幅(ATR)的风险管理系统,包括动态止损、获利目标和跟踪止损功能,同时采用基于风险的仓位管理方法。
策略使用5条不同周期(8、13、21、34、55)的EMA来确定趋势方向。当较短周期EMA位于较长周期EMA之上时,识别为上涨趋势;反之则为下跌趋势。RSI用于确认动量,设定了不同的入场和出场阈值。随机指标作为第三重过滤器,帮助避免过度买入或卖出。风险管理系统使用ATR来设置动态止损(2倍ATR)和获利目标(4倍ATR),并采用1.5倍ATR的跟踪止损来保护利润。仓位规模基于账户权益的1%风险计算。
该策略通过结合多重技术指标和完善的风险管理系统,提供了一个全面的交易解决方案。其核心优势在于多层过滤机制和动态风险管理,但仍需要根据具体市场特征进行优化。策略的成功实施需要持续监控和调整,特别是在不同市场环境下的参数适应性。通过提出的优化方向,该策略有潜力进一步提升其稳定性和盈利能力。
/*backtest
start: 2024-11-04 00:00:00
end: 2024-12-04 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Combined Strategy (Modernized)", overlay = true)
//----------//
// MOMENTUM //
//----------//
ema8 = ta.ema(close, 8)
ema13 = ta.ema(close, 13)
ema21 = ta.ema(close, 21)
ema34 = ta.ema(close, 34)
ema55 = ta.ema(close, 55)
// Plotting EMAs for visualization
plot(ema8, color=color.red, title="EMA 8", linewidth=1)
plot(ema13, color=color.orange, title="EMA 13", linewidth=1)
plot(ema21, color=color.yellow, title="EMA 21", linewidth=1)
plot(ema34, color=color.aqua, title="EMA 34", linewidth=1)
plot(ema55, color=color.lime, title="EMA 55", linewidth=1)
longEmaCondition = ema8 > ema13 and ema13 > ema21 and ema21 > ema34 and ema34 > ema55
exitLongEmaCondition = ema13 < ema55
shortEmaCondition = ema8 < ema13 and ema13 < ema21 and ema21 < ema34 and ema34 < ema55
exitShortEmaCondition = ema13 > ema55
// ---------- //
// OSCILLATORS //
// ----------- //
rsi = ta.rsi(close, 14)
longRsiCondition = rsi < 70 and rsi > 40
exitLongRsiCondition = rsi > 70
shortRsiCondition = rsi > 30 and rsi < 60
exitShortRsiCondition = rsi < 30
// Stochastic
k = ta.stoch(close, high, low, 14)
d = ta.sma(k, 3)
longStochasticCondition = k < 80
exitLongStochasticCondition = k > 95
shortStochasticCondition = k > 20
exitShortStochasticCondition = k < 5
//----------//
// STRATEGY //
//----------//
// ATR for dynamic stop loss and take profit
atr = ta.atr(14)
stopLossMultiplier = 2
takeProfitMultiplier = 4
stopLoss = atr * stopLossMultiplier
takeProfit = atr * takeProfitMultiplier
// Trailing stop settings
trailStopMultiplier = 1.5
trailOffset = atr * trailStopMultiplier
// Risk management: dynamic position sizing
riskPerTrade = 0.01 // 1% risk per trade
positionSize = strategy.equity * riskPerTrade / stopLoss
longCondition = longEmaCondition and longRsiCondition and longStochasticCondition and strategy.position_size == 0
exitLongCondition = (exitLongEmaCondition or exitLongRsiCondition or exitLongStochasticCondition) and strategy.position_size > 0
if (longCondition)
strategy.entry("LONG", strategy.long, qty=positionSize)
strategy.exit("Take Profit Long", "LONG", stop=close - stopLoss, limit=close + takeProfit, trail_offset=trailOffset)
if (exitLongCondition)
strategy.close("LONG")
shortCondition = shortEmaCondition and shortRsiCondition and shortStochasticCondition and strategy.position_size == 0
exitShortCondition = (exitShortEmaCondition or exitShortRsiCondition or exitShortStochasticCondition) and strategy.position_size < 0
if (shortCondition)
strategy.entry("SHORT", strategy.short, qty=positionSize)
strategy.exit("Take Profit Short", "SHORT", stop=close + stopLoss, limit=close - takeProfit, trail_offset=trailOffset)
if (exitShortCondition)
strategy.close("SHORT")