Understanding Series Float in Pine Script
Series float in Pine Script is a fundamental concept that every TradingView coder should understand to write effective and dynamic trading indicators or strategies. This article explains what "series float" means in Pine Script, how it fits into the language's type system, and why it's essential for creating responsive scripts.
What Is Series Float in Pine Script?
In Pine Script, a series represents a sequence of values that change over time-specifically, across the bars of a chart. A float is a data type for numbers that include decimals (floating-point numbers). Combining these, a series float is a stream of floating-point numbers that can vary bar by bar during script execution.
For example, built-in variables like close
, volume
, and the results of many technical analysis functions return series float values because their values update with each new bar on the chart.

Understanding Pine Script's Type System and Qualifiers
Pine Script's type system classifies values by their data type (int, float, bool, string, etc.) and their qualifier, which indicates when and how the value can change:
- const: Values fixed at compile time and never change.
- input: Values set by the user before script execution.
- simple: Values known at the start of the script execution.
- series: Values that can change dynamically on every bar.
Among these, series is the strongest qualifier, meaning values qualified as series can change with every bar and are the most flexible in scripts. When a variable is a series float, it means it holds floating-point numbers that update as new data comes in.
Why Is Series Float Important?
- Dynamic Data Handling: Since financial data changes every bar, series float allows scripts to react to these changes, enabling real-time calculations like moving averages, RSI, or custom indicators.
- Compatibility: Many Pine Script built-in functions require or return series float types, so understanding this helps avoid type errors.
- Flexibility: Variables declared or inferred as series float can interact with other types and qualifiers seamlessly, following Pine Script's type hierarchy rules.
Using the float() Function to Work with Series Float
Pine Script provides a float() casting function to explicitly convert values to the float type. This is particularly useful when dealing with variables that might be na
(not available) or when you need to ensure a variable is treated as a float for calculations.
For example, converting an integer or a potentially undefined value to a series float avoids errors in mathematical operations:
//@version=5
indicator("Example of float()", overlay=true)
var float myVar = na
myVar := float(close) // Ensures close is treated as a float
plot(myVar)
This function accepts constants, inputs, simple, or series types and returns a series float, making it versatile for many scenarios.