Quick Answer
Syntax error at input 'end of line without line continuation' means the Pine Script compiler reached the end of a line and expected the statement to continue, or to be complete, and it was neither. The two most common reasons are a wrapped line that is indented the wrong way, and a statement that is not finished (an open bracket, or a line that ends where an operator or an argument is still missing).
The rule that surprises most people is the indentation. In Pine Script, a line that is indented by 4 spaces (or one tab) starts a local block, the body of an if, a for or a function. A line that continues the statement above must be indented by any number of spaces that is not a multiple of 4. If you wrap a long expression and indent the next line by exactly 4 or 8 spaces, Pine reads it as a new block, not as a continuation, and the error follows.
Key Facts
| Cause | Example | Fix |
|---|---|---|
| Wrapped line indented by a multiple of 4 | 4 or 8 spaces before the continuation | Indent by 1, 2, 3, 5, 6 or 7 spaces (not 4 or 8) |
| Tab used for a wrapped line | A tab before the continuation | A tab is a block indent; use spaces that are not a multiple of 4 |
| Unclosed bracket | plot(ta.sma(close, 20) | Close every (, [ and { |
| Statement ends too early | x = close + with nothing after it | Finish the expression |
| Wrong block indent | An if body indented by 2 spaces | Indent a block by 4 spaces or one tab |
| Mixed spaces and tabs | A tab on one line, spaces on the next | Use one style in the whole script |
Read the Message
Syntax error at input 'end of line without line continuation'
The line number points to the line where the compiler gave up. The real mistake is often on that line or on the line above it, because that is where the statement started. Look at the line, then at the one before it.
The Pine Script Version That Fails
//@version=5
indicator("Wrapped line", overlay = true)
total = close +
open +
high +
low
plot(total / 4)
The three continuation lines are indented by exactly 4 spaces. Pine reads each of them as the start of a local block and not as the continuation of total = ..., so the statement is incomplete at the end of the first line.
Fix 1: Indent a Wrapped Line by a Number That Is Not a Multiple of 4
//@version=5
indicator("Wrapped line fixed", overlay = true)
total = close +
open +
high +
low
plot(total / 4)
Here the continuation lines have 5 spaces. A script editor may show 4 and 5 spaces almost the same, so count them or turn on the display of whitespace in your editor. A formatting tool that re-indents the file to 4 or 8 spaces can bring the error back, which is a common reason why a script that worked once fails after it is pasted somewhere else.
The same rule applies to a long function call. When the arguments are inside brackets, wrap them with an indent that is not a multiple of 4:
//@version=5
indicator("Long call", overlay = true)
plot(ta.sma(close, 20),
title = "SMA 20",
color = color.blue,
linewidth = 2)
Fix 2: Or Put It on One Line, or Use Variables
The most robust fix is to avoid the wrap. Split a long expression into named steps, which also makes the script easier to read:
//@version=5
indicator("Steps", overlay = true)
hl = high + low
oc = open + close
avg = (hl + oc) / 4
plot(avg)
Named steps also help when you convert the script to MQL5, because each step becomes one line of C-like code.
Fix 3: Close Every Bracket
A bracket that is never closed makes the statement run on until the end of the line, where the compiler stops with the same message:
plot(ta.sma(close, 20) // missing the last bracket
plot(ta.sma(close, 20)) // correct
Count the opening and closing brackets in the line that is reported and in the line above it. A good editor highlights the matching bracket when you put the cursor on one.
Fix 4: Finish the Statement
An expression that ends with an operator, a comma or an assignment sign needs something after it:
x = close + // nothing follows
x = close + open // correct
This often happens when you delete a line from the middle of a wrapped expression and leave the operator at the end of the line before it.
Fix 5: Check the Block Indent
The body of an if, a for, a while or a function must be indented by 4 spaces or one tab. If you indent it by 2 or 3, Pine can read it as a continuation line and not as a block:
//@version=5
indicator("Block", overlay = true)
if close > open
label.new(bar_index, high, "up") // 4 spaces: a block
This is the other side of the same rule: 4 spaces means a block, and a number that is not a multiple of 4 means a continuation.
Port It to MQL5
MQL5 does not use indentation to decide what a line means. A statement ends at the semicolon, so you can wrap a long expression anywhere and indent it as you like. The matching MQL5 error is a missing semicolon or an unbalanced bracket, and the compiler reports it with the words semicolon expected or unbalanced parentheses:
datetime g_lastBarTime = 0;
int OnInit()
{
g_lastBarTime = iTime(_Symbol, _Period, 0);
return INIT_SUCCEEDED;
}
bool IsNewBar()
{
datetime currentBarTime = iTime(_Symbol, _Period, 0);
if(currentBarTime == 0 || currentBarTime == g_lastBarTime)
return false;
g_lastBarTime = currentBarTime;
return true;
}
void OnTick()
{
if(!IsNewBar())
return;
double open1 = iOpen(_Symbol, _Period, 1);
double high1 = iHigh(_Symbol, _Period, 1);
double low1 = iLow(_Symbol, _Period, 1);
double close1 = iClose(_Symbol, _Period, 1);
if(open1 == 0.0 || high1 == 0.0 || low1 == 0.0 || close1 == 0.0)
return;
// Like: total = close + open + high + low, wrapped over several lines
double total = close1 +
open1 +
high1 +
low1;
PrintFormat("Average of OHLC on the last closed bar: %.5f", total / 4.0);
}
The wrapped sum is valid here with any indentation, because the semicolon ends the statement. The new-bar check and the closed-bar rule are explained in Pine Script barstate.isnew in MQL5 and Pine Script close[1] in MQL5.
How to Find the Cause
- Read the line number and look at that line and the line above it.
- Is the statement wrapped? Count the spaces before each continuation line. Is the count a multiple of 4?
- Do you see tabs? Turn on whitespace display in the editor.
- Count the brackets in the statement.
- Does the line end with an operator or a comma and nothing after it?
- Shorten the statement. Put it on one line to check that the error goes away, then wrap it again with the right indent.
- Run the script again after each change, because one syntax error can hide the next one.
Common Mistakes
- Wrapping with 4 or 8 spaces. That is a block indent.
- Wrapping with a tab. A tab also starts a block.
- Pasting code from a site or editor that changes the indentation.
- Leaving an operator at the end of a line after deleting the next line.
- Missing a closing bracket in a long call.
- Mixing tabs and spaces in one script.
- Indenting a block by 2 spaces.
FAQ
Related Guides
- Pine Script Error: Undeclared Identifier: scope and typo errors in Pine Script.
- Pine Script Error: Could Not Find Function (ta.cmf): another Pine compile error with a clear fix.
- Pine Script Error: 'series int' Used but 'simple int' Is Expected: a Pine error about a changing length.
- Pine Script v6 to MQL5: version differences and how to convert them.
- Pine Script to MQL5 guide: the full conversion process.
- MQL5 undeclared identifier error: a common MetaEditor compile error.
Convert a Script That Does Not Compile
A script with a syntax error cannot be converted until it compiles. CodeFlowOS translates Pine Script into MQL5 and lets you review the generated code before you test it in the MT5 Strategy Tester. The platform compile check is optional, and outputs are not guaranteed, so always review the result. For the full process, see the Pine Script to MQL5 guide, or try the converter page. If the code does not compile, the Error Fixer can suggest a fix, and the free early-bird Code Review checks an EA for common mistakes.
This article is educational. It does not describe trading performance and is not financial advice. Always compile and test code in MetaEditor and the Strategy Tester before using it on a live account.