Disclaimer: This article is for educational and informational purposes only. It does not constitute financial or investment advice. Trading forex and CFDs carries significant risk of loss. Past performance of any strategy — including backtests — does not guarantee future results. Never trade with money you cannot afford to lose.
What Is This Strategy?
The Swing Pivot Pin Reversal is a pure price-action reversal strategy that combines two classic technical-analysis concepts: fractal swing pivots (which define dynamic support and resistance) and the pin bar (a single-candle rejection pattern with a long wick and a small body). Rather than relying on lagging oscillators or moving-average crossovers, this strategy reads the raw structure of the candles themselves to identify moments when price probes a key level, fails, and snaps back — a behaviour often associated with liquidity sweeps and stop-runs.
A swing pivot is simply a turning point on the chart. A fractal swing high (resistance) is a closed bar whose high is strictly greater than the highs of the bars immediately on either side of it; a swing low (support) is the mirror image. The strategy continuously tracks the most recently confirmed swing high above price and swing low below price, treating these as its active decision levels. When a candle pierces one of these levels but closes back inside it with the shape of a pin bar, the strategy interprets that as rejection — buyers defending support or sellers defending resistance.
This approach is designed primarily for range-bound and mean-reverting market conditions, where price respects horizontal levels and reverses after testing them. It is best suited to traders who want to study how support/resistance and candlestick rejection patterns can be encoded into objective, rule-based logic. As a learning tool, it offers a clear, transparent example of how discretionary price-action concepts translate into a mechanical Expert Advisor (EA). It is not a "set-and-forget" system, and it should be treated as an analytical study rather than a profit opportunity.
How It Works
The strategy evaluates the market once per completed candle (it ignores the still-forming bar), then applies a sequence of filters. Here is the logic in plain English:
- Build the levels: On each new bar, the strategy checks whether the candle that sits
PivotLookback(K) bars back qualifies as a fractal swing high or swing low. If it does, that price becomes the new active resistance or support level. Levels persist until a fresh pivot replaces them. - Identify the signal candle: The most recently closed bar is the "signal bar." The strategy measures its total range, its body size, its upper wick, its lower wick, and where the close sits within the range (0 = at the low, 1 = at the high).
- Long (buy) entry — bullish pin reclaiming support: The strategy signals a potential long when all of these are true:
- The body is small relative to the range (
body / range ≤ BodyMaxRatio). - The lower wick dominates the candle (
lower wick / range ≥ WickRatio). - The close finishes in the upper portion of the range (close position ≥ 0.55).
- The bar's low dipped to or below active support, yet the close finished back above support — a sweep and reclaim of the level.
- Short (sell) entry — bearish pin reclaiming resistance: The mirror conditions apply. The body is small, the upper wick dominates, the close finishes in the lower portion of the range (close position ≤ 0.45), and the bar's high pierced resistance but the close finished back below it.
- One position at a time: The strategy holds only a single open position per symbol and magic number. While a trade is live, it keeps updating swing levels but will not stack new entries.
- Stop-loss logic: Stops are anchored to market structure, not a fixed pip count. For a long, the stop sits below the signal bar's low minus a buffer of
SlAtrBuffer × ATR; for a short, above the signal bar's high plus the same buffer. ATR (Average True Range) is a volatility measure, so the buffer automatically widens in fast markets and tightens in quiet ones. The trade is only submitted if the calculated stop is on the correct side of the entry price. - Take-profit logic: Targets are a volatility multiple —
TpAtrMult × ATRaway from the entry. With the default settings, the target distance is roughly twice the ATR, while the stop is anchored to the wick plus half an ATR, giving the approach a structurally favourable reward-to-risk geometry on paper.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| PivotLookback | 3 | 2 | 6 | Number of bars (K) required on each side of a candle for it to count as a fractal swing pivot. Higher values produce fewer, more significant levels. |
| WickRatio | 0.55 | 0.40 | 0.75 | Minimum size of the dominant (rejection) wick as a fraction of the candle's full range. Higher values demand a more pronounced rejection. |
| BodyMaxRatio | 0.40 | 0.20 | 0.60 | Maximum body size as a fraction of the candle's range. Lower values enforce a smaller, more indecisive body — a stricter pin-bar filter. |
| AtrPeriod | 14 | 7 | 28 | Look-back period for the Average True Range used to size the stop buffer and take-profit distance. |
| SlAtrBuffer | 0.50 | 0.10 | 1.50 | Extra distance beyond the rejection wick for the stop-loss, expressed in ATR multiples. |
| TpAtrMult | 2.00 | 1.00 | 5.00 | Take-profit distance from entry, expressed in ATR multiples. |
| Lots | 0.10 | 0.01 | 1.00 | Fixed trade volume in lots. |

