i am declaring a variable as t1= close[1] however, t1 is showing values in the current bar ie close and not close[1]
var CPPlevel= array.from(H6,H5,H4,H3,H2,H1,PP,L1,L2,L3,L4,L5)
t1 = close[1]
z= array.copy(CPPlevel)
array.push(z,t1)
array.sort(z)
j= array.indexof(z,t1)
for i = 0 to j-1 [1]
if t1 == array.get(z,i)
if i==0
CPP_level_below := low[1]
CPP_level_above := array.get(z,i+1)
if i==j-1
CPP_level_below := array.get(z, i-1)
CPP_level_above := high[1]
if i!=0 and 1!= j-1
CPP_level_above := array.get(z,i+1)
CPP_level_below := array.get(z, i-1)
break
as i am using the variable t1 to determine my trailing sl, this creates problem as the trailing sl is getting triggered in the running bar and not at end of it.
i have tried using the barstate.isconfirmed as below
if barstate.isconfirmed t1 = close[1]
even this is giving the same error values
pls help