Skip to main content

Fair Value Gap Indicator for ThinkOrSwim

Shades every open bull and bear gap on your chart, skips gaps narrower than half an ATR, and removes each gap once price fills it. Free, with the full code and a 25-minute video that builds it line by line.

IndicatorFreeDaily charts25 min video69 lines of codeUpdated Oct 16, 2026
Fair Value Gap indicator on a Bank of America daily chart in ThinkOrSwim. Cyan clouds are open bull gaps and orange clouds are open bear gaps, September 2024 to June 2025.
Bull gap, still open Bear gap, still open BAC daily, Sep 2024 to Jun 2025, default settings
What it marks
Three-candle gaps where candle 1 and candle 3 don't overlap
Default filter
Gaps at least 0.5 × the 14-bar ATR
When a gap clears
Price trades through its far edge
Tested on
116,307 gaps, 650 stocks and ETFs, 2015 to 2026
On this page

What is a fair value gap?

A fair value gap is a three-candle pattern. Candle 2 moves so fast that candle 1's high and candle 3's low don't overlap. The empty space between them is the fair value gap. Price ran through that area so quickly that almost nothing traded there.

The bearish version is the same pattern flipped. Candle 3's high sits below candle 1's low, and candle 2 is the fast candle again. In thinkScript, candle 3 is the current bar and candle 1 is 2 bars back, so each side comes down to one comparison: low > high[2] for a bull gap and high < low[2] for a bear gap.

Bull gapCandle 3's low is above candle 1's high.
Bear gapCandle 3's high is below candle 1's low.
FilledPrice trades through the far edge, and the gap comes off the chart.

What 116,307 fair value gaps did next

Before writing the indicator, I measured every fair value gap on 650 stocks and ETFs, using daily bars from October 2015 to October 2026. Move the filter to see how gap width changes what happens after the gap. The indicator's minGap input works the same way.

