0

As a total beginner in Pine Script, I am trying to iteratively build an array based on the value of two variables. I come from Python experience and, looking at Pine Script documentation, I would expect it to be something similar to what I have tried below. However, I receive a "Mismatched input 'if' expecting 'end of line without line continuation'" error for the first "else if" statement. Does anyone have a second to find what is probably a trivial issue to a more experienced Pine Script coder? Thank you

Here is what I have at the moment:

//@version=5 indicator('Automated Label') past_return = input(10, "Old return - Consider return x old candles") more_recent_return = input(5, "Recent return - Consider return x old candles") Rtd1 = (close - close[past_return]) / close[past_return] Rtd2 = (close - close[more_recent_return]) / close[more_recent_return] pre_label = array.new_float(0) if Rtd1 > 0 and Rtd2 > 0 if Rtd1 > Rtd2 array.push(pre_label, value=4) else array.push(pre_label, value=3) else if Rtd2 > 0 array.push(pre_label, value=1) else if Rtd1 < 0 and Rtd2 < 0) if Rtd1 < Rtd2 array.push(pre_label, -4) else array.push(pre_label, -3) else if Rtd2 < 0 array.push(pre_label, -1) else array.push(pre_label,0) 

1 Answer 1

1

The error is misleading, possibly because it cannot parse the whole if-block properly. The actual cause is an unpared ) in the second else if block:

else if Rtd1 < 0 and Rtd2 < 0) 

Delete the last bracket and it should work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I was going crazy looking for more complex answers; I can't believe I oversaw that. The error is certainly misleading, hopefully a future version will have a better error-giving system. Thanks again!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.