Script anatomy
Every Lipi script has the same shape. It names itself, works out a value, and puts that value on the chart. The interpreter evaluates the whole script once for each bar, so the shape you write once runs many times.
The declaration comes first
A script announces itself with indicator. Treat the declaration as required rather than as a convention.
indicator(const string title, const string shorttitle, const bool overlay, const string format, const int precision) → voidOnly the title has to be supplied.
| Parameter | Type | Required |
|---|---|---|
title | const string | yes |
shorttitle | const string | no |
overlay | const bool | no |
format | const string | no |
precision | const int | no |
overlay sets the overlay flag for the whole script. An individual plot carries its own overlay switch as well, so the two are separate settings.
Every parameter here is const-form. You cannot pass a value that changes from bar to bar, and you cannot pass a value that arrived from a script input. Form types have their own page, const, simple and series.
One statement to a line
A newline ends a statement, and the grammar reads it. Statements are separated by newlines, not by punctuation.
A block is written with braces, and each statement inside the block sits on its own line.
float half = close / 2
if half > 0 {
float quarter = half / 2
}Comments
A comment starts with two slashes and runs to the end of the line. That is the only comment form. There is no paired open-and-close form, so a comment cannot span lines.
A complete script
A declaration and one output make a working script.
indicator("Close", "close", true)
// close is the closing price of the bar being evaluated
plot(close)Where to go next
- Values and types - what a value can hold, and how to write one down.
- const, simple and series - how often a value is allowed to change.
- Operators and expressions - arithmetic, comparison, and the two assignment operators.