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 Pivot RSI Divergence strategy is a swing-trading reversal system that combines two well-established technical tools: floor pivot points (objective horizontal levels of support and resistance derived from recent price action) and RSI divergence (a momentum signal where the Relative Strength Index quietly weakens even as price pushes to a fresh high or low). The Relative Strength Index, or RSI, is a bounded oscillator that measures the speed and size of recent price moves; "divergence" simply means price and the indicator are disagreeing about whether a move still has strength behind it.
Rather than chasing breakouts or riding trends, this approach is designed to identify moments where a move may be running out of fuel right at a price level the market already respects. Pivot points map where a turn is statistically more likely to occur, while RSI divergence helps confirm whether the move that reached that level is genuinely losing momentum. Average True Range (ATR), a volatility measure, is used only to size the protective stop — not to generate signals.
As a learning tool, this strategy is best suited to traders who want to study confluence-based reversal logic — the idea that two independent conditions agreeing produces a higher-quality setup than either condition alone. It is intended for educational study of mean-reverting major currency pairs on intermediate timeframes. It is not a shortcut or a profit guarantee; it is a structured framework for understanding how momentum exhaustion and key levels can be combined into a single, rule-based system.
How It Works
The strategy maintains a rolling memory of recent swing highs and swing lows, detected using a symmetric fractal pattern. A bar is confirmed as a swing low when its low is the strict minimum of the bars on either side of it (and the mirror condition defines a swing high). Each confirmed swing stores its price and the RSI reading on that bar. The system keeps the last two swing lows and the last two swing highs so it can compare them.
Every time a new swing confirms, the strategy recalculates floor pivots from the most recent closed bars and checks for a divergence setup:
- Pivot calculation: Using the highest high (H), lowest low (L), and the last close (C) over the lookback window, the strategy computes the central pivot
PP = (H + L + C) / 3, resistanceR1 = 2×PP − L, and supportS1 = 2×PP − H. A tolerance fraction defines a demand zone just above S1 and a supply zone just below R1. - Long entry — the strategy signals a potential buy when: a new swing low forms a lower low in price but a higher RSI low (bullish divergence), the two lows are no more than
DivMaxGapbars apart, and the new low sits at or inside the pivot demand zone. - Short entry — the strategy signals a potential sell when: a new swing high forms a higher high in price but a lower RSI high (bearish divergence), within the same bar-gap limit, and the new high sits at or inside the pivot supply zone.
- Stop-loss logic: The stop is placed just beyond the confirmed swing extreme, buffered by
StopAtrMult × ATR. This keeps the stop structural — tied to the actual swing that defined the setup — while the ATR buffer adapts to current volatility. - Take-profit logic: The target is set at a fixed
RewardRatiomultiple of the measured stop distance. If the risk per trade is one unit of distance, the target is placedRewardRatiounits away in the favorable direction. - Trade management: Only one position per magic number is allowed at a time, and a spread gate skips the signal whenever the current spread is wider than
MaxSpreadPoints. Once open, the position is managed entirely by its fixed stop and target.
Because entries are evaluated only at the moment a new swing confirms, price has typically already begun to turn before any order is considered — the system reacts to completed structure rather than predicting it.

Strategy Parameters
| Parameter | Default | Min | Max | Description |
|---|---|---|---|---|
| PivotPeriod | 20 | 8 | 60 | Number of recent closed bars used to build the rolling pivot reference window. |
| RsiPeriod | 14 | 7 | 28 | Smoothing period for the RSI momentum oscillator. |
| SwingHalf | 2 | 1 | 5 | Fractal half-width: bars required on each side to confirm a swing high or low. |
| DivMaxGap | 30 | 6 | 80 | Maximum number of bars allowed between the two swing extremes for a valid divergence. |
| PivotTolFrac | 0.30 | 0.00 | 1.00 | How far inside the pivot range still counts as being "at" support or resistance. |
| AtrPeriod | 14 | 7 | 30 | ATR period used to size the protective stop buffer. |
| StopAtrMult | 0.80 | 0.10 | 3.00 | Stop buffer beyond the swing extreme, expressed in ATR multiples. |
| RewardRatio | 1.80 | 0.80 | 4.00 | Take-profit distance as a multiple of the structural stop distance. |
| MaxSpreadPoints | 30 | 1 | 200 | Skip the trade if the current spread (in points) is wider than this. |
| Lots | 0.10 | 0.01 | 1.00 | Fixed order volume per trade. |
| Magic | 4271 | 0 | 9,999,999 | Unique identifier the EA uses to track its own positions. |

Recommended Chart Settings
The Pivot RSI Divergence strategy was designed with a mean-reverting major currency pair in mind — for example GBPUSD or EURUSD — on the M30 or H1 timeframe, reflecting its swing-trading character. These pairs tend to oscillate within ranges often enough to give divergence-at-a-pivot setups room to play out, and the intermediate timeframes filter much of the intrabar noise that affects faster charts.
That said, every market behaves differently across time. A pair and timeframe that produced clean setups during one period may behave very differently when volatility regimes, liquidity, or trend conditions change. Treat the recommended settings as a starting point for study and forward-testing, not as a fixed configuration that will behave identically in every environment.
How to Install on MetaTrader 5
- Download the
PivotRSIDivergence.ex5file 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
The core strength of this approach is its insistence on confluence. A naked RSI-divergence signal fires constantly across a chart, and many "lower-low / higher-RSI" prints happen mid-range where they mean very little — in a strong trend, such signals are routinely overrun. Likewise, a naked pivot bounce assumes every touch of support or resistance holds, which it does not. By requiring the divergence to occur at a pivot demand or supply level, the strategy keeps only the setups where weakening momentum meets a price the market has historically respected, which may help filter out lone-signal noise.
Its limitations follow directly from its design. As a reversal system, it is inherently counter-trend: in a powerful, sustained trend, divergence signals can appear repeatedly while price keeps marching against the setup, and the stop may be hit before any reversal materializes. Pivot levels themselves are statistical, not magical — they are respected often enough to be useful, but they break regularly during high-impact news and strong directional moves. The fixed reward-to-risk target also means trades may close at the target before a larger move develops, or give back unrealized gains if the market reverses before reaching it.
This EA is best understood as a study of reversal mechanics rather than a finished, hands-off solution. Its behaviour is sensitive to parameter choices such as the swing fractal width, the divergence gap limit, and the pivot tolerance, and those interactions are exactly what makes it worth examining on a demo account.
Risk Management Tips
Sound risk management matters far more than any single entry signal. As general educational principles:
- Size positions deliberately. Many traders limit the capital at risk on any one trade to roughly 1–2% of account equity, adjusting lot size to the stop distance rather than trading a fixed lot regardless of risk.
- Test on a demo account first. Run the strategy in a risk-free simulated environment long enough to understand how often it trades and how it behaves in trending versus ranging conditions before considering any live capital.
- Understand drawdown. Even a logically sound system will experience losing streaks. Knowing the depth and duration of historical drawdowns helps you set realistic expectations and avoid abandoning a plan at the worst possible moment.
- Account for costs. Spreads, commissions, and slippage all erode results, which is why the built-in spread gate exists — but real-world execution can still differ from a backtest.
- Never risk money you cannot afford to lose. Leverage magnifies both gains and losses, and no configuration removes the possibility of loss.
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: PivotRSIDivergence.ex5 (1 downloads)
- Source Code: PivotRSIDivergence.mq5 (2 downloads)
- Documentation: PivotRSIDivergence.pdf (2 downloads)