Adaptive Range Filter [MarkitTick]

More exclusive indicators from MarkitTick
Subscribe to MarkitTick for $43.75/month to get exclusive indicators by this author. You pay right on TradingView and can use them on your charts straight away.
Explore MarkitTick๐ก This overlay draws a single trend-following line that stays flat while price wanders inside a volatility-scaled corridor and moves only when price pushes outside it, then trails price at exactly one range distance. The colour of the line and of the candles shows which way the line last moved, BULL and BEAR labels mark each flip between the two sides, and an optional dashboard summarises the current state.
The width of the corridor is not fixed. It is a multiple of a smoothed average of how far price normally moves from one bar to the next, so the line widens in fast markets and tightens in quiet ones. Several optional layers sit on top of this core: an automatic averaging length, a choppiness-based widening, a multi-candle breakout confirmation, a higher-timeframe agreement check and an ADX strength check.
โจ Originality and Utility
A plain moving average follows every tick of price, so in sideways conditions it keeps turning and produces a stream of small direction changes. This script uses a different mechanism: a range filter, which behaves like a dead-band. Price has to travel a full range away from the line before the line reacts, and when it does react, it moves only enough to stay one range behind price.
What this changes in practice:
The script does not try to be a complete system. It gives a clean, readable trend state and a set of optional checks that a trader can enable one at a time to see what each does to the signals.
โ Mashup Justification
Several known ideas are combined here, and each one is attached to a specific weakness of a fixed-width range filter rather than added for its own sake:
The components feed each other in one chain: source, then range, then line, then raw condition, then optional filters, then a flip between opposite conditions. Each layer is off by default, so the base behaviour is the plain range filter and every extra is something the user switches on deliberately.
๐ฌ Methodology and Concepts
โข Source and Smoothing
The line and its range are built from the close. If Smoothing is set to SMA, EMA, RMA, WMA or HMA, they are built from the smoothed close instead, using Smoothing Length. With Smoothing set to None the raw close is used. Signal conditions always compare the raw close against the line, never the smoothed value.
โข The Range
The range starts from the bar-to-bar change of the source, taken as an absolute value so direction does not matter. That series is averaged with an exponential moving average whose length is Range Length (default 20). The exponential average weights recent bars more heavily, using a smoothing factor of 2 divided by (length plus 1).
If Double Smoothing is on, a second exponential average of length (2 times Range Length minus 1) is applied to the first one, which produces a smoother and slower range.
The result is multiplied by the Range Multiplier. The multiplier is chosen from a fixed list: 0.618, 1.0, 1.618, 2.0, 2.618, 3.0 and 3.618.
โข The Filter Line
The line starts at the first source value. On each bar it compares the source with its own previous value:
This is why the line is flat inside the corridor and trails price at one range distance after a move.
โข Direction and Steps
Direction is +1 when the line last moved up and -1 when it last moved down. It holds its value while the line is flat. A step counter records how many bars the line has moved in its current direction since the last flip, with the flip bar counting as 1.
โข Auto Length
When Auto Length is on, the script measures the average absolute close-to-close change over 10 bars and over 200 bars. It takes the natural logarithm of the ratio between them, limited in size to the logarithm of 2.
The averaging length is then set between 100 and 20: equal short and long averages give 100, and a ratio of 2 or more in either direction gives 20, with values in between interpolated and rounded. Because the logarithm is symmetric, a short average twice as large and a short average half as large both give 20.
This needs about 200 bars of history. Until then, or while either average is zero, Range Length is used instead.
โข Chop Widening
When Chop Widening is on, the script compares two numbers over the last 20 bars: the sum of true ranges (ATR with a period of 1) and the span between the highest high and the lowest low.
The chop reading is the logarithm of their ratio divided by the logarithm of 20, never below zero. It is 0 when the two are equal and grows as the sum of true ranges grows relative to the span. The range is then multiplied by (1 plus chop). No widening is applied until 20 bars exist or while the span is zero.
โข Raw Conditions
With Breakout Signals off:
With Breakout Signals on:
โข Filters and the Signal
A raw condition becomes a confirmed condition only if the enabled filters allow it. The last confirmed condition is stored as a state. A signal, shown as a BULL or BEAR label, is the first confirmed condition on the opposite side of the stored state. The very first confirmed condition on the chart sets the state and does not draw a label, because there is no opposite side yet to flip from.
โข HTF Filter
The higher timeframe runs the same calculation with the same settings, including Smoothing and Breakout Candles, and its state is taken from the last completed higher-timeframe bar. With Breakout Signals on, that state is the direction of the last BULL or BEAR condition on the higher timeframe, counted before the HTF and Strength filters. With Breakout Signals off, it is the higher-timeframe line direction.
If the HTF Timeframe equals the chart timeframe, the chart's own state is used and the filter does not block anything. If it is lower than the chart timeframe, the filter is skipped and the dashboard says so. A state that is not known yet, or has not formed yet, passes neither a long nor a short.
โข Strength Filter
ADX is calculated with ADX Length for both the directional index and its smoothing. A signal passes only when ADX is at or above ADX Threshold.
๐จ Visual Guide
๐ How to Use
โ๏ธ Inputs and Settings
โ Core
โ Filters
โ Visuals and Dashboard
โ Alerts
โ Colors
๐ Deconstruction of the Underlying Scientific and Academic Framework
โข Non-linear filtering with a dead-band
A linear smoother such as a moving average responds to every change in its input. The range filter is a non-linear element: its output changes only when the input leaves a band around the current output. In signal-processing terms this is a dead-band, or hysteresis, behaviour. Hysteresis is what keeps a thermostat from switching on and off around its set point, and here it keeps the line from reacting to movement smaller than the band.
โข Dispersion measured on first differences
The band width comes from the average absolute value of the first difference of the series. Averaging absolute deviations is a standard measure of dispersion, close in spirit to the mean absolute deviation, and it is less sensitive to a few large values than a squared measure such as standard deviation. Using first differences measures how much the series moves per step rather than how far it sits from a mean, which fits a filter that must follow a moving series.
โข Exponentially weighted averaging
The exponential moving average is a recursive estimator: each new value is the previous value plus a fixed fraction of the new error, with the fraction equal to 2 divided by (length plus 1). Its average lag is (length minus 1) divided by 2 bars. Cascading two of them, as Double Smoothing does with lengths n and (2n minus 1), adds their lags and gives a smoother output at the cost of a slower response.
โข Regime comparison through a log ratio
Auto Length compares short-horizon and long-horizon average movement. Taking the logarithm of their ratio turns multiplicative differences into symmetric additive ones, so a doubling and a halving are treated as equally large departures from the long-run level. The result is mapped linearly onto the length range from 100 down to 20, which makes the averaging shorter whenever the recent regime differs strongly from the long-run one, in either direction.
โข Path length versus net displacement
The chop reading divides the total distance travelled (sum of true ranges) by the net distance covered (highest high minus lowest low). A ratio near 1 means movement was mostly in one direction. A large ratio means price covered a lot of ground without getting anywhere. Normalising the logarithm of the ratio by the logarithm of the window length gives a value that is mostly between 0 and 1. This ratio of path length to displacement is the same idea behind efficiency-style and fractal-dimension-style measures of market noise, and the formula matches the Choppiness Index with its 0 to 100 scale expressed as 0 to 1.
โข Directional movement
The Strength Filter uses the Average Directional Index from J. Welles Wilder's directional movement system, which measures how strongly price is trending regardless of direction, on a scale of 0 to 100.
โข Multi-timeframe consistency
The HTF Filter applies the idea that a larger timeframe sets the context for a smaller one. Running the identical calculation on both timeframes keeps the two states comparable, because they are produced by the same rules.
โข Limits
Any filter built from past prices reacts after the move has started. The dead-band reduces small reversals but adds delay, and a wider corridor adds more of it. Results depend on the instrument, the timeframe and the settings, and a setting that suits one market can be a poor fit for another.
โ ๏ธ Disclaimer
All provided scripts and indicators are strictly for educational exploration and must not be interpreted as financial advice or a recommendation to execute trades. We expressly disclaim all liability for any financial losses or damages that may result, directly or indirectly, from the reliance on or application of these tools. Market participation carries inherent risk where past performance never guarantees future returns, leaving all investment decisions and due diligence solely at your own discretion.
The width of the corridor is not fixed. It is a multiple of a smoothed average of how far price normally moves from one bar to the next, so the line widens in fast markets and tightens in quiet ones. Several optional layers sit on top of this core: an automatic averaging length, a choppiness-based widening, a multi-candle breakout confirmation, a higher-timeframe agreement check and an ADX strength check.
โจ Originality and Utility
A plain moving average follows every tick of price, so in sideways conditions it keeps turning and produces a stream of small direction changes. This script uses a different mechanism: a range filter, which behaves like a dead-band. Price has to travel a full range away from the line before the line reacts, and when it does react, it moves only enough to stay one range behind price.
What this changes in practice:
- The line has flat stretches. A flat stretch means price has not moved far enough to matter at the current volatility setting.
- Direction is read from the last move of the line, not from the slope of an average, so direction does not flicker while the line is flat.
- The corridor is expressed in price units derived from recent movement, so the same Range Multiplier behaves sensibly on a slow instrument and on a fast one.
- Both the averaging length and the width can adapt on their own when the optional adaptive features are switched on.
The script does not try to be a complete system. It gives a clean, readable trend state and a set of optional checks that a trader can enable one at a time to see what each does to the signals.
โ Mashup Justification
Several known ideas are combined here, and each one is attached to a specific weakness of a fixed-width range filter rather than added for its own sake:
- Range filter core: provides the trend line and its direction. On its own the corridor width is a single fixed multiple of recent movement.
- Auto Length: the averaging length that sets the corridor is compared against a regime measure (short-term versus long-term average movement), so the corridor reacts faster when the volatility regime shifts.
- Chop Widening: a choppiness reading over the last 20 bars widens the corridor when price is covering a lot of ground without making net progress, which is exactly where a narrow corridor produces repeated whipsaws.
- Breakout Signals and Breakout Candles: instead of accepting any close on the correct side of the line, a condition can require the close to clear the line by half a range, for one or several candles in a row.
- HTF Filter: a long is allowed only when the higher-timeframe state is bullish and a short only when it is bearish, so lower-timeframe flips against the larger picture can be skipped.
- Strength Filter: signals pass only when ADX is at or above a chosen threshold, so flips inside very weak directional conditions can be skipped.
- Smoothing: the source the line is built from can be smoothed with one of five averages, while signals still compare the raw close.
The components feed each other in one chain: source, then range, then line, then raw condition, then optional filters, then a flip between opposite conditions. Each layer is off by default, so the base behaviour is the plain range filter and every extra is something the user switches on deliberately.
๐ฌ Methodology and Concepts
โข Source and Smoothing
The line and its range are built from the close. If Smoothing is set to SMA, EMA, RMA, WMA or HMA, they are built from the smoothed close instead, using Smoothing Length. With Smoothing set to None the raw close is used. Signal conditions always compare the raw close against the line, never the smoothed value.
โข The Range
The range starts from the bar-to-bar change of the source, taken as an absolute value so direction does not matter. That series is averaged with an exponential moving average whose length is Range Length (default 20). The exponential average weights recent bars more heavily, using a smoothing factor of 2 divided by (length plus 1).
If Double Smoothing is on, a second exponential average of length (2 times Range Length minus 1) is applied to the first one, which produces a smoother and slower range.
The result is multiplied by the Range Multiplier. The multiplier is chosen from a fixed list: 0.618, 1.0, 1.618, 2.0, 2.618, 3.0 and 3.618.
โข The Filter Line
The line starts at the first source value. On each bar it compares the source with its own previous value:
- If the source is more than one range above the previous line value, the line moves up to source minus range.
- If the source is more than one range below the previous line value, the line moves down to source plus range.
- Otherwise the line stays exactly where it was.
This is why the line is flat inside the corridor and trails price at one range distance after a move.
โข Direction and Steps
Direction is +1 when the line last moved up and -1 when it last moved down. It holds its value while the line is flat. A step counter records how many bars the line has moved in its current direction since the last flip, with the flip bar counting as 1.
โข Auto Length
When Auto Length is on, the script measures the average absolute close-to-close change over 10 bars and over 200 bars. It takes the natural logarithm of the ratio between them, limited in size to the logarithm of 2.
The averaging length is then set between 100 and 20: equal short and long averages give 100, and a ratio of 2 or more in either direction gives 20, with values in between interpolated and rounded. Because the logarithm is symmetric, a short average twice as large and a short average half as large both give 20.
This needs about 200 bars of history. Until then, or while either average is zero, Range Length is used instead.
โข Chop Widening
When Chop Widening is on, the script compares two numbers over the last 20 bars: the sum of true ranges (ATR with a period of 1) and the span between the highest high and the lowest low.
The chop reading is the logarithm of their ratio divided by the logarithm of 20, never below zero. It is 0 when the two are equal and grows as the sum of true ranges grows relative to the span. The range is then multiplied by (1 plus chop). No widening is applied until 20 bars exist or while the span is zero.
โข Raw Conditions
With Breakout Signals off:
- BULL condition: the close is above the line, the line's last move was up, and the close differs from the previous close.
- BEAR condition: the close is below the line, the line's last move was down, and the close differs from the previous close.
With Breakout Signals on:
- BULL condition: the close is above the line by at least half the current range, for as many candles in a row as Breakout Candles sets.
- BEAR condition: the close is below the line by at least half the current range, for as many candles in a row as Breakout Candles sets.
- Each of those candles is checked against the line and range of its own bar.
โข Filters and the Signal
A raw condition becomes a confirmed condition only if the enabled filters allow it. The last confirmed condition is stored as a state. A signal, shown as a BULL or BEAR label, is the first confirmed condition on the opposite side of the stored state. The very first confirmed condition on the chart sets the state and does not draw a label, because there is no opposite side yet to flip from.
โข HTF Filter
The higher timeframe runs the same calculation with the same settings, including Smoothing and Breakout Candles, and its state is taken from the last completed higher-timeframe bar. With Breakout Signals on, that state is the direction of the last BULL or BEAR condition on the higher timeframe, counted before the HTF and Strength filters. With Breakout Signals off, it is the higher-timeframe line direction.
If the HTF Timeframe equals the chart timeframe, the chart's own state is used and the filter does not block anything. If it is lower than the chart timeframe, the filter is skipped and the dashboard says so. A state that is not known yet, or has not formed yet, passes neither a long nor a short.
โข Strength Filter
ADX is calculated with ADX Length for both the directional index and its smoothing. A signal passes only when ADX is at or above ADX Threshold.
๐จ Visual Guide
- Range Filter line: a thick line on the price pane. Bright green (default) while the line is rising, bright magenta while it is falling, light grey before its first move. With Breakout Signals on, the colour follows the last confirmed BULL or BEAR condition instead, and grey is shown until the first one.
- Trend Candles: the whole candle, including body, wicks and border, takes the same colour as the line, so the state can be read from the candles alone.
- BULL label: a green label with white text, placed below the signal bar and pointing up. It marks the first confirmed bullish condition after a bearish one.
- BEAR label: a dark pink label with white text, placed above the signal bar and pointing down. It marks the first confirmed bearish condition after a bullish one.
- Hidden trend output: an invisible plot named External Output - Trend Signal carries +1, -1 or 0 for the line direction. It does not draw anything but can be selected as an input source in other indicators.
- Dashboard header: a two-cell header showing ARF on the left and the ticker with a short timeframe text on the right.
- Trend row: Bullish, Bearish or a dash before the line's first move, coloured with the Bull and Bear colours.
- Price vs Filter row: Above, Below or At, showing where the close sits against the line.
- Last Signal row: BULL or BEAR for the last signal, or a dash before the first signal. The chart keeps at most the last 500 markers.
- Bars Since row: bars since the last signal.
- Range Filter row: the current price level of the line.
- Range row: the distance the line follows price at on this bar, after Chop Widening when it is on.
- Length row: the averaging length actually used this bar. It appears only while Auto Length is on.
- Chop row: the chop reading as a percentage with a ten-block progress bar. It appears only while Chop Widening is on. The bar is teal at 66% and above, amber from 33% up to 66% and red below 33%.
- Steps row: the step count described above.
- HTF row: Bullish, Bearish, a dash, or Skipped on an amber-filled row. Green means the higher-timeframe state agrees with the chart's own state, red means it does not. It appears only while HTF Filter is on.
- Strength row: the ADX value, green when it passes the threshold and red when it does not. It appears only while Strength Filter is on.
- Smoothing row: the smoothing type and length. It appears only when Smoothing is not None.
- Unsupported chart types: on Heikin Ashi, Renko, Kagi, Point & Figure, Range and Line Break charts the indicator draws nothing except a red warning box asking for standard candles, because those chart types show synthetic prices.
๐ How to Use
- Add the indicator to a standard candle chart and read the line colour first. Green says the line last moved up, magenta says it last moved down.
- Treat flat stretches of the line as a sign that price is still inside the corridor. A flat line does not mean the trend has ended, only that price has not travelled a full range away from it.
- Use the BULL and BEAR labels as the points where the confirmed state flips. Read them together with the Steps row: a flip followed by a rising step count means the line keeps moving in the new direction.
- If the line flips too often on your market, raise the Range Multiplier, switch on Chop Widening, or switch on Breakout Signals and raise Breakout Candles.
- If the line reacts too slowly, lower the Range Multiplier or Range Length.
- Switch on HTF Filter when you want signals to agree with a larger timeframe. Read the HTF row: green means agreement and red means the signal would be blocked.
- Switch on Strength Filter when you want to skip flips that occur while ADX is below the threshold. Check the Strength row to see why a flip did or did not pass.
- Change one setting at a time and look at the same stretch of chart, so the effect of each layer is easy to see.
- Test any configuration across several instruments and timeframes. The behaviour depends on volatility, and no setting suits every market.
โ๏ธ Inputs and Settings
โ Core
- Range Multiplier: the corridor width as a multiple of the averaged change. Higher gives a wider corridor and a line that moves less often. Lower gives a narrower corridor and a line that moves more often.
- Range Length: the exponential average length for the absolute change. Higher is slower, lower is faster.
- Auto Length: replaces Range Length with the automatic length described above once there is enough history.
- Double Smoothing: applies a second exponential average to the averaged change for a smoother range.
- Chop Widening: multiplies the range by (1 plus chop) based on the last 20 bars.
- Breakout Signals: requires the close to clear the line by half a range instead of only being on the correct side.
- Breakout Candles: how many candles in a row must clear the line by half a range. 1 means a single candle. Used only while Breakout Signals is on.
โ Filters
- HTF Filter: allows longs only when the higher-timeframe state is bullish and shorts only when it is bearish.
- HTF Timeframe: the higher timeframe used by the filter, 240 minutes by default. Not lower than the chart timeframe.
- Strength Filter: lets signals pass only when ADX is at or above the threshold.
- ADX Threshold: the minimum ADX value, 20 by default.
- ADX Length: the length used to calculate ADX, 14 by default.
- Smoothing: None, SMA, EMA, RMA, WMA or HMA, applied to the close the line and range are built from.
- Smoothing Length: the length of that smoothing, 20 by default.
โ Visuals and Dashboard
- Signal Markers: shows or hides the BULL and BEAR labels.
- Range Filter: shows or hides the line only. Signals, candles and the dashboard are unchanged.
- Trend Candles: shows or hides the candle colouring.
- Show Dashboard: shows or hides the table only. Calculations and alerts are unchanged.
- Position: top right, top left, bottom right or bottom left.
โ Alerts
- Trade Direction: Long & Short, Long Only or Short Only. In Long & Short, a BULL opens a long and closes a short, and a BEAR opens a short and closes a long. In Long Only, a BULL opens a long and a BEAR closes it, and no short orders are sent. In Short Only, a BEAR opens a short and a BULL closes it, and no long orders are sent. Markers, candles and the dashboard show both signals in every mode.
- Long Action, Short Action, Close Long Action and Close Short Action: the text placed in the action field of the alert payload. Defaults are long, short, closelong and closeshort.
- The payload is a text message with the fields action, ticker, tf, direction and trend, where trend is bullish, bearish or neutral from the line direction.
- Four alert conditions are available in the alert dialog: BUY Signal, SELL Signal, Close Long Signal and Close Short Signal.
โ Colors
- Filter Up, Filter Down and Filter Flat colour the line and candles.
- Bull and Bear colour the labels and bullish or bearish dashboard values. Label Text colours the text on the labels.
- Dash Header, Dash BG and Dash Text colour the dashboard. Bar High, Bar Mid and Bar Low colour the progress bar and the passing or failing filter rows. Warning Fill colours a row whose filter is skipped.
๐ Deconstruction of the Underlying Scientific and Academic Framework
โข Non-linear filtering with a dead-band
A linear smoother such as a moving average responds to every change in its input. The range filter is a non-linear element: its output changes only when the input leaves a band around the current output. In signal-processing terms this is a dead-band, or hysteresis, behaviour. Hysteresis is what keeps a thermostat from switching on and off around its set point, and here it keeps the line from reacting to movement smaller than the band.
โข Dispersion measured on first differences
The band width comes from the average absolute value of the first difference of the series. Averaging absolute deviations is a standard measure of dispersion, close in spirit to the mean absolute deviation, and it is less sensitive to a few large values than a squared measure such as standard deviation. Using first differences measures how much the series moves per step rather than how far it sits from a mean, which fits a filter that must follow a moving series.
โข Exponentially weighted averaging
The exponential moving average is a recursive estimator: each new value is the previous value plus a fixed fraction of the new error, with the fraction equal to 2 divided by (length plus 1). Its average lag is (length minus 1) divided by 2 bars. Cascading two of them, as Double Smoothing does with lengths n and (2n minus 1), adds their lags and gives a smoother output at the cost of a slower response.
โข Regime comparison through a log ratio
Auto Length compares short-horizon and long-horizon average movement. Taking the logarithm of their ratio turns multiplicative differences into symmetric additive ones, so a doubling and a halving are treated as equally large departures from the long-run level. The result is mapped linearly onto the length range from 100 down to 20, which makes the averaging shorter whenever the recent regime differs strongly from the long-run one, in either direction.
โข Path length versus net displacement
The chop reading divides the total distance travelled (sum of true ranges) by the net distance covered (highest high minus lowest low). A ratio near 1 means movement was mostly in one direction. A large ratio means price covered a lot of ground without getting anywhere. Normalising the logarithm of the ratio by the logarithm of the window length gives a value that is mostly between 0 and 1. This ratio of path length to displacement is the same idea behind efficiency-style and fractal-dimension-style measures of market noise, and the formula matches the Choppiness Index with its 0 to 100 scale expressed as 0 to 1.
โข Directional movement
The Strength Filter uses the Average Directional Index from J. Welles Wilder's directional movement system, which measures how strongly price is trending regardless of direction, on a scale of 0 to 100.
โข Multi-timeframe consistency
The HTF Filter applies the idea that a larger timeframe sets the context for a smaller one. Running the identical calculation on both timeframes keeps the two states comparable, because they are produced by the same rules.
โข Limits
Any filter built from past prices reacts after the move has started. The dead-band reduces small reversals but adds delay, and a wider corridor adds more of it. Results depend on the instrument, the timeframe and the settings, and a setting that suits one market can be a poor fit for another.
โ ๏ธ Disclaimer
All provided scripts and indicators are strictly for educational exploration and must not be interpreted as financial advice or a recommendation to execute trades. We expressly disclaim all liability for any financial losses or damages that may result, directly or indirectly, from the reliance on or application of these tools. Market participation carries inherent risk where past performance never guarantees future returns, leaving all investment decisions and due diligence solely at your own discretion.
๐ก Proprietary indicators. Original research. Built by analysts who trade.
๐ข Free Telegram: t.me/MarkitTick_Updates
๐ Premium: TradingView Marketplace
๐ Guides: markittick.com
๐ข Free Telegram: t.me/MarkitTick_Updates
๐ Premium: TradingView Marketplace
๐ Guides: markittick.com
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.
๐ก Proprietary indicators. Original research. Built by analysts who trade.
๐ข Free Telegram: t.me/MarkitTick_Updates
๐ Premium: TradingView Marketplace
๐ Guides: markittick.com
๐ข Free Telegram: t.me/MarkitTick_Updates
๐ Premium: TradingView Marketplace
๐ Guides: markittick.com
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.