
La stratégie est un système de trading avancé qui combine le modèle harmonique et le Williams Percentage Point Rating (WPR). Il fonctionne en identifiant les modèles harmoniques sur le marché (tels que les modèles Gartley, Bat, Crab et Butterfly) et en les combinant avec les niveaux de surachat et de survente de l’oscillateur Williams pour déterminer les entrées et les sorties de transactions. La stratégie adopte un mécanisme de confirmation multiple pour améliorer la précision et la fiabilité des transactions grâce à la synergie des indicateurs techniques.
La logique fondamentale de la stratégie comprend les éléments clés suivants :
Cette stratégie construit un système de trading relativement complet en combinant des modèles harmoniques et des indicateurs Williams. Ses avantages résident dans ses méthodes d’analyse multidimensionnelles et ses mécanismes parfaits de contrôle des risques, mais il doit encore prêter attention à des questions telles que l’optimisation des paramètres et l’adaptabilité à l’environnement du marché. Grâce aux orientations d’optimisation suggérées, la stabilité et la fiabilité de la stratégie devraient être encore améliorées.
/*backtest
start: 2025-01-09 00:00:00
end: 2025-01-16 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=5
strategy("Harmonic Pattern with WPR Backtest", overlay=true)
// === Inputs ===
patternLength = input.int(5, title="Pattern Length")
wprLength = input.int(14, title="WPR Length")
wprOverbought = input.float(-20, title="WPR Overbought Level")
wprOversold = input.float(-80, title="WPR Oversold Level")
riskRewardMultiplier = input.float(0.618, title="Take-Profit Risk/Reward Multiplier")
stopLossBuffer = input.float(0.005, title="Stop-Loss Buffer (%)")
// === Manual Calculation of William Percent Range (WPR) ===
highestHigh = ta.highest(high, wprLength)
lowestLow = ta.lowest(low, wprLength)
wpr = ((highestHigh - close) / (highestHigh - lowestLow)) * -100
// === Harmonic Pattern Detection (Simplified Approximation) ===
// Calculate price pivots
pivotHigh = ta.pivothigh(high, patternLength, patternLength)
pivotLow = ta.pivotlow(low, patternLength, patternLength)
// Detect Bullish and Bearish Harmonic Patterns
bullishPattern = pivotLow and close > ta.lowest(close, patternLength) // Simplified detection for bullish patterns
bearishPattern = pivotHigh and close < ta.highest(close, patternLength) // Simplified detection for bearish patterns
// === Entry Conditions ===
longCondition = bullishPattern and wpr < wprOversold
shortCondition = bearishPattern and wpr > wprOverbought
// === Stop-Loss and Take-Profit Levels ===
longEntryPrice = close
longSL = ta.valuewhen(longCondition, low, 0) * (1 - stopLossBuffer) // Stop-loss for long trades
longTP = longEntryPrice * (1 + riskRewardMultiplier) // Take-profit for long trades
shortEntryPrice = close
shortSL = ta.valuewhen(shortCondition, high, 0) * (1 + stopLossBuffer) // Stop-loss for short trades
shortTP = shortEntryPrice * (1 - riskRewardMultiplier) // Take-profit for short trades
// === Backtesting Logic ===
// Long Trade
if longCondition
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long", stop=longSL, limit=longTP)
// Short Trade
if shortCondition
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short", stop=shortSL, limit=shortTP)
// === Visualization ===
bgcolor(longCondition ? color.new(color.green, 90) : na, title="Long Entry Signal")
bgcolor(shortCondition ? color.new(color.red, 90) : na, title="Short Entry Signal")