
Chiến lược này là một hệ thống giao dịch tiên tiến kết hợp mô hình hài hòa và Xếp hạng phần trăm Williams (WPR). Phương pháp này hoạt động bằng cách xác định các mô hình hài hòa trên thị trường (như mô hình Gartley, Dơi, Cua và Bướm) và kết hợp chúng với mức quá mua và quá bán của bộ dao động Williams để xác định điểm vào và thoát lệnh giao dịch. Chiến lược này áp dụng cơ chế xác nhận nhiều lần để cải thiện độ chính xác và độ tin cậy của giao dịch thông qua sự kết hợp của các chỉ báo kỹ thuật.
Logic cốt lõi của chiến lược bao gồm những phần chính sau:
Chiến lược này xây dựng một hệ thống giao dịch tương đối hoàn chỉnh bằng cách kết hợp các mô hình hài hòa và chỉ báo Williams. Ưu điểm của nó nằm ở phương pháp phân tích đa chiều và cơ chế kiểm soát rủi ro hoàn hảo, nhưng vẫn cần lưu ý đến các vấn đề như tối ưu hóa tham số và khả năng thích ứng với môi trường thị trường. Thông qua các hướng tối ưu hóa được đề xuất, tính ổn định và độ tin cậy của chiến lược dự kiến sẽ được cải thiện hơn nữa.
/*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")