OPEN-SOURCE SCRIPT

GEEKSDOBYTE IFVG w/ Buy/Sell Signals

253
1. Inputs & Configuration
Swing Lookback (swingLen)
Controls how many bars on each side are checked to mark a swing high or swing low (default = 5).

Booleans to Toggle Plotting

showSwings – Show small triangle markers at swing highs/lows

showFVG – Show Fair Value Gap zones

showSignals – Show “BUY”/“SELL” labels when price inverts an FVG

showDDLine – Show a yellow “DD” line at the close of the inversion bar

showCE – Show an orange dashed “CE” line at the midpoint of the gap area

2. Swing High / Low Detection
isSwingHigh = ta.pivothigh(high, swingLen, swingLen)

Marks a bar as a swing high if its high is higher than the highs of the previous swingLen bars and the next swingLen bars.

isSwingLow = ta.pivotlow(low, swingLen, swingLen)

Marks a bar as a swing low if its low is lower than the lows of the previous and next swingLen bars.

Plotting

If showSwings is true, small red downward triangles appear above swing highs, and green upward triangles below swing lows.

3. Fair Value Gap (3‐Bar) Identification
A Fair Value Gap (FVG) is defined here using a simple three‐bar logic (sometimes called an “inefficiency” in price):

Bullish FVG (bullFVG)

Checks if, two bars ago, the low of that bar (low[2]) is strictly greater than the current bar’s high (high).

In other words:

bullFVG = low[2] > high
Bearish FVG (bearFVG)

Checks if, two bars ago, the high of that bar (high[2]) is strictly less than the current bar’s low (low).

In other words:
bearFVG = high[2] < low
When either condition is true, it identifies a three‐bar “gap” or unfilled imbalance in the market.

4. Drawing FVG Zones
If showFVG is enabled, each time a bullish or bearish FVG is detected:

Bullish FVG Zone

Draws a semi‐transparent green box from the bar two bars ago (where the gap began) at low[2] up to the current bar’s high.

Bearish FVG Zone

Draws a semi‐transparent red box from the bar two bars ago at high[2] down to the current bar’s low.

These colored boxes visually highlight the “fair value imbalance” area on the chart.

5. Inversion (Fill) Detection & Entry Signals
An inversion is defined as the price “closing through” that previously drawn FVG:

Bullish Inversion (bullInversion)

Occurs when a bullish FVG was identified on bar-2 (bullFVG), and on the current bar the close is greater than that old bar-2 low:

bullInversion = bullFVG and close > low[2]
Bearish Inversion (bearInversion)

Occurs when a bearish FVG was identified on bar-2 (bearFVG), and on the current bar the close is lower than that old bar-2 high:

bearInversion = bearFVG and close < high[2]
When an inversion is true, the indicator optionally draws two lines and a label (depending on input toggles):

Draw “DD” Line (yellow, solid)

Plots a horizontal yellow line from the current bar’s close price extending five bars forward (bar_index + 5). This is often referred to as a “Demand/Daily Demand” line, marking where price inverted the gap.

Draw “CE” Line (orange, dashed)

Calculates the midpoint (ce) of the original FVG zone.

For a bullish inversion:

ce = (low[2] + high) / 2
For a bearish inversion:

ce = (high[2] + low) / 2
Plots a horizontal dashed orange line at that midpoint for five bars forward.

Plot Label (“BUY” / “SELL”)

If showSignals is true, a green “BUY” label is placed at the low of the current bar when a bullish inversion occurs.

Likewise, a red “SELL” label at the high of the current bar when a bearish inversion happens.

6. Putting It All Together
Swing Markers (Optional):

Visually confirm recent swing highs and swing lows with small triangles.

FVG Zones (Optional):

Highlight areas where price left a 3-bar gap (bullish in green, bearish in red).

Inversion Confirmation:

Wait for price to close beyond the old FVG boundary.

Once that happens, draw the yellow “DD” line at the close, the orange dashed “CE” line at the zone’s midpoint, and place a “BUY” or “SELL” label exactly on that bar.

User Controls:

All of the above elements can be individually toggled on/off (showSwings, showFVG, showSignals, showDDLine, showCE).

In Practice
A bullish FVG forms whenever a strong drop leaves a gap in liquidity (three bars ago low > current high).

When price later “fills” that gap by closing above the old low, the script signals a potential long entry (BUY), draws a demand line at the closing price, and marks the midpoint of that gap.

Conversely, a bearish FVG marks a potential short zone (three bars ago high < current low). When price closes below that gap’s high, it signals a SELL, with similar lines drawn.

By combining these elements, the indicator helps users visually identify inefficiencies (FVGs), confirm when price inverts/fills them, and place straightforward buy/sell labels alongside reference lines for trade management.

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.