pine script - End of Line without line continuation - PineScript - Stack Overflow

admin2025-04-17  3

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.

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.

Share Improve this question asked Jan 30 at 19:47 Fugaz13Fugaz13 1 1
  • Looks like a typo somewhere. – CPlus Commented Jan 30 at 20:21
Add a comment  | 

1 Answer 1

Reset to default 0

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]
转载请注明原文地址:http://anycun.com/QandA/1744894035a89126.html