SuperCharting
Sign in Get started Account Open charts

Learn / Pine Script errors

Pine Script error: 'series int' was used but a 'simple int' is expected

Fix the Pine Script error "An argument of 'series int' type was used but a 'simple int' is expected": take the length from input.int().

This TradingView error starts with "Cannot call '<function>' with argument" and goes on to say "An argument of 'series int' type was used but a 'simple int' is expected". It means you passed a length that can change from bar to bar to a function that needs a length fixed before the first bar. The usual fix is to take the length from input.int().

Reading the message

The message follows a pattern. The first part names the function you called, for example ta.ema, and the argument that caused the trouble. The part that stays the same is the type complaint: a series int was given where a simple int is required. Look at the function name in your copy of the message, then find that call in your code.

What causes it

Pine sorts values by when they are known. Two kinds matter here:

Many built-in functions need their length to be simple. The length of ta.ema is one of them.

A length that changes on each bar

Here the length depends on bar_index, so it is a series. This code FAILS on TradingView:

//@version=6
indicator("Series length")
len = bar_index % 10 + 5
plot(ta.ema(close, len))

The values stay between 5 and 14, but that does not matter. What counts is that the length is worked out on each bar, which makes it series.

Lengths computed from price or volatility

The same thing happens with "adaptive" lengths, for example a length that grows when volatility is high. Any formula that uses bar data gives a series result, so passing it to a function that wants a simple length triggers the error.

How to fix it

Take the length from an input

If the length only needs to be adjustable by the user, read it with input.int(). An input is set before the first bar, so it is simple. Tested version:

//@version=6
indicator("Fixed length")
len = input.int(14, "Length")
plot(ta.ema(close, len), "EMA")
plot(ta.sma(close, bar_index % 10 + 5), "SMA, length changes each bar")

The second plot shows that in version 6, ta.sma and some other built-ins accept a series length, so a changing length is allowed there. Which functions accept it differs from one to the next, so check the reference entry for each function before you rely on it.

Write your own function

When you need the length to change on each bar and the built-in will not take it, write the calculation yourself. Your own function has no rule that the length must be simple. This tested example computes an exponential average whose length changes every bar:

//@version=6
indicator("EMA with a changing length")
myEma(src, len) =>
    alpha = 2.0 / (len + 1)
    var float e = na
    e := na(e) ? src : alpha * src + (1 - alpha) * e
    e
len = bar_index % 10 + 5
plot(myEma(close, len), "EMA, length changes each bar")

It uses the usual smoothing factor of 2 divided by the length plus 1, worked out fresh on each bar from whatever length that bar uses. The var line keeps the previous average from one bar to the next.

Choose a fixed length instead

Sometimes the changing length was not needed. If a single value works well enough, type it in or take it from an input and the problem disappears.

What SuperCharting's Script Editor shows

SuperCharting's engine is more lenient here and runs this code. The broken example, which passes a series length to ta.ema, compiles and runs on sample bars without this error. If the script must also work on TradingView, fix it the way shown above. The tested fixes also run in SuperCharting.

To check a script:

  1. Open a chart and open the Script Editor with Ctrl + E.
  2. Paste the script into the code area.
  3. Read the console, then press Add to chart.

Because SuperCharting accepts the series length, look for lengths built from bar data before you move a script to TradingView. The Pine Script code checker page explains the console and the Auto-fix button.

Pine cannot determine the referencing length of a series is another error about lengths and history, this time for [] lookbacks inside a branch. If the function name itself is the problem, for example ema without ta., see Could not find function or function reference. The Pine Script v6 basics page explains inputs and how scripts run bar by bar.

Frequently asked questions

What is the difference between simple and series?

A simple value is fixed before the first bar and stays the same. A series value can change on every bar. Functions that need a simple length will not accept a series one.

Is an input.int() value simple?

Yes. Inputs are read before the script runs on the first bar, so a length from input.int() is accepted where a simple int is needed.

Does ta.sma accept a changing length?

In version 6, yes; ta.sma and some others accept a series length. Check the reference for each function, because not all of them do.

Which function does my message mean?

The start of the message names it, in the pattern "Cannot call '<function>' with argument". Find that call in your code and check the length you pass to it.

TradingView and Pine Script are trademarks of TradingView, Inc. SuperCharting is independent and not affiliated with it.

Try it on a live chart

SuperCharting is an AI-enabled charting and coding platform in your browser: charts, Pine-compatible scripts with AI Auto-fix, the Strategy Tester, alerts and the screener.

Create a free account More guides