Identifiers
Identifiers in Pine Script
Identifiers are names utilized for user-created variables and functions within Pine Script. They must adhere to a certain format and set of rules:
They must start with an uppercase (A-Z) or lowercase (a-z) letter, or an underscore (_).
Following the first character, the identifier can include letters, underscores, or digits (0-9).
They are case-sensitive.
Here are some examples of valid identifiers:
myVar
_myVar
my123Var
functionName
MAX_LEN
max_len
maxLen
Please note, the identifier '3barsDown' is not valid since it begins with a digit.
The Pine Script™ Style Guide recommends adopting the uppercase SNAKE_CASE for constants, and camelCase for other identifiers:
GREEN_COLOR = #4CAF50 // Constant in SNAKE_CASE
MAX_LOOKBACK = 100 // Constant in SNAKE_CASE
int fastLength = 7 // Variable in camelCase
Below is an example function definition following the prescribed naming conventions:
// This function returns 1 if the argument is `true`, 0 if it is `false` or `na`.
zeroOne(boolValue) => boolValue ? 1 : 0 // Function in camelCase
Remember, these conventions help maintain readability and consistency throughout your Pine Script code.
Last updated