Extending a built in indicator

A script can start from an open built in indicator and draw on top of it. Name the base as the second argument of indicator. The builder then draws that indicator, with its own default look, as part of your script, and hands your script its values on every bar. The indicator already on your chart is never touched: a fork is a second, independent indicator.

indicator("CVD with signal", "cvd")
SignatureReturns
base.available() -> boolWhether the base is attached to this run
base.value() -> floatThe base's main value on this bar, its first series
base.series(name: string) -> floatOne named series of the base on this bar. The name must be a literal from the table below
BaseSeriesSettings (input key, default, bounds)Draws in
"cvd"value, open, high, lowcandles true, resetDaily truesub panel
"vwap"value, upper1, lower1, upper2, lower2, upper3, lower3bands 3, 0 to 3price chart
"ema"valueperiod 20, 1 to 500price chart
"rsi"valueperiod 14, 1 to 500; overbought 70, 50 to 100; oversold 30, 0 to 50sub panel
"atr"valueperiod 14, 1 to 500sub panel
"macd"value, signal, histogramfastPeriod 12, slowPeriod 26, signalPeriod 9, each 1 to 500sub panel
  • To expose a base setting, declare an input whose key is the setting name, for example let period: int = input.int(20, "period", "Period", 1, 500, 1). The base then follows that control. Undeclared settings keep their defaults.
  • base.* without a base in indicator(), a base that is not in the table, or a series name the base does not publish is rejected when the script compiles, with one line listing what is accepted.
  • Protected XFlow Charts indicators cannot be a base.
  • Your drawing sits on top of the base's, in the same pane, so a panel base puts your panel lines in its panel.
A fork of VWAP that marks closes outside the second band
//@xfscript 1
indicator("VWAP Stretch", "vwap")

let bands: int = input.int(2, "bands", "Bands", 0, 3, 1)
let upper: float = base.series("upper2")
let lower: float = base.series("lower2")
let stretched_up: bool = base.available() && close > upper
let stretched_down: bool = base.available() && close < lower
plot.marker(stretched_up, high, "#EF4444", "triangle", "above", 9, 3)
plot.marker(stretched_down, low, "#22C55E", "triangle", "below", 9, 3)
plot.label(str.concat("VWAP ", format.fixed(base.value(), 2)), "#E5E7EB")

Všechny vrstvy trhu – od Orderflow po optionflow – v jednom grafu.

Orderflow data institucionální kvality s vestavěným backtestingem a obchodním deníkem. Zapište se na čekací listinu a získejte předběžný přístup.

Získat přístup