该策略是一个基于威廉指标(%R)、移动平均线趋势指标(MACD)和指数移动平均线(EMA)的多重指标组合策略。通过判断市场超买超卖状态,结合动量指标的变化趋势和均线支撑,构建了一个完整的趋势跟踪交易系统。该策略不仅包含了入场信号的生成,还设计了完善的风险管理机制。
策略主要基于以下三个核心指标的协同配合: 1. 威廉指标(%R)用于识别市场的超买超卖状态,当指标从超卖区(-80以下)向上突破时,表明可能出现看涨反转信号 2. MACD指标通过快线与慢线的交叉确认动量变化,当MACD线上穿信号线时,进一步确认上涨动能 3. 55周期EMA作为趋势过滤器,只有当价格位于EMA之上时才考虑做多,反之考虑做空
策略在同时满足以上三个条件时才会开仓。此外,策略还incorporates了基于风险收益比的止盈止损机制,通过设定固定的止损百分比和风险收益比来控制每笔交易的风险。
该策略通过多重技术指标的协同配合,构建了一个较为完善的趋势跟踪交易系统。策略的主要特点是信号可靠性高、风险控制明确,但也存在一定的滞后性和参数敏感性问题。通过建议的优化方向,策略还有进一步提升的空间。在实盘应用时,建议先通过回测充分验证参数组合,并结合市场特征进行针对性优化。
/*backtest
start: 2025-02-19 00:00:00
end: 2025-02-23 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("Williams %R & MACD Swing Strategy", overlay=true)
// INPUTS
length_wpr = input(14, title="Williams %R Length")
overbought = input(-20, title="Overbought Level")
oversold = input(-80, title="Oversold Level")
// MACD Inputs
fastLength = input(12, title="MACD Fast Length")
slowLength = input(26, title="MACD Slow Length")
signalSmoothing = input(9, title="MACD Signal Smoothing")
// EMA for Trend Confirmation
ema_length = input(55, title="EMA Length")
ema55 = ta.ema(close, ema_length)
// INDICATORS
wpr = ta.wpr(length_wpr)
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalSmoothing)
// LONG ENTRY CONDITIONS
longCondition = ta.crossover(wpr, oversold) and ta.crossover(macdLine, signalLine) and close > ema55
if longCondition
strategy.entry("Long", strategy.long)
// SHORT ENTRY CONDITIONS
shortCondition = ta.crossunder(wpr, overbought) and ta.crossunder(macdLine, signalLine) and close < ema55
if shortCondition
strategy.entry("Short", strategy.short)
// RISK MANAGEMENT
riskRewardRatio = input(1.5, title="Risk-Reward Ratio")
stopLossPerc = input(2, title="Stop Loss %") / 100
takeProfitPerc = stopLossPerc * riskRewardRatio
longSL = strategy.position_avg_price * (1 - stopLossPerc)
longTP = strategy.position_avg_price * (1 + takeProfitPerc)
shortSL = strategy.position_avg_price * (1 + stopLossPerc)
shortTP = strategy.position_avg_price * (1 - takeProfitPerc)
strategy.exit("Take Profit / Stop Loss", from_entry="Long", loss=longSL, profit=longTP)
strategy.exit("Take Profit / Stop Loss", from_entry="Short", loss=shortSL, profit=shortTP)