Make your own Fair Value Gap (FVG) Finder in Pinscript

Post Reply
SamiFX
Expert Trader
Posts: 7
Joined: Thu Nov 30, 2023 9:44 am

Make your own Fair Value Gap (FVG) Finder in Pinscript

Post by SamiFX »

This code is for programming your own fair value gaps indicator in Pinescript.
Fair value gaps are a fundamental price action concept that shows us the imbalance zones in the market. Based on our analysis, we can set targets for plan entries.

If you have any questions related to this code of fair value gaps in general please let me know below.

Below is the source code written in Pinescript.

Code: Select all

//@version=5
indicator("Fair Value Gap (FVG) Finder", overlay=true)

// Function to detect FVGs
fvg_detect(c1_high, c1_low, c3_high, c3_low) =>
    bearish_fvg = c1_low > c3_high   // Condition for bearish FVG
    bullish_fvg = c1_high < c3_low   // Condition for bullish FVG
    [bullish_fvg, bearish_fvg]

// Retrieve highs and lows of the three-candle sequence
candle1_high = high[2]    // High of Candle 1 (two bars ago)
candle1_low = low[2]      // Low of Candle 1 (two bars ago)
candle3_high = high      // High of Candle 3 (latest bar)
candle3_low = low        // Low of Candle 3 (latest bar)

// Detect bullish and bearish FVGs
[bullish_fvg, bearish_fvg] = fvg_detect(candle1_high, candle1_low, candle3_high, candle3_low)

// Plot bullish FVG
if bullish_fvg
    line.new(x1=bar_index - 2, y1=candle1_high, x2=bar_index, y2=candle1_high, color=color.new(color.green, 80), width=2, extend=extend.right)
    line.new(x1=bar_index - 2, y1=candle3_low, x2=bar_index, y2=candle3_low, color=color.new(color.green, 80), width=2, extend=extend.right)
    box.new(left=bar_index - 2, top=candle1_high, right=bar_index, bottom=candle3_low,  bgcolor=#0fdb15d0, border_color =#0fdb15d0)

// Plot bearish FVG
if bearish_fvg
    line.new(x1=bar_index - 2, y1=candle1_low, x2=bar_index, y2=candle1_low, color=color.new(color.red, 80), width=2, extend=extend.right)
    line.new(x1=bar_index - 2, y1=candle3_high, x2=bar_index, y2=candle3_high, color=color.new(color.red, 80), width=2, extend=extend.right)
    box.new(left=bar_index - 2, top=candle1_low, right=bar_index, bottom=candle3_high, bgcolor=#df1212cc , border_color =#df1212cc)
Julemanden
Posts: 1
Joined: Tue Dec 24, 2024 11:57 am

Re: Make your own Fair Value Gap (FVG) Finder in Pinscript

Post by Julemanden »

How do we extend the boxes to the current bar so that it keeps extend along the newest bar? :)
Post Reply