Theil Sen Robust Slope [forexobroker]

Theil Sen Robust Slope replaces ordinary least squares with the Theil-Sen estimator: the median of the slopes of all C(N, 2) pairwise lines through the last N closes. Robust to outliers up to a 29 percent breakdown point — a single price spike cannot drag the line. Pairs with a median intercept to give a regression line that ignores wicks and gaps.
🔶 ALGORITHM
1. For each pair (i, j) with i < j in the window, compute slope_ij = (close - close[j]) / (j - i).
2. slope = median(slope_ij) across all C(N, 2) pairs (190 for N = 20).
3. intercept = median(close + i * slope) for i in [0, N-1] -> regression line value at the current bar.
4. Trending regime when |slope| > k * ATR per bar.
🔶 SIGNAL LOGIC
- Buy: trending regime up AND close crosses regression line up AND not already long AND cooldown elapsed AND barstate.isconfirmed.
- Sell: mirror.
- Position-lock state machine.
🔶 INPUTS
- Window N (default 20 -> 190 pairs)
- Slope Threshold x ATR/bar (default 0.10)
- Cooldown Bars (default 4)
- Visual: dashboard, glow, regression line, buy / sell colors
🔶 ALERTS
TSR Buy, TSR Sell, TSR Any Signal, TSR Trend Up Start, TSR Trend Down Start, TSR Cross Up, TSR Cross Down, TSR Slope Zero, TSR Webhook JSON.
🔶 LIMITATIONS
- Computational cost = N * (N - 1) / 2 slope computations per bar. N = 40 is the practical maximum on most plans (780 pairs).
- Theil-Sen is robust to a few outliers but not to sustained regime change; the line lags during fast directional moves.
- Window N must be >= 10 for a meaningful median; very short windows produce noisy slopes.
- Defaults tuned for liquid majors / indices. For low-volatility assets, lower the slope threshold.
🔶 ALGORITHM
1. For each pair (i, j) with i < j in the window, compute slope_ij = (close - close[j]) / (j - i).
2. slope = median(slope_ij) across all C(N, 2) pairs (190 for N = 20).
3. intercept = median(close + i * slope) for i in [0, N-1] -> regression line value at the current bar.
4. Trending regime when |slope| > k * ATR per bar.
🔶 SIGNAL LOGIC
- Buy: trending regime up AND close crosses regression line up AND not already long AND cooldown elapsed AND barstate.isconfirmed.
- Sell: mirror.
- Position-lock state machine.
🔶 INPUTS
- Window N (default 20 -> 190 pairs)
- Slope Threshold x ATR/bar (default 0.10)
- Cooldown Bars (default 4)
- Visual: dashboard, glow, regression line, buy / sell colors
🔶 ALERTS
TSR Buy, TSR Sell, TSR Any Signal, TSR Trend Up Start, TSR Trend Down Start, TSR Cross Up, TSR Cross Down, TSR Slope Zero, TSR Webhook JSON.
🔶 LIMITATIONS
- Computational cost = N * (N - 1) / 2 slope computations per bar. N = 40 is the practical maximum on most plans (780 pairs).
- Theil-Sen is robust to a few outliers but not to sustained regime change; the line lags during fast directional moves.
- Window N must be >= 10 for a meaningful median; very short windows produce noisy slopes.
- Defaults tuned for liquid majors / indices. For low-volatility assets, lower the slope threshold.
🔵Gain access to our powerful tools: kestutisbalciunas.com/tradingview/
🔵Join our free telegram for updates: t.me/algotradingedge
All scripts & content provided by KestutisDigital are for informational & educational purposes only.
🔵Join our free telegram for updates: t.me/algotradingedge
All scripts & content provided by KestutisDigital are for informational & educational purposes only.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
🔵Gain access to our powerful tools: kestutisbalciunas.com/tradingview/
🔵Join our free telegram for updates: t.me/algotradingedge
All scripts & content provided by KestutisDigital are for informational & educational purposes only.
🔵Join our free telegram for updates: t.me/algotradingedge
All scripts & content provided by KestutisDigital are for informational & educational purposes only.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.