-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Indicator Name
Range Filtered Trend Signals
Category
Trend
Description
Introducing the Range Filtered Trend Signals, a cutting-edge trading indicator designed to detect market trends and ranging conditions with high accuracy. This indicator leverages a combination of Kalman filtering and Supertrend analysis to smooth out price fluctuations while maintaining responsiveness to trend shifts. By incorporating volatility-based range filtering, it ensures traders can differentiate between trending and ranging conditions effectively, reducing false signals and enhancing trade decision-making.
🔑 Key Features
✅ Kalman Filter Smoothing – Minimizes market noise while preserving trend clarity.
📊 Supertrend Integration – A dynamic trend-following mechanism for spotting reversals.
🔥 Volatility-Based Range Detection – Detects trending vs. ranging conditions with precision.
🎨 Color-Coded Trend Signals – Instantly recognize bullish, bearish, and ranging market states.
⚙️ Customizable Inputs – Fine-tune Kalman parameters, Supertrend settings, and color themes to match your strategy.
🔔 Alerts for Trend Shifts – Get real-time notifications when market conditions change!
:tools: How to Use
Add the Indicator – Click the star icon to add it to your TradingView favorites.
snapshot
Analyze Market Conditions – Observe the color-coded signals and range boundaries to identify trend strength and direction.
snapshot
Use Alerts for Trade Execution – Set alerts for trend shifts and market conditions to stay ahead without constantly monitoring charts.
snapshot
🔍 How It Works
The Kalman filter smooths price fluctuations by dynamically adjusting its weighting based on market volatility. It helps remove noise while keeping the signal reactive to trend changes. The Supertrend calculation is then applied to the filtered price data, providing a robust trend-following mechanism. To enhance signal accuracy, a volatility-weighted range filter is incorporated, creating upper and lower boundaries that define trend conditions. When price breaks out of these boundaries, the indicator confirms trend continuation, while signals within the range indicate market consolidation. Traders can leverage this tool to enhance trade timing, filter false breakouts, and identify optimal entry/exit zones.
Reference Chart(s)
Chart Description
See image
Parameters
period(int, default=14):source_column(str, default='Close'):
Source / Reference
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlgoAlpha
//@Version=6
indicator("Range Filtered Trend Signals [AlgoAlpha]", "AlgoAlpha - Range Filtered", true)
groupKalman = "Kalman Filter"
kalmanAlpha = input.float(0.01, title="Kalman Alpha", tooltip="The Alpha parameter controls the smoothing factor of the Kalman filter. A smaller value results in more smoothing, while a larger value makes the filter more responsive to price changes.", group=groupKalman)
kalmanBeta = input.float(0.1, title="Kalman Beta", tooltip="The Beta parameter influences the rate of change in the Kalman filter. It adjusts the filter's sensitivity to trend changes.", group=groupKalman)
kalmanPeriod = input.int(77, title="Kalman Period", tooltip="The Period defines the number of bars used in the Kalman filter calculation, affecting the filter's responsiveness to market movements.", group=groupKalman)
dev = input.float(1.2, title="Deviation", tooltip="The Deviation parameter sets the multiplier for the deviation from the trend line, affecting the width of the trend band.", group=groupKalman)
groupSupertrend = "Supertrend"
supertrendFactor = input.float(0.7, title="Supertrend Factor", tooltip="This Factor determines the multiplier for the ATR in the Supertrend calculation, affecting the distance of the trend line from the price.", group=groupSupertrend)
supertrendAtrPeriod = input.int(7, title="ATR Period", tooltip="The ATR Period specifies the number of bars used to calculate the Average True Range, which is a component of the Supertrend indicator.", group=groupSupertrend)
groupColors = "Colors"
green = input.color(#00ffbb, title="Bullish Color", tooltip="This color is used to indicate a bullish trend in the chart.", group=groupColors)
red = input.color(#ff1100, title="Bearish Color", tooltip="This color is used to indicate a bearish trend in the chart.", group=groupColors)
kalman(a, b, alpha, beta) =>
var float v1 = na
var float v2 = 1.0
var float v3 = alpha * b
var float v4 = 0.0
var float v5 = na
if na(v1)
v1 := a[1]
v5 := v1
v4 := v2 / (v2 + v3)
v1 := v5 + v4 * (a - v5)
v2 := (1 - v4) * v2 + beta / b
v1
pine_supertrend(k, factor, atrPeriod) =>
src = k
atr = ta.atr(atrPeriod)
upperBand = src + factor * atr
lowerBand = src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or k[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or k[1] > prevUpperBand ? upperBand : prevUpperBand
int _direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if na(atr[1])
_direction := 1
else if prevSuperTrend == prevUpperBand
_direction := k > upperBand ? -1 : 1
else
_direction := k < lowerBand ? 1 : -1
superTrend := _direction == -1 ? lowerBand : upperBand
[superTrend, _direction]
k = kalman(close, kalmanPeriod, kalmanAlpha, kalmanBeta)
[supertrend, direction] = pine_supertrend(k, supertrendFactor, supertrendAtrPeriod)
vola = ta.wma(high-low, 200)
upper = k+voladev
lower = k-voladev
midbody = math.avg(close, open)
var trend = 0
if close > upper
trend := 1
else if close < lower
trend := -1
ktrend = 0
if direction < 0
ktrend := 1
else if direction > 0
ktrend := -1
t = 70
t_ = 20
p1 = plot(ktrend * trend == 1 ? k : na, color=color.gray, style = plot.style_linebr, linewidth = 3)
m = plot(midbody, color=color.gray, display = display.none)
up = plot(trend == -1 or ktrend * trend == -1 ? upper : na, color=ktrend * trend == -1 ? color.gray : ktrend == -1 ? color.new(red, t) : color.gray, style = plot.style_circles)
lo = plot(trend == 1 or ktrend * trend == -1 ? lower : na, color=ktrend * trend == -1 ? color.gray : ktrend == 1 ? color.new(green, t) : color.gray, style = plot.style_circles)
plotchar(ta.crossover(ktrend * trend, 0) ? k : na, location = location.absolute, color=trend == 1 ? green : red, char="◉", size=size.tiny)
x = color.new(chart.bg_color, 80)
x_ = color.new(trend == -1 ? red : green, t)
fill(p1, m, k, midbody, x, x_)
fill(up, lo, ktrend * trend == -1 ? color.new(color.gray, 90) : na, "Range")
barcolor(ktrend * trend == -1 ? color.new(color.gray, t_) : trend == 1 ? color.new(green, t_) : color.new(red, t_))
////////////////////////Alerts
alertcondition(ta.crossover(ktrend * trend, 0), title="Market Trending", message="The market is trending {{trend == 1 ? 'up' : 'down'}}")
alertcondition(ta.crossunder(ktrend * trend, 0), title="Market Ranging", message="The market is ranging")
alertcondition(ta.crossover(trend, 0), title="Market Short Term Bullish", message="The market is bullish short term")
alertcondition(ta.crossunder(trend, 0), title="Market Short Term Bearish", message="The market is bearish short term")
alertcondition(ta.crossover(ktrend, 0), title="Market Long Term Bullish", message="The market is bullish long term")
alertcondition(ta.crossunder(ktrend, 0), title="Market Long Term Bearish", message="The market is bearish long term")
Expected Output Columns
No response
Deliverables Checklist
- Implementation in
pyindicators/indicators/(pandas + polars support) - Exports in
__init__.pyand__all__ - Unit tests in
tests/indicators/(pandas, polars, edge cases) - Documentation page in
docs/content/indicators/with chart image - Sidebar registration in
docs/sidebars.js - Entry in README.md features list
- Analysis notebook in
analysis/indicators/with plotly chart
Additional Context
No response