1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Impulse Strength (ATR)
float
1.5
impulseAtr
Use Trend Filter
bool
true
useTrend
EMA Period
int
200
emaPeriod
SL ATR Mult
float
0.5
slAtrMult
TP1 RR
float
2.0
tp1RR
TP2 RR
float
3.0
tp2RR
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.
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
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
The Chained Linear Regression Reversal Strategy plots linear regression channels with upper and lower standard deviation bands directly on the price chart across a user-defined time window. When price breaks out of the static channel for a confirmed number of
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
This strategy combines Smart Money Concepts (BOS and CHoCH) with moving average trend filtering and volume spikes to generate trade signals. It checks for 20 EMA and 50 EMA alignment, along with volume 20% above its 20-period SMA. Long entries require a bullis
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