Quant from Scratch by QuantWright

Testing Popular Ideas · Lesson 13

SMC: fair value gaps

Three candles, a space between the first and the third, and the saying that the price comes back to fill it: how often it does when there is nothing to find, and the 24 versions of a rule built on it.

Know the basics? Read the lesson notes

Three candles and a gap

Several lessons cover ideas that traders group under "smart money concepts" (SMC): fair value gaps, order blocks, liquidity sweeps, market structure. They spread through free video lectures and are now taught by many educators, each with their own definitions. We code one common reading, show the switches where readings differ, and test that. It is our reading, not anyone's official method.

Take three candles in a row. A candle (also called a bar) holds the open and close (the first and last price of a stretch of time; here, five minutes) and the high and low in between. If the third candle's low is above the first candle's high, the middle one rose so fast that the first and third never overlap. The empty space between them is a fair value gap; this one is an up gap, and the same picture upside down is a down gap. A popular saying is that the price tends to come back and fill the gap.

The prices in this lesson are simulated: made up by a computer, not a real market. These markets were built so that past prices say nothing about which way the next move goes; the counts here show what gaps and gap rules do when there is nothing to find. They cannot show whether the idea works in a real market.

Three made-up sets of three candles

Each candle: a thin line from its low to its high, a box from its open to its close, empty if it closed higher.

Which set shows an up fair value gap, judged by the highs and lows?

In set A the third candle's low is below the first candle's high, so the two overlap: no gap.
In set B the boxes leave space, but the thin lines overlap: the third low is below the first high, so judged by highs and lows there is no gap. Judged by the boxes there is one: the next card shows that switch.
In set C the third low sits above the first high, so the space between them, now shaded, is an up gap.

Wick or body

Traders read gaps two ways. From the wicks (the thin lines: highs and lows), as on the last card, or from the bodies (the boxes): the bottom of the third candle's box against the top of the first's. The chart is one simulated day, 09:30 to 16:00. Try both readings.

Every gap of one day, two readings (simulated)

Shaded bands: each gap, from its first candle to its third. Any size counts here.

Reading
Gaps this day–

This day has 11 gaps read from the wicks and 38 read from the bodies. Across 1,000 simulated markets: 14.6 a day from the wicks, 39.5 from the bodies.

Why so many from the bodies? In these markets each bar opens where the one before it closed. When three bars in a row close higher, the first and third boxes can't overlap: the middle bar's box is the gap. 42.1 in 100 of the up gaps read from the bodies were exactly that.

How big must a gap be?

A gap of one cent counts as much as a gap of a dollar unless you set a minimum size. Here it is measured as the gap's height in % of the third candle's close: any size, at least 0.05%, or at least 0.10%. Try all three on the same day, read from the wicks.

The same day, gaps read from the wicks, by minimum size (simulated)

Shaded bands: the gaps that are at least the chosen size.

Minimum
Gaps this day–
1,000 markets–

11 gaps, then 2, then 1 on this day. Across the 1,000 simulated markets: 14.6, 6.3 and 2.7 a day. At this day's price of about 106, a cent is about 0.01%, so 7 of this day's 11 are a cent or two.

When is a gap filled?

Three common answers, for an up gap: the price comes back down to the gap's top edge, its near edge (the gap is touched); to its middle (half filled); or to its bottom edge, its far edge (fully filled: the whole gap traded through). A later bar's low reaching the level counts, in the same session (the same trading day). Below: the first gap of at least 0.05% on the same day, from 106.22 to 106.33. Try all three.

One gap and its fill, 09:30 to 11:15 (simulated)

Shaded: the gap. Dashed: the chosen level. Ring: the first later bar to reach it.

Filled when
Level–
Reached–

Touched in the very next bar: the third candle closed at 106.33, the gap's top, so the next bar opened right on it. Half filled in the 10:00 bar, fully filled in the 10:05 bar.

How often do gaps get filled?

From here on the gaps are read from the wicks and are at least 0.05%. Guess: of 100 such gaps, how many are fully filled before 16:00 the same day?