0.50
24,369bull gaps pass the filter, 38.8% of 62,780
89.5%held on the first retest (closed back above the gap's bottom)
33.8%were completely filled within 5 trading days

First-retest hold rate, by gap width

Width in ATRs. Bars at or above minGap are the gaps the indicator shows.

Touched and filled, days after the gap

touched   filled   dashed = all gaps, no filter

Holding is not the same as profit. Five trading days after the first retest, wide bull gaps that held returned +0.56% on average, and 52.9% were positive, about the same as gaps that broke. Use a gap to decide where to look. Use something else to decide when to act.

How this was measured

Universe: 650 stocks and ETFs from our daily bar table, Oct. 27, 2015 to Oct. 12, 2026. A bull gap forms on bar i when low[i] > high[i−2]; the zone runs from high[i−2] to low[i]. Bear gaps mirror it. Touched within N days: price trades back into the zone. Filled within N days: price trades through the far edge. Held on first retest: on the first day price touches the zone, the close is back beyond the far edge. ATR is the 14-bar simple average of true range on the gap bar. Each gap is followed for 20 trading days.

How to read the gaps on a chart

Here's what I look for on the Bank of America daily chart from the video.

BAC daily chart, November to December 2024: price pulls back into the bull gap from the election rally and turns up from it.
A pullback into a cyan gap that holds

Bank of America left a bull gap behind on the November 2024 election rally. In December, price came back down into it, never closed below the bottom of the cloud, and turned back up.

BAC daily chart, January 2025: another gap up, a pullback into it, and a bounce off the bottom.
The same thing in January

Another gap up, a pullback into the gap, the bottom held, and price bounced.

BAC daily chart, March 2025: price climbs back into a wide orange bear gap, stalls, and rolls over.
A push into an orange gap that gets turned away

In February, price poked into 2 small bear gaps and was rejected quickly. The March bear gap was wider. Price climbed back into it at the end of March, stalled, and rolled over right before the April sell-off.

I use the gaps as levels to plan around. The data shows price comes back to them often, and the indicator shows exactly where they sit, so line up the retest with the rest of your setup before you take a trade.

How to install the indicator in ThinkOrSwim

  1. Download the indicator and open the .txt file, then copy all of the code. You can also copy it from the code block on this page.
  2. In ThinkOrSwim, click the Studies icon, then click Create.
  3. Delete the placeholder code and paste in the fair value gap code.
  4. Name the study. I called mine TI_FairValueGap.
  5. Click OK, then Apply. Start on a daily chart, which is what the video and the study use.

New to custom studies? The walkthrough on how to import a thinkScript study into ThinkOrSwim covers the same steps with screenshots.

The Edit Studies window in ThinkOrSwim, with the Create button under the list of studies.
Studies, then Edit studies. Create sits under the list of studies.

Inputs

InputDefaultWhat it controls
minGap0.5Minimum gap width, as a multiple of ATR. Raise it to see only wide gaps, lower it to see more of them.
ATRLength14Number of bars in the ATR average that minGap is measured against.

How the code works

Step 1: The ATR filter

To tell a wide gap from a narrow one, I use ATR as the yardstick. ThinkOrSwim has a built-in ATR function you could call instead. I wrote it out with Average and TrueRange so you can see what it calculates, and pulled the length out as an input.

This step’s code is free with an account. Create one or sign in.

Step 2: Define bull and bear gaps

Each gap has two conditions. The candles can't overlap, and the gap has to be at least minGap times the ATR. With the default of 0.5, a gap has to be at least half the ATR on your current timeframe.

This step’s code is free with an account. Create one or sign in.

While building this, I used AddChartBubble to check that each gap showed up where I expected it. That line is still at the bottom of the code, commented out, if you want it for debugging your own changes.

Step 3: Carry the gap forward without arrays

ThinkOrSwim doesn't have arrays, so I declare bullTop and bullBottom first and set them inside an if/else block. On the bar where a bull gap forms, the top is the current low and the bottom is the high from 2 bars ago. On every bar after that, each variable takes its value from the previous bar, which carries the gap forward.

This step’s code is free with an account. Create one or sign in.

The middle branch clears the gap. Once the low trades down to the bottom of the bull gap, both values reset to Double.nan and the cloud comes off the chart. The bear side mirrors this.

Step 4: Plot the gaps as clouds

If you plot bullTop directly, you get one continuous line that connects each gap to the next. To fix that, the plot returns Double.nan on the bar where a gap forms, so each new gap starts fresh. AddCloud then shades the space between each top and bottom.

This step’s code is free with an account. Create one or sign in.

Full thinkScript code

TI_FairValueGapthinkScript · 68 lines
The full code is free with an account

Create a free account or sign in to copy all 68 lines and download the file.

Video: building the indicator, line by line

25 minutes in ThinkOrSwim, from an empty editor to the finished study. Each chapter opens the video at that point.

The thinkScript editor in ThinkOrSwim with the fair value gap code half written. How to Build a Fair Value Gap Indicator in ThinkOrSwim · 25:30

    Limitations

    ThinkOrSwim only

    The code is thinkScript. There is no TradingView version.

    One gap per side

    A new bull gap replaces the previous bull gap, so older open gaps drop off the chart. Same for bear gaps.

    Not an entry signal

    A gap shows where price may come back to. It doesn't tell you when to act, and the study found no return edge from the retest alone.

    Tested on daily bars

    It plots on intraday and weekly charts, but the study only covers daily bars.

    One chart at a time

    To find every stock sitting in a gap, you need a scan. That's Part 2, below.

    Part 2: the Fair Value Gap Retest Scan

    The Fair Value Gap Retest Scan results in ThinkOrSwim, with each stock's open gap range and depth in an FVG column.
    Scan results with the FVG column: each stock's gap range and how far price has traded into it.

    Part 2 runs the same logic across a whole watchlist. It has three pieces:

    1. An upgrade to this indicator that tracks how deep price has traded into each gap.
    2. A Stock Hacker scan that finds stocks retesting an open fair value gap today.
    3. A custom scan-tab column that prints each stock's gap levels, color coded, so you can rank the results.

    It ends with how I pair the scan with Edge Signals to time an entry.

    Part 2 is for members. It's included with Stock Volatility Box, Futures Volatility Box and the Bundle, along with the Squeeze Course and every other members-only tutorial.

    Questions

    How do I install the Fair Value Gap indicator in ThinkOrSwim?

    Copy the code from this page or the .txt download. In ThinkOrSwim, click Studies, then Create. Delete the placeholder code, paste in the fair value gap code, name the study (I used TI_FairValueGap), and click OK, then Apply.

    What do the cyan and orange clouds mean?

    Cyan clouds are bull gaps, where the current bar's low is above the high from 2 bars ago. Orange clouds are bear gaps, where the current bar's high is below the low from 2 bars ago. Each cloud stays on the chart until price fills it.

    What does the minGap input do?

    minGap sets the minimum gap width as a multiple of ATR. The default of 0.5 keeps gaps at least half of a 14-bar ATR wide. Raise it to 1 to see only the widest gaps, or drop it to 0.1 to see almost every gap.

    How often do fair value gaps get filled?

    Across 650 stocks and ETFs and 11 years of daily bars, half of all bull gaps were completely filled within 5 trading days, and 7 out of 10 were revisited within a week. By 20 trading days, 71.8% were filled.

    Why does the indicator filter out narrow gaps?

    Narrow gaps rarely hold. In the study, bull gaps under a quarter ATR held on the first retest 57.8% of the time. Gaps at least 0.5 ATR wide held 89.5% of the time.

    When does a gap come off the chart?

    A bull gap clears once price trades down to its bottom edge, and a bear gap clears once price trades up to its top edge. A new gap on the same side also replaces the previous one.

    What timeframe should I use?

    Start on daily charts, which is what the video and the study use. The indicator plots on any timeframe, and because the ATR comes from the same bars, the minGap filter scales with the chart.

    Is the free version the full indicator?

    Yes. All 69 lines are on this page. Part 2, for members, adds the scan, the scan-tab column, and the depth upgrade.

    Get each new indicator by email

    One email on Sundays with the week's new tool and its code. A free account also unlocks every .txt download.

    No credit card. Unsubscribe anytime.