Renko框大小自定义(松脚本)

时间:2018-11-13 10:37:15

标签: pine-script

我正在尝试在Tradingview上编写一个松木脚本代码,目的是自动调整Renko框的大小(类似于ATR,但是tradingview的ATR功能不能满足我的要求),我正在考虑使框的大小为5当前价格的百分比(或前一个收盘价的百分比,这更有意义,因为该值是具体的)。

下面是常规轮次的代码,我正在努力使'box_size'变量等于上次收盘价的特定百分比。

//@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)

提前了解任何指导。

2 个答案:

答案 0 :(得分:0)

尝试一下

//@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)

此处close [1]是上一个收盘价 nz(close [1] percentate_value,0)在没有其他值的情况下返回零,否则为previousclose precentage_value

答案 1 :(得分:0)

将此代码添加到您的代码中,它应该可以实现您想要的目标:

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

请记住,在TradingView中,最小交易量为1点(例如,纳斯达克期货为0.25,交易量必须为0.25的倍数)