Skip to main content
On this page

Pine Script Line Continuation: Fix End-of-Line Errors

· 6 min read
Pineify Team
Pine Script and AI trading workflow research team

Pine Script can split an expression across lines without a backslash, but indentation still matters. If you see end of line without line continuation, check the expression's delimiters and continuation indentation before changing its trading logic.

Continuation Versus a Local Block​

Current Pine v6 distinguishes a wrapped expression from an indented local block. Outside parentheses or brackets, continuation indentation must not be a multiple of four spaces. A function or if block uses a tab or four spaces per nesting level. Inside parentheses or brackets, current v6 permits any indentation length.

The official script-structure guide defines these rules. Keep the version annotation consistent with the syntax you use; examples copied from older versions may follow stricter wrapping conventions.

The Best Pine Script Generator

Making Complex Math Readable​

This complete example uses two spaces on each continuation line. A trailing operator alone does not make an unindented next line valid.

//@version=6
indicator("Wrapped Price Average")
price = open * 0.25 +
high * 0.25 +
low * 0.25 +
close * 0.25
plot(price, "OHLC average")

An unclosed parenthesized expression is another option in current v6. Whichever format you choose, keep the same operands and operator order when reformatting.

Cleaning Up Function Calls​

Long argument lists become easier to inspect when each named argument gets a line. This example uses five-space continuation indentation, which also avoids confusing the arguments with a four-space local block.

//@version=6
indicator("Readable Plot Calls", overlay=true)
plot(ta.sma(close, 20),
title="SMA 20",
color=color.blue,
linewidth=2)
plot(ta.ema(close, 20),
title="EMA 20",
color=color.red,
linewidth=2)

For styling choices, see Pine Script plot styles. For language basics, see how to write Pine Script.

Handling Multiple Conditions and Tuple Results​

Split calculations into named values before wrapping a condition. ta.macd() returns three values; destructure them in a tuple declaration. Writing ta.macd(...)[0] does not select the MACD component.

//@version=6
indicator("Readable Boolean Conditions", overlay=true)
[macdLine, signalLine, histogram] = ta.macd(close, 12, 26, 9)
average = ta.sma(close, 20)
rsiValue = ta.rsi(close, 14)
bullishCondition = close > average and
rsiValue < 70 and
macdLine > signalLine
plotshape(bullishCondition, title="Condition true", style=shape.circle, location=location.belowbar)

This shows when the combined condition is true. It is not a backtested entry rule. Breaking a formula into names should preserve its meaning, including the argument order of ta.crossover() and ta.crossunder().

Local Blocks and Arrays​

An if body uses four-space block indentation. A nested if adds another four spaces. This array example illustrates block structure without multiline expressions:

//@version=6
indicator("Rolling Array Example")
var array<float> priceHistory = array.new<float>()
array.push(priceHistory, close)
if array.size(priceHistory) > 50
array.shift(priceHistory)
plot(array.avg(priceHistory), "Average of up to 50 bars")

The array starts empty, so its average uses only observed prices during the first 50 bars.

Common Causes of Continuation Errors​

  • Unwrapped continuation at a block indentation: Use a non-multiple-of-four continuation indent, or enclose the expression according to the current v6 rules.
  • A dangling operator: price = open + still needs a right-hand operand. A comment does not supply one.
  • A trailing comma before a closing parenthesis: Every comma in an argument list must separate arguments; remove the final comma.
  • Unmatched delimiters or quotes: Inspect the preceding line as well as the line reported by the compiler.
  • Block indentation changed during formatting: Moving a statement into or out of an if changes execution, not just appearance.

Compile after each small formatting change so that the error remains easy to locate. Do not assume a line break error means the trading formula is wrong.

Building a Readable Strategy​

This version retains the EMA crossover, RSI filter, and long-term average filter from the original example. Indicator values are calculated on every bar before the conditions are combined. Each unparenthesized continuation has two leading spaces.

//@version=6
strategy("Clean Format Strategy", overlay=true)
length_fast = input.int(12, title="Fast EMA Length", minval=1, maxval=100)
length_slow = input.int(26, title="Slow EMA Length", minval=1, maxval=200)
ema_fast = ta.ema(close, length_fast)
ema_slow = ta.ema(close, length_slow)
rsi_value = ta.rsi(close, 14)
trend_average = ta.sma(close, 200)
cross_up = ta.crossover(ema_fast, ema_slow)
cross_down = ta.crossunder(ema_fast, ema_slow)
long_condition = cross_up and
rsi_value > 50 and
close > trend_average
short_condition = cross_down and
rsi_value < 50 and
close < trend_average
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)

Opposite entries can reverse the existing position. This formatting example does not add stops, realistic costs, or evidence of profitability. Review those choices separately when developing a strategy.

Verify a Formatting Change​

Keep the version, operators, argument order, and scope unchanged unless you intend a logic change. Compile the full script, then compare its signals and orders on the same symbol, timeframe, date range, and inputs. Syntax success alone does not establish behavioral equivalence.

Frequently Asked Questions​

Do I need backslashes for multiline code in Pine Script?

No. Pine uses expression structure and indentation for continuation. A trailing operator still needs a valid continuation line and a right-hand operand.

Can I use four spaces for a continued expression?

In current v6, code inside parentheses or brackets has no continuation-indentation restriction. Outside those delimiters, avoid multiples of four, which are used for local blocks. The examples here use two or five spaces for wrapped lines.

Can I split a boolean condition across lines?

Yes. Keep the operands and operators in the same order, and use continuation indentation or an enclosing expression. Calculate history-dependent functions consistently before combining their results.

Why does the compiler highlight the line after my mistake?

An unfinished expression on the preceding line can make the next token invalid. Check delimiters, quotes, commas, and indentation around both lines.

Does reformatting change trading results?

Line wrapping that preserves the parsed expression should preserve its meaning. Changing indentation can change scope, and changing argument order or expression evaluation can change behavior. Compare results after editing; do not rely on appearance alone.

The Best Pine Script Generator