ScriptingMarket data a script can readPrice and volume

Price and volume

Every bar carries five values you can read by name. Four averaged prices are supplied alongside them, and the bar itself has an index.

The bar’s values

open, high, low, close and volume are float series. Each holds the value for the bar your script is being evaluated on, and each moves on as the script advances through the chart.

NameTypeHolds
openseries floatThe bar’s open
highseries floatThe bar’s high
lowseries floatThe bar’s low
closeseries floatThe bar’s close
volumeseries floatThe bar’s volume

Averaged prices

Four further names average values from the same bar. They exist so that you need not compute the average yourself. Each is a float series, like the values it averages, so you can use one anywhere a price is expected.

NameTypeAverages
hl2series floatThe high and the low
hlc3series floatThe high, the low and the close
hlcc4series floatThe high, the low and the close counted twice
ohlc4series floatThe open, the high, the low and the close

The bar index

bar_index is an int series rather than a float. Like a price, it changes from bar to bar.

NameTypeHolds
bar_indexseries intThe index of the bar

A script that plots two of them

indicator("Close and typical price")
plot(close)
plot(hlc3)

Both plot calls sit at the top level of the script. Chart-output functions have to be called there: a call placed inside a branch, inside a loop or inside a function of your own is rejected.

Reading an earlier bar

To read one of these values from an earlier bar, put an index in square brackets after the name. The index is itself an expression, so it need not be a literal.

close[1]

The rules for reading past bars are set out in Referencing past bars.

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