Smart Money Engine [WillyAlgoTrader]Smart Money Engine (SME) is a comprehensive overlay indicator that automates the core elements of Smart Money Concepts (SMC) analysis: multi-layer market structure detection (BOS / CHoCH), order block identification with strength grading, fair value gap tracking with fill monitoring, inverse FVG generation, and auto-anchored Fibonacci retracement — all in a single, unified tool.
Rather than stacking five separate indicators on your chart — one for structure, one for OBs, one for FVGs, one for IFVGs, and one for Fibonacci — SME integrates these components so they share a common structural context. Order blocks are created at actual structure break points, FVGs are filtered against volatility, IFVGs are born from filled FVGs, and the Fibonacci grid automatically anchors to the current strong high and strong low. Every component is aware of the others, producing a cleaner and more logically consistent chart than layering independent tools.
🔍 WHAT MAKES IT ORIGINAL
1. Dual-layer structure detection (Swing + Internal). The indicator runs two independent pivot-based structure engines simultaneously. The Swing layer (configurable length, default 10) captures major market structure — the higher-timeframe trend. The Internal layer (shorter length, default 5) captures minor structure shifts within the swing trend. Both label BOS (Break of Structure — continuation) and CHoCH (Change of Character — reversal) independently. This dual-layer approach lets you see whether an internal CHoCH is happening against or with the swing trend — a key distinction in SMC methodology that single-layer tools miss.
2. Order Blocks with contextual grading (A / B / C). OBs are not placed at arbitrary candles. They are created only when a swing-level BOS or CHoCH occurs — the script walks back from the break to find the last opposite-colored candle (the institutional candle that initiated the move). Each OB is then graded:
— Grade A : OB overlaps with an FVG and has a volume spike (highest confluence)
— Grade B : OB has one confluence factor (volume spike OR FVG overlap)
— Grade C : basic OB without additional confluence
Grading helps you prioritize which zones to trade from. OBs extend until mitigated (user choice: close-based or wick-based mitigation), and each OB displays a Consequent Encroachment (CE) midline — the 50% level that often acts as the reaction point within the block.
3. Fair Value Gaps with ATR auto-filter and fill tracking. FVGs are detected using the classic three-candle gap method (current low > high two bars ago for bullish, inverse for bearish). A built-in ATR filter (enabled by default) suppresses FVGs smaller than 0.5× ATR, removing the micro-gaps that clutter charts on lower timeframes. Each FVG extends until fully filled, displays a CE midline, and is automatically removed once price closes through the gap.
4. Inverse FVG (IFVG) generation. When an FVG is fully filled by price, it doesn't just disappear — it transforms into an Inverse FVG with flipped bias. A filled bullish FVG becomes a bearish IFVG (potential resistance); a filled bearish FVG becomes a bullish IFVG (potential support). This captures the SMC concept that once institutional imbalance is filled, the zone can flip polarity. IFVGs are displayed with distinct dashed borders and tracked until mitigated by a close through their zone.
5. Auto-anchored Fibonacci retracement. The Fibonacci grid automatically spans from the current Strong High to Strong Low — the trailing extremes of the active swing structure. When a new BOS/CHoCH shifts the structure, the anchor points update and the grid repositions. The OTE (Optimal Trade Entry) zone between 0.5 and 0.618 is highlighted, giving you an immediate visual reference for the premium/discount equilibrium.
6. Strong / Weak High and Low levels. After each structural break, the indicator identifies the trailing high and low as either "Strong" or "Weak" based on their position relative to the current trend direction. In a bullish swing, the low that initiated the trend is the Strong Low (protected) and the high is the Weak High (target). These levels are extended forward as dashed lines, providing clear reference for where the trend is protected and where it is vulnerable.
⚙️ HOW IT WORKS
Structure detection:
Swing pivots are identified using ta.pivothigh() and ta.pivotlow() with the configured lookback length. The script maintains the most recent swing high and swing low. When price closes above the previous swing high (confirmed bar close, no mid-bar signals), it registers a bullish break. If the prior trend was bearish, this is labeled CHoCH (reversal); if bullish, it is labeled BOS (continuation). The same logic applies in reverse for bearish breaks. Internal structure uses an identical algorithm with a shorter lookback, and its labels are drawn with dashed lines and lighter opacity to visually distinguish them from swing-level events.
Order Block detection:
When a swing-level break is confirmed, the script scans backward (up to 30 bars) from the pivot that was broken to find the last candle with opposite polarity — the candle whose body direction opposes the break direction. The full range (high to low) of that candle becomes the OB zone. A volume spike check (volume > 1.5× 20-period SMA) adds confluence for grading. OBs extend right until the mitigation condition is met.
FVG detection:
On every confirmed bar, the script checks whether the current bar's low exceeds the high of two bars ago (bullish FVG) or the current high is below the low of two bars ago (bearish FVG). If the gap size passes the ATR filter, an FVG box is created. The box extends right each bar. If price fills the gap completely (low touches the bottom of a bullish FVG, or high touches the top of a bearish FVG), the FVG is removed and — if IFVG mode is enabled — queued for conversion to an Inverse FVG.
HTF trend filter:
An optional higher-timeframe EMA(50) filter provides directional bias. The HTF data is fetched using request.security() with confirmed-bar referencing ( + lookahead_on pattern) to prevent repainting. When enabled, the dashboard displays the HTF bias, and the confluence can factor into OB grading.
Anti-repaint compliance:
All structure breaks, OB creation, and FVG detection require barstate.isconfirmed — signals fire only after the bar closes. The HTF filter uses the standard non-repainting security call pattern. No future data is accessed.
📖 HOW TO USE
Reading the chart:
— HH / HL / LH / LL labels at swing points classify the market structure
— Solid horizontal lines with BOS or CHoCH labels = swing-level structure breaks
— Dashed lines with BOS/CHoCH = internal (minor) structure breaks
— Colored boxes = Order Blocks (green-tinted = bullish, red-tinted = bearish)
— Letter labels (A/B/C) on OBs = strength grade
— Dotted midline inside OBs = Consequent Encroachment (CE)
— Blue-tinted boxes = bullish FVGs; orange-tinted = bearish FVGs
— Dashed-border boxes labeled IFVG = Inverse Fair Value Gaps
— Dotted horizontal Fibonacci lines with OTE zone highlight = auto retracement grid
— Dashed trailing lines labeled "Strong High/Low" or "Weak High/Low" = structural extremes
Suggested workflow:
— Identify the swing trend direction from BOS/CHoCH labels and Strong/Weak levels
— Check if internal structure aligns with or diverges from swing structure
— Look for entry opportunities at Order Blocks (prioritize Grade A/B) within the Fibonacci OTE zone
— Use FVGs as additional confluence — a bullish OB that overlaps a bullish FVG is a higher-probability zone
— Monitor IFVGs for polarity-flipped zones that may act as new support/resistance
— Use the dashboard to track active OB/FVG/IFVG counts and HTF bias alignment
Timeframe guidance:
— Scalping (1–5min): Swing Length 5–7, Internal 3, increase Max OBs/FVGs for more zones
— Intraday (15min–1H): Swing Length 8–12, Internal 5, default settings work well
— Swing (4H–Daily): Swing Length 15–25, Internal 7–10, reduce Max OBs to keep chart clean
— Use the HTF filter with 1 step up (e.g. 1H chart → 4H HTF, 4H chart → D HTF)
⚙️ KEY SETTINGS REFERENCE
— Swing Detection Length (default 10): lookback for major structure pivots
— Internal Structure Length (default 5): lookback for minor structure pivots (should be < Swing Length)
— OB Mitigation (default Wick): "Close" = OB removed on close through zone; "Wick" = removed on any touch
— Show OB Grade (default On): display A/B/C strength classification on OBs
— Show OB Midline (default On): display CE (50%) line inside order blocks
— Auto-Filter Small FVGs (default On): suppress FVGs smaller than 0.5× ATR
— Max Visible OBs / FVGs / IFVGs (default 5 each): cap on displayed zones to manage chart clutter
— Show Inverse FVGs (default Off): enable IFVG generation from filled FVGs
— Show Fibonacci Retracement (default On): auto-anchored grid with OTE zone highlight
— HTF Trend Filter (default Off): set a higher timeframe for directional bias via EMA(50)
— Volume Confirmation (default On): add confluence when volume > 1.5× average (auto-disabled on forex)
📊 Dashboard
The info panel (adjustable to any chart corner) displays in real time:
— Swing trend direction (Bullish / Bearish)
— Internal trend direction
— Fibonacci range (Strong High — Strong Low)
— Count of active OBs, FVGs, and IFVGs
— HTF bias (if enabled)
— Current timeframe and indicator version
⚠️ IMPORTANT NOTES
— This indicator does not repaint. All signals and zone creations require bar-close confirmation. The HTF filter uses the standard + lookahead_on non-repainting pattern.
— SME is a structural analysis and zone-mapping tool — it identifies where institutional activity likely occurred, but it does not generate explicit buy/sell signals. Trade decisions should incorporate your own entry triggers, risk management, and additional confluence.
— Past structure patterns and zone reactions do not guarantee future price behavior.
— Performance may vary across instruments and timeframes. Lower timeframes produce more zones and structure shifts; use the ATR filter and Max Visible caps to manage noise.
— The indicator works across all asset classes. Volume-based features (OB grading) are automatically adjusted on instruments without volume data.
Pine Script®指标






















