◆ New — Strategy Validator, Code Fixer & Prop Compliance Checker are live. Try one free →
Home / Pine errors / Types
Pine Script v6 error · Types

Pine Script "Cannot call 'ta.sma' with argument 'length'='series int'" (simple int required) — cause & fix

The error
Cannot call 'ta.sma' with argument 'length'='series int'. The argument 'length' of 'ta.sma' should be of type 'simple int'.

You passed a series int where ta.sma expects a simple int length that cannot change bar to bar. Educational only — this reference explains Pine's type qualifiers; no profitability is implied.

Why it happens

Pine values carry a type qualifier: const, input, simple, or series (weakest to strongest). Many ta.* length parameters require simple int — a value fixed for the whole dataset — because the function allocates its internal buffer once. Feeding a length derived from a bar-varying value (bar_index, close, a var counter, or a request.security() result) yields a series int, which is a stronger qualifier than the parameter accepts, so the call is rejected.

How to fix it

Make the length simple. Use a literal (ta.sma(close, 14)) or an input (input.int(...)) — inputs qualify as simple. If the length must vary at runtime, you cannot pass it to ta.sma; instead pick from a set of precomputed fixed-length calls (a switch over several simple lengths), or use a function such as ta.sma implemented over a bounded loop with a constant cap. Never coerce a series into the length slot.

What triggers it

//@version=6
indicator("Series length", overlay = true)
// bar_index is a series int, so this length is 'series int' -> rejected.
dynLen = bar_index % 50 + 1
plot(ta.sma(close, dynLen))

The fix, in code

✓ Validated clean by our own engine

//@version=6
indicator("Simple length", overlay = true)

// input.int() qualifies as 'simple int', which ta.sma accepts.
len = input.int(20, "Length", minval = 1, maxval = 200)
plot(ta.sma(close, len), "SMA", color = color.orange)

// If you must switch length at runtime, precompute fixed-length calls
// (each with a simple/const length) and select between the results.
fast = ta.sma(close, 10)
slow = ta.sma(close, 50)
chosen = close > open ? fast : slow
plot(chosen, "Selected SMA", color = color.purple)

Related errors

Educational, code-correctness reference only — not financial advice. Trading involves substantial risk of loss.

Catch the bug that compiles.Run auditGet Pro