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")| Signature | Returns |
|---|---|
| base.available() -> bool | Whether the base is attached to this run |
| base.value() -> float | The base's main value on this bar, its first series |
| base.series(name: string) -> float | One named series of the base on this bar. The name must be a literal from the table below |
| Base | Series | Settings (input key, default, bounds) | Draws in |
|---|---|---|---|
| "cvd" | value, open, high, low | candles true, resetDaily true | sub panel |
| "vwap" | value, upper1, lower1, upper2, lower2, upper3, lower3 | bands 3, 0 to 3 | price chart |
| "ema" | value | period 20, 1 to 500 | price chart |
| "rsi" | value | period 14, 1 to 500; overbought 70, 50 to 100; oversold 30, 0 to 50 | sub panel |
| "atr" | value | period 14, 1 to 500 | sub panel |
| "macd" | value, signal, histogram | fastPeriod 12, slowPeriod 26, signalPeriod 9, each 1 to 500 | sub 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.
//@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")