Convert Trading View Code to ProrealCode
Forums › ProRealTime English forum › ProBuilder support › Convert Trading View Code to ProrealCode
- This topic has 22 replies, 3 voices, and was last updated 9 months ago by Iván.
-
-
02/14/2024 at 7:04 AM #228127
hi
where do i request or ask for help to convert trading view indicator code to pro-realtime code?
below is the code that i like to convert. it is free indicator code on tradingview so not trying to get paid code from trading view to PRT. Credit for this code is to QUANTNOMAD. Indicator name on TV is UT Bot Alerts.
Note – MOD – please delete if this is not allowed on this platform as i am new not sure of all rules. thanks.
//@version=4study(title=”UT Bot Alerts”, overlay = true)// Inputsa = input(1, title = “Key Vaule. ‘This changes the sensitivity'”)c = input(10, title = “ATR Period”)h = input(false, title = “Signals from Heikin Ashi Candles”)xATR = atr(c)nLoss = a * xATRsrc = h ? security(heikinashi(syminfo.tickerid), timeframe.period, close, lookahead = false) : closexATRTrailingStop = 0.0xATRTrailingStop := iff(src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), src – nLoss),iff(src<nz(xATRTrailingStop[1],0)andsrc[1]<nz(xATRTrailingStop[1],0),min(nz(xATRTrailingStop[1]),src+nLoss),iff(src > nz(xATRTrailingStop[1], 0), src – nLoss, src + nLoss)))pos = 0pos := iff(src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0), 1,iff(src[1]>nz(xATRTrailingStop[1],0)andsrc<nz(xATRTrailingStop[1],0),-1,nz(pos[1],0)))xcolor=pos==-1?color.red:pos==1?color.green:color.blueema = ema(src,1)above = crossover(ema, xATRTrailingStop)below = crossover(xATRTrailingStop, ema)buy =src>xATRTrailingStopandabovesell = src < xATRTrailingStop and belowbarbuy =src>xATRTrailingStopbarsell=src<xATRTrailingStopplotshape(buy, title = “Buy”, text = ‘Buy’, style = shape.labelup, location = location.belowbar, color= color.green, textcolor = color.white, transp = 0, size = size.tiny)plotshape(sell, title = “Sell”, text = ‘Sell’, style = shape.labeldown, location = location.abovebar, color= color.red, textcolor = color.white, transp = 0, size = size.tiny)barcolor(barbuy ? color.green : na)barcolor(barsell ? color.red : na)alertcondition(buy, “UT Long”, “UT Long”)alertcondition(sell, “UT Short”, “UT Short”)02/14/2024 at 8:51 AM #22813902/14/2024 at 8:55 AM #228141I can see that your code has already been translate.
https://www.prorealcode.com/topic/ut-bot-alerts-2/1 user thanked author for this post.
02/14/2024 at 9:07 AM #22814302/14/2024 at 9:21 AM #228146See below, I copied entire code from Trading view to PRT but getting error on defining variable H and then next variable title “xATR”.
you can copy below code and tried to correct it if possible. thanks.
123456789101112131415161718192021222324252627282930313233343536373839404142434445//@version=4//study(title="UT Bot Alerts", overlay = true)// Inputsa = 1c = 10h =xATR = atr(c)nLoss = a * xATRsrc = h ? security(heikinashi(syminfo.tickerid), timeframe.period, close, lookahead = false) : closexATRTrailingStop = 0.0xATRTrailingStop := iff(src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), src - nLoss),iff(src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), src + nLoss),iff(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss)))pos = 0pos := iff(src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0), 1,iff(src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0)))xcolor = pos == -1 ? color.red: pos == 1 ? color.green : color.blueema = ema(src,1)above = crossover(ema, xATRTrailingStop)below = crossover(xATRTrailingStop, ema)buy = src > xATRTrailingStop and abovesell = src < xATRTrailingStop and belowbarbuy = src > xATRTrailingStopbarsell = src < xATRTrailingStopplotshape(buy, title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= color.green, textcolor = color.white, transp = 0, size = size.tiny)plotshape(sell, title = "Sell", text = 'Sell', style = shape.labeldown, location = location.abovebar, color= color.red, textcolor = color.white, transp = 0, size = size.tiny)barcolor(barbuy ? color.green : na)barcolor(barsell ? color.red : na)alertcondition(buy, "UT Long", "UT Long")alertcondition(sell, "UT Short", "UT Short")02/14/2024 at 10:24 AM #228148It’s a complete different language, it can’t be corrected. It needs to be converted (translated) to another language.
02/14/2024 at 8:45 PM #22819802/15/2024 at 10:01 AM #228210Undrestood. I know there’s a conversion list.
02/15/2024 at 4:24 PM #228226Here it is:
PRC_Ut bot alert12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788//PRC_UT Bot Alerts//version = 0//15.02.24//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge///inputsa = 1 //Key Vaule. 'This changes the sensitivity' - Decimalc = 10 //ATR period - Integerdrawsignals = 1 //Show arrows - Booleancolorcandles = 1 //Color candles - Boolean/////////////////xatr = averagetruerange[c](close)nLoss = a * xatrsrc = closeif barindex < c thenxatrTrailingStop = undefinedpos = 0elseif src > xatrTrailingStop[1] and src[1] > xatrTrailingStop[1] thenxAtrTrailingStop = max(xatrTrailingStop[1],src-nLoss)elseif src < xatrTrailingStop[1] and src[1] < xatrTrailingStop[1] thenxAtrTrailingStop = min(xatrTrailingStop[1],src+nLoss)elseif src > xatrTrailingStop[1] thenxAtrTrailingStop = src-nLosselsexAtrTrailingStop = src+nLossendifendifendifif src[1] < xatrTrailingStop[1] and src > xAtrTrailingStop[1] thenpos = 1r=250g=0b=0elseif src[1] > xatrTrailingStop[1] and src < xatrTrailingStop[1] thenpos = -1r=0g=0b=250elsepos = pos[1]endifendifendif///////Trading conditionsema = average[1](src)above = ema crosses over xatrTrailingStopbelow = ema crosses under xatrTrailingStopbuy1 = src > xatrTrailingStop and abovesell1 = src < xatrTrailingStop and belowbarbuy = src > xatrTrailingStopbarsell = src < xatrTrailingStop//////Plot signals and candlesif drawsignals thenif buy1 thendrawarrowup(barindex,low-0.15*averagetruerange[10])coloured("green")elsif sell1 thendrawarrowdown(barindex,high+0.15*averagetruerange[10])coloured("red")endifendifif colorcandles thenif barbuy thenrbar=0gbar=250bbar=0elsif barsell thenrbar=250gbar=0bbar=0elserbar=125gbar=125bbar=125endifDRAWCANDLE(open, high, low, close)coloured(rbar,gbar,bbar)endifreturn xatrTrailingStop as "Trailing Stop" coloured(r,g,b)02/17/2024 at 10:50 AM #228329Thank you for the great effort.
There is slight variation between your code and the one the trading view platform and it could be because the code that I gave above didn’t define Variable ” h ” (if you look at the line no. 8 in my above post #228146).
Trading view defines h as below:
h = input(false, title = “Signals from Heikin Ashi Candles”)which means signals are taken from Heikin Ashi candles while in your code signals are taken from candlesticks.in addition line number 15 in your code above has src = close but in trading view src defined again something from Heikin ashi as below :src = h ? security(heikinashi(syminfo.tickerid), timeframe.period, close, lookahead = false) : closeis there a way to get signals from Heikin Ashi candles similar to code on TV ?03/11/2024 at 10:06 AM #229585@JC_Bywan
Ivan, already converted majority of the code I gave above in #228146 ,however we still don’t have solution to small item i talked in my post #228329 which is resulting in error/incorrect output when using this code in PRT.
are you able to help?
Thanks,
03/11/2024 at 10:25 AM #22959103/11/2024 at 10:50 AM #229599Ivan
Thanks, I updated the code as below. However, there are few issues as below (refer to the screenshot as well).
- In the setting, when I change the key value & ATR period then there is no change in the Green & Red Arrow Indicator Arrow on the chart. Which is not correct as the location of the indicator should change with change in the ATR period or Key value.
- As per the screen shot, “Signals from Heikin Ashi Candles” not active and as you can see in the screenshot it says “Variable not used in the code”.
See below, I copied updated code so you can test it at your end as well. I used ticker code ” WBC ” in the screenshot but the result is same across all ticker code i use from Australia.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293//PRC_UT Bot Alerts//version = 0//15.02.24//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge///inputsa = 1 //Key Vaule. 'This changes the sensitivity' - Decimalc = 10 //ATR period - Integerdrawsignals = 1 //Show arrows - Booleancolorcandles = 1 //Color candles - Boolean/////////////////xatr = averagetruerange[c](close)nLoss = a * xatrheikin = 1 // boolean. True work as Heikin Aif heikin thensrc = (open+close+high+low)/4elsesrc = closeendifif barindex < c thenxatrTrailingStop = undefinedpos = 0elseif src > xatrTrailingStop[1] and src[1] > xatrTrailingStop[1] thenxAtrTrailingStop = max(xatrTrailingStop[1],src-nLoss)elseif src < xatrTrailingStop[1] and src[1] < xatrTrailingStop[1] thenxAtrTrailingStop = min(xatrTrailingStop[1],src+nLoss)elseif src > xatrTrailingStop[1] thenxAtrTrailingStop = src-nLosselsexAtrTrailingStop = src+nLossendifendifendifif src[1] < xatrTrailingStop[1] and src > xAtrTrailingStop[1] thenpos = 1r=250g=0b=0elseif src[1] > xatrTrailingStop[1] and src < xatrTrailingStop[1] thenpos = -1r=0g=0b=250elsepos = pos[1]endifendifendif///////Trading conditionsema = average[1](src)above = ema crosses over xatrTrailingStopbelow = ema crosses under xatrTrailingStopbuy1 = src > xatrTrailingStop and abovesell1 = src < xatrTrailingStop and belowbarbuy = src > xatrTrailingStopbarsell = src < xatrTrailingStop//////Plot signals and candlesif drawsignals thenif buy1 thendrawarrowup(barindex,low-0.15*averagetruerange[10])coloured("green")elsif sell1 thendrawarrowdown(barindex,high+0.15*averagetruerange[10])coloured("red")endifendifif colorcandles thenif barbuy thenrbar=0gbar=250bbar=0elsif barsell thenrbar=250gbar=0bbar=0elserbar=125gbar=125bbar=125endifDRAWCANDLE(open, high, low, close)coloured(rbar,gbar,bbar)endifreturn xatrTrailingStop as "Trailing Stop" coloured(r,g,b)03/11/2024 at 11:33 AM #229602Hi,
I think you are working with previous .itf …
Please, create new indicator, copy the code below and define again input variables or download the attached file.PRC_UT Bot Alerts123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293//PRC_UT Bot Alerts//version = 1//15.02.24//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge///inputsa = 1 //Key Vaule. 'This changes the sensitivity' - Decimalc = 10 //ATR period - Integerdrawsignals = 1 //Show arrows - Booleancolorcandles = 1 //Color candles - Booleanheikin = 1 // boolean. True work as Heikin A/////////////////xatr = averagetruerange[c](close)nLoss = a * xatrif heikin thensrc = (open+close+high+low)/4elsesrc = closeendifif barindex < c thenxatrTrailingStop = undefinedpos = 0elseif src > xatrTrailingStop[1] and src[1] > xatrTrailingStop[1] thenxAtrTrailingStop = max(xatrTrailingStop[1],src-nLoss)elseif src < xatrTrailingStop[1] and src[1] < xatrTrailingStop[1] thenxAtrTrailingStop = min(xatrTrailingStop[1],src+nLoss)elseif src > xatrTrailingStop[1] thenxAtrTrailingStop = src-nLosselsexAtrTrailingStop = src+nLossendifendifendifif src[1] < xatrTrailingStop[1] and src > xAtrTrailingStop[1] thenpos = 1r=250g=0b=0elseif src[1] > xatrTrailingStop[1] and src < xatrTrailingStop[1] thenpos = -1r=0g=0b=250elsepos = pos[1]endifendifendif///////Trading conditionsema = average[1](src)above = ema crosses over xatrTrailingStopbelow = ema crosses under xatrTrailingStopbuy1 = src > xatrTrailingStop and abovesell1 = src < xatrTrailingStop and belowbarbuy = src > xatrTrailingStopbarsell = src < xatrTrailingStop//////Plot signals and candlesif drawsignals thenif buy1 thendrawarrowup(barindex,low-0.15*averagetruerange[10])coloured("green")elsif sell1 thendrawarrowdown(barindex,high+0.15*averagetruerange[10])coloured("red")endifendifif colorcandles thenif barbuy thenrbar=0gbar=250bbar=0elsif barsell thenrbar=250gbar=0bbar=0elserbar=125gbar=125bbar=125endifDRAWCANDLE(open, high, low, close)coloured(rbar,gbar,bbar)endifreturn xatrTrailingStop as "Trailing Stop" coloured(r,g,b)1 user thanked author for this post.
03/11/2024 at 9:44 PM #229621Ivan
Thank you. I created new indicator by copying your code above but it didn’t work so then I copied your itf file and imported into my system and it worked. so it did work using the file you sent through but somehow copying code is not working… !
Somehow, the signal I got on PRT are more then what the code should be giving if it was same as what is on Trading view. See attached image, the bottom part of the image is trading view which gave 4 signals and top part is from PRT using your new code and it gave 6 signals. Two extra signals are highlighted in circle on the top part of the chart.
In addition signal number 1 on PRT is completely different date to what we have on trading view.
i checked on different other tickers and same thing happened as here. more signals are coming out of PRT code then what we get from tradingview code. not sure why it is happening, but PRT is giving false signals which is the issue as too many early buy & sell signals comes out of PRT thn trading view for the same setting.
-
AuthorPosts
Find exclusive trading pro-tools on