Quantile Threshold Bands | NickJoanQuantile Threshold Bands | NickJoan
Core Idea
Quantile Threshold Bands measures the position of price within a lookback window and uses that information to define adaptive upper and lower threshold bands. The script calculates two percentile levels from a user-defined lookback window and uses them to classify the current source value as bullish or bearish.
When the price moves above the upper quantile, the indicator turns bullish. When the price moves below the lower quantile, it turns bearish. When it returns inside the band area, the script keeps the last active state until the opposite threshold is crossed again. This gives the indicator a persistent regime structure.
Calculation Logic
The indicator works through three steps:
Source selection.
- The user chooses the price series to analyze.
Quantile calculation.
- The script looks back over a chosen number of bars.
- From that window, it calculates a lower quantile band and an upper quantile band.
- These values are obtained with a nearest-rank percentile calculation.
State assignment.
- If the source is above the upper band, the state becomes bullish.
- If the source is below the lower band, the state becomes bearish.
- If the source is between the bands, the previous state remains active.
What the Bands Mean
The lower and upper bands represent the selected percentile levels inside the recent price window.
The lower band marks a lower threshold within recent price behavior.
The upper band marks a higher threshold within recent price behavior.
The area between them defines the central zone where price is neither breaking upward nor downward.
Because the levels are recalculated on every bar, they adjust as the market changes. The result is a dynamic set of thresholds that follow the market’s own recent distribution.
Chart Output
The script displays four visual elements on the chart:
Lower Quantile line.
Upper Quantile line.
Filled zone between the two bands.
Colored candles showing the active state.
The color logic is:
Aqua when the regime is bullish.
Olive when the regime is bearish.
No color yet before the first valid state is established.
The output is designed to make the current state readable at a glance.
Inputs
The indicator has four primary inputs:
Source - The series used in the quantile calculation.
Lookback - The number of bars used to build the rolling window.
Lower Quantile % - The percentile used for the lower band.
Upper Quantile % - The percentile used for the upper band.
The lower percentile must be smaller than the upper percentile.
Alerts
The script includes alerts for regime changes:
Long Signal - Triggers when the state turns bullish.
Short Signal - Triggers when the state turns bearish.
These alerts are designed to notify the trader when price breaks into a new regime.
How to Use It
This indicator can be used as a regime filter or market bias tool.
Typical use cases include:
Directional bias filter. Use the bullish state when price is above the upper quantile and the bearish state when price is below the lower quantile.
Threshold-based alerts. Use the long and short alerts to notify you when price breaks into a new percentile regime.
Range / compression read. The distance between the two bands can help show whether recent price action has been compressed or expanded. A narrow band zone suggests tighter recent movement, while a wider band zone suggests broader recent movement.
Trade filtering. Use it to decide whether to allow only long setups, only short setups, or no directional trades depending on regime.
Chỉ báo






















