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

Order block strategy: how to find and trade order blocks, with a free Pine Script

An order block is the last candle that went the other way before a strong move broke the market's structure. Smart money concepts (SMC) traders see it as the area where big orders were placed, and they wait for the price to come back to it. This guide explains bullish and bearish order blocks, gives rules you can test, walks through a GBPUSD example and covers breaker and mitigation blocks too.

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

The rules at a glance

  • Break of structure: a candle closes above the last swing high (for longs) or below the last swing low (for shorts)
  • The order block: the last bearish candle before that break (last bullish candle for shorts), found within the 10 candles before it
  • Strength check: the breaking candle closes at least 1.5 × ATR away from the far edge of the block
  • Entry: a limit order at the near edge of the block (its high for a bullish block, its low for a bearish one)
  • Stop loss and target: beyond the far edge of the block plus a quarter of the ATR; target twice the risk (2R)
  • Cancel: if the order hasn't filled within 30 candles

What an order block is

Strong moves have to start somewhere. In SMC teaching, a bullish order block is the last down candle (a bearish candle) before a rally that breaks above a previous swing high. The story behind it is that large buyers were building their position during that last dip, and when the price comes back to it, they, or traders who expect them, buy again. A bearish order block is the last up candle before a fall that breaks a swing low.

You don't have to accept the story about institutions to use the level. A candle where a strong move began is a level that many traders now watch, and a pullback to it gives you a clear place for a stop: if the price goes back through the whole candle, the move has failed.

What makes a valid order block

Most charts are full of bearish candles followed by bullish ones. What separates an order block from any other candle is what happens next:

Many SMC traders also like blocks that sit next to a fair value gap, or that formed right after a liquidity sweep. Those are extra filters you can test.

The rules, step by step

1. Wait for a break of structure

Mark the last swing high: a candle whose high is above the five candles on each side of it. For a long setup, wait for a candle to close above it.

2. Mark the block

Look back from the breaking candle for the most recent bearish candle, up to 10 candles back. Its high and low are the block. Check the move away was strong enough: 1.5 × ATR from the block's low to the breaking candle's close.

3. Place a limit order at the near edge

Put a buy limit at the block's high. That's the first price the pullback reaches. Some traders use the middle of the block (the "mean threshold") for a better price; it fills less often.

4. Stop beyond the block

The stop goes below the block's low, minus a quarter of the ATR. The target is twice the risk.

5. Cancel if it goes stale or breaks

If the order hasn't filled after 30 candles, cancel it.

Worked example: GBPUSD, 1-hour chart

Order blockSwing high 1.3262Target 1.3267Entry 1.3217Stop 1.3192BOSLimit fills2R
Illustrative chart drawn for this guide to show the rules. It isn't a real day's prices. GBPUSD, 1-hour candles.

GBPUSD sets a swing high at 1.3262, then slides for about ten hours. The last bearish candle of the slide runs from 1.3195 to 1.3217. Five bullish candles follow, and the fifth closes at 1.3270, above the swing high: a break of structure. The move from the block's low to that close is well over 1.5 × the ATR, so the block counts. A buy limit goes at 1.3217.

GBPUSD long
Entry (buy limit at the block high)1.3217
Stop loss1.3192 (block low 1.3195 minus a quarter of the ATR), 25 pips away
Target (2R)1.3267, 50 pips away
Account and risk$10,000, risking 1% = $100
Lot size$100 ÷ (25 pips × $10) = 0.40 lots
Loss if the stop is hit$100.00
Profit at the target$200.00

The price rallies a little further, then pulls all the way back. 9 hours after the break, a candle dips into the block and fills the order. It holds above the block's low, and 7 hours later the target at 1.3267 is reached. The stop was 25 pips because the block itself was 22 pips tall; on a taller block, the same $100 buys a smaller position.

Adding a fair value gap to the block is a common filter; the XAUUSD FVG + order block strategy has the rules and a script.

Breaker blocks and mitigation blocks

Two related terms often come up alongside order blocks. Definitions vary from teacher to teacher, so here is the common version of each.

TermWhat it isHow traders use it
Order blockThe last opposite candle before a move that breaks structureEnter on the first return, stop beyond the block
Breaker blockAn order block that failed: the price broke through it, usually after sweeping a high or low, and the block flipped sidesA broken bullish block is watched as resistance on the way back up, and the other way round
Mitigation blockLike a breaker, but the failed move didn't sweep a high or low first; it simply failed to make a new oneWatched the same way, as a level the price may react to on its return

The idea behind both is the same as a break and retest: a level that held and then broke often acts from the other side on the way back. The script on this page trades only the first kind, the order block itself.

Risk management

Common mistakes

  1. Marking blocks with no break of structure. Without the break, any candle could be called an order block.
  2. Picking the block after the fact. It's easy to find the "right" candle once you know where the price turned. Fixed rules, like the script's, stop you doing that.
  3. Trading a block the price has already returned to. The first touch is the setup; later touches are weaker.
  4. Stops inside the block. Pullbacks often dig deep into the block before they turn.
  5. Ignoring the higher timeframe. A bullish block on the 15-minute chart sitting under 4-hour resistance has a ceiling close above it.

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 GBPUSD 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. Try the swing strength (3 to 8 candles), how far back to look for the block, the minimum move away (1 to 2.5 × ATR), how long the order waits, and the stop buffer. Run the same settings on EURUSD and XAUUSD, and on the 15-minute 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. Because entries are limit orders, the fill is almost always at your limit price, or better if a candle opens beyond it.

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 rules, a worked example, the lot size maths and a checklist, to keep next to your chart.

