OPEN-SOURCE SCRIPT
Range Compression Percentile - Hour Ranked

This indicator gives no directional signal. It answers a single question: will the amplitude of the coming hours be large enough to be worth paying a round turn?
What makes it different
Intraday amplitude on a futures contract varies by a factor of 3 to 4 across the trading day. Any absolute threshold — "range below 50 points means compression" — therefore mostly measures what time it is, not the state of the market. A quiet 10:00 in New York and a busy 02:00 can show the same raw range while meaning opposite things.
This script ranks the current range as a percentile against the history of the same hour of the day. That hour-for-hour ranking is the part I have not seen elsewhere, and it is what makes the reading comparable at any time of day.
How it is calculated
The range of the last N bars (default 78, which is 6h30 on a 5-minute chart, one full RTH session) is measured as (highest high − lowest low) / close, expressed in basis points so it is comparable across instruments and across price levels.
Once per elapsed hour, that value is stored in a circular buffer belonging to that hour of the day. Each of the 24 hours keeps its own history, 120 observations by default — roughly six months of sessions.
The current range is then ranked against that hour's stored history. The result is a percentile from 0 to 100, plotted as a histogram and coloured by quintile.
A second reading divides the current range by a user-supplied round-turn cost, giving an amplitude-to-cost ratio.
What the measurements show
Tested on MNQ 5-minute data (12 months, 317 sessions) and GC 5-minute data (5.6 years, 1,737 sessions). Range of the following 2 hours, grouped by the quintile this indicator reports, computed causally — ranking only against hours already elapsed, exactly as the script does live:
MNQ: 39.3 / 43.4 / 47.0 / 53.8 / 64.4 bp from Q1 to Q5
GC: 35.2 / 37.9 / 41.0 / 44.2 / 59.8 bp from Q1 to Q5
Monotonic on both instruments. The bottom quintile runs at roughly 0.6x the amplitude of the top quintile.
The effect also survives a control for the last hour's range, which is the amplitude predictor already widely known: adding the compression indicator to a regression already containing the one-hour range gives it a coefficient of −10.65 bp (t = −8.65) on MNQ and −4.58 bp (t = −7.27) on gold, with hour-of-day fixed effects and standard errors clustered by session.
The result runs against the common belief. Compression does not announce expansion here. It announces more quiet.
What it does not do
It carries no directional information, and I would rather state that plainly than let the histogram suggest otherwise. On the same samples, the signed return of the 2 hours following a compression is indistinguishable from zero (MNQ −0.47 bp, t = −0.55). A range breakout traded as a symmetric bracket loses about the same amount whether traded with the break or against it (−0.241 R versus −0.258 R) — two opposite directions losing the same amount is what no information looks like.
Use it to decide whether conditions are worth trading, never which way.
How to use it
Bottom quintile (red, below 20): the next hours are likely to stay quieter than usual for this time of day. Fixed costs buy less movement.
Top quintile (green, above 80): wide amplitude relative to this hour.
The amplitude-to-cost ratio is the absolute check, and it is independent of the percentile. A market can be compressed for its hour and still offer plenty of room. Both readings are shown because they answer different questions.
Settings
Range window: number of bars in the measured range. 78 is the value the effect was measured on.
Closed bars only: freezes the range on the previous bar so the value stops moving inside the forming bar.
Reference time zone: used only to split the day into hours.
Observations kept per hour, and minimum before displaying: control how much history is required before a percentile is shown.
Round-turn cost in basis points: commission plus slippage against notional. Reference points measured on micro futures: MNQ 0.98, MES 1.89, MYM 2.06, MGC 3.00 to 3.44 depending on the price of gold. This figure depends on price and is never constant over time, so it is an input rather than a constant.
Notes and limitations
No repainting. The percentile is computed only against hours that are over and closed.
The indicator needs history before it displays anything: 20 observations for a given hour by default, so about 20 sessions.
The numbers quoted above come from two instruments over the periods stated. They are measurements on that data, not a guarantee of future behaviour.
Designed and measured on 5-minute futures charts. On other timeframes or asset classes the window length should be reconsidered.
What makes it different
Intraday amplitude on a futures contract varies by a factor of 3 to 4 across the trading day. Any absolute threshold — "range below 50 points means compression" — therefore mostly measures what time it is, not the state of the market. A quiet 10:00 in New York and a busy 02:00 can show the same raw range while meaning opposite things.
This script ranks the current range as a percentile against the history of the same hour of the day. That hour-for-hour ranking is the part I have not seen elsewhere, and it is what makes the reading comparable at any time of day.
How it is calculated
The range of the last N bars (default 78, which is 6h30 on a 5-minute chart, one full RTH session) is measured as (highest high − lowest low) / close, expressed in basis points so it is comparable across instruments and across price levels.
Once per elapsed hour, that value is stored in a circular buffer belonging to that hour of the day. Each of the 24 hours keeps its own history, 120 observations by default — roughly six months of sessions.
The current range is then ranked against that hour's stored history. The result is a percentile from 0 to 100, plotted as a histogram and coloured by quintile.
A second reading divides the current range by a user-supplied round-turn cost, giving an amplitude-to-cost ratio.
What the measurements show
Tested on MNQ 5-minute data (12 months, 317 sessions) and GC 5-minute data (5.6 years, 1,737 sessions). Range of the following 2 hours, grouped by the quintile this indicator reports, computed causally — ranking only against hours already elapsed, exactly as the script does live:
MNQ: 39.3 / 43.4 / 47.0 / 53.8 / 64.4 bp from Q1 to Q5
GC: 35.2 / 37.9 / 41.0 / 44.2 / 59.8 bp from Q1 to Q5
Monotonic on both instruments. The bottom quintile runs at roughly 0.6x the amplitude of the top quintile.
The effect also survives a control for the last hour's range, which is the amplitude predictor already widely known: adding the compression indicator to a regression already containing the one-hour range gives it a coefficient of −10.65 bp (t = −8.65) on MNQ and −4.58 bp (t = −7.27) on gold, with hour-of-day fixed effects and standard errors clustered by session.
The result runs against the common belief. Compression does not announce expansion here. It announces more quiet.
What it does not do
It carries no directional information, and I would rather state that plainly than let the histogram suggest otherwise. On the same samples, the signed return of the 2 hours following a compression is indistinguishable from zero (MNQ −0.47 bp, t = −0.55). A range breakout traded as a symmetric bracket loses about the same amount whether traded with the break or against it (−0.241 R versus −0.258 R) — two opposite directions losing the same amount is what no information looks like.
Use it to decide whether conditions are worth trading, never which way.
How to use it
Bottom quintile (red, below 20): the next hours are likely to stay quieter than usual for this time of day. Fixed costs buy less movement.
Top quintile (green, above 80): wide amplitude relative to this hour.
The amplitude-to-cost ratio is the absolute check, and it is independent of the percentile. A market can be compressed for its hour and still offer plenty of room. Both readings are shown because they answer different questions.
Settings
Range window: number of bars in the measured range. 78 is the value the effect was measured on.
Closed bars only: freezes the range on the previous bar so the value stops moving inside the forming bar.
Reference time zone: used only to split the day into hours.
Observations kept per hour, and minimum before displaying: control how much history is required before a percentile is shown.
Round-turn cost in basis points: commission plus slippage against notional. Reference points measured on micro futures: MNQ 0.98, MES 1.89, MYM 2.06, MGC 3.00 to 3.44 depending on the price of gold. This figure depends on price and is never constant over time, so it is an input rather than a constant.
Notes and limitations
No repainting. The percentile is computed only against hours that are over and closed.
The indicator needs history before it displays anything: 20 observations for a given hour by default, so about 20 sessions.
The numbers quoted above come from two instruments over the periods stated. They are measurements on that data, not a guarantee of future behaviour.
Designed and measured on 5-minute futures charts. On other timeframes or asset classes the window length should be reconsidered.
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.