Skip to main content

Module smc

Module smc 

Source
Expand description

Structure & SMC (Smart Money Concepts) Suite

High-performance, streaming-first implementation of Smart Money Concepts (SMC) and Market Structure analytics for algorithmic trading and quantitative research.

§Included Detectors

  1. Choch / ChochDetector: Market Structure Break (BOS) and Change of Character (CHoCH) detector. Tracks swing highs and swing lows via a symmetric sliding window, determines structural trend (Bullish, Bearish, Undetermined), and emits rich break events:

    • BOS (Break of Structure): Continuation of current trend (e.g., closing above previous swing high in an uptrend, or below previous swing low in a downtrend).
    • CHoCH (Change of Character): Reversal of structure (e.g., closing below previous swing low in an uptrend, or above previous swing high in a downtrend).
  2. OrderBlock / OrderBlockDetector: Institutional Order Block (OB) detector with lifecycle mitigation tracking:

    • Bullish Order Block: The last down-closing candle prior to a strong bullish breakout/displacement. Zone covers [low, high] (or body).
    • Bearish Order Block: The last up-closing candle prior to a strong bearish breakdown/displacement. Zone covers [low, high] (or body).
    • Tracks incoming price action against active order blocks: unmitigated, partially mitigated (tested), and fully mitigated (violated / invalidated).
  3. FairValueGap / FairValueGapDetector: 3-bar price imbalance detector (Fair Value Gap / FVG):

    • Bullish FVG: low[t] > high[t - 2]. Imbalance zone is [high[t - 2], low[t]].
    • Bearish FVG: high[t] < low[t - 2]. Imbalance zone is [high[t], low[t - 2]].
    • Tracks retest penetration and full mitigation as subsequent candles fill the imbalance.

§Formulas and References

  • CHoCH / BOS: Canonical SMC market structure: $$ \begin{aligned} \text{SwingHigh}t &= \operatorname{high}t \ge \operatorname{high}{t \pm i}, \quad \forall i \in [1, L] \ \text{SwingLow}t &= \operatorname{low}t \le \operatorname{low}{t \pm i}, \quad \forall i \in [1, L] \ \text{BOS}{\text{bull}} &= \text{Close} > \text{SwingHigh} \quad (\text{Trend} = \text{Bullish}) \ \text{CHoCH}{\text{bear}} &= \text{Close} < \text{SwingLow} \quad (\text{Trend} = \text{Bullish} \to \text{Bearish}) \end{aligned} $$ Source: https://www.tradingview.com/support/solutions/43000703076-market-structure/

  • Order Blocks: Institutional footprints preceding displacement moves: $$ \text{Bullish OB} = \text{Candle}_{t-1} (\text{Close} \le \text{Open}) \land \text{Close}t > \text{High}{t-1} $$ Source: https://www.tradingview.com/support/solutions/43000703077-order-blocks/

  • Fair Value Gaps: 3-bar price imbalance / liquidity voids: $$ \text{Bullish FVG} = \text{Low}t > \text{High}{t-2}, \quad \text{Bearish FVG} = \text{High}t < \text{Low}{t-2} $$ Source: https://www.tradingview.com/support/solutions/43000703078-fair-value-gaps/

Structs§

Choch
Market Structure detector tracking Swings, BOS, and CHoCH.
ChochState
Snapshot output of the Market Structure (CHoCH / BOS) detector.
FairValueGap
3-bar Fair Value Gap (FVG) detector with lifecycle fill tracking.
FairValueGapZone
Structural representation of an identified Fair Value Gap.
FvgState
Snapshot output of the Fair Value Gap detector.
OrderBlock
Institutional Order Block detector with lifecycle mitigation tracking.
OrderBlockConfig
Tunable parameters for Order Block detection.
OrderBlockState
Snapshot output of the Order Block detector.
OrderBlockZone
Structural representation of an identified Order Block.
SmcSwingPoint
Confirmed swing extreme with bar index and price level.
StructureBreakEvent
Structural break event emitted when price closes beyond an active swing level.

Enums§

FvgDirection
Direction of price imbalance for Fair Value Gaps.
MitigationStatus
Mitigation status for order blocks and fair value gaps.
OrderBlockType
Order block classification.
OrderBlockZoneMode
Calculation mode for the order block price zone boundaries.
StructureBreakDirection
Direction of structure break.
StructureBreakType
Category of structure break.
StructureTrend
Structural market trend derived from swing highs and swing lows.
SwingType
Type of swing extreme.

Constants§

CHOCH_METADATA
FAIR_VALUE_GAP_METADATA
ORDER_BLOCK_METADATA

Functions§

choch_batch
Compute Choch over a batch of (high, low, close) bars.
fair_value_gap_batch
Compute FairValueGap over a batch of (high, low, close) bars.
order_block_batch
Compute OrderBlock over a batch of (open, high, low, close) bars.

Type Aliases§

ChochDetector
FairValueGapDetector
OrderBlockDetector