Gaps filled by 16:00, of 100 (simulated)

Counted over 1,000 simulated markets, every gap of at least 0.05% read from the wicks.

This market, fully filled?
1,000 markets?

Across the 1,000 simulated markets, 73.9 gaps in 100 were fully filled by 16:00; 87.8 were touched and 80.3 half filled. So "gaps get filled" is true here most of the time, in markets built with nothing to find.

Why? The near edge sits at or just below the third candle's close, and the price has hours left to wander. Is the gap pulling it back, or is any level that close reached as often? The next card checks.

The mirror test

For each gap, take each level's distance from the third candle's close and put a mirror level the same distance on the other side. On the day you saw, the far edge, 106.22, was 0.11 below the close of 106.33, so its mirror is 106.44. Nobody calls a mirror level a gap. If gaps pull the price back, their levels should be reached more often than their mirrors.

Gap levels and their mirror levels reached by 16:00, of 100 (simulated)

Orange: the gap's levels. Grey: the mirror levels. 1,000 simulated markets.

The mirror levels were reached about as often: 73.7 in 100 against 73.9 for the far edges; 87.5 against 87.8 touched, 80.2 against 80.3 half filled. In these markets the fill rate is a base rate (how often something happens anyway, before any rule acts on it): a level that close is reached that often, gap or no gap.

A second generator setting adds a small within-day pull-back; there the far edge was reached in 72.6 in 100 and its mirror in 71.4, a difference of about 1. This lesson uses the setting without it.

For the preciseThe pull-back setting (bridge "t") against the one used here (bridge "normal"), the same 100 markets: far edge 72.6 against mirror 71.4, against 73.9 and 73.6. With the setting used here the far edge sat above its mirror in 650 of the 1,000 markets and below in 345, by 0.2 points pooled; most of that comes from rounding prices to the cent (the same 100 markets at 1,000 times the price: far edge 73.4, mirror 73.4). The slow upward drift fills up gaps a little less often than their mirrors (73.5 against 74.1) and down gaps a little more (74.3 against 73.3). Highs and lows: this simulation draws a bar's high and low a random distance beyond its open and close rather than from a price path. In 20,000 sessions of a plain random walk with the same bar sizes, highs and lows taken from the path gave 9.28 gaps a day of at least 0.05%, fully filled 70.9 in 100 with mirrors 70.9; the generator's way gave 7.67, 73.3 and 73.3. The fill rate depends on how highs and lows are made; the match with the mirrors does not. Each market's fully-filled share ran from 72.3 to 75.6 in 100.

A rule, and its versions

A rule built on the idea: take the day's first gap. For an up gap, an order (an instruction to trade) waits to buy when the price comes back to the near edge, or to the middle; for a down gap it sells short there (sells first and buys back later, so the trade gains when the price falls). A stop, a set price that ends a losing trade, sits at the far edge, or there is none. Every trade ends by 16:00. One trade a day at most; if the price never comes back, no trade.

Each set of choices is a version: the same idea with different settings (see the How we test an idea lesson). Reading (wicks or bodies), minimum size (three), entry, stop: how many versions?

That adds the choices (2 + 3 + 2 + 2). Every choice goes with every other, so they multiply.
That leaves out one of the two-way choices. Multiply all four.
2 readings × 3 sizes × 2 entries × 2 stops = 24 versions.

One version against just holding

Start with one exact rule: wicks, at least 0.05%, enter at the near edge, stop at the far edge, out at 16:00. Call it the baseline version: this lesson's starting point, not anyone's published rule.

It runs from 2015 to 2021 against just holding (buying once, never selling). Each buy and each sale costs 0.1% of the price (the Costs lesson); holding pays that once. Results are in % a year (the steady yearly growth giving the same total). Holding made 4.4% a year. Where did the baseline version end, after costs?

The baseline version and just holding, 2015–2021, after costs (simulated)

Accounts starting at 100. Orange: the baseline version. Dotted: holding.

Your guess: it ends
Baseline version?
Holding?

