Skip to Content
While25SDK docs
Output and panels

Indicators

Lines, histograms and zones drawn on the chart, and an indicator's numbers inside a strategy.

One indicator, one label, as many lines as you like:

import while25
from while25 import Fill, Indicator, Plot, on
from while25.inputs import Float, Int


class MyBollinger(Indicator):
    id      = "my_bb"
    label   = "My Bollinger"      # ONE legend entry for all three lines
    overlay = True

    inputs = [Int("length", default=20, minimum=2, maximum=500, step=1),
              Float("mult", default=2.0, step=0.1)]

    plots = [Plot("basis", color="#e0a34a", width=2),
             Plot("upper", color="#4aa3e0", style="dashed"),
             Plot("lower", color="#4aa3e0", style="dashed")]
    fills = [Fill("upper", "lower", color="#4aa3e0", opacity=0.08)]

    warmup = lambda params: int(params.get("length", 20))

    def compute(self, ctx):
        n    = while25.params["length"]
        rows = while25.bars          # While25 streams you the chart's bars
        ...
        self.times = [int(r["time"]) for r in rows]
        return {"basis": basis, "upper": upper, "lower": lower}
  • inputs become a config dialog the user can edit — the same one built-in indicators use.
  • plots set the DEFAULT colour, width and line style. The user can still override every one of them in the chart settings, exactly as for a built-in.
  • Plot(plot_type=...) takes line · histogram · area · stepline; Level(70) draws a reference line and Band(top, bottom) shades a zone.
  • compute() returns a dict keyed by your plot names. Returning a name you did not declare is an error rather than a silently missing line. Every indicator writes its own compute(self, ctx): a class without one is refused when the file is saved.
  • A chart starts indicators and nothing else. If a file on a chart is saved again as a Strategy, a Monitor or an App under the same id, the chart draws nothing for it and starts nothing: its log says so. Take it off the chart, and start the new module the way its kind is started.
  • An indicator RECEIVES its series. While25 streams the chart's series — scrollback included — to Python, and every change to it recomputes you; the client no longer sends bars. while25.bars is that array, oldest first, replaced whole every pass. while25.forming is the unclosed bar and is present only while a bucket is forming (otherwise None; it is never inside bars). while25.price is the price the chart's candles are built from: "last", or "mark" on a Binance futures chart set to Mark price (no volume). while25.future_times is the chart's projected grid. The times are the chart's own wire times, so self.times = [r["time"] for r in rows] lands every value on the candle it came from. Sourcing a second series is refused: candles(..., source="live") inside compute() raises LIVE_IN_COMPUTE. Two series drift after a scrollback, and the chart's by-timestamp merge then blanks the line exactly where the user scrolled.
  • warmup declares what you need — an int, or a callable of the params when it is derived (DEMA needs 2*period-1). Short input reports warming up — 12 of 39 bars instead of drawing nothing. A bigger limit is never the answer: it truncates a fetch, and here there is no fetch.
  • Plot(name, color="", width=1, style="solid", plot_type="line", color_down="", opacity=1.0, overlay=None, visible=True). width is 1 to 4; style is solid · dotted · dashed · large-dashed · sparse-dotted; color_down is a histogram's or bi-colour plot's second colour; overlay None follows the indicator's own overlay. Fill(upper, lower, color="", opacity=0.08) shades between two of your plots. levels = [Level(70, color="", width=1, style="dashed")] draws reference lines and bands = [Band(top, bottom, color="", opacity=0.06)] shades zones. y_min / y_max fix the pane's scale (RSI 0 to 100) and precision its decimals. intrabar = True recomputes as the bar forms, not only when it closes (a full recompute per tick: off by default). A declaration the chart cannot draw — no plots, a plot named twice, a fill naming a plot you did not declare, a band whose top is not above its bottom — is refused when the file is registered.
  • while25.instrument and while25.interval are the chart's: the symbol and interval it is drawing, set per compute, so one indicator works on any chart.

An indicator's numbers in a strategy

from indicators.my_rsi import MyRsi

class TslaRsi(Strategy):
    id = "tsla_rsi"
    tsla = Bars("EQ:US:TSLA", "5m", keep=100)

    @on.bar(tsla)
    def on_bar(self, ctx, bar):
        rsi = self.tsla.indicator(MyRsi, length=14)["rsi"]
        if rsi[-1] > 70:
            ...

line.indicator(cls, *, forming=False, **params) works an indicator out from a Bars line's own bars. It is while25.indicator with bars=line.rows:

while25.indicator(cls, *, bars=None, forming=False, instrument="", interval="", **params) works another indicator out in this process, from the bars you hand it, and returns exactly what its compute() returned. Nothing is drawn and no chart is needed. Only a chart hands an indicator bars by itself, so a strategy passes its own.

  • bars: oldest first, your warm-up and @on.bar bars, or candles() rows. The indicator reads them as while25.bars in a chart's row shape (time in epoch ms, open, high, low, close, volume), so one written for a chart works unchanged; while25.forming is None.
  • forming: True also counts the bar still forming, see below.
  • instrument, interval: what it reads as while25.instrument and while25.interval; left out, the bars' own.
  • **params: its inputs, checked and defaulted as on a chart.

ValueError, without running it: fewer bars than its warmup, bars out of order or two at one time, a bar without a time or a price, bars of two series in one list (two @on.bar lines), an instrument or interval that is not the bars' own. With no bars=, an indicator that reads while25.bars raises ValueError saying so; only one called inside another indicator's compute() reads its caller's bars.

Before the bar closes. @on.bar wakes the strategy once a bar has closed. To act while it is still forming, ask from a tick handler with forming=True:

    @on.tick("EQ:US:TSLA")
    def on_tick(self, ctx, tick):
        rsi = self.tsla.indicator(MyRsi, forming=True, length=14)["rsi"]

It adds the bar still forming on that @on.bar line after your bars, as While25 last sampled it (about once a second; the chart's moving candle is the same bar). The indicator reads it as its last bar; your own list is not changed.

  • Added only when it is the bar right after your last one: never a bar you already hold closed, and never past a closed bar your list has not got yet. Otherwise, and while nothing is forming, the indicator is worked out from your bars as they are.
  • bars must be those of one of the module's own bar lines (a Bars line, or an @on.bar line's warm-up and bars), whatever its interval: that line is what holds the symbol's prices while the module runs. Anything else raises ValueError.
  • Its warmup is counted in closed bars.