//@lipi=2 selects the language version, indicator()
declares the script (strategy() does it for a script that trades, see Strategies and backtesting) and plot() puts a value on the chart. In this page we build an indicator that shows how wide each bar is and
its moving average. Type each step into the editor and check it (see The Lipi editor).
the smallest script
high and low are the bar’s high and low. high - low is calculated for every bar, and plot draws one point per bar. The
second argument of indicator is the short title; with no overlay argument the line is drawn in a pane of its own, not over the
price bars.give the calculation a name
float states the type of barRange; it may be left out, as in barRange = high - low. A name is
created once with = and changed later with :=.Two rules to keep in mind
Output calls sit at the top level.plot and the other output calls (plotshape, plotchar, plotarrow, plotbar,
plotcandle, hline, fill, bgcolor, barcolor, alertcondition) cannot be placed inside an if, a loop or a function.
Drawings such as label.new, alert and strategy orders can (see Script anatomy):
plot() must be called in the global scope. When a plot should change with a condition, put the condition in an
argument, such as the color: plot(barRange, color = barRange > 5 ? color.red : color.gray).
One statement to a line. There is no ; between statements, and a block’s statements go on their own lines (see
Statements and lines).
What we built
An indicator with one calculation and two lines.Next
Add an input to your script
let the chart user change the 14.
The Lipi editor
what a check reports.
Plotting
the rest of what
plot accepts.