It lost 38.4% a year after costs. It traded on 227 days a year, paying 0.1% to buy and 0.1% to sell each time. Each of those days keeps 0.998 of the account; 0.998 multiplied 227 times is 0.63, so costs alone take about 37% of the account a year.

One market is one draw, so run it on 1,000 more.

The baseline version against holding on 1,000 simulated markets

Bars: markets, by the version's % a year minus holding's. Grey: after costs. Orange outline: before costs.

On 2015 to 2021, before costs, it beat holding in 117 of the 1,000 simulated markets; after costs, in none. Its trades averaged −0.0013% before costs: about zero.

Notice where its trades ended: 86.5 in 100 at the stop (these are the gaps the rule traded, a different group from the 73.9 in 100 of all gaps that were filled). The stop is the gap's far edge, so a gap that is fully filled after the entry ends the trade at a loss. The fill the saying promises is this rule's stop.

For the preciseAgainst holding it averaged −8.97 points a year before costs and −44.81 after, across the 1,000 simulated markets; its trades gained in 13.0 in 100. On the market shown it lost 3.0% a year before costs. Holding owns this simulated market's slow rise day and night; the rule is in the market for part of each day and sells short about half the time.

All 24 versions

Here are all 24 versions on the same simulated market and years, 2015 to 2021. Each bar is a version's % a year minus holding's, in points (a point is 1% a year). Show them, then turn the costs on.

24 versions: each one's lead over holding, 2015–2021 (simulated)

One bar per version, grouped by reading. Above the line: beat holding. Black: the baseline version. Solid orange: the best.

Costs
Beat holding?
The best?

On this market 7 of the 24 beat holding before costs, and none after. The best after costs read the wicks, needed at least 0.10%, entered at the middle and had no stop: −28.1 points a year. The baseline version came 19th of 24: its place, counting from the version furthest ahead of holding.

On 2015 to 2021, after costs, none of the 24 beat holding in any of the 1,000 simulated markets.

For the preciseBefore costs, at least one of the 24 beat holding in 395 of the 1,000 simulated markets (3.84 versions on average).

Does the best stay best?

Before any version was run, 2022 to 2024 were set aside: years held out, to be used once (see the held-out test lesson).

On each of the 1,000 simulated markets we took the best of the 24 on 2015–2021, after costs, and ran it once on 2022–2024. A blind draw, one version taken at random, would be best there in about 42 of 1,000 (1,000 ÷ 24 = 41.7). But the 24 don't cost the same: versions that trade on fewer days pay less in costs. So a fairer comparison is the version that trades least (wicks, at least 0.10%, entry at the middle, with the stop), chosen in advance without looking at any result: it was best on 2022–2024 in 381 of the 1,000. Guess how often the best stayed best.

The best version's place on 2022–2024, on 1,000 simulated markets, after costs

One bar per place, 1st on the left. Dashed: a blind draw.

Stayed best?

The best stayed best in 422 of the 1,000 simulated markets, against a blind draw's 42. It beat holding there, after costs, in 1.

Why 422, close to the 381 of the version chosen in advance? Mostly because it traded least: in 963 of the 1,000 markets the best was that version or the same version without the stop, which trades on the same days (134.8 a year, the other 22 on 150.1 to 245.5), so the two pay the least in costs. When the best came 2nd (219 markets) or 3rd (237), the version ahead of it was mostly its twin (161 and 217 of those). It is not skill, and it says nothing about a real market.

Theory

Reaching a level: the reflection principle

If a price has no pattern in which way it moves, the chance it reaches a level depends only on how far away the level is and how much the price will move before time runs out. The reflection principle: the chance of touching a level is twice the chance of ending beyond it, because every path that touches it and ends back on the near side has a twin, flipped at the level, that ends beyond it. The formula has no "gap" in it: only distance, σ and time; that is why the mirror level is reached just as often.

