Here I leave an adaptation of the supertrend indicator.
We have the cloud, which shows us the price trend according to color.
On the other hand we have the adapted version of the supertrend, which can be used as a trailstop or confirmation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
//PRC_Smart Supertrend | indicator //version = 0 //09.02.24 //Iván González @ www.prorealcode.com //Sharing ProRealTime knowledge /////////////////INPUTS///////////////////////////////////// src = open prd = 2 //PP period factor = 3//Atr factor Pd = 12//Atr period len = 12//Cloud length Adxlen = 24//Adx length th = 24//Adx treshold showsignals = 0//boolean colorcandle = 0//boolean /////////////////////////Indicators/////////////////////////////// ////////CLOUD pi=2*asin(1) er = abs(src-src[len])/summation[len](abs(src-src[1])) fastlimit = er slowlimit = er*0.1 if barindex<6 then mesaperiod = 0 smooth = 0 detrender = 0 I1 = 0 I2 = 0 Q1 = 0 jI = 0 Q2 = 0 phase = 0 else mesaperiodmult = 0.075*mesaperiod[1] + 0.54 smooth = (4*src + 3*src[1]+2*src[2]+src[3])/10 detrender = (0.0962*smooth + 0.5769*smooth[2] - 0.5769*smooth[4]-0.0962*smooth[6])*mesaPeriodMult I1= detrender[3] Q1 =(0.0962*detrender + 0.5769*detrender[2] - 0.5769*detrender[4]-0.0962*detrender[6])*mesaPeriodMult jI= (0.0962*I1 + 0.5769*I1[2] - 0.5769*I1[4]-0.0962*I1[6])*mesaPeriodMult jQ = (0.0962*Q1 + 0.5769*Q1[2] - 0.5769*Q1[4]-0.0962*Q1[6])*mesaPeriodMult I2 = I1 - jQ Q2 = Q1 + jI I2 = 0.2*I2 + 0.8*I2[1] Q2 = 0.2*Q2 + 0.8*Q2[1] Re = I2*I2[1] + Q2*Q2[1] Im = I2*Q2[1] - Q2*I2[1] Re = 0.2*Re + 0.8*Re[1] Im = 0.2*Im + 0.8*Im[1] if Re <> 0 and Im <> 0 then mesaperiod=2 * pi/atan(Im/Re) endif if mesaperiod>1.5*mesaperiod[1] then mesaperiod=1.5*mesaperiod[1] endif if mesaperiod<0.67*mesaperiod[1] then mesaperiod=0.67*mesaperiod[1] endif if mesaperiod < 6 then mesaperiod = 6 endif if mesaperiod > 50 then mesaperiod = 50 endif mesaperiod = 0.2*mesaperiod+0.8*mesaperiod[1] if I1 <> 0 then phase=(180/pi)*atan(Q1/I1) endif deltaphase = phase[1]-phase if deltaphase < 1 then deltaphase = 1 endif alpha = fastlimit/deltaphase if alpha < slowlimit then alpha = slowlimit endif endif a = alpha b = alpha/2 if barindex < 12 then mama = 0 fama = 0 kama = 0 else mama = a*src + (1-a)*mama[1]//[1] fama = b*mama + (1-b)*fama[1]//[1] alpha = pow((er*(b-a))+a,2) kama = alpha*src + (1-alpha)*kama[1] endif Lcloud = kama > kama[1] Scloud = kama < kama[1] if Lcloud then rcloud=0 gcloud=230 bcloud=218 elsif Scloud then rcloud=255 gcloud=82 bcloud=82 endif colorbetween(mama,fama,rcloud,gcloud,bcloud) /////////ADX pdi = DIplus[Adxlen](close) mdi = DIminus[Adxlen](close) myadx = adx[Adxlen] ladx = pdi > mdi and myadx > th //long trend sadx = pdi < mdi and myadx > th //short trend /////////PRICE POSITION ////////pivothigh ph1 = high < high[prd] ph2 = highest[prd](high) < high[prd] ph3 = high[prd] > highest[prd](high)[prd+1] if ph1 and ph2 and ph3 then pivotH = high[prd] else pivotH = pivotH endif ////////pivotlow pl1 = low > low[prd] pl2 = lowest[prd](low) > low[prd] pl3 = low[prd] < lowest[prd](low)[prd+1] if pl1 and pl2 and pl3 then pivotL = low[prd] else pivotL = pivotL endif ////////Trailing if barindex = 0 then center = 0 lastpp = 0 Tup=0 Tdown=0 Trend=0 else if pivotH <> pivotH[1] then lastpp = pivotH center = (center*2+lastpp)/3 elsif pivotL <> pivotL[1] then lastpp = pivotL center = (center*2+lastpp)/3 else lastpp = lastpp[1] center = center[1] endif atr = averagetruerange[pd](close) Up = center-(factor*atr) Dn = center+(factor*atr) if close[1]>Tup[1] then Tup = max(Up,Tup[1]) else Tup = Up endif if close[1] < Tdown[1] then Tdown = min(Dn,Tdown[1]) else Tdown = Dn endif if close > Tdown[1] then Trend = 1 elsif close < Tup[1] then Trend = -1 else Trend = Trend[1] endif if trend = 1 then Trailings1 = Tup else Trailings1 = Tdown endif endif //////////SIGNALS if showsignals then bsignal = Trend=1 and Trend[1]=-1 ssignal = Trend=-1 and Trend[1]=1 if bsignal and not Scloud then firstlong = Trailings1 else firstlong = undefined endif if ssignal and not Lcloud then firstshort = Trailings1 else firstshort = undefined endif secondlong = Lcloud and Ladx and trend=1 secondshort = Scloud and Sadx and trend=-1 long = secondlong and firstlong short = secondshort and firstshort once longshort = 0 longlast = long and (longshort[1]=0 or longshort[1]=-1) shortlast = short and (longshort[1]=0 or longshort[1]=1) if longlast = 1 then longshort = 1 elsif longshort = 1 then longshort = -1 else longshort = longshort[1] endif lastlongcond = long and longlast lastshortcond = short and shortlast if (bsignal and not scloud) or (lastlongcond) then longplot = Trailings1 drawarrowup(barindex,low-0.10*atr)coloured(0,250,0) else longplot = undefined endif if (ssignal and not lcloud) or (lastshortcond) then shortplot = trailings1 drawarrowdown(barindex,high+0.10*atr)coloured(250,0,0) else shortplot = undefined endif if ssignal and lcloud then longstop = trailings1 drawtext("✘",barindex,high+0.10*atr)coloured(0,250,0) else longstop = undefined endif if bsignal and scloud then shortstop = trailings1 drawtext("✘",barindex,low-0.10*atr)coloured(250,0,0) else shortstop = undefined endif endif ///////////COLOR CANDLES if colorcandle then if Lcloud then rbar=0 gbar=210 bbar=0 elsif Scloud then rbar=255 gbar=0 bbar=0 endif DRAWCANDLE(open, high, low, close)coloured(rbar,gbar,bbar) endif return mama as "Cloud A" coloured(rcloud,gcloud,bcloud), fama as "Cloud B" coloured(rcloud,gcloud,bcloud), Trailings1 as "PP line" coloured(rcloud,gcloud,bcloud) |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :
Filename : download the ITF files
How to import ITF files into ProRealTime platform?
PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Hello Ivan
You have interesting topics on indicators , smart supertrend, optimised trend tracker, end ema9-21 , but did you have some exemples of wining strategy with this indicators.
Congratulations
Hi! thanks. All of these codes are translations requested in the forum. I’ve on mind to backtest all of them.
Buenos días Iván, estoy intentando llevar el código eliminando los colores y pasando un Backtest para sacar estadística de funcionamiento real.
Marqué orden de compra y venta en el siguiente punto, por favor, está correcto ?
Muchas gracias
src = open
prd = 2 //PP period
factor = 3//Atr factor
Pd = 12//Atr period
len = 12//Cloud length
Adxlen = 24//Adx length
th = 24//Adx treshold
showsignals = 0//boolean
colorcandle = 0//boolean
/////////////////////////Indicators///////////////////////////////
////////CLOUD
pi=2*asin(1)
er = abs(src-src[len])/summation[len](abs(src-src[1]))
fastlimit = er
slowlimit = er*0.1
if barindex<6 then
mesaperiod = 0
smooth = 0
detrender = 0
I1 = 0
I2 = 0
Q1 = 0
jI = 0
Q2 = 0
phase = 0
else
mesaperiodmult = 0.075*mesaperiod[1] + 0.54
smooth = (4*src + 3*src[1]+2*src[2]+src[3])/10
detrender = (0.0962*smooth + 0.5769*smooth[2] – 0.5769*smooth[4]-0.0962*smooth[6])*mesaPeriodMult
I1= detrender[3]
Q1 =(0.0962*detrender + 0.5769*detrender[2] – 0.5769*detrender[4]-0.0962*detrender[6])*mesaPeriodMult
jI= (0.0962*I1 + 0.5769*I1[2] – 0.5769*I1[4]-0.0962*I1[6])*mesaPeriodMult
jQ = (0.0962*Q1 + 0.5769*Q1[2] – 0.5769*Q1[4]-0.0962*Q1[6])*mesaPeriodMult
I2 = I1 – jQ
Q2 = Q1 + jI
I2 = 0.2*I2 + 0.8*I2[1]
Q2 = 0.2*Q2 + 0.8*Q2[1]
Re = I2*I2[1] + Q2*Q2[1]
Im = I2*Q2[1] – Q2*I2[1]
Re = 0.2*Re + 0.8*Re[1]
Im = 0.2*Im + 0.8*Im[1]
if Re 0 and Im 0 then
mesaperiod=2 * pi/atan(Im/Re)
endif
if mesaperiod>1.5*mesaperiod[1] then
mesaperiod=1.5*mesaperiod[1]
endif
if mesaperiod<0.67*mesaperiod[1] then
mesaperiod=0.67*mesaperiod[1]
endif
if mesaperiod 50 then
mesaperiod = 50
endif
mesaperiod = 0.2*mesaperiod+0.8*mesaperiod[1]
if I1 0 then
phase=(180/pi)*atan(Q1/I1)
endif
deltaphase = phase[1]-phase
if deltaphase < 1 then
deltaphase = 1
endif
alpha = fastlimit/deltaphase
if alpha < slowlimit then
alpha = slowlimit
endif
endif
a = alpha
b = alpha/2
if barindex kama[1]
Scloud = kama mdi and myadx > th //long trend
sadx = pdi th //short trend
/////////PRICE POSITION
////////pivothigh
ph1 = high < high[prd]
ph2 = highest[prd](high) highest[prd](high)[prd+1]
if ph1 and ph2 and ph3 then
pivotH = high[prd]
else
pivotH = pivotH
endif
////////pivotlow
pl1 = low > low[prd]
pl2 = lowest[prd](low) > low[prd]
pl3 = low[prd] < lowest[prd](low)[prd+1]
if pl1 and pl2 and pl3 then
pivotL = low[prd]
else
pivotL = pivotL
endif
////////Trailing
if barindex = 0 then
center = 0
lastpp = 0
Tup=0
Tdown=0
Trend=0
else
if pivotH pivotH[1] then
lastpp = pivotH
center = (center*2+lastpp)/3
BUY 10000 CASH AT MARKET NextBarOpen
elsif pivotL pivotL[1] then
lastpp = pivotL
center = (center*2+lastpp)/3
sell at market NextBarOpen
else
lastpp = lastpp[1]
center = center[1]
endif
atr = averagetruerange[pd](close)
Up = center-(factor*atr)
Dn = center+(factor*atr)
if close[1]>Tup[1] then
Tup = max(Up,Tup[1])
else
Tup = Up
endif
if close[1] Tdown[1] then
Trend = 1
elsif close < Tup[1] then
Trend = -1
else
Trend = Trend[1]
endif
if trend = 1 then
Trailings1 = Tup
else
Trailings1 = Tdown
endif
endif
//////////SIGNALS
if showsignals then
bsignal = Trend=1 and Trend[1]=-1
ssignal = Trend=-1 and Trend[1]=1
if bsignal and not Scloud then
firstlong = Trailings1
else
firstlong = undefined
endif
if ssignal and not Lcloud then
firstshort = Trailings1
else
firstshort = undefined
endif
secondlong = Lcloud and Ladx and trend=1
secondshort = Scloud and Sadx and trend=-1
long = secondlong and firstlong
short = secondshort and firstshort
once longshort = 0
longlast = long and (longshort[1]=0 or longshort[1]=-1)
shortlast = short and (longshort[1]=0 or longshort[1]=1)
if longlast = 1 then
longshort = 1
elsif longshort = 1 then
longshort = -1
else
longshort = longshort[1]
endif
lastlongcond = long and longlast
lastshortcond = short and shortlast
if (bsignal and not scloud) or (lastlongcond) then
longplot = Trailings1
//drawarrowup(barindex,low-0.10*atr)
else
longplot = undefined
endif
if (ssignal and not lcloud) or (lastshortcond) then
shortplot = trailings1
//drawarrowdown(barindex,high+0.10*atr)
else
shortplot = undefined
endif
if ssignal and lcloud then
longstop = trailings1
//drawtext("✘",barindex,high+0.10*atr)coloured(0,250,0)
else
longstop = undefined
endif
if bsignal and scloud then
shortstop = trailings1
//drawtext("✘",barindex,low-0.10*atr)coloured(250,0,0)
else
shortstop = undefined
endif
endif
///////////COLOR CANDLES
if colorcandle then
if Lcloud then
rbar=0
gbar=210
bbar=0
elsif Scloud then
rbar=255
gbar=0
bbar=0
endif
ENDIF
//return mama as "Cloud A" coloured(rcloud,gcloud,bcloud), fama as "Cloud B" coloured(rcloud,gcloud,bcloud), Trailings1 as "PP line" coloured(rcloud,gcloud,bcloud)
//return a*src as "a*src",(1-a) as "1-a"