ScriptingWriting LipiScript anatomy

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) → void

Only the title has to be supplied.

ParameterTypeRequired
titleconst stringyes
shorttitleconst stringno
overlayconst boolno
formatconst stringno
precisionconst intno

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.
Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.
Upgrade