OPEN-SOURCE SCRIPT

FVG (ICT) with Swing Levels

By jugerardo
This indicator, called "Fair Value Gaps (ICT) with Swing Levels", overlays on the main chart and does the following:

Initial Setup:

It defines user-adjustable parameters:

lookback: Lookback period to keep FVGs visible.
swingPeriod: Period for calculating swing highs and lows.
bullColor and bearColor: Colors for bullish and bearish FVGs.




Fair Value Gaps (FVGs) Detection:

Uses a function to identify FVGs by comparing candle high and low prices.
A bullish FVG forms when the low of two candles ago is higher than the high of the current candle.
A bearish FVG forms when the high of two candles ago is lower than the low of the current candle.


Swing Levels Calculation:

Calculates swing highs and lows over the specified period.
These swing levels define the current market range.


Current Range Verification:

Implements a function to check if an FVG is within the range defined by swing levels.
This ensures only the most relevant FVGs for the current market situation are displayed.


FVG Drawing:

When it detects an FVG (bullish or bearish) within the current range, it draws a box on the chart.
Boxes extend from the bar where the FVG formed to the current bar.
Bullish FVGs are drawn in green and bearish in red (colors are customizable).


Old FVGs Management:

On each new bar, the indicator checks all existing FVG boxes.
It removes boxes that are outside the specified lookback period.
It also removes boxes that are no longer within the current range of swing levels.


Swing Levels Visualization:

Draws lines on the chart to show swing highs (in blue) and swing lows (in purple).
These lines help visualize the current market range.


Continuous Update:

The indicator updates on each new candle, constantly refreshing FVGs and swing levels.



In summary, this indicator identifies and visualizes Fair Value Gaps according to the ICT methodology, filtering them based on higher timeframe swing levels. This helps traders focus on the most significant FVGs within the current market context, reducing visual noise and potentially improving trading decision-making.
fairvaluegapFractalfvgictictconceptsictfvgictstudent

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer