1
votes

i am trying to write a pine script code on Tradingview, the aim is to adjust the renko box size automatically (something like ATR, but tradingview's ATR feature doesnt do what i want), i am thinking to make the box size 5% of the current price (or of the previous close, this makes more sense because the value would be concrete).

below is the code for the regular renko, what i am struggling is to make 'box_size' variable equal to a specific percentage of the previous close.

//@version=3
study("Renko", shorttitle = "Renko")
src = input(title = "Source (close or open or hl2 or hlc3 or ohlc4)", type = 
string, defval = "close") 
box_size = 0.5
renko_tickerid = renko(tickerid, src, "Traditional", box_size)
renko_close = security(renko_tickerid, period, close)
renko_open = security(renko_tickerid, period, open)
renko_high = security(renko_tickerid, period, high)
renko_low = security(renko_tickerid, period, low)
plotcandle(renko_open, renko_high, renko_low, renko_close, color = renko_open < renko_close ? green : red)

appreciate any guidance in advance.

2

2 Answers

0
votes

Try this out

//@version=3
study("Renko", shorttitle = "Renko")
src = input(title = "Source (close or open or hl2 or hlc3 or ohlc4)", type = 
string, defval = "close")
percentate_value = 0.01   // 1/100 =0.01 1%   
box_size = nz(close[1]*percentate_value, 0)

renko_tickerid = renko(tickerid, src, "Traditional", box_size)
renko_close = security(renko_tickerid, period, close)
renko_open = security(renko_tickerid, period, open)
renko_high = security(renko_tickerid, period, high)
renko_low = security(renko_tickerid, period, low)
plotcandle(renko_open, renko_high, renko_low, renko_close, color = renko_open < renko_close ? green : red)

here close[1] is previous close value nz(close[1]percentate_value, 0) this return zero when there is not previous value else previouscloseprecentage_value

0
votes

Add this to your code, it should achieve what you are looking for:

size=input(2)
renko_tickerid = renko(syminfo.tickerid, "Traditional", size)

Keep in mind that in TradingView the minimum box size is 1 pip (for example for NASDAQ futures it's 0.25 and the box size has to be a multiple of 0.25)