= - Pine Script Operator
Overview
Section titled “Overview”The = operator declares a variable and assigns its initial value. Use := to
reassign a variable that has already been declared.
Syntax
Section titled “Syntax”variableName = initialValueThe compiler infers the variable’s type from the expression unless you declare a type explicitly.
Example
Section titled “Example”//@version=6indicator("Assignment example")
int length = 20float average = ta.sma(close, length)color plotColor = close >= average ? color.green : color.red
plot(average, "Average", color = plotColor)Remarks
Section titled “Remarks”=initializes a new variable; it does not update an existing variable.- Use
varorvaripwhen the initialization should persist across executions, then use:=for later reassignment. - A tuple declaration also uses
=, for example[macd, signal, histogram] = ta.macd(close, 12, 26, 9).