Skip to main content

Module supertrend

Module supertrend 

Source
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 downtrend

Default: ATR period 10, mult 3.0 (SupertrendParams::standard).

Output: SupertrendBar with value and direction (+1 uptrend / −1 downtrend).


§Trading perspective

EventHabit (classic)
Direction flips to +1Long regime / trail under price
Direction flips to −1Short regime / trail over price
Price pulls to ST lineSupport/resistance screen in trend

Supertrend is a stop + regime tool, not an oscillator. Mult↑ → fewer flips, wider trail.

§vs Parabolic SAR / Donchian / Keltner

SupertrendSARDonchianKeltner
DriverATR × midAcceleration on extremesPure HH/LLEMA + ATR
Flip styleClose through bandTouch SARChannel breakBand tag
Best forATR-scaled trailFast reverse systemsBreakout structureChannel 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

SupertrendParamssupertrend / SupertrendStatesupertrend_solution.
Uses shared AtrState (Wilder). Batch via state.
First defined bar seeds direction from close vs mid (implementation convention).

Structs§

SupertrendBar
SupertrendParams
Supertrend pack: Wilder ATR period + band multiplier.
SupertrendSeries
SupertrendSolution
SupertrendState
Incremental Supertrend.
ValidatedSupertrend

Functions§

supertrend
supertrend_solution
Examples