
This strategy is a multi-indicator combination strategy based on Williams %R, Moving Average Convergence Divergence (MACD), and Exponential Moving Average (EMA). By assessing market overbought/oversold conditions, combined with momentum indicator trends and moving average support, it creates a complete trend-following trading system. The strategy includes both entry signal generation and comprehensive risk management mechanisms.
The strategy primarily relies on the coordination of three core indicators: 1. Williams %R is used to identify market overbought/oversold conditions, with a bullish reversal signal potentially occurring when the indicator breaks above the oversold zone (below -80) 2. MACD confirms momentum changes through crossovers of fast and slow lines, with additional confirmation when the MACD line crosses above the signal line 3. 55-period EMA serves as a trend filter, considering long positions only when price is above EMA, and vice versa
The strategy only opens positions when all three conditions are simultaneously met. Additionally, it incorporates a risk-reward based stop-loss and take-profit mechanism, controlling risk for each trade through fixed stop-loss percentages and risk-reward ratios.
The strategy constructs a relatively comprehensive trend-following trading system through the coordination of multiple technical indicators. Its main features are high signal reliability and clear risk control, though it faces some challenges with lag and parameter sensitivity. Through the suggested optimization directions, there is room for further improvement. For live trading implementation, it is recommended to thoroughly validate parameter combinations through backtesting and optimize specifically based on market characteristics.
/*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)