Show the code (Pine Script v6, 103 lines)
//@version=6
// Order Block strategy by PipLedger (https://pipledgerfx.com/order-block-strategy)
// After a break of structure, marks the last opposite candle before the move (the order block) and trades the first return to it.
// Free to use and change. For education and backtesting only; not financial advice.
strategy("PipLedger: Order Block", shorttitle="Order Block", 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
swingLen = input.int(5, "Swing strength (bars on each side)", minval=2)
lookback = input.int(10, "Bars to search back for the order block candle", minval=2, maxval=50)
minMove  = input.float(1.5, "Minimum move away from the block (x ATR 14)", minval=0.0, step=0.1)
validFor = input.int(30, "Candles the block stays valid", minval=1)
stopBuf  = input.float(0.25, "Stop buffer beyond the block (x ATR)", minval=0.0, step=0.05)
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

// high and low of the most recent bearish (dir = -1) or bullish (dir = 1) candle before this one
lastCandle(int dir) =>
    float h = na
    float l = na
    for i = 1 to lookback
        if (dir == -1 and close[i] < open[i]) or (dir == 1 and close[i] > open[i])
            h := high[i]
            l := low[i]
            break
    [h, l]

atr = ta.atr(14)
ph  = ta.pivothigh(high, swingLen, swingLen)
pl  = ta.pivotlow(low, swingLen, swingLen)
[dnH, dnL] = lastCandle(-1)
[upH, upL] = lastCandle(1)

// ---------- Structure
var float swHi = na
var float swLo = na
if not na(ph)
    swHi := ph
if not na(pl)
    swLo := pl

bosUp = not na(swHi) and close > swHi and close[1] <= swHi
bosDn = not na(swLo) and close < swLo and close[1] >= swLo
if bosUp
    swHi := na  // each swing level breaks once
if bosDn
    swLo := na

var float zTop = na
var float zBot = na
var int   zDir = 0     // 1 = a buy order waits at a bullish block, -1 = a sell order waits at a bearish block
var int   zBar = na
flat = strategy.position_size == 0

if not flat
    zDir := 0
if zDir == 1 and (bar_index - zBar >= validFor or close < zBot)
    strategy.cancel("Long")
    zDir := 0
if zDir == -1 and (bar_index - zBar >= validFor or close > zTop)
    strategy.cancel("Short")
    zDir := 0

// bullish block: the last bearish candle before a close above the swing high, with a real move away from it
newLong  = flat and bosUp and not na(dnL) and dnH < close and close - dnL >= minMove * atr
newShort = flat and bosDn and not na(upH) and upL > close and upH - close >= minMove * atr

// ---------- Orders: a limit order at the near edge of the block, stop beyond its far edge
if newLong
    strategy.cancel("Short")
    zTop := dnH
    zBot := dnL
    zDir := 1
    zBar := bar_index
    float sl = zBot - atr * stopBuf
    float q  = calcQty(zTop, sl)
    if q > 0
        strategy.entry("Long", strategy.long, qty=q, limit=zTop)
        strategy.exit("Long exit", "Long", stop=sl, limit=zTop + (zTop - sl) * rr)
else if newShort
    strategy.cancel("Long")
    zTop := upH
    zBot := upL
    zDir := -1
    zBar := bar_index
    float sl = zTop + atr * stopBuf
    float q  = calcQty(zBot, sl)
    if q > 0
        strategy.entry("Short", strategy.short, qty=q, limit=zBot)
        strategy.exit("Short exit", "Short", stop=sl, limit=zBot - (sl - zBot) * rr)

// ---------- Chart
plot(swHi, "Swing high", color=color.new(color.gray, 40), style=plot.style_linebr)
plot(swLo, "Swing low", color=color.new(color.gray, 40), style=plot.style_linebr)
plot(zDir != 0 ? zTop : na, "Block top", color=color.new(color.orange, 0), linewidth=2, style=plot.style_linebr)
plot(zDir != 0 ? zBot : na, "Block bottom", color=color.new(color.orange, 40), linewidth=2, style=plot.style_linebr)
plotshape(newLong, "Bullish break", shape.triangleup, location.belowbar, color.teal, size=size.small)
plotshape(newShort, "Bearish break", shape.triangledown, location.abovebar, color.red, size=size.small)

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. 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: liquidity sweep, fair value gap, BOS and CHoCH, ICT kill zones, XAUUSD FVG + order block. All 34 strategies are compared on one page in forex trading strategies.

Quick answers

What is an order block in trading?

In smart money concepts, it's the last candle that moved against a strong move before that move broke the market's structure: the last bearish candle before a rally that breaks a swing high, or the last bullish candle before a fall that breaks a swing low.

How do you identify a bullish order block?

Find a candle that closes above the last swing high. Look back for the most recent bearish candle before that rally. If the rally moved well away from it, that candle's high and low are the bullish order block.

What is the difference between an order block and a breaker block?

An order block is a level that hasn't failed yet. A breaker block is an order block that the price broke through, usually after sweeping a high or low; traders then watch it from the other side, so a broken bullish block can act as resistance.

What is a mitigation block?

It's a failed level like a breaker block, but the move that failed didn't sweep a high or low first. Definitions vary between SMC teachers, so check how the source you follow uses the term.

Where should the stop loss go on an order block trade?

Beyond the far edge of the block, with a little room: these rules use a quarter of the 14-period ATR. If the price closes through the whole block, the setup has failed.

Do order blocks work in forex and gold?

The idea can be applied to any liquid market. Whether it works on a particular pair, timeframe and cost level is something only a backtest can show, which is why the free script is on this page.

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.