Jokes apart, There was a script that I had attempted to create in pine script about a year ago and eventually gave up since I never could get past the syntax error....
What I needed was equivalent of Flip function of Amibroker, that accepts two arrays and persists signal of first array. I use pair of flip function in tandem to create a DPDT switch. Could not discover equivalent function in PineScript so attempted to roll my own....
condOne, condTwo, condThree, condFour are results arrays (series in pinescript world) returned from basic
cross function and will either have 1 or 0. Pine script treats it as boolean.
Code:
/// Pine script implementation .... failed without loop and hence tried with loop
/// loop inverted because I want to traverse left to right
oneFlip = 0
twoFlip = 0
for i = bar_index to 0 by -1
oneFlip[i] = condOne[i] ? 1 : condTwo[i] ? -1 : oneFlip[i + 1]
twoFlip[i] = condThree[i] ? 1 : (condFour[i] ? -1 : twoFlip[i + 1])
Above code reports syntax error
"line 72: Syntax error at input '='. "
Loop less version for single element is
oneFlip[0] = condOne[0] ? 1 : condTwo[0] ? -1 : oneFlip[1]
Code:
//Amibroker code of the logic I want is
oneFlip = Flip(condOne, condTwo) - Flip(condTwo, condOne);
twoFlip = Flip(condThree, condFour) - Flip(condFour condThree);
Writing this code in amibroker loop is also straight forward