=> - Pine Script Syntax
Overview
Section titled “Overview”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.
Function syntax
Section titled “Function syntax”functionName(parameter1, parameter2) => localBlock returnExpressionThe last expression in the function body becomes its return value.
Example
Section titled “Example”//@version=6indicator("Function declaration example")
average(float first, float second) => float sum = first + second sum / 2
plot(average(open, close), "Average price")Switch case
Section titled “Switch case”string sessionLabel = switch session.isfirstbar => "Session open" session.islastbar => "Session close" => "Regular bar"Remarks
Section titled “Remarks”- 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.