Back to TradingView PineScript for CFD Traders
Part 1

What is PineScript? The Pine Editor explained

PineScript is TradingView's purpose-built language for custom indicators and strategies. Here is what it is, what it isn't, and how to open the editor.

Beginner5 min readBeginner → AdvancedLesson 01 / 17
Try it in TradingView
The smallest script that does something

Paste this in and you get a close line plus a 20-period SMA. Two plots, one overlay — proof the whole toolchain works.

//@version=5
indicator("Lesson 1 - My first script", overlay=true)

// Plot the closing price as a line.
plot(close, "Close", color=color.blue)

// Plot a 20-period simple moving average on top.
plot(ta.sma(close, 20), "SMA 20", color=color.orange, linewidth=2)
To run it
  1. 1. Open any chart in TradingView and click Pine Editor at the bottom.
  2. 2. Select everything in the editor and paste this over it, then click Save.
  3. 3. Click Add to chart. Open the Strategy Tester tab if it is a strategy.

What PineScript actually is

PineScript is a domain-specific language that runs only inside TradingView. It is purpose-built for financial chart work — variables default to time series, the language is sandboxed (no network, no filesystem), and every script returns either an indicator you can overlay on the chart or a strategy you can backtest.

Compared with general-purpose languages like Python or JavaScript, Pine gives up a lot of flexibility in exchange for three things that matter on a chart: it understands close, high, low, open, volume without you defining them; it plots series with one line; and every change re-runs across the chart history instantly.

What PineScript isn't

It is not a general programming language. You cannot open a file, talk to a broker, or run Pine outside TradingView. Strategies backtest inside TradingView only — there is no live execution path from Pine itself. For live trading you wire an alert from Pine to your broker or to automation software.

Versions: Pine v5 vs v6

Pine v5 has been the stable default since 2021 and is what every example in this course uses. Pine v6 is the newer line with stronger type checking and a few syntax changes; if you start a script today, TradingView will default you into v5. v6 is fine to learn later — the data model and the indicator/strategy split are the same.

Opening the Pine Editor

From any chart, click Pine Editor at the bottom of the screen. The editor opens with a default template. Click Save, then Add to chart — your first custom script is now on the price chart. The output appears in a separate pane below the candles (for studies) or overlays the candles (for strategies with plot shapes).

The minimum viable script

The shortest Pine script is two lines:

//@version=5
plot(close)

//@version=5 is the version directive. plot(close) draws the closing price as a line. That is a complete, valid indicator.

What you'll build by the end of this course

By the time you finish Part 4, you will have written a complete trend-following system that signals entries, sizes positions by account risk, draws stops and targets on the chart, and fires alerts you can route to your broker or automation tool.

What you just did

Lesson 01 of 17 in TradingView PineScript for CFD Traders. When you have run the examples or read the section, tick it off and move to the next lesson.