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