You are on page 1of 12

Basic Syntax

Overview
In this tutorial, we will explore the fundamental features of Pine Script. By the end of this section you will
learn:

● How a script is structured


● Versions
● The difference between a “study” and a “strategy”
● Lines & Indentation
● Comments
How a script is structured
● //@version=4
● A study or a strategy annotation call.
● A series of statements which implement
the script’s algorithm.
● A study must contain at least one
function/annotation call which produces
some output on the chart
● A strategy must contain at least one
strategy.* call, e.g., strategy.entry
Versions -- //@version=4

● There are currently four versions of the Pine Script Language.


● If you forget to include the //@version=N directive, the compiler will default to version 1.
● Pine Script Language versions are incompatible with each other.
● If you are modifying an existing script, make sure you are working with the same version
or you will run into problems.
● Most //@version=3 scripts can be modified with the click of a button.
Versions -- //@version=4
Study vs. Strategy

Study Strategy
● Can plot information on charts ● Can plot information on charts
● Contain calculations ● Contain calculations
● Cannot be used in backtesting ● Used to run backtests.
● Do Not contain strategy.* calls ● Contain strategy.* calls to generate buy and
● Can create and use alertcondition() sell orders
● Can create, but NOT use alertcondition()
Strategies cannot use
alerts!
Lines & Indentation

● There is no known limit for the length of one line.


● Empty lines have no effect on the compiler.
● Lines that are too long can be placed onto more than one
line.
● When using multiline statements, spacing and indentation
is very important.
● 4 spaces or 1 tab is the required amount for line wrapping.
Comments
● Pine Script supports single-line comments only.
● Anything after // is a comment. The only minor exception being the @version directive.
● ctrl+/ (Windows) or cmd+/ (Mac) are hot keys for commenting and uncommenting lines
● Comments have no effect on the script.
Comments
● Pine Script supports single-line comments only.
● Anything after // is a comment. The only minor exception being the @version directive.
● ctrl+/ (Windows) or cmd+/ (Mac) are hot keys for commenting and uncommenting lines
● Comments have no effect on the script.
● Versions
○ 4 different versions
○ Default is 1.
○ 4 is the newest.
Recap ○ Non Compatible
● The difference between a “study” and a
“strategy”
○ Strategies can run backtests
● How a script is structured. ○ Studies can use alerts
○ Version Directive ○ They both can plot and calculate
○ Study or Strategy ● Lines & Indentation
○ Statements ○ Lines can be as long as you want
○ Outputs ○ Spanning multiple lines is possible
with 4 spaces.
● Comments
○ Anything after // is a comment
○ Can’t be used in multline statements

You might also like