Convert from Tradingview to PRT
Forums › ProRealTime English forum › ProBuilder support › Convert from Tradingview to PRT
- This topic has 4 replies, 3 voices, and was last updated 1 year ago by lukasmartens.
Viewing 5 posts - 1 through 5 (of 5 total)
-
-
08/09/2023 at 6:52 AM #218757
Hello,
I have a code in tradingview that I have tried to convert to PRT but I struggeling.The code in Tradingview is:
I dont need the plot shapes and so on just the indicator.
src = input(defval=close, title=’Source’)per = input.int(defval=100, minval=1, title=’Sampling Period’)mult = input.float(defval=3.0, minval=0.1, title=’Range Multiplier’)smoothrng(x, t, m) =>wper = t * 2 – 1avrng = ta.ema(math.abs(x – x[1]), t)smoothrng = ta.ema(avrng, wper) * msmoothrngsmrng = smoothrng(src, per, mult)rngfilt(x, r) =>rngfilt = xrngfilt := x > nz(rngfilt[1]) ? x – r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x – r : x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + rrngfiltfilt = rngfilt(src, smrng)upward = 0.0upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])downward = 0.0downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 : nz(downward[1])hband = filt + smrnglband = filt – smrngfiltcolor = upward > 0 ? color.lime : downward > 0 ? color.red : color.orangebarcolor = src > filt and src > src[1] and upward > 0 ? color.lime : src > filt and src < src[1] and upward > 0 ? color.green : src < filt and src < src[1] and downward > 0 ? color.red : src < filt and src > src[1] and downward > 0 ? color.maroon : color.orangefiltplot = plot(filt, color=filtcolor, linewidth=3, title=’Range Filter’)hbandplot = plot(hband, color=color.new(color.aqua, 100), title=’High Target’)lbandplot = plot(lband, color=color.new(color.fuchsia, 100), title=’Low Target’)fill(hbandplot, filtplot, color=color.new(color.aqua, 90), title=’High Target Range’)fill(lbandplot, filtplot, color=color.new(color.fuchsia, 90), title=’Low Target Range’)barcolor(barcolor)longCond = bool(na)shortCond = bool(na)longCond := src > filt and src > src[1] and upward > 0 or src > filt and src < src[1] and upward > 0shortCond := src < filt and src < src[1] and downward > 0 or src < filt and src > src[1] and downward > 0CondIni = 0CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]longCondition = longCond and CondIni[1] == -1shortCondition = shortCond and CondIni[1] == 1plotshape(longCondition, title=’Buy Signal’, text=’LONG’, textcolor=color.new(color.white, 0), style=shape.labelup, size=size.normal, location=location.belowbar, color=color.new(color.green, 0))plotshape(shortCondition, title=’Sell Signal’, text=’SHORT’, textcolor=color.new(color.white, 0), style=shape.labeldown, size=size.normal, location=location.abovebar, color=color.new(color.red, 0))alertcondition(longCondition, title=’Buy Alert’, message=’BUY’)alertcondition(longCondition, title=’Buy Alert’, message=’BUY’)alertcondition(longCondition, title=’Buy Alert’, message=’BUY’)alertcondition(shortCondition, title=’Sell Alert’, message=’SELL’)08/09/2023 at 6:58 AM #218758As far I have tried:
indicator(title=’LONG SHORT ASR’, overlay=true)src = input(defval=close, title=’Source’)per = input.int(defval=100, minval=1, title=’Sampling Period’)mult = input.float(defval=3.0, minval=0.1, title=’Range Multiplier’)src = closeperioddefault = 100periodminvalue = 1mult = 3.0multmin = 0.1smoothrng = Abs(x / t / m)wper = t * 2 – 1avrng = exponensial.average(abs(x – x[1]), t)smoothrng = exponensial.average(avrng, wper) * msmoothrngsmrng = smoothrng(src / per / mult)rngfilt = abs(x / r) =>rngfilt abs(x / r) =float filt = xprevFilt = nz(rngfilt[1])if x > prevFilt thenfilt = min(x – r, prevFilt)elsefilt = max(x + r, prevFilt)endiffilt = rngfilt(src, smrng)var float upward = 0.0upward = iff(filt > filt[1], nz(upward[1]) + 1, iff(filt < filt[1], 0, nz(upward[1])))downward = 0.0downward = iff(filt < filt[1], nz(downward[1]) + 1, iff(filt > filt[1], 0, nz(downward[1])))hband = filt + smrnglband = filt – smrngboolean longCond = falseboolean shortCond = falselongCond = (src > filt and src > src[1] and upward > 0) or (src > filt and src < src[1] and upward > 0)shortCond = (src < filt and src < src[1] and downward > 0) or (src < filt and src > src[1] and downward > 0)CondIni = 0CondIni = iff(longCond, 1, iff(shortCond, -1, CondIni[1]))longCondition = longCond and CondIni[1] = -1shortCondition = shortCond and CondIni[1] = 108/09/2023 at 10:07 AM #21877608/09/2023 at 10:35 AM #218789This is the code of a “Range Filter”…
There is a “Twin Range Filter” in the library that gives the same results when you adjust the settings of the second filter…
https://www.prorealcode.com/prorealtime-indicators/twin-range-filter/
1 user thanked author for this post.
08/09/2023 at 10:54 AM #218795 -
AuthorPosts
Viewing 5 posts - 1 through 5 (of 5 total)
Find exclusive trading pro-tools on
Similar topics: