forge.draw
Colours, plot styles and drawing calls for Forge indicators.
Style is data, separate from logic: nothing here can change a value an indicator computes.
Colours A colour is one of: a name (``color.red``), ``rgb(30, 144, 255)`` with an optional alpha, a ``'#rrggbb'`` or ``'#rrggbbaa'`` string, or a theme colour (``color.theme.up``, written ``theme.up`` or ``theme.up/0.50`` with an alpha). A theme colour is chosen by the chart's theme, so it follows light and dark mode; a fixed colour never changes. The theme colours are ``up``, ``down``, ``neutral``, ``accent``, ``warning``, ``background``, ``text``, ``grid`` and the eight series colours ``series_a`` to ``series_h``. ``chart.bg_color`` is the chart's own background.
Up and down colours A line-style value output with ``color_up`` and ``color_down`` takes ``color_up`` where the value is above the previous bar's value, ``color_down`` where it is below, and keeps the previous colour where it is equal. A ``histogram`` or ``columns`` output takes ``color_up`` at or above its ``base`` and ``color_down`` below. An event takes ``color_up`` on +1 and ``color_down`` on -1.
Styles ``value``: line, step, line_gaps, histogram, columns, area, area_gaps, dots, cross, square, dash, marker, zigzag. ``state``: background, bar_color, marker. ``event``: marker, background, bar_color. ``zone``: area. ``width`` applies to every value style but ``marker``; ``dash`` (``solid``, ``dot``, ``dash``) to line, step, line_gaps and zigzag; ``base`` to histogram, columns and the two area styles; ``shift`` (bars, drawing only) to every style but background and bar_color.
Drawings ``label``, ``line``, ``hline``, ``vline``, ``level`` and ``box`` draw on the chart while an indicator runs (in ``setup``, ``calculate`` or ``on_bar``). Each returns a ``Drawing`` handle with ``update`` and ``delete``; ``find(id)`` and ``all(kind)`` list the live ones. Drawings are for eyes: a handle exposes no coordinate, text or colour, so anything a strategy needs must be an output.
Points A ``Point`` is anchored by ``bar=`` or by ``time=`` (nanoseconds since the epoch in Python, milliseconds on the wire). On time bars a time after the last bar is counted forward by the bar length; on other bar types (renko, range, and so on) draw by bar. A drawing reaches at most 500 bars past the last bar.
When drawings are kept A chart run keeps them; a test run (engine mode) keeps none, so a backtest never pays for drawing. An indicator that draws in ``calculate`` is recalculated from bar 0 on each update. A bar-by-bar indicator's drawings on the forming bar are shown, then rolled back like its state. Code drawings live only in the indicator's own series payload, never in the chart's saved drawings, so clearing the drawings a user made cannot remove them.
Caps At most 500 drawings of each kind and ``max_drawings`` in all are kept; past either the oldest goes. The first drop of a run adds one warning to the log and nothing is raised.
| Name | Kind | Summary |
|---|---|---|
| BASE_STYLES | constant | |
| Color | class | A fixed colour (``rgb``) or a theme colour (``token``), with an optional alpha. |
| DASH_STYLES | constant | |
| DEFAULT_FILL_ALPHA | constant | |
| DEFAULT_STYLE_BY_KIND | constant | |
| DRAWINGS_PER_KIND | constant | |
| DRAWING_KINDS | constant | |
| Drawing | class | A handle on one drawing. |
| EXTENDS | constant | |
| FONTS | constant | |
| LABEL_SIZES | constant | |
| LINE_DASHES | constant | |
| MARKER_SHAPES | constant | |
| MARKER_WHERE | constant | |
| MAX_FUTURE_BARS | constant | |
| MAX_SHIFT | constant | |
| MAX_TEXT | constant | |
| MAX_WIDTH | constant | |
| NAMED_COLORS | constant | |
| NO_SHIFT_STYLES | constant | |
| OUTPUT_KINDS | constant | |
| PLOT_STYLES | constant | |
| PlotStyle | class | How one output is drawn. |
| Point | class | A place on the chart: a bar (``bar=12``) or a time (``time=ns``), and a price. |
| SERIES_TOKENS | constant | |
| SHOW_TARGETS | constant | |
| STYLES_BY_KIND | constant | |
| TEXT_ALIGN | constant | |
| THEME_TOKENS | constant | |
| TIME_AXIS_KINDS | constant | |
| UP_DOWN_KINDS | constant | |
| WIDTH_STYLES | constant | |
| all | function | Every live drawing, oldest first; ``kind`` keeps one kind (``"label"``, ``"box"``, ...). |
| box | function | A rectangle between two bars and two prices, with optional text inside. |
| chart | constant | |
| color | constant | |
| find | function | The live drawing with this id, or ``None``. |
| gradient | function | The colour between ``c1`` (at ``lo``) and ``c2`` (at ``hi``) for ``value``. |
| hline | function | A horizontal line across the whole chart at ``price``. |
| label | function | Write ``text`` on the chart at a price (``where="at_price"``) or on a bar. |
| level | function | A horizontal line from ``start`` that stops at the first bar whose range reaches it. |
| line | function | A straight line between two points (each needs a price); ``extend`` makes it a ray. |
| make_style | function | Check a style against the vocabulary and fill the defaults. |
| parse_color | function | A colour from a ``Color`` or one of its written forms; anything else is a ``ValueError``. |
| rgb | function | A fixed colour from red, green and blue (0 to 255) and an optional alpha (0 to 1). |
| validate_wire_style | function | Check a style as a ``SeriesPage`` or the registry carries it: known keys, then every rule. |
| vline | function | A vertical line through one bar. |