P(reach) = 2 × (1 − Φ(d ÷ (σ × √n)))
d
the distance from the price now to the level
σ
the standard deviation of one bar's move (how far a typical bar moves, as in the Volatility lesson)
n
the number of bars left; √n is its square root (√9 = 3)
Φ(z)
the chance that a draw from the bell curve (the hump-shaped spread of many random results; the Bell curve lesson) is below z standard deviations; in a spreadsheet, NORM.S.DIST(z,TRUE)
P(reach)
the chance the price touches the level before time runs out, for a price with no drift (no steady rise or fall) and no pattern in which way it moves, moving in small steps of a steady size
Worked example: the gap you filled

On the day shown, the far edge, 106.22, was 0.11 below the third candle's close of 106.33: d = 0.11 ÷ 106.33 = 0.103%. That day's 78 five-minute moves had a standard deviation of σ = 0.059%, and n = 73 bars were left (this σ uses the day's own moves, which a trader would not know in advance). So σ × √73 = 0.059% × 8.54 = 0.504%; d ÷ 0.504% = 0.20; Φ(0.20) = 0.58; P = 2 × (1 − 0.58) = 0.84, about 84 in 100. It was reached three bars later.

Across the 1,000 simulated markets, using each gap's own distance and what the rest of its day's moves added up to, the formula gives 72.0 in 100 for the far edge; a later close reached it in 65.7, and a later low or high in 73.9.

Holds when
  • from any price, an up move is as likely as a down move, with no drift (a steady rise or fall);
  • the price moves in small steps of a steady size.
Breaks when

Counting only closes misses touches between them (65.7 above). A pull-back raises the chance; a drift raises it on one side and lowers it on the other.

A gap's far edge is 0.30% below the price. Each bar's move has a standard deviation of 0.05%, and 9 bars are left. The bell curve puts 95.4 draws in 100 within 2 standard deviations of the middle. About how many gaps in 100 like this one are fully filled?

Hint: work out σ × √n and how many of those the edge is away. Only one side counts, so halve what lies outside ±2, then double it for touching.

σ × √9 = 0.05% × 3 = 0.15%; d ÷ 0.15% = 2. Beyond 2 on one side: (100 − 95.4) ÷ 2 = 2.3 in 100; twice that: 4.6 in 100.
0.05% × √9 = 0.15%, so the edge is 2 standard deviations away. Ending beyond it: (100 − 95.4) ÷ 2 = 2.3 in 100. Touching it is twice as likely: 4.6 in 100.

What this means for your test

  1. Write the exact definition before you count.

    Wicks or bodies; the minimum size; which level counts as filled; the same session or longer; and, for a rule, the entry, the stop and the costs.

Practice 1 of 3

"Gaps always fill"

The situationAn invented post says that 80% of five-minute gaps fill the same day, so gaps must pull the price back.

Which count would tell you whether the gaps pull the price back?

More days make the 80% more precise, but it still has nothing to compare with: a level that close may be reached that often anyway.
A mirror level, the same distance from the price on the other side, shows how often a level that close is reached with no gap. In this lesson's simulated markets the two matched.
Bigger gaps are filled less often because their far edge is further away, with or without a pull. The count still needs something to compare with.
Practice 2 of 3

A wider gap

The situationA gap's far edge is 0.24% below the price. Each five-minute bar's move has a standard deviation of 0.04%, and 36 bars are left. The bell curve puts 68.3 draws in 100 within 1 standard deviation of the middle.

For a price with no pattern and no drift, about how many gaps in 100 like this are fully filled?

Hint: first work out σ × √n, then how many of those the edge is away.

0.04% × √36 = 0.24%: the edge is 1 standard deviation away. Ending beyond it: (100 − 68.3) ÷ 2 = 15.85; twice that: 31.7 in 100.
σ × √n = 0.04% × 6 = 0.24%, so d ÷ that = 1. Beyond 1 on one side: (100 − 68.3) ÷ 2 = 15.85 in 100. The reflection principle doubles it: 31.7 in 100.
Practice 3 of 3

A bigger search

The situationA friend tests gaps read from wicks or bodies, four minimum sizes, entries at the near edge, the middle or the far edge, and a stop or none, then checks whether the best stays best on held-out years across 1,000 simulated markets.

In about how many of the 1,000 would a blind draw be best?

Hint: first multiply the choices to get the number of versions, then divide 1,000 by it.

2 × 4 × 3 × 2 = 48 versions; 1,000 ÷ 48 = 20.8, about 21.
Versions: 2 readings × 4 sizes × 3 entries × 2 stops = 48. A blind draw is best in about 1,000 ÷ 48 = 20.8 of 1,000.
✓

Lesson done

A fair value gap is the space between the first and third of three candles when they don't overlap; reading it from wicks or bodies, its minimum size and when it counts as filled are choices, and with a rule's entry and stop they made 24 versions here. These simulated markets were built so that past prices say nothing about which way the next move goes, so the counts show what happens when there is nothing to find: 73.9 in 100 gaps (wicks, at least 0.05%) were fully filled the same day, and mirror levels the same distance on the other side were reached 73.7 times in 100. On 2015 to 2021, after costs, none of the 24 beat just holding in any of the 1,000 simulated markets; the best of 24 stayed best on held-out years in 422 (a blind draw: about 42; the least-trading version chosen in advance: 381), mostly because it traded least. The counts cannot show whether gap rules work in any real market.

Key ideas

Fair value gap
three candles in a row whose first and third don't overlap; the space between them. Up gap: the third's low above the first's high (wick reading)
Wick, body reading
comparing the candles' highs and lows, or their open-to-close boxes; when each bar opens at the last close, three bars closing the same way make a body gap
Near edge, far edge
the gap's side nearer the price now, and the other side; touched, half filled and fully filled mean the price came back to the near edge, the middle or the far edge
Mirror level
a level the same distance from the price on the other side; the base rate a gap's fill rate is compared with
Version
the same idea with different settings; count every one

Formulas

P(reach) = 2 × (1 − Φ(d ÷ (σ × √n))), for a price with no drift and no pattern in which way it moves, moving in small steps of a steady size: d the distance to the level, σ one bar's standard deviation, n the bars left (the reflection principle)

Lesson notes

A fair value gap is the space between the first and third of three candles in a row when the two don't overlap. Whether it is read from the wicks or the bodies, how big it must be, and when it counts as filled are choices; with a rule's entry and stop they made 24 versions in this lesson. Its simulated markets were built so that past prices say nothing about which way the next move goes, so its counts show what gaps and gap rules do when there is nothing to find. In them most gaps were filled the same day, and levels the same distance on the other side of the price were reached about as often; on 2015 to 2021, after costs, none of the 24 versions beat just holding (buying once and never selling) in any of 1,000 simulated markets. The counts cannot show whether gap rules work in any real market; that needs its own test.

The gap, and two readings

The lesson's simulated market (prices made up by a computer) has one session (trading day) a day, 09:30 to 16:00, in 78 five-minute bars. A bar, or candle, holds its open and close (the first and last price of its five minutes), drawn as a box (the body), and its high and low, drawn as a thin line (the wick). Read from the wicks, three bars make an up gap when the third bar's low is above the first bar's high, and a down gap when the third's high is below the first's low; the gap runs between those two prices. Read from the bodies, the same comparison uses the tops and bottoms of the boxes. In these markets every bar opens where the one before it closed, so three bars in a row closing higher always make a body gap: the middle box is the gap. That is why body gaps are so common: across 1,000 simulated markets, 14.6 a day from the wicks and 39.5 from the bodies.

Minimum size

A minimum size (the gap's height in % of the third bar's close) thins them out: from the wicks, 14.6, 6.3, 2.7 a day for any size, at least 0.05% and at least 0.10%.

Filled: three levels

For an up gap the near edge is its top and the far edge its bottom; for a down gap, the other way round. "Touched" means a later bar of the same session reached the near edge, "half filled" the middle, "fully filled" the far edge. Across the 1,000 simulated markets, of the gaps read from the wicks and at least 0.05%, 87.8, 80.3, 73.9 in 100 were touched, half filled and fully filled by 16:00.

The mirror test

A mirror level sits the same distance from the third bar's close on the other side (on the example day the far edge, 106.22, was 0.11 below the close of 106.33; its mirror was 106.44). If gaps pulled the price back, their levels would be reached more often than their mirrors. In the 1,000 simulated markets the mirrors were reached 87.5, 80.2, 73.7 times in 100, against 87.8, 80.3 and 73.9: the fill rate is a base rate (how often something happens anyway), and a level that close is reached that often, gap or no gap. A second generator setting adds a small pull-back within the day; there the far edge was reached in 72.6 in 100 and its mirror in 71.4, so the lesson uses the setting without it.

A rule, just holding, and the best of 24

The rule takes the day's first gap: an order buys (up gap) or sells short (down gap; selling first, buying back later) at the near edge or the middle; a stop (a set price that ends a losing trade) at the far edge, or none; out by 16:00. That makes 2 × 3 × 2 × 2 = 24 versions. The baseline version (wicks, at least 0.05%, near edge, stop at the far edge) ran from 2015 to 2021 against just holding, with 0.1% of the price on every buy and sale. On the lesson's simulated market holding made 4.4% a year after its one cost; the baseline version lost 38.4% a year after costs. It traded on 227 days a year; each trading day pays 0.1% to buy and 0.1% to sell and keeps 0.998 of the account; 0.998 multiplied 227 times is 0.63, so costs alone took about 37% of the account a year. On 2015 to 2021 across the 1,000 simulated markets it beat holding before costs in 117 and after costs in 0. 86.5 in 100 of its trades ended at the stop, because a gap fully filled after the entry is this rule's stop (the trades are a different group from all gaps counted above). On 2015 to 2021, after costs, none of the 24 beat holding in any of the 1,000 markets. With 2022 to 2024 held out (set aside, used once), the best of 24 on 2015 to 2021 (after costs) stayed best there in 422 of the 1,000, against about 42 for a blind draw (1,000 ÷ 24). The 24 don't cost the same, so the fairer comparison is the version that trades least, chosen in advance: it was best there in 381. The best stayed best mostly because it traded least, and paid least in costs. That is not skill, and it says nothing about a real market.

Formula: the reflection principle

If a price has no pattern in which way it moves and no drift (no steady rise or fall), the chance it touches a level is twice the chance it ends beyond it: every path that touches the level and ends back on the near side has a twin, flipped at the level, that ends beyond it. The formula has no "gap" in it, only distance, how much prices move and time, which is why mirror levels are reached as often.

P(reach) = 2 × (1 − Φ(d ÷ (σ × √n)))
d
the distance from the price now to the level
σ
the standard deviation of one bar's move (how far a typical bar moves)
n
the number of bars left; √n is its square root
Φ(z)
the chance a bell-curve draw is below z standard deviations
P(reach)
the chance the price touches the level before time runs out, for a price with no drift and no pattern in which way it moves, moving in small steps of a steady size
Worked example: the example day's gap

The far edge was d = 0.103% below the third bar's close; that day's 78 five-minute moves had a standard deviation of σ = 0.059% (measured on the day itself, which a trader would not know in advance), with 73 bars left. P = 2 × (1 − Φ(0.20)) = 0.84. Across the 1,000 simulated markets the formula gave 72.0 in 100 for the far edges; a later close reached them in 65.7, a later low or high in 73.9.

Holds whenBreaks when

Prices seen only at bar closes miss touches between them (65.7 above); a pull-back raises the chance; a drift raises it on one side and lowers it on the other.

One more worked example

Made-up round numbers

A down gap's far edge is 0.20% above the price, each bar's move has a standard deviation of 0.10%, and 4 bars are left (20 minutes). σ × √4 = 0.20%, so the edge is 1 standard deviation away. The bell curve puts 68.3 draws in 100 within 1 standard deviation, so ending beyond it: (100 − 68.3) ÷ 2 = 15.85 in 100. Touching it: 2 × 15.85 = 31.7 in 100. With 64 bars left instead, σ × √64 = 0.80%, the edge is 0.25 standard deviations away, and the chance of touching it rises to about 80 in 100 (Φ(0.25) is about 0.599). More time and a nearer edge both make a fill more likely, in a market with no pattern.

Common mistakes

Check yourself

  1. Three five-minute bars: the first has high 50.10 and low 49.90, the third high 50.40 and low 50.18. Is there an up gap, read from the wicks, and how tall is it?
    Answer

    Yes: the third low, 50.18, is above the first high, 50.10. The gap runs from 50.10 to 50.18, 0.08 tall.

  2. A test reads gaps from the wicks only, with two minimum sizes, three entries and one stop. How many versions?
    Answer

    1 × 2 × 3 × 1 = 6.

  3. In the lesson's simulation, 73.9 gaps in 100 were fully filled by 16:00. Does that show that gaps pull the price back?
    Answer

    No. Mirror levels, the same distance from the price on the other side, were reached 73.7 times in 100. A level that close is reached that often in markets built with nothing to find; a real market needs its own test.

Try it yourself

The rules, written before the code. Five-minute bars, one session a day; all three bars of a gap, and everything after it, in the same session; a gap completed by the last bar is not counted. Wicks: an up gap when bar 3's low > bar 1's high (gap from bar 1's high to bar 3's low); a down gap when bar 3's high < bar 1's low. Bodies: the same with min(open, close) and max(open, close). Size: the gap's height in % of bar 3's close; any, at least 0.05%, at least 0.10%. Filled: a later bar's low (high, for a down gap) at or beyond the near edge, the middle or the far edge, by 16:00. Mirror: 2 × bar 3's close − the level. The rule: the day's first gap; an order at the near edge or the middle buys (up gap) or sells short (down gap) when a later bar reaches it; a stop at the far edge, watched from the entry bar, or none; out at 16:00. 0.1% of the price per buy and per sell, or no costs. Compared with buying at the first close and holding, which pays 0.1% once.

Run the script. Every number in this lesson comes from one Python script (below). It imports simmarket.py, the course's simulated market, which must sit in the same folder. Add a fill judged by closes, or a gap that may last into the next day, and watch the fill and mirror counts move.

By hand. In a spreadsheet with one row per five-minute bar (high in C, low in D), an up gap at row 3 of a session reads =D3>C1; its height is =D3-C1.

Written by QuantWright from plain-word definitions of the three-candle gap, its size and its fill, and the rules above. No code from any indicator script or charting platform.

The code behind every number (Python, imports SimMarket, seed 20261109)
Loading…
For the preciseThe lesson's market: SimMarket Market 1, seed 20261109, effect=False (no planted pattern), five-minute bars built with bridge="normal" (no pull-back within the day), the same bars as the Previous day high and low and Opening range lessons. The 1,000 simulated markets: the same generator and setting with seeds 2026241301 to 2026242300. Choosing years: from the close of 5 Jan 2015 to 31 Dec 2021 (6.99 calendar years); held-out: to 31 Dec 2024 (3.00 years). % a year = (the account's growth factor)1 ÷ years − 1; a long trade's return is exit ÷ entry − 1, a short trade's 1 − exit ÷ entry; after costs each traded day is multiplied by 0.999². The lesson's market: holding 4.38% a year before its cost, 4.36% after (choosing), 10.00% (held-out). Gaps from the wicks, at least 0.05%, over its 2,607 days: 8,358 up and 8,214 down; touched 14,531, half filled 13,342, fully filled 12,335; their mirrors 14,540, 13,339 and 12,295. Baseline version: −2.99% a year before costs, −38.35% after (1,583 trading days, 226.6 a year), lead −7.37 then −42.71, 19th of 24; held-out lead −50.34, 24th. The best after costs (wicks, at least 0.10%, middle, no stop): lead −3.17 before costs, −28.05 after (141.1 trading days a year); held-out lead −27.74, 1st. The 1,000 simulated markets: the baseline version's average held-out lead −44.92; the best on 2015–2021 read the wicks in 996 markets and needed 0.10% in all 1,000, had no stop in 537; average held-out place 2.2; no market had a tie for first place; held-out results after costs that beat holding came in 5 markets. Two of the 1,000 markets closed below $30 at some point (the lowest close, $26.82).

Honest notes

Where this comes from