-
SuperTrend Extended indicator.
This command version provides inputs for price data, which allows to use this indicator over MACD or RSI data for example.
Input paramaters:
* h, l, and c : Price data used for ATR.
* src : [NEW] source prices for the baseline (can be a moving average for example).
* atrPeriod : ATR period length (for example 22).
* atrMult : ATR multiplier (for example 3).
* [priceCut] : [NEW] Whether or not it is price that flips the ST. If false, src will be the flipper.
* [wicks] : Whether to take wicks into account or not (default is false).
* [id] : [NEW] Optional unique ID in case you run this command in a loop and need more than one line.Output:
* SuperTrend line values**NOTE**: The command does not handle any plotting nor does it produce any signals!
Example of usage:
local maSrc = InputSourcePrice('MA Source', HLPriceSource) local maType = InputMaTypes('MA Type', SmaType) local maLen = Input('MA Length', 10) local atrLen = Input('ATR Length', 10) local atrMul = Input('ATR Multiplier', 3) local priceCut = Input('Price Flips ST?', false, 'If false, EMA flips the ST line.') local wicks = Input('Use Wicks?', false, 'If true, price wicks will flip the ST line. Doesn\'t work if price cut is enabled.') local h = HighPrices() local l = LowPrices() local c = ClosePrices() local baseline = MA(SourcePrices(maSrc), maLen, maType) local st = CC_SuperTrendExt(h, l, c, baseline, atrLen, atrMul, priceCut, wicks, 'MySuperTrend') -- Plot baseline EMA Plot(0, 'EMA', baseline) local upperId = Load('uid', NewGuid()) local lowerId = Load('lid', NewGuid()) if st < baseline then upperId = NewGuid() -- reset upper id Plot(0, 'Long Stop', st, {c=Green, id=lowerId}) -- DoBuy() else lowerId = NewGuid() -- reset lower id Plot(0, 'Short Stop', st, {c=Red, id=upperId}) -- DoSell() end Save('uid', upperId) Save('lid', lowerId)
**UPDATED**: Added new input parameters and did some optimizations and other fixes.