Learning Pine Script™ Roadmap

This document aims to provide information that will be useful for newcomers to the Pine Script programming language. Pine Script is the programming language used on the TradingView charting platform.

Table of Contents

Where to go?

There are many resources to learn Pine. These are the most important. While you will not begin by reading the Reference Manual, it’s important to know where it is. The Quickstart Guide is a good place to start and branch out to key areas of the User Manual.

  1. The two primary sources of information on Pine are the Pine v4 User Manual and Pine v4 Reference Manual.
    Follow the instructions in the User Manual’s Quickstart Guide page to put your first script in action on a chart, and follow the links in that page to familiarize yourself with Pine’s key concepts.
  2. Once you start working in the Pine Editor, you can bring up the Reference Manual by Ctrl/⌘-clicking on any colored language keyword. From the editor, you can also view a list of keyboard shortcuts by selecting Pine Editor Keyboard Shortcuts from the Help menu. The editor’s Help menu will link you to v4 and v3 documentation, and to forums where you can ask questions on Pine.
  3. PineCoders maintains a FAQ & Code and a Resources document where you will find links to educational material and tools.
  4. Kodify.net is the largest repository of Pine-related articles out there. In more than 200 articles related to Pine programming, they explore Pine features thoroughly and also present techniques for realizing common tasks in Pine. If you have never programmed before, Kodify is the best place to get started.
  5. YouTube has content by Pine coders. Our Resources page has a section on Pine Videos. A search for pine introduction tradingview will also turn up a few videos.
  6. Backtest Rookies also has some articles on Pine. They produce quality material illustrating many of the typical things Pine coders want to do or explore.

What’s Pine?

Pine is a specialized language used to write scripts that can take two very different forms: studies (a.k.a. indicators, as we will name them) or backtesting strategies. Indicators are used to show graphic information on a chart or in an indicator Pane. If you wish to write a MACD indicator in Pine, you do that by creating a script using the study() declaration statement at the beginning of the script. Strategies use the strategy() declaration statement and can display visual information on charts or in panes in the same way an indicator would, but they also contain additional Pine statements to simulate trades in order to run backtests.

If you want to design a trading system that trades on MACD setups, you may write a strategy to test it, and then convert it to an indicator to generate alerts in order to discretionary trade on them, or send them to a third-party execution bot for relaying orders to markets. Be sure to look at the PineCoders Backtesting and Trading Engine if this is your objective.

Because it is specialized, Pine is very powerful. You can write two lines of Pine to do what could take hundreds in other languages. The same specialization that makes Pine powerful also implies a high abstraction level; until you understand a few key concepts about Pine and its runtime environment, it will be difficult to make sense of Pine code.

There are 4 supported versions of Pine, from 1 to 4. A compiler directive used in the script’s first line will tell you what version of Pine the script is written for (when no such directive is present, v1 is the default used). It is important to know which version the code you will be writing or studying is, as keywords and programming techniques can vary quite a bit between versions.

Pine runtime environment

Pine scripts run directly in TradingView chart Editor:

Step 1: Go to https://www.tradingview.com/
Step 2: Select “Chart” button
Step 3: Open the Pine Editor pane by clicking on the “Pine Editor” tab at the bottom of the chart.
Pine Editor

Pine indicator code executes once for each bar of the dataset, starting from the beginning of the chart’s history. When the realtime bar is reached, indicator scripts execute every time price changes, while strategy scripts may be configured to behave like indicators, or to run only at the close of the realtime bar (the default). See here for more information.

Series

The main data type used in Pine scripts is called a series. It is a continuous list of values that stretches back in time from the current bar and where one value exists for each bar. While this structure may remind many of an array, a Pine series is totally different and thinking in terms of arrays will be detrimental to understanding this key Pine concept. You can read about series here and get more information on how to use them here.
     — quoted from the Pine v4 documentation

Programming in Pine

If you are new to programming, then you have a double learning curve to go through: learn to program and learn Pine. You will need to do your homework and spend the countless hours required to become able to convert your trading ideas into working code.

Either way, the most productive way to learn is always to start playing with real code early. Start with the examples in the next section. Make slight changes to the code and see what impact they have, and you’ll be on your way.

If you already have programming experience, learning Pine is mostly about becoming proficient in manipulating series, and then understanding the abstractions, the runtime environment and the typing and runtime limitations, as the language itself is straightforward.

Whether you are new to programming or a veteran, the PineCoders Pine Coding Conventions will provide useful coding guidelines you can choose to adopt.

Code examples

Troubleshooting Pine code

Here are a few methods for troubleshooting pine-related issues:

search

Conversion from other platforms

The TradingView platform does not run indicators written for other platforms. They will require conversion in Pine before they can run on TradingView charts.