Converting series integer to integer in pinescript

China☆狼群 提交于 2021-02-10 14:16:26

问题


I am using pinescript, and I have been trying to figure out why the following code does not work. The console keeps showing that series[integer] cannot output integer. I understand that series is not compatible with non-series values. If this is the case, is there a way to change series[integer] to integer?

The following code does not work:

x = barssince(crossover(cci,100))
y = barssince(crossover(100,cci))
xy = x-y //in this case the xy value is 9
z = highest(cci, abs(xy))
plot(z)

The following code works:

z = highest(cci, 9) //assuming xy is 9
plot(z)

Any help would be greatly appreciated. Thank you

Thomas


回答1:


Converting series integer to integer in pinescript to cannot be done. Therefore, it is necessary to look for workarounds. In your case, you can use the following script.

//@version=4
study("Help (hi/lo between conditions)")

cci = cci(close, 14)
plot(cci, title="cci")
hline(100)
hline(-100)

up_top_boder = crossover(cci,100)
dn_top_boder = crossunder(cci,100)
up_bottom_boder = crossover(cci,-100)
dn_bottom_boder = crossunder(cci,-100)

hi = float(na)
lo = float(na)
var look_hi = false
var look_lo = false
if up_top_boder or look_hi   
    if dn_top_boder          
        look_hi := false
    else    
        look_hi := true
        hi := max(cci, nz(hi[1]))
    
if dn_bottom_boder or look_lo   
    if up_bottom_boder          
        look_lo := false
    else    
        look_lo := true
        lo := min(cci, nz(lo[1]))
        
plot(hi, title="hi", style=plot.style_circles, linewidth=2, color=color.green)
plot(lo, title="lo", style=plot.style_circles, linewidth=2, color=color.red)



来源:https://stackoverflow.com/questions/65765086/converting-series-integer-to-integer-in-pinescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!