1

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

Thomas
  • 73
  • 2
  • 6
  • Do you want to find a high between bars x and y? – AnyDozer Jan 18 '21 at 05:33
  • Yes, you are right. My approach is to find the number of bars between x and y and then use the highest() function to find the peak, but the highest function() only accepts constant integers. I am trying to figure out a way around this, since obviously each peak can occur between varying number of bars – Thomas Jan 18 '21 at 21:18
  • See the answer to this question https://stackoverflow.com/questions/65704469/find-the-highest-and-lowest-value-for-a-time-frame-in-the-pine-editor/65751573#65751573 If you do not succeed on your own, then I will try to help. – AnyDozer Jan 19 '21 at 10:56

1 Answers1

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)

enter image description here

AnyDozer
  • 2,236
  • 2
  • 5
  • 22
  • 1
    @AnyDozer Are you actually converting series to int or something else, there's no explanation to go with your snippet – lasec0203 Jan 02 '22 at 08:14
  • @lasec0203 Converting series integer to integer in pinescript to cannot be done. Therefore, it is necessary to look for workarounds. – AnyDozer Jan 03 '22 at 06:07