PipLedger
Today's forex newsNFP, CPI, FOMC and other high-impact eventsEconomic calendarCalendar →

RSI divergence strategy: trading reversals with exact rules and a free Pine Script

When the price makes a new low but the RSI doesn't, the selling is losing force. That's divergence, and it's one of the most popular ways to look for reversals. It's also one of the easiest to misuse, because divergence can appear again and again while the price keeps falling. This strategy adds confirmation: it only buys when the price trades above the bounce. Here are the rules, a worked EURUSD example with the lot size and a free TradingView script.

By M. A. Horaira. Updated 10 October 2026. 10 minute read.

The rules at a glance

  • Market: any major pair on the 1-hour chart; the example uses EURUSD
  • Swing lows: a candle whose low is below the 5 candles before it and the 3 after it (so it's confirmed 3 candles later)
  • Divergence: a new swing low below the previous one while the RSI (14) at the new low is higher; the first low's RSI must be under 30, and the two lows 5 to 60 candles apart
  • Entry: a buy stop just above the highest high since the second low (plus 5% of an ATR), open for 5 candles; cancelled if a candle closes below the second low
  • Stop loss: a quarter of an ATR below the second low
  • Target: twice the risk (2R)
  • Bearish: the mirror image: a higher high with a lower RSI high, the first one above 70

What RSI divergence is

The RSI measures momentum: how strong the recent up moves are compared with the down moves. In a falling market, each new low usually comes with a low RSI. When the price makes a lower low but the RSI makes a higher low, the latest push down had less force behind it than the one before. That's bullish divergence. Bearish divergence is the opposite: a higher high in price with a lower high in the RSI.

PriceRSIWhat it suggests
Bullish divergenceLower lowHigher lowSelling is weakening; a turn up is possible
Bearish divergenceHigher highLower highBuying is weakening; a turn down is possible
Hidden bullishHigher lowLower lowOften read as a pullback in an uptrend (not traded here)
Hidden bearishLower highHigher highOften read as a rally in a downtrend (not traded here)

Why divergence alone isn't a signal

Divergence shows momentum fading, not the price turning. In a strong downtrend you can see two or three divergences in a row while the price keeps falling. That's why this strategy doesn't buy the second low itself. It places a buy stop above the bounce and only gets in if the price shows it's turning. If the price closes below the second low first, the order is cancelled.

There's a second catch, and it matters for any divergence indicator. A swing low can only be confirmed after the candles to its right have formed, three of them here. Many scripts draw the divergence mark back on the swing candle, so on a finished chart it looks as if you knew at the low. You didn't. The trade in this strategy is placed on the confirmation candle, three candles later, and the backtest uses that timing.

The rules, step by step

1. Find two swing lows

On a 1-hour chart, a swing low is a candle whose low is below the five candles before it and the three after it. Note the RSI (14) at each one.

2. Check for bullish divergence

The newer swing low must be below the previous one, while its RSI is higher. The first low's RSI must have been under 30, so the market was oversold, and the two lows must be between 5 and 60 candles apart.

3. Place a buy stop above the bounce

When the second low is confirmed, place a buy stop just above the highest high since that low, plus 5% of an ATR. Leave it for five candles. Cancel it if it doesn't fill, or if a candle closes below the second low.

4. Stop below the low, target 2R

The stop goes a quarter of an ATR below the second low. The target is twice the risk. Bearish divergence works the same way upside down, with a sell stop under the dip.

Worked example: EURUSD, 1-hour chart

Target 1.16936Buy stop 1.16384Stop 1.16108Low 1Lower lowOrder fills2R7030Low 1Higher lowRSI (14)

RSI (14)

Illustrative chart drawn for this guide to show the rules. It isn't a real day's prices. EURUSD, 1-hour candles, with the 14-period RSI below.

EURUSD falls hard to a swing low at 1.1619, with the RSI at 24.2, under 30. It bounces, then drifts down to a lower low at 1.1613, 25 candles later. This time the RSI only falls to 30.7: a higher low, so there's bullish divergence. The low is confirmed three candles later, and the highest high since it is 1.1638. Adding 5% of the 8.9-pip ATR puts the buy stop at 1.16384.

EURUSD long
Buy stop1.16384
Stop loss (a quarter of an ATR below the second low)1.16108, 27.6 pips away
Target (2R)1.16936, 55.2 pips away
Lot size at 1% of $10,000$100 ÷ (27.6 pips × $10) = 0.362, rounded down to 0.36 lots
Loss if the stop is hit$99.36
Profit at the target$198.72

The next candle trades through the buy stop, and EURUSD rallies to the target 10 candles after the fill. Notice the cost of waiting for confirmation: the entry is 25 pips above the low, so the stop is wider than if you had bought the low itself. In return, you skip the divergences that never bounce.

Risk management

Common mistakes

  1. Buying the divergence before it's confirmed. Until the swing low has formed, there's no divergence yet.
  2. Trusting marks drawn on past swings. Divergence indicators that plot on the swing candle show signals earlier than they could be known.
  3. Seeing divergence everywhere. Compare swing lows with swing lows, not with any random dip.
  4. Ignoring a strong trend. In a powerful move, divergence can repeat many times before a turn.

Backtest it yourself on TradingView

This page doesn't quote a win rate or a profit figure, and you should be wary of anyone who does without showing the test. Results change with the market, the dates, the data feed and the costs you put in. The honest way is to run the test yourself, and the free script below does the work in a couple of minutes.

  1. Open the chart. On TradingView, open EURUSD on the 1-hour chart.
  2. Add the script. Open the Pine Editor from the Pine icon in the panel on the right of the chart (older layouts have it as a tab under the chart), delete the code that's already there, paste this strategy's code and click "Add to chart".
  3. Put in your costs. Open the strategy's settings and go to Properties. Enter your broker's commission and a little slippage. A test without costs flatters every strategy, and short-term ones most of all.
  4. Read the Strategy Tester. The panel under the chart shows the net profit, the maximum drawdown, the profit factor, the number of trades and a list of every trade. Click a few trades and check on the chart that each one follows the rules. Trade sizes are shown in units rather than lots: 100,000 units is one lot of a forex pair, and 100 ounces is one lot of gold.
  5. Change one setting at a time. Compare the swing settings (5 and 3 against 5 and 5), the oversold level (25, 30 and 35), how far apart the lows can be, how long the order stays open and the 2R target against 1.5R. Then test the bearish side on its own, and try the 4-hour chart.

As a rough guide, don't trust a result with fewer than 100 trades, a profit factor under 1 once costs are in, or a drawdown you couldn't sit through with real money. Settings tuned to look good on one stretch of history often fail on the next, so check the same settings on dates you didn't tune them on, then demo trade the strategy for a few weeks. How much history you can test depends on your TradingView plan: the free plan loads 5,000 candles, which is a few months of 15-minute candles but years of daily ones.

The script sizes each trade from the stop loss and your risk percentage, starts with $10,000 and assumes 1:100 leverage (a 1% margin setting), so the tester doesn't flag margin calls on normal forex trade sizes. Change these under Properties to match your account. By default TradingView fills orders at the open of the candle after the signal, so the fill can differ a little from the signal candle's close.

Download the free Pine Script and PDF

The script is written in Pine Script version 6 for this guide and follows the rules above. It can't read the economic calendar, so skipping news days is up to you. It's free to use, change and share. The PDF is a one-page cheat sheet with the four kinds of divergence, the rules, a worked example and a checklist, to keep next to your chart.

Show the code (Pine Script v6, 100 lines)
//@version=6
// RSI Divergence reversal strategy by PipLedger (https://pipledgerfx.com/rsi-divergence-strategy)
// Bullish divergence: the price makes a lower swing low while the RSI makes a higher low, after the first low was oversold. A buy stop above the bounce confirms the turn. Bearish divergence is the mirror image.
// Free to use and change. For education and backtesting only; not financial advice.
strategy("PipLedger: RSI Divergence Reversal", shorttitle="RSI Divergence", overlay=true, initial_capital=10000, pyramiding=0, default_qty_type=strategy.fixed, default_qty_value=1, margin_long=1, margin_short=1, currency=currency.USD)

// ---------- Inputs
rsiLen    = input.int(14, "RSI length", minval=2)
leftBars  = input.int(5, "Swing: candles to the left", minval=1)
rightBars = input.int(3, "Swing: candles to the right (confirmation delay)", minval=1)
minGap    = input.int(5, "Swings at least this many candles apart", minval=1)
maxGap    = input.int(60, "Swings at most this many candles apart", minval=5)
osLvl     = input.float(30.0, "First low's RSI must be below", minval=5.0, maxval=50.0)
obLvl     = input.float(70.0, "First high's RSI must be above", minval=50.0, maxval=95.0)
bufAtr    = input.float(0.05, "Entry buffer (x ATR 14)", minval=0.0, step=0.01)
stopBuf   = input.float(0.25, "Stop buffer beyond the swing (x ATR)", minval=0.0, step=0.05)
validBars = input.int(5, "Candles the entry order stays open", minval=1)
rr        = input.float(2.0, "Target (R multiple)", minval=0.5, step=0.25)
riskPct   = input.float(1.0, "Risk per trade (% of equity)", minval=0.1, maxval=5.0, step=0.1)

// ---------- Helpers
fx = strategy.convert_to_account(1.0)  // one unit of the chart's quote currency in account currency (1 on USD-quoted charts)
calcQty(float entry, float stop) =>
    float dist = math.abs(entry - stop)
    dist > 0 and not na(fx) ? strategy.equity * riskPct / 100 / (dist * syminfo.pointvalue * fx) : 0.0

rsi = ta.rsi(close, rsiLen)
atr = ta.atr(14)
pl  = ta.pivotlow(low, leftBars, rightBars)
ph  = ta.pivothigh(high, leftBars, rightBars)
rAt = rsi[rightBars]                         // the RSI on the swing candle itself
hiSince = ta.highest(high, rightBars + 1)    // from the swing candle to now
loSince = ta.lowest(low, rightBars + 1)

// ---------- Divergences, found when the newer swing is confirmed
var float l1 = na
var float rl1 = na
var int   bl1 = na
var float h1 = na
var float rh1 = na
var int   bh1 = na
bullDiv = false
bearDiv = false
if not na(pl)
    int b = bar_index - rightBars
    bullDiv := not na(l1) and pl < l1 and rAt > rl1 and rl1 < osLvl and b - bl1 >= minGap and b - bl1 <= maxGap
    l1  := pl
    rl1 := rAt
    bl1 := b
if not na(ph)
    int b = bar_index - rightBars
    bearDiv := not na(h1) and ph > h1 and rAt < rh1 and rh1 > obLvl and b - bh1 >= minGap and b - bh1 <= maxGap
    h1  := ph
    rh1 := rAt
    bh1 := b

var int   pend = 0     // 1 = a buy stop waits, -1 = a sell stop waits
var int   pBar = na
var float pLvl = na    // the second swing's low (or high): a close beyond it cancels the order
flat     = strategy.position_size == 0
newLong  = flat and bullDiv
newShort = flat and bearDiv and not bullDiv

// a trade has opened, the order is too old, or the price closed beyond the swing: cancel what's waiting
if pend != 0 and not newLong and not newShort and (not flat or bar_index - pBar >= validBars or (pend == 1 and close < pLvl) or (pend == -1 and close > pLvl))
    strategy.cancel("Long")
    strategy.cancel("Short")
    pend := 0

// ---------- Orders: stop order beyond the bounce, stop loss beyond the second swing
if newLong
    strategy.cancel("Short")
    float entry = hiSince + bufAtr * atr
    float sl    = pl - stopBuf * atr
    float q     = calcQty(entry, sl)
    pend := 0
    if q > 0
        strategy.entry("Long", strategy.long, qty=q, stop=entry)
        strategy.exit("Long exit", "Long", stop=sl, limit=entry + (entry - sl) * rr)
        pend := 1
        pBar := bar_index
        pLvl := pl
if newShort
    strategy.cancel("Long")
    float entry = loSince - bufAtr * atr
    float sl    = ph + stopBuf * atr
    float q     = calcQty(entry, sl)
    pend := 0
    if q > 0
        strategy.entry("Short", strategy.short, qty=q, stop=entry)
        strategy.exit("Short exit", "Short", stop=sl, limit=entry - (sl - entry) * rr)
        pend := -1
        pBar := bar_index
        pLvl := ph

// ---------- Chart (add TradingView's RSI indicator to see the divergence on the oscillator)
// the marks sit on the confirmation candle, where the order is placed, not back on the swing candle
plotshape(bullDiv, "Bullish divergence", shape.triangleup, location.belowbar, color.teal, size=size.small)
plotshape(bearDiv, "Bearish divergence", shape.triangledown, location.abovebar, color.red, size=size.small)
plot(pend != 0 ? pLvl : na, "Swing being defended", color=color.new(color.orange, 0), style=plot.style_linebr)

Trading this from India

Residents can trade EURUSD, GBPUSD and USDJPY futures and options on NSE and BSE through a SEBI-registered broker. The contracts are quoted the same way as the spot pair, one lot is 1,000 units of the base currency, and they're cash-settled in rupees. They trade only from 9 a.m. to 7:30 p.m. IST, volumes are thin and not every broker offers them, so check the hours and the spread first. On the exchange contracts one EURUSD lot is €1,000, so a pip is worth $0.10 a lot. Trading forex or CFDs with offshore online platforms isn't allowed for residents under FEMA, even if the app is easy to download. Details are in is forex trading legal in India.

Related strategies: ADX trend following, 20 and 50 EMA pullback, ATR trailing stop, EMA and RSI(2), 9 and 21 EMA crossover, MACD and 200 EMA, RSI 60/40. All 34 strategies are compared on one page in forex trading strategies.

Quick answers

What is RSI divergence?

It's when the price and the RSI disagree. Bullish divergence is a lower low in price with a higher low in the RSI; bearish divergence is a higher high in price with a lower high in the RSI. It suggests the move is losing momentum.

Is RSI divergence reliable?

On its own, not very: divergence can appear several times while a trend carries on. These rules add confirmation, entering only if the price trades above the bounce, and the free script lets you test how often that works on your market.

What's the difference between bullish and bearish divergence?

Bullish divergence happens at lows and points to a possible turn up; bearish divergence happens at highs and points to a possible turn down. This strategy trades both, with a buy stop or a sell stop for confirmation.

What is hidden divergence?

Hidden bullish divergence is a higher low in price with a lower low in the RSI; it's usually read as a pullback in an uptrend rather than a reversal. This strategy only trades regular divergence.

Which timeframe is best for RSI divergence?

This strategy uses the 1-hour chart. Divergence on the 4-hour and daily charts appears less often and tends to lead to bigger moves; on very short timeframes it's frequent and noisy.

Does RSI divergence repaint?

The divergence itself doesn't change once it's confirmed, but it can only be confirmed after the swing low has formed, a few candles later. Indicators that draw the mark on the swing candle make it look earlier than it was. This script trades on the confirmation candle.

More guides

All 75 guides →

हिंदी में पढ़ें: Lot size kaise nikale?, Prop firm challenge kaise pass kare?, Gold trading kaise kare?, Forex trading kya hai, और India में यह legal है या नहीं?

Trading psychology

The habits that decide whether a good strategy makes money.

All 14 trading psychology guides

8 popular prop firms

Well-known firms for forex, gold and index traders that were still operating in 2026. Compare their rules before you buy a challenge.

If a link in this list is a referral link, PipLedger may earn a commission if you sign up, at no extra cost to you. This list is not a recommendation. Programs, prices and rules change often, so check each firm's own site, including its margin and drawdown rules, before you buy a challenge.