OPEN-SOURCE SCRIPT
Telah dikemas kini IFVG Extended

This indicator identifies and visualizes "Imbalance Fair Value Gaps" (IFVGs) on a price chart. It highlights these gaps, tracks their evolution, and signals when they are "filled" or "invalidated" by price action. The script is quite advanced, using custom types, arrays, and dynamic drawing.
1. Types and Variables
Custom Types:
lab: Stores label information (x, y, direction).
fvg: Stores Fair Value Gap data, including its boundaries, direction, state, labels, and other properties.
Arrays:
Four arrays track bullish and bearish FVGs, and their "invalidated" (filled) versions.
Signals:
Boolean variables to store if a bullish or bearish signal is triggered.
2. User Inputs and Parameters
Display Settings:
How many recent FVGs to show, signal preference (close or wick), ATR multiplier for gap size filtering, and colors for bullish/bearish/midline.
3. Chart Data
Price Data:
Open, high, low, close, and ATR (Average True Range) are stored for use in calculations.
4. Functions
label_maker:
Draws an up or down arrow label at a given point, colored for bullish or bearish.
fvg_manage:
Checks if any FVGs in the array have been "invalidated" (i.e., price has crossed their boundary). If so, moves them to the invalidated array.
inv_manage:
Manages invalidated FVGs, checking if a signal should be fired (i.e., price has reacted to the gap). Also removes old FVGs.
send_it:
Draws the FVGs and their labels on the chart, using boxes and lines for visualization.
5. Main Logic and Visualization
FVG Detection:
On each bar, checks for new bullish or bearish FVGs based on price action and ATR filter.
Adds new FVGs to the appropriate array.
FVG Management:
Updates the arrays, moves invalidated FVGs, and checks for signals.
Drawing:
On the last bar, clears all previous drawings and redraws the current FVGs and their labels.
6. Alerts
Alert Conditions:
Sets up alerts for when a bullish or bearish IFVG signal is triggered, so users can be notified.
Summary
In short:
This script automatically finds and tracks "Imbalance Fair Value Gaps" on your chart, highlights them, and alerts you when price interacts with them in a significant way. It uses advanced Pine Script features to manage and visualize these zones dynamically, helping traders spot potential reversal or continuation points based on gap theory
1. Types and Variables
Custom Types:
lab: Stores label information (x, y, direction).
fvg: Stores Fair Value Gap data, including its boundaries, direction, state, labels, and other properties.
Arrays:
Four arrays track bullish and bearish FVGs, and their "invalidated" (filled) versions.
Signals:
Boolean variables to store if a bullish or bearish signal is triggered.
2. User Inputs and Parameters
Display Settings:
How many recent FVGs to show, signal preference (close or wick), ATR multiplier for gap size filtering, and colors for bullish/bearish/midline.
3. Chart Data
Price Data:
Open, high, low, close, and ATR (Average True Range) are stored for use in calculations.
4. Functions
label_maker:
Draws an up or down arrow label at a given point, colored for bullish or bearish.
fvg_manage:
Checks if any FVGs in the array have been "invalidated" (i.e., price has crossed their boundary). If so, moves them to the invalidated array.
inv_manage:
Manages invalidated FVGs, checking if a signal should be fired (i.e., price has reacted to the gap). Also removes old FVGs.
send_it:
Draws the FVGs and their labels on the chart, using boxes and lines for visualization.
5. Main Logic and Visualization
FVG Detection:
On each bar, checks for new bullish or bearish FVGs based on price action and ATR filter.
Adds new FVGs to the appropriate array.
FVG Management:
Updates the arrays, moves invalidated FVGs, and checks for signals.
Drawing:
On the last bar, clears all previous drawings and redraws the current FVGs and their labels.
6. Alerts
Alert Conditions:
Sets up alerts for when a bullish or bearish IFVG signal is triggered, so users can be notified.
Summary
In short:
This script automatically finds and tracks "Imbalance Fair Value Gaps" on your chart, highlights them, and alerts you when price interacts with them in a significant way. It uses advanced Pine Script features to manage and visualize these zones dynamically, helping traders spot potential reversal or continuation points based on gap theory
Nota Keluaran
1) Indicator setup and resource limits:Renamed indicator to “IFVG/FVG Extended” with short title “IFVG/FVG Ext”.
max_labels_count set to 0 (labels removed to reduce clutter and improve performance).
2) Data structures simplified:
Removed the custom lab type and all label handling.
fvg type retained but simplified to store only geometry/state fields (left, top, right, bot, mid, dir, state, x_val).
3) Inputs reworked and expanded:
Signal Preference default changed to “Wick” (previously “Close”).
Added comprehensive visibility controls:
IFVG: toggle IFVG boxes and “Show Last IFVGs”.
FVG: toggle original FVG boxes and “Show Last FVGs”.
Overlaps: option to display ONLY the overlapping areas between FVG and IFVG.
Added independent extension controls (bars to extend into the future):
extend_fvg_bars, extend_ifvg_bars, and extend_overlap_bars.
Added global and granular line visibility for IFVGs:
Global on/off for all lines.
Separate toggles for Bull IFVG top/mid/bottom lines and Bear IFVG top/mid/bottom lines.
Added line appearance controls (width and style per top/mid/bottom) and an optional “overhang” to extend only the top/bottom lines past the IFVG box.
Expanded color settings:
Separate colors for Bull/Bear IFVG and Bull/Bear original FVG.
Distinct colors for Bullish and Bearish overlap zones.
4) Visualization changes:
IFVG rendering split into boxes and lines:
IFVG boxes (pre/post invalidation) respect the new visibility toggles and future extension.
Lines for top/mid/bottom are drawn with independent visibility, style, width, and optional overhang.
Original FVGs now optionally displayed, with independent “Show Last” and extension controls.
New overlap visualization between FVGs and IFVGs:
When enabled, draws only the intersecting zones or full FVGs depending on the chosen option.
Uses dedicated overlap colors and respects the overlap extension setting.
All label-based arrow markers removed.
5) Logic refinements
IFVG invalidation and state progression preserved; arrays are still buffered and managed similarly.
Touch detection logic for alerts now includes an explicit Outside→Inside filter using prior bar wick positioning (helpers prev_above_top / prev_below_bot).
6) Alerts redesigned
Replaced single bull/bear signal alerts with broader, configurable alerts:
Any IFVG Top touched (outside→inside) and Any IFVG Bottom touched (outside→inside), with mode selectable per “Wick” or “Close”.
New alerts for IFVG & FVG overlap zones (Top/Bottom touched, outside→inside), also mode-selectable.
Per-alert touch evaluation iterates only over the most recent items, respecting the user-defined “Show Last” counts for IFVGs/FVGs.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.