Start at the top
The first line is//@lipi=2, the language version. The next statement declares the script:
indicator("Title", ...)is an indicator. The arguments set its title, short title and whether it draws over the price (overlay=true) or in a pane of its own.strategy("Title", ...)is a strategy. Its arguments set the account:initial_capital,default_qty_value,commission_value,pyramidingand others. Look forstrategy.entry,strategy.closeandstrategy.exitto see when it trades.
The usual order
Most scripts follow the same order, which tells you where to look:- Inputs (
input.int,input.float,input.color, …): the settings the chart user can change. - Declarations:
typeandenumblocks, and functions (func, ordeffor a method), which must come before the line that uses them. - Calculations: variables,
talib.*calls and conditions. Astaticvariable keeps its value from bar to bar; a plain one is created again on every bar. - Output:
plotand the rest of the plot family at the top level, drawings (label.new,line.new,box.new,table.new) anywhere, andalertoralertcondition.
Names to look up
When a name is not one you know, look it up before deciding it is a mistake. A name with a dot belongs to a namespace (talib.sma, array.push, strategy.entry, str.tostring): open the reference page of that namespace (for example
array or global for names without a dot). Names the language
supplies, such as close, hl2, bar_index, barstate.islast and syminfo.ticker, are listed there too.
If a name is not in the reference, it is one of the names on What Lipi does not do or
Names and conventions, or a mistake in the script.
Check it, then read on
Check the script in the editor first. A check reports every error with its position, and a clean check also returns the symbol table: the variables, functions, types and enums the script declares (see The Lipi editor). A script that passes can still stop when it runs or be refused on Add to chart; the same page lists those cases. A script that does not start with//@lipi=2 is read as Lipi v1. See
Moving a script from Lipi v1 to v2 before you change it.