Strategy vault / Multi-timeframe
Multi Timeframe Trading Strategy Combining Harmonic Patterns and Williams R
This strategy is an advanced trading system that combines Harmonic Patterns with the Williams Percent Range (WPR) indicator. It identifies harmonic formations (such as Gartley, Bat, Crab, and Butterfly patterns) in…

Overview
This strategy is an advanced trading system that combines Harmonic Patterns with the Williams Percent Range (WPR) indicator. It identifies harmonic formations (such as Gartley, Bat, Crab, and Butterfly patterns) in the market and uses WPR's overbought/oversold levels to determine trade entry and exit points. The strategy employs multiple confirmation mechanisms, utilizing the synergy of technical indicators to enhance trading accuracy and reliability.
Strategy Principles
The core logic includes several key components:
- Harmonic Pattern Recognition: Uses price pivot points to identify potential harmonic formations by analyzing the relationships between highs and lows.
- Williams %R Calculation: Employs a custom period for calculating WPR, analyzing relationships between high, low, and closing prices to determine market conditions.
- Entry Conditions:
- Long Entry: When a bullish harmonic pattern appears and WPR is in oversold territory
- Short Entry: When a bearish harmonic pattern appears and WPR is in overbought territory
- Risk Management: Implements dynamic stop-loss based on recent lows/highs and sets take-profit levels using risk-reward ratios.
Strategy Advantages
- Multi-dimensional Analysis: Combines pattern analysis with momentum indicators for more reliable trading signals.
- Robust Risk Control: Uses dynamic stop-loss and risk-reward based take-profit settings to effectively control risk per trade.
- High Adaptability: Can be adapted to different market environments and instruments through parameter optimization.
- Signal Confirmation Mechanism: Reduces false signals through dual confirmation using harmonic patterns and WPR.
Strategy Risks
- Pattern Recognition Risk: Simplified harmonic pattern recognition may lead to misidentification of some formations.
- Parameter Sensitivity: Multiple parameters require careful optimization, as improper settings can affect strategy performance.
- Market Environment Dependency: May underperform in highly volatile or ranging markets.
- Signal Lag: Technical indicator-based signals may have inherent lag.
Strategy Optimization Directions
- Enhanced Pattern Recognition:
- Add stricter harmonic ratio validation
- Incorporate price structure analysis for improved pattern identification
- Signal Filtering:
- Add trend filters
- Consider volatility indicators for market environment adaptation
- Risk Management Optimization:
- Implement dynamic risk-reward ratio adjustments
- Add volatility-based position sizing
Summary
This strategy builds a comprehensive trading system by combining harmonic patterns with the Williams %R indicator. Its strengths lie in its multi-dimensional analysis approach and robust risk control mechanisms, though attention must be paid to parameter optimization and market environment adaptation. Through the suggested optimization directions, the strategy's stability and reliability can be further enhanced.
Source Pine Script
/*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")
Published by ChaoZhang on the FMZ strategy square · last modified 2025-01-17. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Multi-Timeframe-Trading-Strategy-Combining-Harmonic-Patterns-and-Williams-R.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- Multi Timeframe Liquidity Pivot Heatmap StrategyPine Script · Multi-timeframe · 4h
- Multi Timeframe Smart Money Concept Support and Resistance Dynamic Trading StrategyPine Script · Multi-timeframe · 2d
- Advanced Multi Timeframe Ichimoku Cloud Trading Strategy with Dynamic Multidimensional AnalysisPine Script · Multi-timeframe · 2h
- High Frequency Quantitative Multi Timeframe Heatmap Sniper StrategyPine Script · Multi-timeframe · 1h
- Multi Timeframe Quantitative Trading Strategy Based on EMA Smoothed RSI and ATR Dynamic Stop Loss Take ProfitPine Script · Multi-timeframe · 1d
- Multi Timeframe EMA with Fibonacci Retracement and Pivot Points Trading StrategyPine Script · Multi-timeframe · 1d