Supertrend on EMA
Forums › ProRealTime English forum › ProBuilder support › Supertrend on EMA
- This topic has 7 replies, 6 voices, and was last updated 2 years ago by johann8.
Viewing 8 posts - 1 through 8 (of 8 total)
-
-
01/27/2022 at 6:54 PM #186760
Dear All,
I would like to request your help for the conversion of the attached pinescript code for a supertrend indicator based on an exponential moving average.
You can follow the original script either here:
https://www.tradingview.com/script/xEtpZd0t/
or in the attached word file (where you can find also a picture of the aspect of the indicator).
Many thanks in advance
Loop
01/28/2022 at 11:04 AM #186819Suoertrend with EMA1234567891011121314151617181920//@version=2study("Supertrend with EMA", overlay=true)EmaPer = input(4, minval = 1, maxval = 100)TrPer = input(7, minval = 1, maxval = 100)factor=input(1.7, minval = 1, type = float, maxval = 10)ema = ema(close, EmaPer)up = ema - (factor * atr(TrPer))down = ema + (factor * atr(TrPer))TUp=ema[1]>TUp[1]? max(up,TUp[1]) : upTDown=ema[1]<TDown[1]? min(down,TDown[1]) : downTrend = ema >TDown[1] ? 1: ema <TUp[1]? -1: nz(Trend[1],1)Trailingsl = Trend == 1 ?TUp :TDownlinecolor = Trend == 1 ? lime : redplot(Trailingsl, color = linecolor, style = line, linewidth = 2)plotarrow(Trend == 1 and Trend[1] == -1 ? Trend :na, title="Up Trend Arrow", colorup=blue, maxheight = 40, minheight = 30, transp=0)plotarrow(Trend == -1 and Trend[1] == 1 ? Trend : na, title="Down Trend Arrow", colordown=black, maxheight = 40, minheight = 30, transp=0)01/28/2022 at 8:11 PM #18688302/15/2022 at 3:43 PM #188300It doesn’t work because it’s not written in the ProRealTime language.
02/18/2022 at 9:37 AM #188447Nothing too fancy, a Supertrend calculated on EMA of X periods:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152Emaper=4multiplier=1.7period=7moy=averagetruerange[period](close)price=average[emaper,1]up=price+multiplier*moydn=price-multiplier*moyonce trend=1if close>up[1] thentrend=1elsif close<dn[1] thentrend=-1endifif trend<0 and trend[1]>0 thenflag=1elseflag=0endifif trend>0 and trend[1]<0 thenflagh=1elseflagh=0endifif trend>0 and dn<dn[1] thendn=dn[1]endifif trend<0 and up>up[1] thenup=up[1]endifif flag=1 thenup=price+multiplier*moyendifif flagh=1 thendn=price-multiplier*moyendifif trend=1 thenmysupertrend=dnelsemysupertrend=upendifif mysupertrend > mysupertrend[1] thencolor1=0color2=255color3=0elsif mysupertrend < mysupertrend[1] thencolor1=255color2=0color3=0endifreturn mysupertrend coloured (color1,color2,color3) as "SuperTrend"06/22/2022 at 2:14 PM #19586606/22/2022 at 3:20 PM #19586806/22/2022 at 6:48 PM #195885 -
AuthorPosts
Viewing 8 posts - 1 through 8 (of 8 total)
Find exclusive trading pro-tools on
Similar topics: