ScriptingGetting startedWrite your first script

Write your first script

A script needs two calls. indicator() declares the script. plot() puts a value on the chart. Together they are the smallest complete script you can write.

The example: cumulative delta

Cumulative delta is a running total of each bar’s delta, and orderflow.cvd() calculates it for you. It takes no arguments and returns a series of whole numbers, so the call stays short.

Two details are worth knowing before you plot it. The running total restarts from zero on the first bar of a session. A bar whose delta is na leaves the total where it was, rather than breaking the rest of the series.

Here is the complete indicator:

indicator("Cumulative delta")
plot(orderflow.cvd())

Two lines. The first declares the script and names it. The second calls the cumulative-delta function and hands the result to plot, which draws it on the chart.

Two rules to keep in mind

Output calls must sit at the top level of a script. A plot written inside a branch, inside a loop, or inside a function of your own is rejected with a named error. When you want a plot to change with a condition, the condition belongs in the colour argument, not around the call.

Orderflow values read na on a bar that has no footprint data. A script that uses them has to expect na rather than a number.

Next

Check the script before you run it. The editor reports each problem with a start and an end position — see The Lipi editor.

Ready to put this into practice?
Try GoCharting Premium
Unlock advanced orderflow, market profile, options desk, and real-time data — everything you just read about, live in your charts.
Upgrade