Expand description
§Supertrend
ATR-based trailing band (common breakout / stop overlay):
mid = (high + low) / 2
basic_upper = mid + mult * ATR
basic_lower = mid − mult * ATR
final bands stick until price closes through the opposite band
Supertrend = final_lower in uptrend, final_upper in downtrendDefault: ATR period 10, mult 3.0 (SupertrendParams::standard).
Output: SupertrendBar with value and direction (+1 uptrend / −1 downtrend).
§Trading perspective
| Event | Habit (classic) |
|---|---|
| Direction flips to +1 | Long regime / trail under price |
| Direction flips to −1 | Short regime / trail over price |
| Price pulls to ST line | Support/resistance screen in trend |
Supertrend is a stop + regime tool, not an oscillator. Mult↑ → fewer flips, wider trail.
§vs Parabolic SAR / Donchian / Keltner
| Supertrend | SAR | Donchian | Keltner | |
|---|---|---|---|---|
| Driver | ATR × mid | Acceleration on extremes | Pure HH/LL | EMA + ATR |
| Flip style | Close through band | Touch SAR | Channel break | Band tag |
| Best for | ATR-scaled trail | Fast reverse systems | Breakout structure | Channel mean reversion |
§Pairs well with
- ADX — enter Supertrend flips only when ADX rising / above threshold.
- Volume (OBV/RVOL) — confirm breakout volume.
- Higher-timeframe MA — only long Supertrend with HTF trend.
§Engineering
SupertrendParams → supertrend / SupertrendState → supertrend_solution.
Uses shared AtrState (Wilder). Batch via state.
First defined bar seeds direction from close vs mid (implementation convention).
Structs§
- Supertrend
Bar - Supertrend
Params - Supertrend pack: Wilder ATR period + band multiplier.
- Supertrend
Series - Supertrend
Solution - Supertrend
State - Incremental Supertrend.
- Validated
Supertrend
Functions§
- supertrend
- supertrend_
solution - Examples