Super Trended Moving Averages

Category: Indicators By: JS Created: June 26, 2023, 8:17 AM
June 26, 2023, 8:17 AM
Indicators
0 Comments

A different approach to SuperTrend:
adding 100 periods Exponential Moving Average in calculation of SuperTrend and also 0.5 ATR Multiplier to have a clear view of the ongoing trend and also provides significant Supports and Resistances.

Default Moving Average type set as EMA (Exponential Moving Average) but users can choose from 11 different Moving Average types as:

SMA : Simple Moving Average
EMA : Exponential Moving Average
WMA : Weighted Moving Average
DEMA : Double Exponential Moving Average
TMA : Triangular Moving Average
VAR : Variable Index Dynamic Moving Average a.k.a. VIDYA
WWMA : Welles Wilder’s Moving Average
ZLEMA : Zero Lag Exponential Moving Average
TSF : True Strength Force
HULL : Hull Moving Average
TILL : Tillson T3 Moving Average

(description from author KivancOzbilgic)

src = Close //Data type
mav = 1 //Moving Average  Value: 0=SMA, 1=EMA, 2=WMA, 3=DEMA, 4=TMA, 5=VAR, 6=WWMA, 7=ZLEMA, 8=TSF, 9=HMA, 10=T3
length = 100 //Moving Average Length
Periods = 10 //ATR period
Multiplier = 0.5 //ATR Multiplier

T3a1 = 0.7 //Tillson T3 Volume Factor

valpha = 2 / (length+1)

If src > src[1] then //Green candle
vud1 = src - src[1] //Green profit
else
vud1 = 0
EndIf

If src < src[1] then //Red candle
vdd1 = src[1] - src //Red Loss
else
vdd1=0
EndIf

vUD = Summation[9](vud1) //Summation [9] Green profit
vDD = Summation[9](vdd1) //Summation [9] Red Loss

vCMO = ((vUD - vDD) / vUD + vDD) //Cumulative Market Oscillator
Once VAR = 0
VAR = (valpha * Abs(vCMO) * src) + (1 - valpha * Abs(vCMO)) * VAR[1]

xDEMA = 2 * ExponentialAverage[length](src) - ExponentialAverage[length](ExponentialAverage[length](src))

wwalpha = 1 //Length
Once WWMA = 0
WWMA = wwalpha * src + (1 - wwalpha) * WWMA[1]

If (length / 2) = Round(length / 2) then //Check even/odd length for "zero lag"
zxLag = (length / 2)
Else
zxLag = ((length-1) / 2)
EndIf

zxEMAData = src + src - src[zxLag]
xZLEMA = ExponentialAverage[length](zxEMAData) //Zero Lag Exponential Average

lrc = LinearRegression[length](src)
lrc1 = lrc[1]
lrs = lrc - lrc1
TSF = LinearRegression[length](src) + lrs //Time Series Forecast

HMA = WeightedAverage[Round(SQRT(length))](2 * WeightedAverage[length/2](src) - WeightedAverage[length](src)) //Hull Moving Average

T3e1 = ExponentialAverage[length](src)
T3e2 = ExponentialAverage[length](T3e1)
T3e3 = ExponentialAverage[length](T3e2)
T3e4 = ExponentialAverage[length](T3e3)
T3e5 = ExponentialAverage[length](T3e4)
T3e6 = ExponentialAverage[length](T3e5)

T3c1 = -T3a1 * T3a1 * T3a1
T3c2 = 3 * T3a1 * T3a1 + 3 * T3a1 * T3a1 * T3a1
T3c3 = -6 * T3a1 * T3a1 - 3 * T3a1 - 3 * T3a1 * T3a1 * T3a1
T3c4 = 1 + 3 * T3a1 + T3a1 * T3a1 * T3a1 + 3 * T3a1 * T3a1
T3 = T3c1 * T3e6 + T3c2 * T3e5 + T3c3 * T3e4 + T3c4 * T3e3 //T3 Moving Average

Once MA = 0
If mav = 0 then
MA = Average[length,0](src) //SMA
ElsIf mav = 1 then
MA = Average[length,1](src) //EMA
ElsIf mav = 2 then
MA = Average[length,2](src) //WEMA
ElsIf mav = 3 then
MA = xDEMA //DEMA
ElsIf mav = 4 then
MA = Average[Floor(length / 2) + 1](Average[Ceil(length / 2)](src)) //TMA
ElsIf mav = 5 then
MA = VAR //VAR a.k.a. VIDYA Variable Index Dynamic Moving Average
ElsIf mav = 6 then
MA = WWMA //WWMA Welles Wilder's Moving Average
ElsIf mav = 7 then
MA = xZLEMA //ZLEMA Zero Lag Exponential Moving Average
ElsIf mav = 8 then
MA = TSF //TSF Time Series Forecast
ElsIf mav = 9 then
MA = HMA //HMA Hull Moving Average
ElsIf mav = 10 then
MA = T3 //T3 Tillson Moving Average
EndIf

atr = AverageTrueRange[Periods](src)
up = MA - Multiplier * atr
up1 = up[1]
If src[1] > up1 then
up = Max(up, up1)
Else
up = up
EndIf
dn = MA + Multiplier * atr
dn1 = dn[1]
If src[1] < dn1 then
dn = Min(dn, dn1)
else
dn = dn
EndIf

Once trend = 1
If trend = -1 and Close > dn1 then
trend = 1
ElsIf trend = 1 and Close < up1 then
trend = -1
EndIf

If trend = 1 then
upR=0
upG=255
upB=0
upAlpha=0
Else
upR=0
upG=0
upB=0
upAlpha=0
EndIf

//If Close > up then
//ColorBetween(Close,up,0,255,0)
//EndIf

If trend = -1 then
dnR=255
dnG=0
dnB=0
dnAlpha=0
else
dnR=0
dnG=0
dnB=0
dnAlpha=0
EndIf

//If Close < dn then
//ColorBetween(Close,dn,255,0,0)
//EndIf

Return up as "Up Trend" coloured(upR,upG,upB,upAlpha), dn as "Down Trend" coloured(dnR,dnG,dnB, dnAlpha)

Download
Filename: Super-Trended-Moving-Averages.itf
Downloads: 132
JS Senior
Code artist, my biography is a blank page waiting to be scripted. Imagine a bio so awesome it hasn't been coded yet.
Author’s Profile

Comments

Logo Logo
Loading...