Strategy · Pine Script v5 · On the chart

SMC Order Block + FVG

by LePotoRico2105

SMC Order Block + FVG is an intraday strategy combining market structure breaks, order blocks, and fair value gaps.

View on GitHub

GitHub stars4on the repository
Pine versionv5runs as is
Lines of code109
Settings4inputs
LicenceMIT
Last update6 months ago3 Apr 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

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.

Details

Published by

LePotoRico2105 on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

SMC / ICT / price action, Support & resistance, Trend

Markets

Forex, Gold

Timeframes

M15-H1

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

algorithmic-tradingbacktestingforexictpinescriptsmcstrategytradingtradingview

Settings

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

SettingTypeDefaultVariable
Order Block Lookbackint20obLookback
Min FVG Size (ATR multiplier)float0.5fvgMinSize
ATR Lengthint14atrLen
BOS Lookback Periodint50bosLookback
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

FilledValueGap A006

by ruckard
13 stars

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

Strategy v5 SMC / ICT / price actionTrend
Updated 1 year ago · None stated GitHub repository of FilledValueGap A006

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

Strategy v6 SMC / ICT / price actionTrend
Updated yesterday · MIT GitHub repository of Reversal Engine Score [WavesUnchained] Strategy

XXX

by MeridianAlgo
9 stars

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

Strategy v5 TrendMoving averages Repaints
Updated 4 months ago · MIT GitHub repository of XXX

FVG Strategy

by muammeryldrm42
7 stars

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

Strategy v5 SMC / ICT / price actionSupport & resistance
Updated 3 months ago · MIT GitHub repository of FVG Strategy

NQ 9:45-10:15 ICT Strategy

by eddiebelaval
7 stars

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

Strategy v6 SMC / ICT / price actionSessions & time Repaints
Updated 3 months ago · None stated GitHub repository of NQ 9:45-10:15 ICT Strategy

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