ox-charts

Arrays, maps and user types

Collections and your own types, with methods, for scripts that keep state across bars.

A rolling list of swing highs in a user type
//@oxscript=1
indicator("Swing highs", overlay=true)
type Swing
    float price
    int bar
var swings = array.new<Swing>()
ph = ta.pivothigh(high, 5, 5)
if not na(ph)
    swings.push(Swing.new(ph, bar_index - 5))
    if swings.size() > 10
        swings.shift()
last = swings.size() > 0 ? swings.last().price : na
plot(last, "Last swing high", color=color.red, style=plot.style_stepline)
  • array.new<float>(), array.new_float(), literals like [1, 2, 3]. Call methods on the value: a.push(x), a.size(), a.last().
  • map.new<string, float>() with put, get, contains, keys.
  • type declares fields with optional defaults; Swing.new(...) creates one and Swing.copy(s) clones it.
  • method push(Stack s, float v) => ... adds a method you call as s.push(v).

Sizes are capped

Arrays and matrices hold up to 100,000 items and maps 50,000 entries. Past that the script stops with an error that says so.