该策略是一个结合了谐波模式和威廉指标(WPR)的高级交易系统。它通过识别市场中的谐波形态(如Gartley、蝙蝠、螃蟹和蝴蝶模式),并结合威廉指标的超买超卖水平来确定交易入场和出场时机。策略采用了多重确认机制,通过技术指标的协同作用来提高交易的准确性和可靠性。
策略的核心逻辑包含以下几个关键部分: 1. 谐波模式识别:使用价格转折点来识别潜在的谐波形态,通过分析高点和低点的关系来确定市场结构。 2. 威廉指标计算:采用自定义周期计算威廉指标,通过分析最高价、最低价和收盘价之间的关系来判断市场状态。 3. 入场条件: - 多头入场:当出现看涨谐波形态且威廉指标处于超卖区域时 - 空头入场:当出现看跌谐波形态且威廉指标处于超买区域时 4. 风险管理:使用基于近期低点/高点的动态止损,并通过风险收益比来设定止盈位置。
该策略通过结合谐波模式和威廉指标,构建了一个较为完整的交易系统。其优势在于多维度的分析方法和完善的风险控制机制,但仍需要注意参数优化和市场环境适应性的问题。通过建议的优化方向,策略的稳定性和可靠性有望得到进一步提升。
/*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")