Theil Sen Robust Slope [forexobroker]

545
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.

면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.