The “Twin Range Filter Free indicator for Ninja Trader” is essentially a trend-following logic combined with adaptive volatility filters.
- The indicator starts with a given price series, usually the close of each bar (the source). All calculations are based on this input.
Send download link to:TwinRangeFilter
Same indicator for TradingView can be found HERE
Range Trading Explained HERE
- Computing the Smoothed Range :
The indicator calculates two “smoothed ranges” based on two different periods (a fast period and a slow period) and then averages them.- Fast Range: Uses a shorter period and a multiplier to measure recent volatility.
- Slow Range: Uses a longer period and a multiplier to gauge a more extended volatility measure.
The process involves:
a. Taking the absolute difference between the current price and the previous bar’s price.
b. Applying exponential moving averages (EMAs) twice: once over that absolute difference to get a baseline volatility measure, and then another EMA to smooth it further.
c. Scaling the result by the multiplier.After computing these two smoothed ranges, it takes the average . This final averaged smoothed range represents a dynamically adjusting “range” that adapts to current market volatility.
- Range Filter Line :
Using the computed smoothed range, the indicator creates a “filter” line . This line is not just a simple moving average; it adapts to price action by allowing for a certain range of movement.The logic is something like this:- If the price is currently above yesterday’s Range filter, then the filter tries to follow the price up but doesn’t drop below a certain threshold.
- If the price is currently below yesterday’s Range filter the filter moves down but is constrained by the algo.
In other words, the Range filter line tries to “hug” the price, but within a controlled band defined by the adaptive range. When price moves strongly in one direction, the filter line follows, but when price whipsaws, the filter line helps smooth out the noise.
- Direction Counters (upward and downward):
The indicator keeps track of how many consecutive bars the filter line has been moving upward or downward:These counters reset whenever the filter changes direction. They help confirm the strength or continuity of a move.
- Conditions for Long and Short Signals:
The indicator defines conditions for potential long and short trades based on the relationship between price and the filter line, as well as the direction counters:- Long Condition : Occurs when the source price is above the filter line and there’s a sign of upward continuity , regardless of whether the current bar is higher or lower than the previous bar. Essentially, if price is above the filter and the filter line is drifting upward, it suggests a bullish environment.
- Short Condition : Occurs when the source price is below the filter line and there’s downward continuity , indicating a bearish environment.
An internal state variable helps determine when a direction changes from bullish to bearish or vice versa. It stores the values and by comparing the current condition to the previous Condition state, the code identifies genuine shifts in direction to generate entries rather than false signals.
- Generating Signals (Long/Short):
Once a long or short condition is met and it represents a change from the opposite condition, a signal is generated: - Visualization:
- A green upward arrow when a long condition arises.
- A red downward arrow when a short condition appears.
In Summary:
- The indicator first measures volatility using a combination of fast and slow range calculations, smoothing them to avoid noise.
- It creates a dynamic filter line that tries to capture the underlying trend direction while accounting for volatility.
- Upward and downward counters track how persistently the filter line has been moving in one direction.
- Signals (Long/Short) appear when the price position relative to the filter and the persistence of the trend (via counters) indicate a probable shift in market direction.
This combination allows the Twin Range Filter to attempt to filter out choppy market behavior and only signal when there is a more meaningful directional move underway.