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
109 lines of Pine Script v5 from strategies/smc_ob_fvg.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
smc_ob_fvg.pine
// This Pine Script v5 strategy is licensed under the MIT License
// Tested with Backtrex (https://backtrex.com) on 10 years of M1 data
// Anti-repainting: all references use close[1]
// SMC/ICT Strategy: Order Block + Fair Value Gap confluence
//@version=5
strategy("SMC Order Block + FVG", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=2, max_bars_back=500)
// Inputs
obLookback = input.int(20, "Order Block Lookback")
fvgMinSize = input.float(0.5, "Min FVG Size (ATR multiplier)")
atrLen = input.int(14, "ATR Length")
bosLookback = input.int(50, "BOS Lookback Period")
// ATR for dynamic sizing
atr = ta.atr(atrLen)
// ============ BREAK OF STRUCTURE (BOS) ============
// Using close[1] for all calculations
swingHigh = ta.pivothigh(high[1], 5, 5)
swingLow = ta.pivotlow(low[1], 5, 5)
var float lastSwingHigh = na
var float lastSwingLow = na
var bool bullBOS = false
var bool bearBOS = false
if not na(swingHigh)
lastSwingHigh := swingHigh
if not na(swingLow)
lastSwingLow := swingLow
// BOS detection
bullBOS := close[1] > lastSwingHigh and close[2] <= lastSwingHigh
bearBOS := close[1] < lastSwingLow and close[2] >= lastSwingLow
// ============ ORDER BLOCKS ============
// Bullish OB: last bearish candle before a strong bullish move
var float bullOBTop = na
var float bullOBBottom = na
var bool bullOBActive = false
// Bearish OB: last bullish candle before a strong bearish move
var float bearOBTop = na
var float bearOBBottom = na
var bool bearOBActive = false
// Detect strong moves (3+ ATR)
strongBullMove = close[1] - open[1] > atr * 2
strongBearMove = open[1] - close[1] > atr * 2
// Find OB (last opposite candle before strong move)
if strongBullMove and close[2] < open[2]
bullOBTop := open[2]
bullOBBottom := close[2]
bullOBActive := true
if strongBearMove and close[2] > open[2]
bearOBTop := close[2]
bearOBBottom := open[2]
bearOBActive := true
// ============ FAIR VALUE GAPS ============
// Bullish FVG: gap between bar[3].high and bar[1].low
bullFVG = low[1] > high[3] and (low[1] - high[3]) > atr * fvgMinSize
bearFVG = high[1] < low[3] and (low[3] - high[1]) > atr * fvgMinSize
var bool recentBullFVG = false
var bool recentBearFVG = false
if bullFVG
recentBullFVG := true
if bearFVG
recentBearFVG := true
// Reset FVG flag after 20 bars
if ta.barssince(bullFVG) > 20
recentBullFVG := false
if ta.barssince(bearFVG) > 20
recentBearFVG := false
// ============ ENTRY CONDITIONS ============
// Long: price retraces to bullish OB zone + recent bullish FVG + bullish BOS
longCondition = bullOBActive and recentBullFVG and low[1] <= bullOBTop and low[1] >= bullOBBottom and ta.barssince(bullBOS) < 30
// Short: price retraces to bearish OB zone + recent bearish FVG + bearish BOS
shortCondition = bearOBActive and recentBearFVG and high[1] >= bearOBBottom and high[1] <= bearOBTop and ta.barssince(bearBOS) < 30
// Execute trades
if longCondition
sl = bullOBBottom - atr * 0.5
tp = lastSwingHigh
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long", stop=sl, limit=tp)
bullOBActive := false
if shortCondition
sl = bearOBTop + atr * 0.5
tp = lastSwingLow
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short", stop=sl, limit=tp)
bearOBActive := false
// ============ PLOTS ============
plotshape(longCondition, "Long Signal", shape.triangleup, location.belowbar, color.green, size=size.small)
plotshape(shortCondition, "Short Signal", shape.triangledown, location.abovebar, color.red, size=size.small)
Overview
SMC Order Block + FVG identifies breaks of structure using pivot points, isolates order blocks following strong ATR-based impulses, and tracks fair value gaps. Long trades enter when price retraces into a bullish order block zone with an active fair value gap and recent bullish structure break, while short trades mirror this setup. Stop loss levels are placed beyond the order block using an ATR buffer, with profit targets at recent swing points.
Break of structure detection using pivot points
Order block identification via ATR-based impulse moves
Fair value gap filtering with adjustable ATR multiplier
Retracement entry signals with ATR-based stop loss
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Order Block Lookback
int
20
obLookback
Min FVG Size (ATR multiplier)
float
0.5
fvgMinSize
ATR Length
int
14
atrLen
BOS Lookback Period
int
50
bosLookback
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 strategy enters trades in the opposite direction of filled value gaps, operating under the assumption that price action will resume the primary trend after filling a recent gap. It plots directly on the main price chart and supports MA-based trend filters
This strategy identifies reversal opportunities based on liquidity sweeps and multi-gate confluence scoring. It evaluates setups using mandatory conditions such as swing sweeps, body and ATR filters, and dual EMA higher-timeframe trend alignment, alongside opt
This multi-timeframe scalping strategy plots moving averages alongside Smart Money Concepts elements on the price chart. It calculates trend signals using configurable moving average types like ALMA, Hull MA, or TEMA across alternate timeframes. It also plots
Calculates three-bar Fair Value Gaps (FVG) and filters them using Average True Range. When price mitigates the FVG midpoint, the strategy enters a position in the direction of the gap, provided an optional EMA trend filter is satisfied. Exits are defined by an
This ICT-based strategy trades during the 9:45 AM to 10:15 AM New York session window. It calculates a daily bias using a 20-period daily EMA and tracks previous day highs and lows to identify liquidity sweeps. The script refines order block entry levels and m
This strategy detects liquidity sweeps and market structure shifts by computing swing highs and lows on a base timeframe then drawing zones around them. On a confirmation timeframe it identifies sweeps when price exceeds zone boundaries followed by rejection c