SuperTrend
All functions · nseries package
SuperTrend
func (s Series) SuperTrend(h, l, c Series, mult float64, trLen int) Series
SuperTrend returns the receiver series offset by mult x SMA(TrueRange, trLen), i.e. a single ATR-offset band (equivalent to KeltnerSS with priceLen 1), consistent with the TradeStation indicator it is verified against.
Note that this is NOT Olivier Seban’s published SuperTrend indicator, which uses a (high+low)/2 basis, paired upper/lower bands with ratcheting, and a trend flip when the close crosses the opposite band. Values from this function will not match SuperTrend implementations found on other platforms.
The band is added with Add, so it is right-aligned with the receiver at the most recent bar: when h, l and c are shorter than s, the receiver’s leading bars without a band are zero. When h, l and c differ in length from each other, TrueRange is empty and the result is all zeros. KeltnerSS, which requires all four lengths to be equal, gives zeros whenever any differs.
Bars 0 to trLen-2 are s[i] + mult*TrueRange[i], because the true-range average passes its input through.