Skip to main content
Scripts are short and share one shape, so you can learn an unfamiliar one quickly. Read it in the order below, then check it in the editor. For a line-by-line walk through a script, see Read someone else’s script. To share your own scripts, see Sharing scripts.

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, pyramiding and others. Look for strategy.entry, strategy.close and strategy.exit to see when it trades.
A script has exactly one declaration.

The usual order

Most scripts follow the same order, which tells you where to look:
  1. Inputs (input.int, input.float, input.color, …): the settings the chart user can change.
  2. Declarations: type and enum blocks, and functions (func, or def for a method), which must come before the line that uses them.
  3. Calculations: variables, talib.* calls and conditions. A static variable keeps its value from bar to bar; a plain one is created again on every bar.
  4. Output: plot and the rest of the plot family at the top level, drawings (label.new, line.new, box.new, table.new) anywhere, and alert or alertcondition.

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.