Skip to content
Algo Trade Analytics Docs

= - Pine Script Operator

The = operator declares a variable and assigns its initial value. Use := to reassign a variable that has already been declared.

variableName = initialValue

The compiler infers the variable’s type from the expression unless you declare a type explicitly.

//@version=6
indicator("Assignment example")
int length = 20
float average = ta.sma(close, length)
color plotColor = close >= average ? color.green : color.red
plot(average, "Average", color = plotColor)
  • = initializes a new variable; it does not update an existing variable.
  • Use var or varip when 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).