Pine Script Structure
Pine Script is a programming language created by TradingView and Rewrite by Bulltrading for the creation of custom technical analysis tools.
Script Definition
A Pine Script starts with a //@version
directive which denotes the version of Pine Script to be used. For instance, //@version=5
.
After this, you can define the script properties using indicator
for indicators.
Example:
//@version=5
indicator("My Script", shorttitle = "MS")
Variables and Types
Pine Script has several data types including series
, float
, integer
, bool
, color
, and string
. Variables can be declared using the <type> <variable-name>
syntax, and assignment is done with the :=
operator.
Example:
float a = na
a := close
Functions and Control Structures
Pine Script supports built-in functions and control structures.
Functions are defined with parameters and a block of code. They return the result of the last executed line.
Control structures, such as if
, for
, and while
loops, are also available.
Example:
codef_sum(x, y) =>
x + y
if (high > low)
result = high - low
else
result = 0
Plotting and Visualization
plot
function is used for drawing on the chart. It can take several parameters, like the series to plot, color, and line width.
Example:
plot(close, color=color.red, linewidth=2)
Backtesting
Indicators in Pine Script are used for backtesting trading ideas. It include positive or negative signal.
Example:
indicator("My Strategy")
indicator.signal(ta.crossover(sma(close, 14), sma(close, 28)))
This is just a simple overview of Pine Script structure, and the language has many more features and details to be discovered.
Last updated