//@lipi=2 line. To move one, add the line as the first line and check the script again.
Almost every v1 script keeps compiling; this page lists what Lipi v2 adds and the few things that change.
Lipi v2 runs in Terminal V2. The Classic Terminal runs scripts written for Lipi v1.
Step 1: the header
//@lipi=N it finds. With N equal to 2 the script is checked as Lipi v2. With no line, or with
//@lipi=1, it is checked as Lipi v1, which is why a v2 script pasted without its header fails with errors such as
No variable with name `array` found. A number above 2 is refused: unsupported //@lipi=3 at line 1, column 1: lipi should be <= 2.
What Lipi v2 adds
Each of these is refused by the v1 check and accepted in v2.
The v1 check already accepts these, so a v1 script that uses them needs no change:
type and enum declarations with
Name.new(...) and field assignment, switch, for, while, break and continue, static and intra, functions written with
func or no keyword, def methods, tuple returns, alert and alertcondition, talib.* and ta.*, and every input.* function except
input.enum. The check compares what the compiler accepts, not what the script draws; test a moved script on a chart.
Compound assignment is the change you will use most. A v1 script, as it stands:
+=.
What to check when you move a v1 script
math.sum(a, b, c)adds its arguments in v1. In v2 it is a moving sum,math.sum(source, length). A v1 call with three arguments is refused:Too many arguments passed into the `math.sum()` function call. Passed 3 arguments but expected 2.A call whose second argument is a whole number compiles in both versions and means something else. Writea + b + cfor the v1 meaning;math.sum(close, 10)is the sum of the last 10 closes.- Variable names that match a namespace now warn. Lipi v2 has many more namespaces, so a v1 variable called
line,label,box,table,array,strategy,position,order,text,format,chartorintervalcompiles with the warningVariable `line` hides the built-in namespace `line`.Rename it. plotbartakesdisplaybeforeforce_overlay. A v1 call that passesforce_overlayas the seventh argument is refused (Cannot call `plotbar` with argument `display`=`true`. ...); pass it by name.- A negative history index is now refused by the check.
close[-1]passes the v1 check; v2 stops it:History index must be >= 0. Got -1. - Run the Add to chart rules. Lipi v2 applies further rules when the script is added to the chart (see The Lipi editor). A clean editor check is not enough.
- Functions have more arguments, all at the end.
plot,hline,fill,barcolor,bgcolor, theplotshapefamily and theinput.*functions gaineddisplayand, for some,format. Scripts that pass their arguments by name or in the v1 order are unaffected (apart fromplotbar, above).
var, varip, ^ and ; are refused in both versions. See What Lipi does not do.