Strategy · Pine Script v5 · On the chart

Order Block Strategy

by muammeryldrm42

This strategy identifies bullish and bearish order blocks using an average true range impulse filter and plots corresponding boxes on the price chart.

View on GitHub

GitHub stars7on the repository
Pine versionv5runs as is
Lines of code61
Settings6inputs
LicenceMIT
Last update3 months ago8 Jul 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

61 lines of Pine Script v5 from public/code/smc__order_block.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

smc__order_block.pine
//@version=5
strategy("Order Block Strategy", overlay=true,
         default_qty_type=strategy.percent_of_equity, default_qty_value=10)

impulseAtr   = input.float(1.5, "Impulse Strength (ATR)", minval=0.5)
useTrend     = input.bool(true, "Use Trend Filter")
emaPeriod    = input.int(200, "EMA Period")
slAtrMult    = input.float(0.5, "SL ATR Mult")
tp1RR        = input.float(2.0, "TP1 RR")
tp2RR        = input.float(3.0, "TP2 RR")

atrVal   = ta.atr(14)
emaTrend = ta.ema(close, emaPeriod)
trendUp  = close > emaTrend
trendDn  = close < emaTrend

// Bullish OB: red candle + following strong green impulse
bullOB = close[1] < open[1] and (high - low[1]) >= atrVal * impulseAtr and close > high[1]
// Bearish OB: green candle + following strong red impulse
bearOB = close[1] > open[1] and (high[1] - low) >= atrVal * impulseAtr and close < low[1]

var float bullTop    = na
var float bullBottom = na
var float bearTop    = na
var float bearBottom = na

if bullOB
    bullTop    := high[1]
    bullBottom := low[1]
    box.new(bar_index - 1, bullTop, bar_index + 30, bullBottom,
            bgcolor=color.new(color.green, 85), border_color=color.green)

if bearOB
    bearTop    := high[1]
    bearBottom := low[1]
    box.new(bar_index - 1, bearTop, bar_index + 30, bearBottom,
            bgcolor=color.new(color.red, 85), border_color=color.red)

longRetest  = not na(bullTop)  and low <= bullTop  and high >= bullBottom and (not useTrend or trendUp)
shortRetest = not na(bearTop)  and high >= bearBottom and low <= bearTop  and (not useTrend or trendDn)

if longRetest and strategy.position_size == 0
    entry = (bullTop + bullBottom) / 2
    sl    = bullBottom - slAtrMult * atrVal
    risk  = entry - sl
    strategy.entry("OB Long", strategy.long, limit=entry)
    strategy.exit("X Long", "OB Long", stop=sl, limit=entry + risk * tp2RR)
    bullTop := na

if shortRetest and strategy.position_size == 0
    entry = (bearTop + bearBottom) / 2
    sl    = bearTop + slAtrMult * atrVal
    risk  = sl - entry
    strategy.entry("OB Short", strategy.short, limit=entry)
    strategy.exit("X Short", "OB Short", stop=sl, limit=entry - risk * tp2RR)
    bearTop := na

plotshape(longRetest,  "Long OB",  shape.triangleup,   location.belowbar, color.green)
plotshape(shortRetest, "Short OB", shape.triangledown, location.abovebar, color.red)
alertcondition(longRetest,  "OB Long",  "Order Block bullish retest")
alertcondition(shortRetest, "OB Short", "Order Block bearish retest")

Overview

Order Block Strategy enters positions on price retests of the order block zones, optionally filtered by an exponential moving average trend direction. Risk management includes ATR-based stop losses and configurable risk-to-reward ratio take profit levels.

Details

Published by

muammeryldrm42 on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

SMC / ICT / price action, Trend, Breakout

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

cryptofuturessodexsosovaluestrategyvaluechain

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Impulse Strength (ATR)float1.5impulseAtr
Use Trend FilterbooltrueuseTrend
EMA Periodint200emaPeriod
SL ATR Multfloat0.5slAtrMult
TP1 RRfloat2.0tp1RR
TP2 RRfloat3.0tp2RR
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr

Strategy v6 BreakoutTrend
Updated today · AGPL-3.0 GitHub repository of Forven S01509 - Simple Donchian 20/10 Breakout
257 stars

This strategy plots running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos

Strategy v6 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of Best Chart 1m Strategy Candle Bar

12/26-IT Strategy

by hasnocool
106 stars

This strategy executes trades based on crossovers between a 12-period and a 26-period exponential moving average (EMA). Long positions can be filtered by pivot resistance breakouts and RSI boundary ranges. For trade management, it provides two configurable par

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 12/26-IT Strategy

均线突破交易系统

by tangly1024
76 stars

This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of 均线突破交易系统

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers