OPEN-SOURCE SCRIPT
ILM & IFVG Strategy

Please feel free to adjust in any way possible. Let me know if you can create something better from this initial coding.
//═══════════════════════════════════════════════════════════════════════
// Inverted Liquidity Model (ILM) – Strategy
//═══════════════════════════════════════════════════════════════════════
//
// The **Inverted Liquidity Model (ILM)** is a liquidity-based algorithm
// built to capture high-probability reversals after:
//
// • A liquidity sweep (SSL/BSL taken)
// • Rejection back inside the range
// • A Fair Value Gap (FVG) forms
// • That FVG becomes invalidated → becomes an IFVG entry zone
//
// ILM combines:
// • LTF BOS / CHOCH structure confirmation
// • HTF structure (expansion) filtering
// • Premium / Discount filter (17:00 CST session midline)
// • Optional ATR volatility filter
// • Optional trading session restrictions
// • Optional partial profit-taking + runners
//
// When all conditions align, the strategy enters:
// ✔ Long after sweep of SSL + valid long IFVG + trend confirmation
// ✔ Short after sweep of BSL + valid short IFVG + trend confirmation
//
// Stops are placed at the sweep wick.
// Full target is set at the next structural high/low.
// Optional partial TP sends a runner to full target.
//
// Visual tools (labels, sweep lines, IFVG boxes, midline) assist
// with review and forward testing.
//
//───────────────────────────────────────────────────────────────────────
// USER CONFIGURABLE FEATURES
//───────────────────────────────────────────────────────────────────────
//
// • **Liquidity & Structure**
// - pivotLen → swing length for pivots / liquidity
// - htfOn → toggle higher-timeframe pivots
// - htfTF → timeframe for HTF structure/liquidity
// - useStructureFilter → enforce LTF BOS/CHOCH trend
// - useHtfExpansionFilter → enforce HTF trend
// - showStructureLabels → show BOS/CHOCH labels
// - showHtfStructureLabels → show HTF BOS/CHOCH labels
//
// • **Premium / Discount Midline**
// - usePremiumDiscountFilter → only long in discount / short in premium
// - pdSession → session used for midline (default 17:00 CST)
// - showPdMidLine → show 50% midline
//
// • **FVG / IFVG Detection**
// - useBodyGapFVG → FVG uses candle bodies instead of wicks
// - useDisplacementFVG → require displacement bar
// - dispAtrMult → minimum ATR threshold for displacement
// - showIFVG → draw IFVG boxes
//
// • **ATR / Volatility / Sessions**
// - useRangeFilter → require minimum ATR%
// - atrLen → ATR period
// - minAtrPerc → minimum ATR% of price
// - useSessionFilter → restrict trading hours
// - sessionTimes → allowed trading session
//
// • **Sweep Visualization**
// - showSweepLines → draw sweep lines at SSL/BSL sweeps
// - sweepLineWidth → thickness of sweep lines
//
// • **Exits: Partial Targets & Runners**
// - usePartialTargets → enable partial TP logic
// - tp1QtyPercent → percent closed at TP1
// - tp1FractionOfPath → TP1 relative to path to full target
//
// • **Formatting / Visibility**
// - labelFontSizeInput → tiny / small / normal / large / huge
// - showEntries → entry markers
// - showTargets → target lines
//
//═══════════════════════════════════════════════════════════════════════
// END OF STRATEGY DESCRIPTION
//═══════════════════════════════════════════════════════════════════════
//═══════════════════════════════════════════════════════════════════════
// Inverted Liquidity Model (ILM) – Strategy
//═══════════════════════════════════════════════════════════════════════
//
// The **Inverted Liquidity Model (ILM)** is a liquidity-based algorithm
// built to capture high-probability reversals after:
//
// • A liquidity sweep (SSL/BSL taken)
// • Rejection back inside the range
// • A Fair Value Gap (FVG) forms
// • That FVG becomes invalidated → becomes an IFVG entry zone
//
// ILM combines:
// • LTF BOS / CHOCH structure confirmation
// • HTF structure (expansion) filtering
// • Premium / Discount filter (17:00 CST session midline)
// • Optional ATR volatility filter
// • Optional trading session restrictions
// • Optional partial profit-taking + runners
//
// When all conditions align, the strategy enters:
// ✔ Long after sweep of SSL + valid long IFVG + trend confirmation
// ✔ Short after sweep of BSL + valid short IFVG + trend confirmation
//
// Stops are placed at the sweep wick.
// Full target is set at the next structural high/low.
// Optional partial TP sends a runner to full target.
//
// Visual tools (labels, sweep lines, IFVG boxes, midline) assist
// with review and forward testing.
//
//───────────────────────────────────────────────────────────────────────
// USER CONFIGURABLE FEATURES
//───────────────────────────────────────────────────────────────────────
//
// • **Liquidity & Structure**
// - pivotLen → swing length for pivots / liquidity
// - htfOn → toggle higher-timeframe pivots
// - htfTF → timeframe for HTF structure/liquidity
// - useStructureFilter → enforce LTF BOS/CHOCH trend
// - useHtfExpansionFilter → enforce HTF trend
// - showStructureLabels → show BOS/CHOCH labels
// - showHtfStructureLabels → show HTF BOS/CHOCH labels
//
// • **Premium / Discount Midline**
// - usePremiumDiscountFilter → only long in discount / short in premium
// - pdSession → session used for midline (default 17:00 CST)
// - showPdMidLine → show 50% midline
//
// • **FVG / IFVG Detection**
// - useBodyGapFVG → FVG uses candle bodies instead of wicks
// - useDisplacementFVG → require displacement bar
// - dispAtrMult → minimum ATR threshold for displacement
// - showIFVG → draw IFVG boxes
//
// • **ATR / Volatility / Sessions**
// - useRangeFilter → require minimum ATR%
// - atrLen → ATR period
// - minAtrPerc → minimum ATR% of price
// - useSessionFilter → restrict trading hours
// - sessionTimes → allowed trading session
//
// • **Sweep Visualization**
// - showSweepLines → draw sweep lines at SSL/BSL sweeps
// - sweepLineWidth → thickness of sweep lines
//
// • **Exits: Partial Targets & Runners**
// - usePartialTargets → enable partial TP logic
// - tp1QtyPercent → percent closed at TP1
// - tp1FractionOfPath → TP1 relative to path to full target
//
// • **Formatting / Visibility**
// - labelFontSizeInput → tiny / small / normal / large / huge
// - showEntries → entry markers
// - showTargets → target lines
//
//═══════════════════════════════════════════════════════════════════════
// END OF STRATEGY DESCRIPTION
//═══════════════════════════════════════════════════════════════════════
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.