CBc Gaps and Windows — daily gap lines
Draws a line at each recent daily gap up — red lines above the price, one green line below it.
About
CBc Gaps and Windows finds days that opened above the high of the day before. It draws a line at each of those old highs. Red lines sit above the price. One green line sits below it.
To find it, click Indicators at the top of a KAGAMI chart. It is in the KAGAMI group, named CBc Gaps and Windows. See Indicators.
It comes with KAGAMI Pro. Without KAGAMI Pro, its name ends in · Pro in the list. If you add it, nothing is drawn — a box says it comes with KAGAMI Pro.
What you see on the chart
A chart shows the price as candles. A candle (also called a bar) is one slice of time. A daily candle is one trading day.
A candle's high is its highest price. A gap up is a day that opens above the high of the day before. On a daily chart, it leaves an empty space between the two candles.
For each recent gap up, the indicator draws a flat line:
- The line sits at the high of the day before the gap. That is the bottom edge of the gap.
- It starts on that day and runs to the right edge of the chart.
- A small tag on the right shows its price.
The colour shows where the line is compared with the latest close. The close is the last price of a candle.
- Red lines are above the latest close. You see up to 20, the nearest first.
- One green line is the nearest gap line below the latest close. There is never more than one.
- Gap lines further below the green one are not drawn.
The lines always come from daily candles, whatever timeframe you use. So a 5-minute chart shows the same gap levels as a daily chart.
Why "windows"? A window is a day that stayed above the previous high all day long. Every window also opened above that high. So windows are marked too.
You cannot move or edit these lines. They are not saved. To hide them, hide the indicator. To remove them, remove the indicator.
How traders often read it
- Many traders read a red line as a possible ceiling. They call it resistance.
- Many traders read the green line as a possible floor. They call it support.
- Some traders watch for the moment a line changes colour. A close above a red line turns it green.
- A close below the green line turns it red. Many traders read that as broken support.
- Some traders look at how close the nearest red line is to the price.
An indicator only describes past prices. It cannot tell you what the price will do next.
The settings
KAGAMI shows no settings for this indicator. You cannot change how it works. It always uses fixed values. The ones that matter most:
- Which gaps: days that opened above the previous day's high.
- How far back: the last 186 trading days.
- How many red lines: up to 20, the nearest to the price first.
- Data errors: some one-day jumps are left out. A jump counts when the open is over three times the previous close. It is left out only if it is gone the next morning.
- Colours: red for lines above the price, green for the line below it.
When it can mislead
- Today's gap comes later. A new gap line appears only when its day has closed. For US stocks, that is at 16:00 New York time.
- The newest candle. Colours change only when a candle closes. While a candle forms, the price can be on the other side of a line.
- Each timeframe has its own close. A 5-minute chart and a daily chart can show the same line in different colours.
- A line is only an old price. The price can go straight through it.
- Crypto rarely gaps. Crypto trades day and night, so a day seldom opens above the day before. Often nothing is drawn.
- Old gaps are left out. Gaps older than 186 trading days are not shown.
- Only 20 red lines. Lines further up are not drawn. They still turn green if a close gets above them.
- Data errors. A one-day data error can show as a line until the next day opens.
- Hidden tags. The price tags sit a few candles past the newest one. If the chart has no space on the right, scroll left a little.
Charts are for learning, not advice. Read our Risk Disclaimer.
An example
Open NASDAQ:AAPL and choose the daily timeframe. Add CBc Gaps and Windows. The prices below are made up.
- Say one day's high is 100.
- The next morning, the price opens at 103. That is a gap up.
- That day closes at 104. At 16:00 New York time, a line appears at 100.
- The line at 100 is below the close of 104. It is the nearest one, so it is green.
- A few days later, a day closes at 98. The line at 100 is now above the close. It turns red.
- Say an older gap line sits at 95. It is now the nearest line below the close. It shows as the green line.
- Later, a day closes at 102. The line at 100 turns green again. The line at 95 is no longer drawn.
Technical details
This part is for readers who want the exact rules. KAGAMI's servers compute everything below. The page only draws the result.
The calculation
- KAGAMI reads the symbol's own daily candles, whatever the chart's timeframe: the latest ones, up to 2,000 (fewer for some markets).
- A daily candle that has not opened yet is dropped. The one still trading keeps only its open. Its high, low and close are not read until it closes.
- Each daily candle D is tested as a gap day:
open of D > high of the day before D. The day before is the previous daily candle in the data. Equal is not a gap. - The gap's line is at the high of the day before.
- When the next day opens, the gap is checked for a bad print (see Bad prints). A bad print is dropped.
- On every closed candle of the chart, the gaps in the look-back get their colours (see The colours).
- Only the current state is drawn: the colours as of the newest closed candle.
The look-back. A gap is used when its gap day is one of the last 186 closed daily candles, as of the chart candle being judged. A daily candle still trading is not one of them. Daily candles exist only for trading days, so this counts trading days. Crypto trades every day, so there it counts calendar days.
Inputs
KAGAMI shows no inputs for this indicator. It always uses these fixed values, which are the original script's defaults:
| Original input | Value in KAGAMI | What it does |
|---|---|---|
| Gap type | Opening gap | A day that opens above the previous day's high |
| Look-back (trading days) | 186 | How many closed daily candles are searched |
| Red lines shown | 20 | The most red lines drawn, nearest first |
| Ignore bad prints | On | Leaves out one-day data errors |
| Bad-print jump (× previous close) | 3 | How big a jump is checked as a bad print |
| Resistance colour, width | red #F23645, 1 | The red lines and their tags |
| Support colour, width | green #089981, 2 | The green line and its tag |
| Price labels on the lines | On | The price tag on each line |
Not offered in KAGAMI:
- every input above (you cannot change them);
- the Window gap type, which only counts a day whose low stayed above the previous high;
- Message when a line changes colour, because KAGAMI's indicators raise no alerts.
Bad prints
A bad print is a one-day data error. Take the gap day D, the day before it P, and the day after it N. D is not used as a gap when both are true:
- It jumped:
open of D > 3 × close of P. - It was gone the next morning:
open of N < high of P, oropen of N < open of D ÷ 3.
The check runs when N opens. Until then, D's gap is shown (once D has closed). If D was a bad print, its line goes at N's open.
A real jump that holds the next day still counts. A bad print is only left out as a gap. It is still the day before N, so N is a gap only if it opens above the bad print's high.
The colours
On every closed candle of the chart, with close C, for each gap line in the look-back:
- A line is a support candidate when its level is below C. A line exactly at C is a candidate only if it was the green line after the candle before.
- The green line is the highest candidate. If two gaps share that level, the newer gap is the one.
- Every line that is not a candidate is red: above C, or exactly at C without having been green.
- The other candidates, below the green line, are hidden.
What this means:
- A close above the nearest red line turns it green. The old green line is then hidden.
- A close below the green line turns it red. The next gap line down, if any, becomes green.
- A close exactly on a line leaves it the colour it was.
- A close that passes several lines on the way up makes the highest of them green. On the way down, every line it passes turns red.
The lines and tags
| Line | Colour | Width and style | How many |
|---|---|---|---|
| Support (green) | green #089981 | 2 px, solid | at most 1 |
| Resistance (red) | red #F23645 | 1 px, solid | at most 20, nearest above the close first |
- Where a line starts: at the open of the day before the gap day, the day whose high it marks. For US stocks that is 09:30 New York, for crypto 00:00 UTC, for FX and metals 17:00 New York.
- Older lines: if that day is before the chart candles KAGAMI reads, the line starts at the first day's open inside them (or at the first candle, if there is none).
- Where a line ends: it runs on to the right edge of the chart.
- The tag shows the line's price, rounded to the tick (halves round up), with the tick's decimals. It sits three candles to the right of the newest closed candle, in a small bubble in the line's colour that points at its line. The text is white (
#FFFFFF) or near-black (#111827), whichever stands out more on that colour. On both colours that is near-black. - The tick: US stocks 0.01 (0.0001 when the newest close is below 1). FX and metals: one unit of the instrument's own price precision. Crypto: one unit of the chart's price scale, which is 0.0001 when the highest price in the data is below 1, 0.001 below 10, and 0.01 otherwise.
Daily candles per market
| Market | A daily candle opens | It closes |
|---|---|---|
| US stocks | 09:30 New York | 16:00 New York, the same day |
| Crypto | 00:00 UTC | 00:00 UTC the next day |
| FX and metals | 17:00 New York | 17:00 New York the next day |
- US stocks. KAGAMI times each stock day by the regular session, 09:30 to 16:00 New York. A gap appears at 16:00. It stays through the evening, the night and the next morning. A bad print is judged at the next 09:30 open.
- Crypto. A gap appears at 00:00 UTC, when the day closes. Because crypto trades all the time, a day's open is usually near the close of the day before, so gaps are rare.
- FX and metals. A gap appears at the 17:00 New York close. Gaps there usually come at the start of the week, after the weekend pause.
When values change
- Closed candles only. A chart candle is judged once its start time plus its length has passed. The forming candle is never judged. A daily US stock candle counts as closed at 16:00 New York.
- Closed days only. A day is used only by a chart candle that closes at or after that day's close. A day still trading gives nothing but its open. Before that day closes, only the bad-print check of the day before uses it.
- Current state only. Only the newest closed candle's state is drawn. When a line changes colour, that line and its tag are drawn again.
- Lines appear at the close of a gap day. Lines go when their gap day leaves the look-back, or when they are found to be a bad print at the next open.
- Tags move one candle to the right with each new closed candle. The lines stay put. The left end of a very old line moves forward as old chart candles drop out of the candles KAGAMI reads.
- History reads like the live chart. The same rules run on past candles.
- When the page redraws. The page asks KAGAMI's servers for the drawings when you add the indicator, when the symbol or timeframe changes, when a new candle appears, and every 60 seconds while the page is open. On very short timeframes it redraws at most once every 2 seconds.
- Not saved. The drawings are made again each time you open or reload the chart.
Timeframes
- Every timeframe works, seconds charts included (crypto only). On seconds, minute, hour and daily charts the line levels are the same. Only the colours, judged on the chart's own close, and the tag's position differ.
- Intraday charts: each chart candle uses the newest daily candle that had opened by the chart candle's start. That day's own gap counts once the chart candle closes at or after the day's close.
- Stock candles before 09:30 or after 16:00 New York belong to the last closed day. They still show that day's gap.
- Daily charts: each candle uses its own day. On a US stock chart it counts as closed at 16:00 New York.
- Weekly and monthly charts: each candle uses the gaps as of the last day inside it. Its colours are judged on its own close. So these charts show the gaps as of the end of their newest closed candle: gaps from days after it are not drawn yet. KAGAMI treats a month as 30 days when it decides whether the newest monthly candle has closed.
Differences from the original Pine script
KAGAMI's version follows the original script's rules step by step. These are the differences:
- No settings. Every input is fixed at its default (see Inputs). The Window gap type is not offered.
- No alerts. The original can raise "Red line turned green" and "Green line turned red" alerts. KAGAMI's indicators raise no alerts.
- No data window values. The original shows Support and Nearest resistance in TradingView's data window. KAGAMI does not.
- No hover text. The original's tags show the gap's date and its prices when you point at them. KAGAMI's tags have no hover text.
- The daily candles. The original reads TradingView's regular-session daily candles. KAGAMI reads the daily candles of its own market data (up to 2,000) and times each day as in Daily candles per market.
- Older lines. The original starts a line older than the chart at the chart's first candle. KAGAMI starts it at the first day's open inside the candles it reads, so it does not shift with every new candle.
- The tag shape. The original's tag is centred on its line. KAGAMI's tag is a bubble whose point sits on the line, so it sits just above the line.
- The tick. The original uses the symbol's own minimum price step from TradingView. KAGAMI uses the rule in The lines and tags.
- Monthly charts. TradingView closes a monthly candle at the end of the month. KAGAMI treats a month as 30 days.
- Stock splits. TradingView adjusts stock prices for splits. KAGAMI's stock prices are not adjusted (see Edge cases).
Edge cases
- Short history. A symbol with fewer daily candles than the look-back uses all it has.
- No gaps. If there is no gap in the look-back, nothing is drawn.
- Too few chart candles. If the chart has fewer than 3 closed candles, nothing is drawn.
- Same level twice. Two gaps with the same line level: the newer gap is the line.
- A close exactly on a line keeps the colour the line had.
- A bad print is still the day before the next day. That next day gaps only over the bad print's high.
- Holidays and weekends have no daily candle. The day before a gap day is the last day that traded.
- Stock splits. KAGAMI's stock prices are not adjusted for splits, on the chart or in the lines. Lines from before a split sit at the old price level. A reverse split can show up as a new gap.
- Missing data. If KAGAMI cannot get the chart's candles or the daily candles, nothing is drawn.