Skip to main content
On this page

Series Float in Pine Script: Types, Qualifiers, and History

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

In Pine Script, series float combines a numeric type, float, with the strongest value qualifier, series. It describes a floating-point value that may vary across executions; it does not require the value to change on every bar.

Separate the type from its qualifier​

The qualifier hierarchy is const → input → simple → series. An argument that accepts a stronger qualifier can generally accept weaker ones of the compatible base type. The reverse is not allowed: a series value cannot be passed where only a simple value is accepted.

This is why a price series can be plotted, but may be unsuitable for a parameter requiring a fixed length. Comparing a series price with a constant threshold is normally valid. See the official type system for each qualifier's rules.

var controls initialization and persistence, not this qualifier hierarchy. A value retained with var does not become simple merely because your code assigns it once.

What float() does​

This existing complete v5 example plots close and the high/low midpoint:

//@version=5
indicator("Series Float Example", overlay=true)

// Declare a variable that can hold float values
var float myPrice = na

// Convert the closing price to ensure it's treated as a float
myPrice := float(close)

// Plot it on the chart
plot(myPrice, title="Current Price", color=color.blue)

// You can also use it in calculations
float avgPrice = (float(high) + float(low)) / 2
plot(avgPrice, title="Mid Price", color=color.red)

The casts of close, high, and low are redundant: those built-ins already have float values. The casts are harmless here, but they do not align timeframes, remove repainting, or reduce a series qualifier to simple.

Compatible integers can be converted to floats in numeric expressions; mixing int and float is not inherently an error. String parsing uses str.tonumber() rather than treating float() as a general text parser. For an unavailable initial value, an explicit declaration such as float myValue = na supplies its base type.

Historical and realtime values​

close refers to the current execution's close value; close[1] refers to the previous bar's value. History references can be unavailable when there are too few bars. Numeric series can also contain na because an upstream calculation lacks valid data.

Historical bars normally execute once, while indicators can execute on realtime updates before the bar closes. Strategies have their own calculation settings. Thus “once per bar” is not a complete description of every script's behavior. The execution model explains rollback and confirmation.

Diagnose a type error​

Read the parameter name and its required type/qualifier, then trace the argument's dependencies. An input.int() can supply a configurable fixed length where allowed; it cannot accept an arbitrary price-derived series as its default to erase a type error.

request.security() returns values according to its expression; it is not restricted to float results. Whether requested data is confirmed is a separate question from its numeric type.

For missing-data handling, compute a history-dependent moving average consistently and test its returned value with na(). A conditional block containing only a comment is not a runnable example, so that earlier placeholder has been removed. Decide whether missing values should suppress output, retain a prior value, or trigger an error; replacing them with zero can materially change the calculation.