Fugaz13
Fugaz13

Reputation: 1

End of Line without line continuation - PineScript

I'm running into issues with a PineScript strategy. Syntax error at input 'end of line without line continuation'.

Here is the code:

calculateRisk(entryPrice, isLong) =>
    atr = ta.atr(atrLength)
    baseStop = useAtrStops ? 
       (isLong ? 
          (entryPrice - (atr * atrMultiplier)) : 
       (entryPrice + (atr * atrMultiplier))) : 
    (isLong ? 
       ta.lowest(low, 5)[1] : 
    ta.highest(high, 5)[1])
    
    riskAmount = strategy.equity * riskPct
    stopDistance = math.abs(entryPrice - baseStop)
    positionSize = riskAmount / stopDistance
    tp = isLong ? 
       (entryPrice + (stopDistance * rrRatio)) : 
    (entryPrice - (stopDistance * rrRatio))
    [positionSize, baseStop, tp]

I get the error just after the line "baseStop = useAtrStops ?"

Expecting the code to work. I've reviewed the documentation on line wrapping and tried various spacing, but I can't get past it. Any help would be appreciated.

Upvotes: 0

Views: 52

Answers (1)

vitruvius
vitruvius

Reputation: 21342

I get the error just after the line "baseStop = useAtrStops ?"

Because the very next line ((isLong ?) starts with 8 spaces.

As it is stated in the documentation that you linked:

If [a line] wraps to the next line then the continuation of the statement must begin with one or several (different from multiple of 4) spaces

So, fix your spacing and it will be good.

calculateRisk(entryPrice, isLong) =>
    atr = ta.atr(atrLength)
    baseStop = useAtrStops ? 
         (isLong ? 
          (entryPrice - (atr * atrMultiplier)) : 
          (entryPrice + (atr * atrMultiplier))) : 
          (isLong ? 
          ta.lowest(low, 5)[1] : 
          ta.highest(high, 5)[1])
    
    riskAmount = strategy.equity * riskPct
    stopDistance = math.abs(entryPrice - baseStop)
    positionSize = riskAmount / stopDistance
    tp = isLong ? 
       (entryPrice + (stopDistance * rrRatio)) : 
       (entryPrice - (stopDistance * rrRatio))
    [positionSize, baseStop, tp]

Upvotes: 0

Related Questions