Skip to main content
Lipi accepts several spellings for some things. This page picks one so that scripts read alike. Breaking a rule is never an error.

One spelling

  • Logic: and, or, not, not &&, ||, ! (the same tokens).
  • Functions: func spread(float h, float l) => h - l. The keyword-less form compiles too; def declares a method, not another spelling.
  • Body: an arrow while the body is one expression; braces and return from two statements.
  • Parameters: write the type; add a qualifier (const, simple) only to restrict. The default is series.
  • Analysis: talib.sma(...); ta.sma(...) is the same namespace.
  • Persistence: static, or intra for a value kept across the ticks of one forming bar only; declare them after the inputs, assign with :=. var does not exist.
  • Arrays: array.new<float>(0) and the method form a.push(x).
  • Drawings: create once into a static variable and change it with set_*.
  • Strategy ids: one string constant per order id.
  • Absence: na(x), not x == na (a warning).
  • Enumerated arguments: plotStyle.histogram, display.pane, size.small, not strings or numbers.
  • Colors: color.red or #RRGGBB; fade with color.new(color.red, 0.7) (opacity 0 to 1).
  • Arguments: name every argument after the second: plot(x, title="Spread", color=color.red). step= may be named.

Layout

  • Order: //@lipi=2, the declaration, inputs, calculations, then plot and other output calls.
  • One statement per line, four spaces per block level, else on the line of the closing }. Break a long statement after a comma or an operator, never before one.
  • Comparisons do not chain and have unusual precedence: write a < b and b < c, and parenthesise mixed conditions.

Names

  • Variables, functions, arguments: lowerCamelCase (fastLength).
  • Types, enums and their members: UpperCamelCase (Swing, Speed.Fast).
  • Never reuse a built-in name (rules in Names and conventions).