Declaring variables
Pine uses = for assignment. length = 14 creates an integer variable. src = close assigns the close series. Once assigned, you can reuse them anywhere in the script.
Arithmetic and comparison
+, -, *, /, % work as you'd expect. Comparisons: ==, !=, >, <, >=, <=. A single = is assignment; == is comparison.
Logical operators
and, or, not are the keywords (not &&, ||, !). x and y is true only when both are true. not (a > b) is true when the comparison is false.
The ternary operator
Pine has a one-line if/else: condition ? valueIfTrue : valueIfFalse. Example: plot(close > close[1] ? color.green : color.red) paints the line green on up-bars and red on down-bars.
Comments
// starts a single-line comment. /* ... */ is a block comment. Comments are not just for other people — Pine runs them through the chart history too. If a line becomes long, break it across multiple lines and explain why you made the choice you made.
Variable scope
Variables declared at the top level of a script are global. Variables declared inside a function are local. Pine v5 also has var for state that persists across bars (we will use this heavily in Part 3 for entry/exit state).