ProRealCode - Trading & Coding with ProRealTime™
Hello everyone,
I’m trying to replicate the same Renko as PRT. I chose Boxsize 100 on Dow H1 and used the code provided by Nicolas here https://www.prorealcode.com/prorealtime-indicators/renko-boxes-on-price-chart/
However, the values are sometimes identical and sometimes different. I’d like to have the exact same values than PRT. Can someone please help?
Thanks
I think your problem come that the price can “jump” 2 or more renko bars size during 1 code read, and you can only paint 1 bar on a single period. That’s tricky to code, I know this product from the marketplace replicate the same exact values with quantity of boxes, on a classic chart: https://market.prorealcode.com/product/prt-renko/
After searching a bit, I found this free code on TradingView (Pine). It’s way beyond my conversion skills. If someone is interested to convert it.
//@version=4
study(“Renko”, max_bars_back = 5000)
get_renko(box_size) =>
var float base_price = input(title=”Base price”, type=input.source, defval=close)
var float r_open = base_price – box_size
var float r_close = close
var int up_list = 0
var int down_list = 0
var int up_move = 0
var int down_move = 0
var int built_bricks_up = 0
var int built_bricks_down = 0
var int counter_up_series = 0
var int counter_down_series = 0
var int required_series_up = 0
var int required_series_down = 0
var int required_bricks_up = 0
var int required_bricks_down = 0
var bool b_up_list = false
var bool b_down_list = false
var bool b_up_move = false
var bool b_down_move = false
var bool in_the_range_up = false
var bool in_the_range_down = false
var int up_stop_index = 0
var int down_stop_index = 0
var int up_temporary_index = 0
var int down_temporary_index = 0
// creating lists
if bar_index > 0
if close > open
down_move := 0
if b_up_list
up_move := int((close – base_price) / box_size)
if up_move > up_list
up_list := up_move
down_list := na
else if b_down_list
up_move := int((close – (base_price – down_list * box_size)) / box_size)
else
down_list := na
up_list := na
else if close < open
up_move := 0
if b_down_list
down_move := int((base_price – close) / box_size)
if down_move > down_list
down_list := down_move
up_list := na
else if b_up_list
down_move := int(((base_price + up_list * box_size) – close) / box_size)
else
down_list := na
up_list := na
if b_up_list and down_move >= 2
base_price := base_price + (up_list – 1) * box_size
b_up_list := false
up_list := na
b_down_list := true
down_list := down_move – 1
else if b_down_list and up_move >= 2
base_price := base_price – (down_list – 1) * box_size
b_down_list := false
down_list := na
b_up_list := true
up_list := up_move – 1
if not b_up_list and not b_down_list
up_move := int((close – base_price) / box_size)
down_move := int((base_price – close) / box_size)
if up_move > 0
down_move := 0
b_up_list := true
b_up_move := true
up_list := up_move
down_list := na
else if down_move > 0
up_move := 0
b_down_list := true
b_down_move := true
down_list := down_move
up_list := na
else
up_list := na
down_list := na
r_close := na
// creating open and close series
if b_up_move
for i = 0 to bar_index – up_stop_index – 1
if not na(up_list[i]) and na(up_list[i+1])
counter_up_series := counter_up_series + 1
required_bricks_up := up_list[i]
if i == bar_index – up_stop_index – 1
for j = i to 0
up_temporary_index := bar_index[j]
required_bricks_up := up_list[j]
if j == 0
break
if not na(up_list[j]) and na(up_list[j-1])
up_temporary_index := bar_index[j-1]
break
break
if counter_up_series == 1 and not na(up_list[0])
in_the_range_up := true
counter_up_series := 0
if built_bricks_up < required_bricks_up
r_open := r_open + box_size
r_close := r_open + box_size
built_bricks_up := built_bricks_up + 1
else if in_the_range_up and built_bricks_up == required_bricks_up
r_close := na
else
up_stop_index := up_temporary_index
built_bricks_up := 0
built_bricks_down := 1
b_up_move := false
b_down_move := true
r_close := r_open – box_size
in_the_range_up := false
else if b_down_move
for i = 0 to bar_index – down_stop_index – 1
if not na(down_list[i]) and na(down_list[i+1])
counter_down_series := counter_down_series + 1
required_bricks_down := down_list[i]
if i == bar_index – down_stop_index – 1
for j = i to 0
down_temporary_index := bar_index[j]
required_bricks_down := down_list[j]
if j == 0
break
if not na(down_list[j]) and na(down_list[j-1])
down_temporary_index := bar_index[j-1]
break
break
if counter_down_series == 1 and not na(down_list[0])
in_the_range_down := true
counter_down_series := 0
if built_bricks_down < required_bricks_down
if up_stop_index == 0 and down_stop_index == 0 and built_bricks_down == 0
r_open := r_open + box_size
r_close := r_open – box_size
built_bricks_down := built_bricks_down + 1
else
r_open := r_open – box_size
r_close := r_open – box_size
built_bricks_down := built_bricks_down + 1
else if in_the_range_down and built_bricks_down == required_bricks_down
r_close := na
else
down_stop_index := down_temporary_index
built_bricks_down := 0
built_bricks_up := 1
b_down_move := false
b_up_move := true
r_close := r_open + box_size
in_the_range_down := false
else
r_close := na
[r_open, r_open > r_close ? r_open : r_close, r_open < r_close ? r_open : r_close, r_close]
[r_open, r_high, r_low, r_close] = get_renko(input(defval = 200.0, title = “Box size”, type = input.float, minval = 0.00000001))
plotcandle(r_open, r_high, r_low, r_close, color = r_close > r_open ? color.green : color.red)
I tried my best to convert the above code. I’m stuck in the loops where I think I didn’t place the “endif” in the appropriate location.
I need a bit of help PLEEEEEEEAAAASE!
Thanks a million!
DEFPARAM CALCULATEONLASTBARS = 1000
boxsize = 100
Baseprice = close
ropen = baseprice - boxsize
rclose = close
uplist = 0
downlist = 0
upmove = 0
downmove = 0
builtbricksup = 0
builtbricksdown = 0
counterupseries = 0
counterdownseries = 0
requiredseriesup = 0
requiredseriesdown = 0
requiredbricksup = 0
requiredbricksdown = 0
boolbupist = 0
boolbdownlist = 0
boolbupmove = 0
boolbdownmove = 0
boolintherangeup = 0
boolintherangedown = 0
intupstopindex = 0
intdownstopindex = 0
intuptemporaryindex = 0
intdowntemporaryindex = 0
if barindex>0 then
if close > open then
downmove = 0
if buplist >0 then
upmove = abs((close - baseprice) / boxsize)
if upmove > uplist then
uplist = upmove
downlist = 0
elsif bdownlist >0 then
upmove = abs((close - (baseprice - downlist * boxsize)) / boxsize)
else
downlist = 0
uplist = 0
endif
elsif close < open then
upmove = 0
if bdownlist > 0 then
downmove = abs((baseprice - close) / boxsize)
if downmove > downlist then
downlist = downmove
uplist = 0
elsif buplist>0 then
downmove = abs(((baseprice + uplist * boxsize) - close) / boxsize)
else
downlist = 0
uplist = 0
if buplist and downmove >= 2 then
baseprice = baseprice + (uplist - 1) * boxsize
buplist = 0
uplist = 0
bdownlist = 1
downlist = downmove - 1
elsif bdownlist=1 and upmove >= 2 then
baseprice = baseprice - (downlist - 1) * boxsize
bdownlist = 0
downlist = 0
buplist = 1
uplist = upmove - 1
if not buplist and not bdownlist then
upmove = abs((close - baseprice) / boxsize)
downmove = abs((baseprice - close) / boxsize)
if upmove > 0 then
downmove = 0
buplist = 1
bupmove = 1
uplist = upmove
downlist = 1
elsif downmove > 0 then
upmove = 0
bdownlist = 1
bdownmove = 1
downlist = downmove
uplist = 0
else
uplist = 0
downlist = 0
rclose = 0
endif
endif
endif
endif
endif
endif
endif
endif
// creating open and close series
if barindex>0 then
if bupmove = 1 then
if (uplist[i])<>0 and (uplist[i+1])<>0 then
for i = 0 to barindex - upstopindex - 1
counterupseries = counterupseries + 1
requiredbricksup = uplist[i]
break
if i = barindex - upstopindex - 1 then
for j = i to 0
uptemporaryindex = barindex[j]
requiredbricksup = uplist[j]
if j = 0 then
break
elsif (uplist[j])<>0 and (uplist[j-1])<>0 then
uptemporaryindex = barindex[j-1]
//break
endif
//break
if counterupseries = 1 and (uplist[0])<>0 then
intherangeup = 1
counterupseries = 0
if builtbricksup < requiredbricksup then
ropen = ropen + boxsize
rclose = ropen + boxsize
builtbricksup = builtbricksup + 1
elsif intherangeup and builtbricksup = requiredbricksup then
rclose = 0
endif
else
upstopindex = uptemporaryindex
builtbricksup = 0
builtbricksdown = 1
bupmove = 0
bdownmove = 1
rclose = ropen - boxsize
intherangeup = 0
endif
if bdownmove=1 then
for i = 0 to barindex - downstopindex - 1
if (downlist[i])<>0 and (downlist[i+1])<>0 then
counterdownseries = counterdownseries + 1
requiredbricksdown = downlist[i]
if i = barindex - downstopindex - 1 then
for j = i to 0
downtemporaryindex = barindex[j]
requiredbricksdown = downlist[j]
if j = 0 then
break
if (downlist[j])<>0 and (downlist[j-1])<>0 then
downtemporaryindex = barindex[j-1]
//break
//break
if counterdownseries = 1 and (downlist[0])<>0 then
intherangedown = 1
counterdownseries = 0
if builtbricksdown < requiredbricksdown then
if upstopindex = 0 and downstopindex = 0 and builtbricksdown = 0 then
ropen = ropen + boxsize
rclose = ropen - boxsize
builtbricksdown = builtbricksdown + 1
else
ropen = ropen - boxsize
rclose = ropen - boxsize
builtbricksdown = builtbricksdown + 1
endif
elsif intherangedown and builtbricksdown = requiredbricksdown then
rclose = 0
else
downstopindex = downtemporaryindex
builtbricksdown = 0
builtbricksup = 1
bdownmove = 0
bupmove = 1
rclose = ropen + boxsize
intherangedown = 0
endif
else
//rclose = na
//endif
endif
endif
endif
DRAWCANDLE(ropen, high, low, rclose)coloured(0,0,255)
RETURN
The best I could with my limited coding skills. Except a few exceptions, all the open and close match the PRT Renko. Can you please Nicolas have a look if it’s correct and why I have gaps between certain Renko candles?
DEFPARAM CALCULATEONLASTBARS = 1000
boxsize = 50
Baseprice = close
ropen = baseprice - boxsize
rclose = close
uplist = 0
downlist = 0
upmove = 0
downmove = 0
builtbricksup = 0
builtbricksdown = 0
counterupseries = 0
counterdownseries = 0
requiredseriesup = 0
requiredseriesdown = 0
requiredbricksup = 0
requiredbricksdown = 0
boolbupist = 0
boolbdownlist = 0
boolbupmove = 0
boolbdownmove = 0
boolintherangeup = 0
boolintherangedown = 0
intupstopindex = 0
intdownstopindex = 0
intuptemporaryindex = 0
intdowntemporaryindex = 0
if barindex>0 then
if close > open then
downmove = 0
if buplist >0 then
upmove = abs((close - baseprice) / boxsize)
if upmove > uplist then
uplist = upmove
downlist = 0
elsif bdownlist >0 then
upmove = abs((close - (baseprice - downlist * boxsize)) / boxsize)
else
downlist = 0
uplist = 0
endif
elsif close < open then
upmove = 0
endif
if bdownlist > 0 then
downmove = abs((baseprice - close) / boxsize)
if downmove > downlist then
downlist = downmove
uplist = 0
elsif buplist>0 then
downmove = abs(((baseprice + uplist * boxsize) - close) / boxsize)
else
downlist = 0
uplist = 0
if buplist and downmove >= 2 then
baseprice = baseprice + (uplist - 1) * boxsize
buplist = 0
uplist = 0
bdownlist = 1
downlist = downmove - 1
elsif bdownlist=1 and upmove >= 2 then
baseprice = baseprice - (downlist - 1) * boxsize
bdownlist = 0
downlist = 0
buplist = 1
uplist = upmove - 1
if not buplist and not bdownlist then
upmove = abs((close - baseprice) / boxsize)
downmove = abs((baseprice - close) / boxsize)
if upmove > 0 then
downmove = 0
buplist = 1
bupmove = 1
uplist = upmove
downlist = 1
elsif downmove > 0 then
upmove = 0
bdownlist = 1
bdownmove = 1
downlist = downmove
uplist = 0
else
uplist = 0
downlist = 0
rclose = 0
endif
endif
endif
endif
endif
endif
endif
// creating open and close series
if barindex>0 then
if bupmove = 1 then
if (uplist[i])<>0 and (uplist[i+1])<>0 then
for i = 0 to barindex - upstopindex - 1
counterupseries = counterupseries + 1
requiredbricksup = uplist[i]
//break
next
if i = barindex - upstopindex - 1 then
for j = i to 0
uptemporaryindex = barindex[j]
requiredbricksup = uplist[j]
next
if j = 0 then
break
endif
elsif (uplist[j])<>0 and (uplist[j-1])<>0 then
uptemporaryindex = barindex[j-1]
//break
endif
//break
if counterupseries = 1 and (uplist[0])<>0 then
intherangeup = 1
counterupseries = 0
if builtbricksup < requiredbricksup then
ropen = ropen + boxsize
rclose = ropen + boxsize
builtbricksup = builtbricksup + 1
elsif intherangeup and builtbricksup = requiredbricksup then
rclose = 0
endif
else
upstopindex = uptemporaryindex
builtbricksup = 0
builtbricksdown = 1
bupmove = 0
bdownmove = 1
rclose = ropen - boxsize
intherangeup = 0
endif
endif
endif
if bdownmove=1 then
for i = 0 to barindex - downstopindex - 1
if (downlist[i])<>0 and (downlist[i+1])<>0 then
counterdownseries = counterdownseries + 1
requiredbricksdown = downlist[i]
if i = barindex - downstopindex - 1 then
for j = i to 0
downtemporaryindex = barindex[j]
requiredbricksdown = downlist[j]
if j = 0 then
endif
next //break
endif
endif
next
if (downlist[j])<>0 and (downlist[j-1])<>0 then
downtemporaryindex = barindex[j-1]
//break
//break
if counterdownseries = 1 and (downlist[0])<>0 then
intherangedown = 1
counterdownseries = 0
if builtbricksdown < requiredbricksdown then
if upstopindex = 0 and downstopindex = 0 and builtbricksdown = 0 then
ropen = ropen + boxsize
rclose = ropen - boxsize
builtbricksdown = builtbricksdown + 1
else
ropen = ropen - boxsize
rclose = ropen - boxsize
builtbricksdown = builtbricksdown + 1
endif
elsif intherangedown and builtbricksdown = requiredbricksdown then
rclose = 0
else
downstopindex = downtemporaryindex
builtbricksdown = 0
builtbricksup = 1
bdownmove = 0
bupmove = 1
rclose = ropen + boxsize
intherangedown = 0
endif
else
//rclose = na
//endif
endif
endif
endif
endif
if rclose>=rclose[1] then
DRAWCANDLE(ropen, high, low, rclose)coloured(0,255,0)
endif
if rclose<rclose[1] then
DRAWCANDLE(ropen, high, low, rclose)coloured(255,0,0)
endif
RETURN
Sorry if I’m posting too much. I hope you can review this very last version, which seems to replicate exactly the PRT Renko, with no gaps between boxes.
the graph in blue is the version with %, changing boxsize from 50pts to “close*.1/100”
DEFPARAM CALCULATEONLASTBARS = 500
boxsize = 50
Baseprice = close
ropen = baseprice - boxsize
rclose = close
uplist = 0
downlist = 0
upmove = 0
downmove = 0
builtbricksup = 0
builtbricksdown = 0
counterupseries = 0
counterdownseries = 0
requiredseriesup = 0
requiredseriesdown = 0
requiredbricksup = 0
requiredbricksdown = 0
boolbupist = 0
boolbdownlist = 0
boolbupmove = 0
boolbdownmove = 0
boolintherangeup = 0
boolintherangedown = 0
intupstopindex = 0
intdownstopindex = 0
intuptemporaryindex = 0
intdowntemporaryindex = 0
if barindex>0 then
if close > open then
downmove = 0
if buplist >0 then
upmove = abs((close - baseprice) / boxsize)
if upmove > uplist then
uplist = upmove
downlist = 0
elsif bdownlist >0 then
upmove = abs((close - (baseprice - downlist * boxsize)) / boxsize)
else
downlist = 0
uplist = 0
endif
elsif close < open then
upmove = 0
endif
if bdownlist > 0 then
downmove = abs((baseprice - close) / boxsize)
if downmove > downlist then
downlist = downmove
uplist = 0
elsif buplist>0 then
downmove = abs(((baseprice + uplist * boxsize) - close) / boxsize)
else
downlist = 0
uplist = 0
if buplist and downmove >= 2 then
baseprice = baseprice + (uplist - 1) * boxsize
buplist = 0
uplist = 0
bdownlist = 1
downlist = downmove - 1
elsif bdownlist=1 and upmove >= 2 then
baseprice = baseprice - (downlist - 1) * boxsize
bdownlist = 0
downlist = 0
buplist = 1
uplist = upmove - 1
if not buplist and not bdownlist then
upmove = abs((close - baseprice) / boxsize)
downmove = abs((baseprice - close) / boxsize)
if upmove > 0 then
downmove = 0
buplist = 1
bupmove = 1
uplist = upmove
downlist = 1
elsif downmove > 0 then
upmove = 0
bdownlist = 1
bdownmove = 1
downlist = downmove
uplist = 0
else
uplist = 0
downlist = 0
rclose = 0
endif
endif
endif
endif
endif
endif
endif
// creating open and close series
if barindex>0 then
if bupmove = 1 then
if (uplist[i])<>0 and (uplist[i+1])<>0 then
for i = 0 to barindex - upstopindex - 1
counterupseries = counterupseries + 1
requiredbricksup = uplist[i]
//break
next
if i = barindex - upstopindex - 1 then
for j = i to 0
uptemporaryindex = barindex[j]
requiredbricksup = uplist[j]
next
if j = 0 then
break
endif
elsif (uplist[j])<>0 and (uplist[j-1])<>0 then
uptemporaryindex = barindex[j-1]
//break
endif
//break
if counterupseries = 1 and (uplist[0])<>0 then
intherangeup = 1
counterupseries = 0
if builtbricksup < requiredbricksup then
ropen = ropen + boxsize
rclose = ropen + boxsize
builtbricksup = builtbricksup + 1
elsif intherangeup and builtbricksup = requiredbricksup then
rclose = 0
endif
else
upstopindex = uptemporaryindex
builtbricksup = 0
builtbricksdown = 1
bupmove = 0
bdownmove = 1
rclose = ropen - boxsize
intherangeup = 0
endif
endif
endif
if bdownmove=1 then
for i = 0 to barindex - downstopindex - 1
if (downlist[i])<>0 and (downlist[i+1])<>0 then
counterdownseries = counterdownseries + 1
requiredbricksdown = downlist[i]
if i = barindex - downstopindex - 1 then
for j = i to 0
downtemporaryindex = barindex[j]
requiredbricksdown = downlist[j]
if j = 0 then
endif
next //break
endif
endif
next
if (downlist[j])<>0 and (downlist[j-1])<>0 then
downtemporaryindex = barindex[j-1]
//break
//break
if counterdownseries = 1 and (downlist[0])<>0 then
intherangedown = 1
counterdownseries = 0
if builtbricksdown < requiredbricksdown then
if upstopindex = 0 and downstopindex = 0 and builtbricksdown = 0 then
ropen = ropen + boxsize
rclose = ropen - boxsize
builtbricksdown = builtbricksdown + 1
else
ropen = ropen - boxsize
rclose = ropen - boxsize
builtbricksdown = builtbricksdown + 1
endif
elsif intherangedown and builtbricksdown = requiredbricksdown then
rclose = 0
else
downstopindex = downtemporaryindex
builtbricksdown = 0
builtbricksup = 1
bdownmove = 0
bupmove = 1
rclose = ropen + boxsize
intherangedown = 0
endif
else
//rclose = na
//endif
endif
endif
endif
endif
if rclose>=rclose[1] and ropen>ropen[1] then
DRAWCANDLE(ropen, high, low, rclose)coloured(0,255,0)
endif
if rclose<rclose[1] and ropen<ropen[1] then
DRAWCANDLE(high, high, low, rclose)coloured(255,0,0)
endif
RETURN
@Nicolas Good morning, may I please take a little bit of your time to review the latest Renko code posted above? Many Thanks!
If you apply your indicator on a renko chart, it will obviously create renko bars. Did you try on classic chart? I thought it was the purpose of your query in the first place?
Indeed. Just wanted to use this code in a strategy as Exit when the Renko changes color. As you know the PRT native Renko cannot be added in ProOrder. So, if you can please check if this code is consistent with PRT native Renko. Many Thanks
Sorry I don’t get it 🙂 You just have to put your code on a 1 minute chart for instance and compare side by side with a renko chart of the same brick size, so i’m wondering why you are asking me? 🙂
Renko PRT Renko PRC
This topic contains 9 replies,
has 2 voices, and was last updated by
Nicolas
4 years ago.
| Forum: | ProBuilder: Indicators & Custom Tools |
| Language: | English |
| Started: | 01/28/2022 |
| Status: | Active |
| Attachments: | 8 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.