Skip to content

Types and qualifiers ​

What can a variable hold, and when is its value known? Every value has a type, such as float or string, and a qualifier, which says whether it is fixed when the script is written, when its settings are read, on the first bar, or on every bar.

pine
//@version=6
indicator("Types at work")
const int LEN = 20                              // const: fixed in the text
src = input.source(close, "Source")             // series: an input of the bar's prices
float avg = ta.sma(src, LEN)                    // a typed declaration
bool rising = avg > avg[1]                      // a bool is true or false, never na
plot(avg, "Average", rising ? color.green : color.red)

Types ​

TypeHoldsIts na
intWhole numbers. Mixed with a float, it becomes one.na
floatNumbers with a fraction.na
booltrue or false.None: where a condition reads a na, it reads false.
colorA colour and its transparency.No colour.
stringText.The empty string, "".
label, line, box, table, linefill, polylineA drawing on the chart. See Drawings.No drawing.
chart.pointA point on the chart: a time, a bar index and a price. See chart.point.No point.
array<T>, matrix<T>, map<K, V>Collections of one type. See array, matrix and map.No collection.
A type you declareFields you name. See type.No object.
An enum you declareOne of the fields you list. See enum.na

What na does to a calculation, how to test for it and why a bool can't be na are in What na is.

To change a value's type, call the type as a function: int(x) cuts the fraction toward zero, and float, bool, string and color convert as their entries say. box(na), line(na) and the other drawing casts give a typed na.

Qualifiers ​

A qualifier says when a value is known. They rank from the earliest to the latest:

QualifierKnownExamples
constWhen the script is written.Literals such as 20 or "Fast", and names declared const.
inputWhen the study's settings are read, before the first bar.What an input.* call returns, but input.source.
simpleOn the first bar, then fixed for the run.syminfo.*, timeframe.*.
seriesOn each bar, and may change from bar to bar.close, time, what ta.sma returns.

An expression takes the latest qualifier of its parts, so close * 2 is a series float. Some arguments need an earlier one: ta.ema's length must be a simple int, and an input.int's default a const int. Where the engine checks such an argument, it warns and runs the script anyway: see what a qualifier warning means.

Declaring a variable's type ​

Write the type before the name: float level = na, var int count = 0, array<float> closes = array.new<float>(). A declaration of na needs its type, since na alone has none: strict Pine refuses x = na. See Declaring.

A collection of collections, such as array<array<int>>, is AmenoScript only. TradingView needs a type with an array field in between. See AmenoScript's extensions.

Types are checked loosely here

This engine runs some scripts TradingView refuses: int n = 1.5 keeps 1.5, a reassignment can change a variable's type, and a number can stand as a condition, as in if close. Check a script on TradingView before relying on it there. The full list is in What runs here that TradingView refuses.

AmenoScript is compatible with Pine Script v6. Pine Script is a trademark of TradingView, Inc., which has no part in AmenoScript.