Search code examples
pine-scriptpine-script-v5tradingview-api

IF, ELSE IF, ELSE referencing back to a defined parameter


I'm hoping someone can help me. I'm in the process of building my first strategy in pine script v5, but I'm running into an error in my code at the reference to "prev" at the end of line 16. Error code is "Extraneous input 'prev' expecting 'end of line without line continuation'".

prev = ta.highest(high - multiplier * ta.atr(atrPeriod), hhvPeriod)
barsSinceCondition = ta.barssince(close > ta.highest(high - multiplier * 
ta.atr(atrPeriod), hhvPeriod) and close > close[1])
ts = if ta.cum(1) < 16
    close
else if close > ta.highest(high - multiplier * ta.atr(atrPeriod), hhvPeriod) and close > close[1]
    ta.highest(high - multiplier * ta.atr(atrPeriod), hhvPeriod)
else prev

I was expecting the code to save error free, but I can't seem to get it to save without an error despite messing with it for the last couple hours. Any recommendations?


Solution

  • prev should be at a new line and not right after the else.

    ts = if ta.cum(1) < 16
        close
    else if close > ta.highest(high - multiplier * ta.atr(atrPeriod), hhvPeriod) and close > close[1]
        ta.highest(high - multiplier * ta.atr(atrPeriod), hhvPeriod)
    else
        prev