Order Block Sweeps vs Break of Structure (BOS): Pine Script v6 Detection
Smart Money Concepts (SMC)

Order Block Sweeps vs Break of Structure (BOS): Algorithmic Detection in Pine Script v6

Order Block Sweeps vs BOS on TradingView Chart

In classical retail technical analysis, traders are taught that when price breaks above a previous swing high, it signifies a breakout and an opportunity to buy. However, in institutional algorithmic order flow, over 65% of swing high breaches are merely Liquidity Sweeps (Turtle Soups) designed to trigger retail stop-loss orders and fill institutional sell blocks.

To automate SMC (Smart Money Concepts) profitably in Pine Script v6, an algorithm must mathematically differentiate a Liquidity Sweep from a genuine Break of Structure (BOS).

The Structural Anatomy of a Sweep vs BOS

The distinction between a sweep and a continuation lies entirely in candle close validation and volume displacement:

SmartCat Algo S&D Zones and Order Block Detection
Figure 1: Automated Order Block and Supply/Demand zone mapping with zero repaint in Pine Script v6.

Pine Script v6 Algorithmic Detection Logic

Below is a production Pine Script v6 architecture showing how to track structural swing points and flag sweeps vs BOS events using non-repainting arrays:

//@version=6 indicator("SMC Liquidity Sweep vs BOS Engine", overlay=true) // 1. Pivot Detection (Left/Right Bars) leftBars = input.int(5, "Left Strength") rightBars = input.int(5, "Right Strength") pHigh = ta.pivothigh(high, leftBars, rightBars) pLow = ta.pivotlow(low, leftBars, rightBars) var float lastSwingHigh = na var float lastSwingLow = na if not na(pHigh) lastSwingHigh := pHigh if not na(pLow) lastSwingLow := pLow // 2. Sweep vs BOS Evaluation (Confirmed on Bar Close) isHighSweep = not na(lastSwingHigh) and high > lastSwingHigh and close < lastSwingHigh isHighBOS = not na(lastSwingHigh) and close > lastSwingHigh // 3. Visual Plotting (Zero Repaint) plotshape(isHighSweep, "Liquidity Sweep (Short Trap)", shape.triangledown, location.abovebar, color.red, size=size.small) plotshape(isHighBOS, "BOS Continuation", shape.labelup, location.belowbar, color.green, size=size.small)

Ensuring Zero Repainting on Pivot Highs

TradingView built-in functions like ta.pivothigh() confirm pivots only after rightBars have closed. Plotting historical levels in real time without buffering can cause repainting. Always evaluate signals on confirmed bar closes (barstate.isconfirmed).

Combining Sweeps with Order Block Mitigation

A liquidity sweep alone is not enough for an entry. High-probability trade execution requires the sweep to interact with an unmitigated Order Block (OB) or Fair Value Gap (FVG). When an order block is tested and rejected on a higher timeframe, the lower timeframe sweep provides the exact trigger for entry with an asymmetric risk-to-reward ratio.

Institutional SMC Engine for TradingView

SmartCat Algo automates Order Block mapping, BOS/CHoCH transitions, and volume sweeps directly on your charts. Open-source Pine Script v6 code without recurring subscriptions.

Get SmartCat Algo (8 One-Time)