Edgoro
Compile error · Types and qualifiers

Pine Script: simple variable cannot accept series (fix)

Fix "A variable declared with the simple keyword cannot accept values of the series int form" in Pine Script, and see what counts as simple or series.

Pine Editor console · line 3
A variable declared with the "simple" keyword cannot accept values of the "series int" form. Assign a "simple" value to this variable or remove the "simple" keyword from its declaration.

Cause

The variable is declared with the simple keyword, which promises a value that never changes after the first bar, but the expression depends on bar_index, so it is a series.

Broken code

TradingView reports the error on line 3.

Pine Script v6
//@version=6
indicator("EMA length")
simple int len = bar_index < 500 ? 10 : 20
plot(ta.ema(close, len))

Fixed code

The same script, corrected for Pine Script v6. Paste it into the Pine Editor and save.

Pine Script v6
//@version=6
indicator("EMA length")
simple int len = input.int(20, "EMA length", minval = 1)
plot(ta.ema(close, len))

Why it works

Inputs, literals and values such as timeframe.multiplier or syminfo.mintick stay the same for the whole run, so they qualify as simple. Anything derived from bar_index, prices or other per-bar data is a series, and a series can never be turned back into a simple value. An input gives you the configurable length without breaking the rule.

In the broken version the compiler also flags line 4, because len then reaches ta.ema() as a series; both errors go away with the fix.

If the value really has to change during the chart, remove the simple keyword and use functions that accept series arguments, for example ta.sma() instead of ta.ema().

Series into simple, in general

This is the declaration-side version of the "series used but simple expected" family. The same rule produces series int used but simple int expected when the series value goes straight into a function argument instead of a simple variable.

Questions

What does it mean to assign a series value to a simple variable?

A simple variable must hold a value that is known on the first bar and never changes. A series value can change on every bar, so Pine refuses the assignment. Use an input or a literal, or drop the simple keyword.

Do I need the simple keyword at all?

Rarely. Without it, Pine infers the qualifier from the value. Its purpose is to make the compiler reject series values at the declaration, instead of at the function call that needs a simple value.

The scripts on this page are minimal examples written to show the error and its fix, not trading systems. Trading involves substantial risk of loss and is not suitable for every investor. Edgoro is a software tool, not a broker or financial adviser: nothing it produces is investment advice, and past or backtested performance does not guarantee future results.

Still getting an error?

Paste your script and the message into the free Pine Script error fixer: it explains what went wrong and returns a corrected v6 version. Or describe the indicator in plain English and let Edgoro write the code.