I am trying to plot this indicator but I get the "already defined" error for "=" or "Mismatched input ':=' expecting '='" for ":=" when I try assigning to tuple
lb( x, a0, a1, a2, a3, c ) =>
if( x == 1 and c > a3 )
[x, a1, a2, a3, c]
else if( x == 1 and c < a0 )
[-1, a3, a3, a2, c]
else if( x == -1 and c < a3 )
[x, a1, a2, a3, c]
else if( x == -1 and c > a0 )
[ 1, a3, a3, a2, c ]
f_x = 1
f_a0 = 0.0
f_a1 = 0.0
f_a2 = 0.0
f_a3 = 0.0
[f_x, f_a0, f_a1, f_a2, f_a3] := lb( f_x, f_a0, f_a1, f_a2, f_a3, close )
plot( f_a0 , color=color.red )
Thank you!
You cannot use :=
to assign values to a tuple.
Only =
is allowed, which means you must not define those target tuple variables on beforehand.
Something like this would work though:
//@version=5
indicator("My Script", overlay=true)
lb( x, a0, a1, a2, a3, c ) =>
if( x == 1 and c > a3 )
[x, a1, a2, a3, c]
else if( x == 1 and c < a0 )
[-1, a3, a3, a2, c]
else if( x == -1 and c < a3 )
[x, a1, a2, a3, c]
else if( x == -1 and c > a0 )
[ 1, a3, a3, a2, c ]
var float f_x = na
var float f_a0 = na
var float f_a1 = na
var float f_a2 = na
var float f_a3 = na
if barstate.isfirst
f_x := 1
f_a0 := 0.0
f_a1 := 0.0
f_a2 := 0.0
f_a3 := 0.0
[f_x_dummy, f_a0_dummy, f_a1_dummy, f_a2_dummy, f_a3_dummy] = lb( f_x, f_a0, f_a1, f_a2, f_a3, close )
f_x := f_x_dummy
f_a0 := f_a0_dummy
f_a1 := f_a1_dummy
f_a2 := f_a2_dummy
f_a3 := f_a3_dummy
plot( f_a0 , color=color.red )