# Fair Value Gaps

> Fair Value Gaps is an indicator drawn over the price chart.

Source: https://algobarsx.com/docs/ex-22-fair-value-gaps/

```algobarsx
indicator "Fair Value Gaps"
    pane: price

input keep = 15
input min_gap = 0.5

state gaps: list<Zone> = []

for gap in fair_value_gaps(min_size: min_gap, new_only: true):
    gaps.push(gap)
gaps = gaps.filter(g => not g.mitigated).keep_last(keep)

for g in gaps:
    box id: g.id, from: (g.formed_bar, g.top), to: (bar.index, g.bottom), color: if g.bullish then teal.fade(75) else orange.fade(75)
    label if g.bullish then "FVG +" else "FVG -", at: (g.formed_bar, g.mid), color: gray
```
What this script says

Fair Value Gaps is an indicator drawn over the price chart.

You can change 2 inputs: `keep` (default 15) and `min_gap` (default 0.5).

It remembers `gaps` from one bar to the next.

It calculates `gaps` as `gaps.filter(g => not g.mitigated).keep_last(keep)`.

On each bar, it goes through each `gap` in the fair value gaps and adds `gap` to `gaps`.

On each bar, it goes through each `g` in `gaps` and draws a box and labels if g.bullish then "FVG +" else "FVG -".
