Technical Articles
Pine Script Part 2: Variables, Operators, and Data Structures
Nov 28, 2025•14•
#Pine Script#TradingView#variables#algo trading#strategy development
Pine Script Part 2: Variables, Operators, and Data Structures
In this part, we explore the core components of Pine Script: variables, operators, bar values, data types, and arrays. These concepts form the foundation of all indicators and strategies.
Data Types in Pine Script
Common types:
- int
- float
- string
- bool
- color
- line / label
Example:
myNumber = 10
myText = "Hello"
isBull = close > open
Creating Variables
Standard variable:
x = close
Persistent variable (only initialized once):
var counter = 0
counter += 1
Operators
- Math:
+ - * / - Logical:
and or not - Comparison:
== != > < >= <=
Example:
longCondition = close > open and volume > volume[1]
Accessing Bar Values
close[1] // previous close
open[3] // open from 3 bars ago
Arrays
myArray = array.new_float()
array.push(myArray, close)
Open TradingView Editor
Start coding in the Pine Script editor:
https://sancoqhub.com/go/tradingview
Premium Recommendation
More charts, more indicators, more alerts:
https://sancoqhub.com/go/tradingview
Conclusion
In this part you learned core structures of Pine Script. Next chapter will focus on indicator creation and plot functions.