Writing an indicator

Calculate, draw, and publish values.

AlgoBarsX
indicator "Trend Ribbon"
pane: price
input fast = 20
input slow = 50
fast_line = ema(close, fast)
slow_line = ema(close, slow)
export up = fast_line > slow_line
export strength = (fast_line - slow_line) / atr(14)
plot fast_line as fast, color: if up then green else red
plot slow_line as slow, color: gray
  • pane: price draws over the price chart. pane: new gives the indicator its own pane.
  • plot draws a series. as gives the plot a name. Colours can depend on a condition.
  • export publishes a value. Anything exported can be read by a strategy, an alert or another indicator that uses this one.

Using an indicator or a library from another script

AlgoBarsX
use indicator "Trend Ribbon" v3 as ribbon (fast: 10, slow: 30)
use library "Quant Toolkit" v2 as qt

You import by name and version, give it a short name with as, and set its inputs in brackets. After that, ribbon.up reads like any other value. A script names the version it uses, so an update to the indicator does not silently change a strategy that depends on it.

Try this in the Terminal. AlgoBars is free: $0 a month, no card needed.

Create my free account