Skip to content

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.

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.

//@version=6
indicator("My First Script", overlay = true)
plot(close)

This script has three important parts:

  1. //@version=6 tells the compiler which Pine Script version to use.
  2. indicator() declares that the script is an indicator.
  3. plot(close) draws the closing price as a line.

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

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.

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.

  1. Open TradingView’s Pine Editor.
  2. Create a new blank indicator.
  3. Replace its content with the minimal script above.
  4. Save it and select Add to chart.
  5. Change close to high, then add it to the chart again.

You have now created and modified your first Pine Script.