Recommended Chart Settings
Because the strategy reads all bar data through the chart's selected timeframe, it will run on whatever timeframe you attach it to. Pin-bar rejection patterns at swing levels are most commonly studied on the higher intraday and swing timeframes — such as H1, H4, and D1 — where individual candles carry more weight and false signals from market noise tend to be reduced. Liquid major forex pairs (for example EUR/USD or GBP/USD) are a sensible starting point for study because their clean structure makes swing pivots easier to identify.
That said, no single symbol or timeframe is universally "correct." Behaviour can change dramatically from one instrument to another and across different volatility regimes. Always test the strategy across multiple symbols and timeframes in the Strategy Tester before drawing any conclusions, and remember that results will vary as market conditions change.
How to Install on MetaTrader 5
- Download the .ex5 file from the link below
- Copy it to your MT5
MQL5\Expertsfolder - Restart MetaTrader 5 or refresh the Navigator panel
- Drag the EA onto a chart matching the recommended symbol and timeframe
- Configure the input parameters and enable Algo Trading
What to Consider Before Using This EA
Strengths of the approach. The strategy is built on well-established price-action concepts. Its entries are objective and repeatable, removing much of the discretionary guesswork that surrounds manual pin-bar trading. Anchoring the stop to the actual rejection wick — rather than an arbitrary pip value — means the risk is defined by genuine market structure, and using ATR for both the buffer and the target lets the system adapt to changing volatility. The "one position at a time" rule keeps exposure contained and the logic easy to follow.
Known limitations. Reversal strategies, by their nature, trade against the immediate move, which means they can struggle badly in strong, sustained trends. A market that is genuinely breaking out will repeatedly sweep a level and keep going, turning what looks like a rejection into a losing fade. Pin bars and swing pivots are also somewhat subjective concepts; the WickRatio and BodyMaxRatio filters approximate them numerically, but the "right" thresholds differ between instruments and timeframes. Because only the most recently confirmed pivot is used, the active level can sometimes be stale or located at a price that is no longer meaningful.
Where it may underperform. Expect weaker behaviour during low-liquidity sessions, around high-impact news releases when spreads widen and wicks become erratic, and in choppy conditions that generate many marginal pin-bar lookalikes. The strategy may indicate a signal that historically would have reversed, yet still fail when the broader context is trending. Treat every signal as a hypothesis to be evaluated, not a certainty.
Risk Management Tips
Sound risk management matters far more than any single entry rule. Keep these general principles in mind:
- Risk a small, fixed fraction per trade. A common educational guideline is to risk no more than 1–2% of account equity on any single position. The fixed
Lotsinput does not automatically scale to your balance, so calculate your position size against your stop distance manually. - Test on a demo account first. Run the EA on a demo or in the MT5 Strategy Tester for an extended period before considering any live use, so you understand how it behaves across different conditions.
- Understand drawdown. Even a structurally sound strategy will experience losing streaks. Know the maximum historical drawdown you are studying and ask whether you could tolerate it emotionally and financially.
- Mind costs. Spreads, commissions, and slippage all erode results, especially on lower timeframes where trades are more frequent. Factor realistic costs into any evaluation.
- Never over-leverage. Leverage magnifies losses as readily as gains. Use it conservatively, and never trade with money you cannot afford to lose.
Risk Warning
Trading foreign exchange, CFDs, and other leveraged financial instruments involves substantial risk of loss and is not suitable for all investors. The strategies and tools discussed on this page are provided for educational purposes only and do not constitute financial advice, investment recommendations, or solicitation to trade. Always consult a qualified financial adviser before making trading decisions. Past backtest performance is not indicative of future results.
Downloads
- Expert Advisor: SwingPivotPinReversal.ex5 (7 downloads)
- Source Code: SwingPivotPinReversal.mq5 (5 downloads)
- Documentation: SwingPivotPinReversal.pdf (5 downloads)