OPEN-SOURCE SCRIPT
First-Hour Imbalance

Concept
The First-Hour Imbalance is the high/low range established during the first hour of a trading session. That opening hour is where institutional order flow is heaviest — it sets the auction's initial balance. Once that range is complete, its high, low, and 50% midpoint become the session's reference levels. Price breaking and sweeping those levels is the trade signal.
The indicator automates the full lifecycle: capture → freeze → persist → signal.
Session Definitions
Four sessions, each with its own color and independent state machine:
Session Window (chart time) Color Notes
Asia 20:00 – 21:00 🟡 Yellow Tokyo open
London 02:00 – 03:00 🟢 Teal London open
NY AM 09:30 – 10:30 ET 🟠 Orange True equity open — intentionally diverges from the 08:30 start used in Liquidity Sweep PRO
NY PM 13:30 – 14:30 ET 🟣 Magenta Afternoon session
What It Draws
For each session, three horizontal lines anchored at the session's first hour and extended rightward:
Line Meaning
High IB Highest high of the first hour
50% Midpoint of the range (dashed) — the equilibrium / premium-discount divider
Low IB Lowest low of the first hour
Lines persist through the rest of the session and beyond — they don't vanish when the capture window closes. Each line is labeled at its right end.
State Machine
Each session runs its own four-state cycle:
ST_IDLE → ST_CAPTURING → ST_FROZEN → ST_DONE
ST_IDLE — outside the session window, no range yet
ST_CAPTURING — inside the first hour; high/low expanding bar by bar
ST_FROZEN — first hour closed; range locked, three lines drawn
ST_DONE — sweep detected, signal fired, lines persist to session end
Signal Logic — Definition A Sweep
The signal fires when price breaks the range boundary and then sweeps it:
SHORT signal — price wicks above High IB (liquidity grab above the range), then closes back below → Direction: SHORT
LONG signal — price wicks below Low IB, then closes back above → Direction: LONG
The sweep is the trap: stops sitting just beyond the range high/low get taken, and the reversal is the trade. A SHORT / LONG label is drawn at the signal bar.
Dashboard
A table in the top-right corner displays the live state:
Field Description
Session Currently active session (Asia / London / NY AM / NY PM)
Direction Current signal direction — SHORT, LONG, or WAIT
Last Signal Signal type — e.g. High IB Sweep
Signal Price Exact price level where the sweep occurred
Signal Time Bar time of the signal
Worked Example — London Session
Chart: HTX:BTCUSDT25U2026 · 2-minute
1. Capture (02:00 – 03:00) The first hour of London trades between:
High IB = 81,117
Low IB = 80,000
50% = 81,000 (derived)
2. Freeze (03:00) The hour closes. Range locks. Three lines draw at 81,117 / 81,000 / 80,000, extending rightward.
3. Sweep (03:08) Price wicks above 81,117 — taking out buy-side liquidity sitting above the range high — then closes back below.
4. Signal fires
Session: London
Direction: SHORT ← rendered in red
Last Signal: High IB Sweep
Signal Price: 81117.0
Signal Time: 03:08
A red SHORT label is drawn at the 03:08 bar, anchored to the High IB line.
5. Interpretation The wick above 81,117 was a liquidity grab. Price failed to hold above the range high, signalling sellers defending that level. The trade thesis: short the failed breakout, target the 50% midpoint (81,000), then the Low IB (80,000).
Reading the Levels
Scenario Interpretation
Price holds above High IB Bullish acceptance — range high becomes support; look for continuation
Price sweeps above High IB then rejects Bearish — liquidity taken, expect rotation back into range
Price holds above 50% Premium — sellers have the edge; longs need discount
Price holds below 50% Discount — buyers have the edge; shorts are chasing
Price sweeps below Low IB then reclaims Bullish — sell-side liquidity taken, expect rotation up
Price holds below Low IB Bearish acceptance — range low becomes resistance
The 50% line is the bias divider: above = premium (favour shorts), below = discount (favour longs).
Technical Notes
Pine v6, Midniteblade
max_bars_back history buffers declared on reassigned series variables (volSeries, hlc3Series, closeSeries, openSeries) — required because Pine keys history buffers to the specific series referenced, not the built-in name
Dynamic indexing inside the capture loop uses those reassigned variables, not the built-ins
max_lines_count / max_labels_count sized for four sessions × three lines × labels across the visible history
Lines anchored at the freeze bar, extended rightward, persisting through session end
Why It Works
The first hour of a session is where the day's initial auction resolves. Once that range is set, it becomes the map: the high and low are where stops cluster, and the 50% is where the market decides premium vs discount. The indicator doesn't predict direction — it marks the levels where liquidity sits, then tells you when that liquidity gets taken.
The sweep signal is the payoff: a break of the range that fails is far more informative than a break that holds.
The First-Hour Imbalance is the high/low range established during the first hour of a trading session. That opening hour is where institutional order flow is heaviest — it sets the auction's initial balance. Once that range is complete, its high, low, and 50% midpoint become the session's reference levels. Price breaking and sweeping those levels is the trade signal.
The indicator automates the full lifecycle: capture → freeze → persist → signal.
Session Definitions
Four sessions, each with its own color and independent state machine:
Session Window (chart time) Color Notes
Asia 20:00 – 21:00 🟡 Yellow Tokyo open
London 02:00 – 03:00 🟢 Teal London open
NY AM 09:30 – 10:30 ET 🟠 Orange True equity open — intentionally diverges from the 08:30 start used in Liquidity Sweep PRO
NY PM 13:30 – 14:30 ET 🟣 Magenta Afternoon session
What It Draws
For each session, three horizontal lines anchored at the session's first hour and extended rightward:
Line Meaning
High IB Highest high of the first hour
50% Midpoint of the range (dashed) — the equilibrium / premium-discount divider
Low IB Lowest low of the first hour
Lines persist through the rest of the session and beyond — they don't vanish when the capture window closes. Each line is labeled at its right end.
State Machine
Each session runs its own four-state cycle:
ST_IDLE → ST_CAPTURING → ST_FROZEN → ST_DONE
ST_IDLE — outside the session window, no range yet
ST_CAPTURING — inside the first hour; high/low expanding bar by bar
ST_FROZEN — first hour closed; range locked, three lines drawn
ST_DONE — sweep detected, signal fired, lines persist to session end
Signal Logic — Definition A Sweep
The signal fires when price breaks the range boundary and then sweeps it:
SHORT signal — price wicks above High IB (liquidity grab above the range), then closes back below → Direction: SHORT
LONG signal — price wicks below Low IB, then closes back above → Direction: LONG
The sweep is the trap: stops sitting just beyond the range high/low get taken, and the reversal is the trade. A SHORT / LONG label is drawn at the signal bar.
Dashboard
A table in the top-right corner displays the live state:
Field Description
Session Currently active session (Asia / London / NY AM / NY PM)
Direction Current signal direction — SHORT, LONG, or WAIT
Last Signal Signal type — e.g. High IB Sweep
Signal Price Exact price level where the sweep occurred
Signal Time Bar time of the signal
Worked Example — London Session
Chart: HTX:BTCUSDT25U2026 · 2-minute
1. Capture (02:00 – 03:00) The first hour of London trades between:
High IB = 81,117
Low IB = 80,000
50% = 81,000 (derived)
2. Freeze (03:00) The hour closes. Range locks. Three lines draw at 81,117 / 81,000 / 80,000, extending rightward.
3. Sweep (03:08) Price wicks above 81,117 — taking out buy-side liquidity sitting above the range high — then closes back below.
4. Signal fires
Session: London
Direction: SHORT ← rendered in red
Last Signal: High IB Sweep
Signal Price: 81117.0
Signal Time: 03:08
A red SHORT label is drawn at the 03:08 bar, anchored to the High IB line.
5. Interpretation The wick above 81,117 was a liquidity grab. Price failed to hold above the range high, signalling sellers defending that level. The trade thesis: short the failed breakout, target the 50% midpoint (81,000), then the Low IB (80,000).
Reading the Levels
Scenario Interpretation
Price holds above High IB Bullish acceptance — range high becomes support; look for continuation
Price sweeps above High IB then rejects Bearish — liquidity taken, expect rotation back into range
Price holds above 50% Premium — sellers have the edge; longs need discount
Price holds below 50% Discount — buyers have the edge; shorts are chasing
Price sweeps below Low IB then reclaims Bullish — sell-side liquidity taken, expect rotation up
Price holds below Low IB Bearish acceptance — range low becomes resistance
The 50% line is the bias divider: above = premium (favour shorts), below = discount (favour longs).
Technical Notes
Pine v6, Midniteblade
max_bars_back history buffers declared on reassigned series variables (volSeries, hlc3Series, closeSeries, openSeries) — required because Pine keys history buffers to the specific series referenced, not the built-in name
Dynamic indexing inside the capture loop uses those reassigned variables, not the built-ins
max_lines_count / max_labels_count sized for four sessions × three lines × labels across the visible history
Lines anchored at the freeze bar, extended rightward, persisting through session end
Why It Works
The first hour of a session is where the day's initial auction resolves. Once that range is set, it becomes the map: the high and low are where stops cluster, and the 50% is where the market decides premium vs discount. The indicator doesn't predict direction — it marks the levels where liquidity sits, then tells you when that liquidity gets taken.
The sweep signal is the payoff: a break of the range that fails is far more informative than a break that holds.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.