Skip to content
Algo Trade Analytics Docs

=> - Pine Script Syntax

The => token separates a user-defined function header from its body. It is also used between a switch case and the case’s local block or expression.

functionName(parameter1, parameter2) =>
localBlock
returnExpression

The last expression in the function body becomes its return value.

//@version=6
indicator("Function declaration example")
average(float first, float second) =>
float sum = first + second
sum / 2
plot(average(open, close), "Average price")
string sessionLabel = switch
session.isfirstbar => "Session open"
session.islastbar => "Session close"
=> "Regular bar"
  • Multiline function bodies must be indented consistently.
  • User-defined functions cannot be nested inside other functions.
  • A function’s return type depends on its final expression and the types and qualifiers used in the call.