j’utilise cet indicateur intéressant sur Tradingview “SMART SUPERTREND” (voir pièce jointe) et j’aimerais l’adapter sur ProRealTime pour programmer des screeners.
J’aurais besoin d’aide pour convertir cet indicateur vers Prorealtime, car je n’ai pas les notions assez avancées sur PRT pour convertir ce code 😉
// © wielkieef
//@version=4
study(“Smart SuperTrend”, overlay = true)
//INPUTS ——————————————————————————————————————————————————————————————————————————————————————————————————————–
src = input(open)
prd = input(2, title=”PP period”)
Factor = input(3, title = “ATR Factor”)
Pd = input(12, title = “ATR Period”)
len = input(12, title=”Cloud Length”)
ADX_options = input(“CLASSIC”, title = “ADX OPTION”, options = [“CLASSIC”, “MASANAKAMURA”])
ADX_len = input(24, title = “ADX Lenght”, type = input.integer)
th = input(24, title = “ADX Treshold”, type = input.float)
//INDICATORS —————————————————————————————————————————————————————————————————————————————————————————————————————–
PI = 2 * asin(1)
hilbertTransform(src) =>
0.0962 * src + 0.5769 * nz(src[2]) – 0.5769 * nz(src[4]) – 0.0962 * nz(src[6])
computeComponent(src, mesaPeriodMult) =>
hilbertTransform(src) * mesaPeriodMult
computeAlpha(src, fastLimit, slowLimit) =>
mesaPeriod = 0.0
mesaPeriodMult = 0.075 * nz(mesaPeriod[1]) + 0.54
smooth = 0.0
smooth := (4 * src + 3 * nz(src[1]) + 2 * nz(src[2]) + nz(src[3])) / 10
detrender = 0.0
detrender := computeComponent(smooth, mesaPeriodMult)
I1 = nz(detrender[3])
Q1 = computeComponent(detrender, mesaPeriodMult)
jI = computeComponent(I1, mesaPeriodMult)
jQ = computeComponent(Q1, mesaPeriodMult)
I2 = 0.0
Q2 = 0.0
I2 := I1 – jQ
Q2 := Q1 + jI
I2 := 0.2 * I2 + 0.8 * nz(I2[1])
Q2 := 0.2 * Q2 + 0.8 * nz(Q2[1])
Re = I2 * nz(I2[1]) + Q2 * nz(Q2[1])
Im = I2 * nz(Q2[1]) – Q2 * nz(I2[1])
Re := 0.2 * Re + 0.8 * nz(Re[1])
Im := 0.2 * Im + 0.8 * nz(Im[1])
if Re != 0 and Im != 0
mesaPeriod := 2 * PI / atan(Im / Re)
if mesaPeriod > 1.5 * nz(mesaPeriod[1])
mesaPeriod := 1.5 * nz(mesaPeriod[1])
if mesaPeriod < 0.67 * nz(mesaPeriod[1])
mesaPeriod := 0.67 * nz(mesaPeriod[1])
if mesaPeriod < 6
mesaPeriod := 6
if mesaPeriod > 50
mesaPeriod := 50
mesaPeriod := 0.2 * mesaPeriod + 0.8 * nz(mesaPeriod[1])
phase = 0.0
if I1 != 0
phase := (180 / PI) * atan(Q1 / I1)
deltaPhase = nz(phase[1]) – phase
if deltaPhase < 1
deltaPhase := 1
alpha = fastLimit / deltaPhase
if alpha < slowLimit
alpha := slowLimit
[alpha,alpha/2.0]
er = abs(change(src,len)) / sum(abs(change(src)),len)
[a,b] = computeAlpha(src, er, er*0.1)
mama = 0.0
mama := a * src + (1 – a) * nz(mama[1])
fama = 0.0
fama := b * mama + (1 – b) * nz(fama[1])
alpha = pow((er * (b – a)) + a, 2)
kama = 0.0
kama := alpha * src + (1 – alpha) * nz(kama[1])
L_cloud = kama > kama[1]
S_cloud = kama < kama[1]
CLOUD_COLOR = L_cloud ? color.lime : S_cloud ? color.red : na
mama_p = plot(mama, title=”Cloud A”, color=CLOUD_COLOR )
fama_p = plot(fama, title=”Cloud B”, color=CLOUD_COLOR )
fill (mama_p,fama_p, color=CLOUD_COLOR )
calcADX(_len) =>
up = change(high)
down = -change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = rma(tr, _len)
_plus = fixnan(100 * rma(plusDM, _len) / truerange)
_minus = fixnan(100 * rma(minusDM, _len) / truerange)
sum = _plus + _minus
_adx = 100 * rma(abs(_plus – _minus) / (sum == 0 ? 1 : sum), _len)
[_plus,_minus,_adx]
calcADX_Masanakamura(_len) =>
SmoothedTrueRange = 0.0
SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementMinus = 0.0
TrueRange = max(max(high – low, abs(high – nz(close[1]))), abs(low – nz(close[1])))
DirectionalMovementPlus = high – nz(high[1]) > nz(low[1]) – low ? max(high – nz(high[1]), 0) : 0
DirectionalMovementMinus = nz(low[1]) – low > high – nz(high[1]) ? max(nz(low[1]) – low, 0) : 0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) – (nz(SmoothedTrueRange[1]) /_len) + TrueRange
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) – (nz(SmoothedDirectionalMovementPlus[1]) / _len) + DirectionalMovementPlus
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) – (nz(SmoothedDirectionalMovementMinus[1]) / _len) + DirectionalMovementMinus
DIP = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIM = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = abs(DIP-DIM) / (DIP+DIM)*100
adx = sma(DX, _len)
[DIP,DIM,adx]
[DIPlusC,DIMinusC,ADXC]=calcADX(ADX_len)
[DIPlusM,DIMinusM,ADXM] = calcADX_Masanakamura(ADX_len)
DIPlus = ADX_options == “CLASSIC” ? DIPlusC : DIPlusM
DIMinus = ADX_options == “CLASSIC” ? DIMinusC : DIMinusM
ADX = ADX_options == “CLASSIC” ? ADXC : ADXM
L_adx = DIPlus > DIMinus and ADX > th
S_adx = DIPlus < DIMinus and ADX > th
//PRICE POSITION ——————————————————————————————————————————————————————————————————————————————————————————————————-
float ph = pivothigh(prd, prd)
float pl = pivotlow(prd, prd)
var float center = na
float lastpp = ph ? ph : pl ? pl : na
if lastpp
if na(center)
center := lastpp
else
center := (center * 2 + lastpp) / 3
Up = center – (Factor * atr(Pd))
Dn = center + (Factor * atr(Pd))
float TUp = na
float TDown = na
Trend = 0
TUp := close[1] > TUp[1] ? max(Up, TUp[1]) : Up
TDown := close[1] < TDown[1] ? min(Dn, TDown[1]) : Dn
Trend := close > TDown[1] ? 1: close < TUp[1]? -1: nz(Trend[1], 1)
Trailingsl = Trend == 1 ? TUp : TDown
plot(Trailingsl, color = CLOUD_COLOR , linewidth = 1, title = “PP line”)
bsignal = Trend == 1 and Trend[1] == -1
ssignal = Trend == -1 and Trend[1] == 1
first_long = bsignal and not S_cloud ? Trailingsl : na
first_short = ssignal and not L_cloud ? Trailingsl : na
second_long = L_cloud and L_adx and Trend == 1
second_short = S_cloud and S_adx and Trend == -1
Long = second_long or first_long
Short = second_short or first_short
long_short = 0
long_last = Long and (nz(long_short[1]) == 0 or nz(long_short[1]) == -1)
short_last = Short and (nz(long_short[1]) == 0 or nz(long_short[1]) == 1)
long_short := long_last ? 1 : short_last ? -1 : long_short[1]
longPrice = valuewhen(long_last, close, 0)
shortPrice = valuewhen(short_last, close, 0)
last_long_cond = Long and long_last
last_short_cond = Short and short_last
Long_plot = bsignal and not S_cloud ? Trailingsl : na or last_long_cond ? Trailingsl : na
Short_plot = ssignal and not L_cloud ? Trailingsl : na or last_short_cond ? Trailingsl : na
Long_stop = ssignal and L_cloud ? Trailingsl : na
Short_stop = bsignal and S_cloud ? Trailingsl : na
// Plots ———————————————————————————————————————————————————————————————————————————————————————————————————
plot(Trailingsl, color = CLOUD_COLOR , linewidth = 1, title = “Smart SuperTrend”)
plotshape(Long_plot, title=”Long”, text=”Long “, location = location.belowbar, style = shape.triangleup, size = size.small, color = color.blue, textcolor = color.blue, transp = 0)
plotshape(Short_plot, title=”Short”, text=”Short “, location = location.abovebar, style = shape.triangledown, size = size.small, color = color.red, textcolor = color.red, transp = 0)
plotshape(Long_stop, title=”Long exit”, text=”Long Close”, location = location.abovebar, style = shape.xcross, size = size.small, color = color.white, textcolor = color.white, transp = 0)
plotshape(Short_stop, title=”Short exit”, text=”Short Close”, location = location.belowbar, style = shape.xcross, size = size.small, color = color.white, textcolor = color.white, transp = 0)
barcolor (color = CLOUD_COLOR)
alertcondition(Long_plot, title=”Long”)
alertcondition(Short_plot, title=”Short”)
alertcondition(Long_stop, title=”Long Close”)
alertcondition(Short_stop, title=”Short Close”)
//By wielkieef