OPEN-SOURCE SCRIPT

FiboZone

595
FiboZone combines three independent zone-based concepts into a single overlay, so the levels a trader usually keeps on separate scripts can be read against each other on one chart:

1. Fibonacci Pivot Levels - a nine-level pivot grid derived from the previous Daily, Weekly, or Monthly candle.
2. Order Blocks and Breaker Blocks - the last unmitigated supply and demand zones, and what happens to them once price breaks through.
3. Fair Value Gaps - three-candle imbalances, each one tracked until price returns to it.

The value of putting them together is confluence. A Fibonacci pivot is a static level known before the session opens; an order block and an FVG are reactive levels created by price itself. Where a pivot level lands inside an unmitigated order block, or where an FVG forms exactly at S1 or R2, the same price area is being marked by three different methods that were calculated independently of one another. Those overlaps are what the script is designed to make visible.


1. FIBONACCI PIVOT LEVELS

The pivot grid is calculated from the previous completed higher-timeframe candle, so the levels are fixed for the entire duration of the current period and never move under your feet:

Range = previousHigh - previousLow
PP = (previousHigh + previousLow + previousClose) / 3

R1 = PP + 0.382 * Range S1 = PP - 0.382 * Range
R2 = PP + 0.618 * Range S2 = PP - 0.618 * Range
R3 = PP + 1.000 * Range S3 = PP - 1.000 * Range
R4 = PP + 1.618 * Range S4 = PP - 1.618 * Range

Unlike classic floor-trader pivots, which space the levels using the range in whole multiples, this variant projects the range through Fibonacci ratios. The result is a tighter cluster around the pivot point at 0.382 and 0.618, with two wider extension levels at 1.000 and 1.618 that act as targets when a period trends away from its pivot.

Two display modes are available:

- Current period only (default) - only the pivot set for the period in progress is drawn, as horizontal lines starting at the first bar of that period and extending to the right. This keeps the chart clean when you only care about today's levels.
- Show Historical Levels - every period's pivot set is drawn as a stepped plot across the whole chart, so you can review how price behaved around past pivots.

Price labels showing the exact value sit at the right-hand edge. R3 and S3 are drawn dotted to distinguish the 1.000 extension from the rest.

A guard prevents a meaningless configuration: if the chart timeframe is higher than the selected pivot period, for example a Weekly chart with Daily pivots, the levels are hidden and an on-chart warning explains which timeframe is required.


2. ORDER BLOCKS AND BREAKER BLOCKS

Swing detection. The script tracks a directional state that flips when the bar N positions back sets a new extreme relative to the most recent N bars: a new high turns the state bearish, a new low turns it bullish. Each flip records a confirmed swing top or swing bottom along with its price and bar position. Swing Lookback controls how much structure is required before a point counts as a swing, with a minimum of 3.

Order block construction. When price closes above the most recent swing top that has not yet been crossed, the script walks back from the previous bar to the swing bar and finds the candle with the lowest low in that leg. That single candle, its high as the top and its low as the bottom, becomes the bullish order block: the last down-candle before the move that broke structure. Bearish order blocks mirror this, taking the candle with the highest high in the leg down through a swing bottom.

Use Candle Body switches the boundaries from wick-to-wick to body-only, producing tighter zones.

Breaker blocks. An order block does not simply disappear when it fails. A bullish block is marked as broken the moment min(close, open) closes below its bottom, and from that bar onward it is drawn in the breaker colour while the original portion keeps the order block colour. This is the polarity flip: a level that was demand becomes supply, and it often gets retested from the other side. The block is only discarded once price closes back above its top, which invalidates the flip. Bearish blocks work in reverse.

The two-tone rendering, original zone up to the break and breaker zone from the break onward, is what makes the transition readable at a glance, rather than having a zone silently change colour with no record of where the break happened.

Polarity change markers, optional, mark with a small down or up triangle the swing points that formed inside an already-broken block. These flag the moments where structure was built on top of a flipped level.


3. FAIR VALUE GAPS

An FVG marks a price range that was crossed in one impulsive move without two-sided trading, an imbalance that price frequently returns to fill.

Detection requires a three-candle pattern where all three candles point in the same direction, which filters out the gaps that form inside choppy, indecisive ranges:

- Bullish FVG: current low is above the high from two bars ago, and the previous close is also above it, with all three candles bullish. The zone spans from that high up to the current low.
- Bearish FVG: current high is below the low from two bars ago, and the previous close is also below it, with all three candles bearish. The zone spans from the current high up to that low.

Auto Threshold, on by default, discards gaps smaller than 10 percent of the average bar range over the last 20 bars. Without it, low-volatility sessions produce dozens of one-tick gaps that carry no information. The threshold adapts to the instrument and timeframe automatically, so no manual tuning per symbol is needed.

Mitigation tracking. A gap is marked mitigated as soon as a later bar's wick reaches into it: a bullish gap when a low touches its top, a bearish gap when a high touches its bottom. Rather than being deleted, a mitigated gap turns grey and shrinks. This is deliberate, because a filled gap is still information. It tells you the imbalance in that area has already been resolved, so the level is no longer a pending magnet. Deleting it would erase that distinction and make an untested gap look identical to a spent one.

