Conversion indicateur Tradingview “Smart Supertrend” vers ProRealTime
Forums › ProRealTime forum Français › Support ProBuilder › Conversion indicateur Tradingview “Smart Supertrend” vers ProRealTime
- This topic has 2 replies, 2 voices, and was last updated 9 months ago by Iván.
-
-
01/06/2023 at 7:18 PM #206923
Hello à tous,
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 😉
Les paramètres que j’appliquent sont les suivants :
Src: Open
pp period: 2
ATR factor: 6
ATR period: 12
Cloud length: 12
ADX option: CLASSIC
ADX length: 24
ADX Treshold: 24
Voici le code Tradingview de l’indicateur SMART SUPERTREND :
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © wielkieef//@version=4study(“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) * mesaPeriodMultcomputeAlpha(src, fastLimit, slowLimit) =>mesaPeriod = 0.0mesaPeriodMult = 0.075 * nz(mesaPeriod[1]) + 0.54smooth = 0.0smooth := (4 * src + 3 * nz(src[1]) + 2 * nz(src[2]) + nz(src[3])) / 10detrender = 0.0detrender := computeComponent(smooth, mesaPeriodMult)I1 = nz(detrender[3])Q1 = computeComponent(detrender, mesaPeriodMult)jI = computeComponent(I1, mesaPeriodMult)jQ = computeComponent(Q1, mesaPeriodMult)I2 = 0.0Q2 = 0.0I2 := I1 – jQQ2 := Q1 + jII2 := 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 != 0mesaPeriod := 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 < 6mesaPeriod := 6if mesaPeriod > 50mesaPeriod := 50mesaPeriod := 0.2 * mesaPeriod + 0.8 * nz(mesaPeriod[1])phase = 0.0if I1 != 0phase := (180 / PI) * atan(Q1 / I1)deltaPhase = nz(phase[1]) – phaseif deltaPhase < 1deltaPhase := 1alpha = fastLimit / deltaPhaseif alpha < slowLimitalpha := 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.0mama := a * src + (1 – a) * nz(mama[1])fama = 0.0fama := b * mama + (1 – b) * nz(fama[1])alpha = pow((er * (b – a)) + a, 2)kama = 0.0kama := 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 : namama_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.0SmoothedDirectionalMovementPlus = 0.0SmoothedDirectionalMovementMinus = 0.0TrueRange = 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) : 0DirectionalMovementMinus = nz(low[1]) – low > high – nz(high[1]) ? max(nz(low[1]) – low, 0) : 0SmoothedTrueRange := nz(SmoothedTrueRange[1]) – (nz(SmoothedTrueRange[1]) /_len) + TrueRangeSmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) – (nz(SmoothedDirectionalMovementPlus[1]) / _len) + DirectionalMovementPlusSmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) – (nz(SmoothedDirectionalMovementMinus[1]) / _len) + DirectionalMovementMinusDIP = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100DIM = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100DX = abs(DIP-DIM) / (DIP+DIM)*100adx = sma(DX, _len)[DIP,DIM,adx][DIPlusC,DIMinusC,ADXC]=calcADX(ADX_len)[DIPlusM,DIMinusM,ADXM] = calcADX_Masanakamura(ADX_len)DIPlus = ADX_options == “CLASSIC” ? DIPlusC : DIPlusMDIMinus = ADX_options == “CLASSIC” ? DIMinusC : DIMinusMADX = ADX_options == “CLASSIC” ? ADXC : ADXML_adx = DIPlus > DIMinus and ADX > thS_adx = DIPlus < DIMinus and ADX > th//PRICE POSITION ——————————————————————————————————————————————————————————————————————————————————————————————————-float ph = pivothigh(prd, prd)float pl = pivotlow(prd, prd)var float center = nafloat lastpp = ph ? ph : pl ? pl : naif lastppif na(center)center := lastppelsecenter := (center * 2 + lastpp) / 3Up = center – (Factor * atr(Pd))Dn = center + (Factor * atr(Pd))float TUp = nafloat TDown = naTrend = 0TUp := close[1] > TUp[1] ? max(Up, TUp[1]) : UpTDown := close[1] < TDown[1] ? min(Dn, TDown[1]) : DnTrend := close > TDown[1] ? 1: close < TUp[1]? -1: nz(Trend[1], 1)Trailingsl = Trend == 1 ? TUp : TDownplot(Trailingsl, color = CLOUD_COLOR , linewidth = 1, title = “PP line”)bsignal = Trend == 1 and Trend[1] == -1ssignal = Trend == -1 and Trend[1] == 1first_long = bsignal and not S_cloud ? Trailingsl : nafirst_short = ssignal and not L_cloud ? Trailingsl : nasecond_long = L_cloud and L_adx and Trend == 1second_short = S_cloud and S_adx and Trend == -1Long = second_long or first_longShort = second_short or first_shortlong_short = 0long_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_lastlast_short_cond = Short and short_lastLong_plot = bsignal and not S_cloud ? Trailingsl : na or last_long_cond ? Trailingsl : naShort_plot = ssignal and not L_cloud ? Trailingsl : na or last_short_cond ? Trailingsl : naLong_stop = ssignal and L_cloud ? Trailingsl : naShort_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 wielkieefMerci par avance pour votre aide 😉02/12/2024 at 11:18 AM #227978Salut
Vous pouvez trouver le code ici:
https://www.prorealcode.com/prorealtime-indicators/smart-supertrend/02/12/2024 at 11:18 AM #227979Salut
Vous pouvez trouver le code ici:
https://www.prorealcode.com/prorealtime-indicators/smart-supertrend/ -
AuthorPosts
Find exclusive trading pro-tools on