001 — What is Pine Script?
Pine Script is TradingView’s programming language for creating chart-based trading tools.
You write a script in the Pine Editor, save it, and add it to a TradingView chart. TradingView then runs the script across the chart’s bars and displays the result.
What can you build?
Section titled “What can you build?”Pine Script supports three main kinds of scripts:
| Script type | Purpose | Example |
|---|---|---|
| Indicator | Calculates and displays information | Moving average, ATR bands, custom oscillator |
| Strategy | Simulates orders for backtesting and forward testing | Breakout system, crossover system |
| Library | Packages reusable code for other scripts | Shared calculations or helper functions |
For most beginners, the best place to start is an indicator.
A minimal Pine Script
Section titled “A minimal Pine Script”//@version=6indicator("My First Script", overlay = true)
plot(close)This script has three important parts:
//@version=6tells the compiler which Pine Script version to use.indicator()declares that the script is an indicator.plot(close)draws the closing price as a line.
Why use Pine Script?
Section titled “Why use Pine Script?”Pine Script is useful when you want to:
- Turn a visual chart idea into exact rules
- Build an indicator that TradingView does not already provide
- Test a strategy on historical data
- Create alerts from custom conditions
- Combine several calculations into one tool
- Send alert data to another service through a webhook
What Pine Script is not
Section titled “What Pine Script is not”Pine Script runs inside TradingView. It is not a general-purpose replacement for Python, JavaScript, Go, or Rust.
Use Pine Script when the chart, TradingView data, or TradingView alerts are central to the task. Use a general-purpose language when you need unrestricted file access, databases, large research pipelines, custom servers, or direct control of a broker API.
How Pine Script thinks
Section titled “How Pine Script thinks”A Pine script normally runs repeatedly across chart data, one bar after another. Values such as open, high, low, close, and volume therefore form time series: they can have a different value on every bar.
That bar-by-bar model is the key idea behind the language. We will use it throughout the course.
Try it
Section titled “Try it”- Open TradingView’s Pine Editor.
- Create a new blank indicator.
- Replace its content with the minimal script above.
- Save it and select Add to chart.
- Change
closetohigh, then add it to the chart again.
You have now created and modified your first Pine Script.