FVG boxes are drawn at a fixed width, 3 bars by default, rather than extended indefinitely to the right, keeping the chart readable when many gaps are on screen.


REPAINTING BEHAVIOUR

Confirm Zones On Bar Close is enabled by default. With it on, order blocks and fair value gaps are evaluated only on closed bars, so a zone never appears mid-bar and then vanishes. Turn it off if you prefer to see zones form intrabar, accepting that they may change until the bar closes.

The Fibonacci levels are built from the previous higher-timeframe candle, so they are fixed for the whole period and do not repaint in either mode.


SETTINGS

Fibonacci Settings
- Show Fibonacci Levels - master toggle for the pivot grid.
- Fibonacci Period - Daily, Weekly, or Monthly.
- Show Historical Levels - off shows only the current period as lines, on shows every period as stepped plots.
- Show All Levels (R3, R4, S3, S4) - hides the 1.000 and 1.618 extensions when off.
- Show Price Labels - level name and value at the right edge.
- Level Extend (bars) - how far past the last bar the current-period lines and labels are placed.
- Individual colours for PP, R1, R2, S1, S2, and the extension levels.

Order Block Settings
- Show Order Blocks - master toggle.
- Swing Lookback - structure required to confirm a swing point, minimum 3. Higher values give fewer, more significant blocks.
- Show Last Bullish OB and Show Last Bearish OB - how many of the most recent blocks to draw, 0 disables that side.
- Use Candle Body - body-only boundaries instead of wick-to-wick.
- Show Historical Polarity Changes - triangle markers on swing points inside broken blocks.
- OB Extend (bars) - how far to the right active blocks are projected.
- Separate colours for bullish and bearish blocks and for their breaker state.

FVG Settings
- Show FVG Zones - master toggle.
- Show Last Bullish FVG and Show Last Bearish FVG - how many gaps to draw per side, 0 disables that side.
- Auto Threshold - volatility filter for insignificant gaps.
- FVG Width (bars) - box width for unmitigated gaps.
- Colours for bullish, bearish, and mitigated gaps.

General
- Confirm Zones On Bar Close - see the repainting section above.
- Max History Bars - how far back zones are detected, 3000 by default, 0 for all available history. Lowering it speeds up loading on long intraday histories.


HOW TO USE IT

The three modules answer different questions, and reading them together is the point.

Establish the framework first. The pivot grid is known before the period opens. PP acts as the balance point for the period: sustained trade above it favours the long side, below it the short side. R1/S1 and R2/S2 are the levels where a normal session tends to stall, while R3/S3 and R4/S4 come into play only when the period trends strongly.

Then look for reactive confirmation. An order block sitting on top of a pivot level is a stronger area than either alone, because a static calculation and an actual footprint of aggressive orders point at the same price. An unmitigated FVG between the current price and a pivot level suggests an unfilled imbalance in the path, which is useful when judging whether a target is likely to be reached in one move.

Use breakers to read failure. When a bullish block flips to breaker and price returns to it from below, an area that failed as support is being tested as resistance. Combined with the pivot grid, a breaker forming just under PP after a failed reclaim gives a different picture than the same breaker forming at R2.

Mitigated gaps set expectations. A cluster of grey, mitigated gaps below price means that region has already been rebalanced, while the remaining coloured gaps mark where imbalance is still open.

Practical starting points: on intraday charts use Daily pivots with Swing Lookback around 10. On 4H and Daily charts use Weekly or Monthly pivots and raise the lookback to 15 to 20, so only major structure produces blocks. Turn off Show All Levels when the extensions sit far outside the period's range and add nothing.

None of these are entry signals on their own. Every zone this script draws is an area of interest that still requires your own confirmation, risk placement, and context.


NOTES AND LIMITATIONS

- Drawing objects are created once and repositioned rather than deleted and redrawn every bar, which keeps the script responsive on long histories.
- Stored zones are capped at 100 per type internally, and the display is capped at 50 per side, to stay within platform drawing limits.
- Boxes are positioned by bar index rather than by time, so zone widths stay consistent across weekend and holiday gaps.
- The pivot grid requires the chart timeframe to be at or below the selected pivot period.
- Fair value gaps are detected on the chart timeframe only. There is no multi-timeframe FVG option in this version.


ALERTS

Eleven alert conditions are available: price crossing PP, R1, R2, S1, and S2, plus bullish and bearish order block formation, bullish and bearish breaker block confirmation, and bullish and bearish FVG formation.


CREDITS AND LICENSE

The order block and breaker block logic in this script is based on LuxAlgo's open-source Pine Script work, used and re-shared under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license (CC BY-NC-SA 4.0). Full credit for that component goes to LuxAlgo.

The Fibonacci pivot module, the fair value gap detection with mitigation tracking, the current-period display mode, the drawing-reuse architecture, and the integration of the three modules are original work by the author. This script was ported from the author's own MetaTrader 5 implementation.

This script is published under the same CC BY-NC-SA 4.0 license.


This script is a technical analysis tool for research and educational purposes. It is not financial advice, it does not predict future prices, and it makes no claim about profitability. Trade at your own risk.

Penafian

Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.