Drawing — fills & backgrounds

10 functions

FILLRGN(COND, PRICE1, PRICE2)

Fill between two series where COND holds; the colour comes from the trailing modifier.

COND(condition)
Which bars are filled.
PRICE1(series)
One edge of the fill.
PRICE2(series)
The other edge.
// shade the moving-average ribbon by which side is on top —
// the colour comes from the modifier, so it takes two calls
MA1 := MA(CLOSE, 5);
MA2 := MA(CLOSE, 20);
FILLRGN(MA1 > MA2, MA1, MA2), COLORGREEN;
FILLRGN(MA1 < MA2, MA1, MA2), COLORRED;
FILLRGN(PRICE1, PRICE2, COND1, COLOR1, COND2, COLOR2, …)

Four-or-more-argument form: fill between PRICE1 and PRICE2, colouring by the first matching condition. Up to fifteen pairs.

PRICE1(series)
One edge of the fill.
PRICE2(series)
The other edge.
COND1(condition)
First condition, tested first.
COLOR1(color)
Fill colour where COND1 holds.
COND2(condition)
Next condition. Up to fifteen pairs.
COLOR2(color)
Fill colour where COND2 holds.
// one call instead of two, because the colour is an argument
FILLRGN(CLOSE, OPEN, CLOSE > OPEN, RGB(255,0,0),
                    CLOSE < OPEN, RGB(0,255,0));

// three bands, ordered most specific first
MID := MA(CLOSE, 20);
FILLRGN(CLOSE, MID, CLOSE > MID * 1.05, RGBA(255,198,0,0.25),
                    CLOSE > MID,        RGBA(38,166,120,0.18),
                    1,                  RGBA(239,83,80,0.18));
FILLTOPRGN(PRICE, COND1, COLOR1, …)

Fill from PRICE up to the top of the pane.

PRICE(series)
Lower edge of the fill; the upper edge is the pane's top.
COND1(condition)
First condition. Condition/colour pairs follow as in FILLRGN.
COLOR1(color)
Fill colour where COND1 holds.
// shade the overbought zone of an oscillator without having
// to know where the top of the pane actually is
FILLTOPRGN(70, RSI > 70, RGBA(239,83,80,0.15));
FILLBOTTOMRGN(PRICE, COND1, COLOR1, …)

Fill from PRICE down to the bottom of the pane.

PRICE(series)
Upper edge of the fill; the lower edge is the pane's bottom.
COND1(condition)
First condition. Condition/colour pairs follow as in FILLRGN.
COLOR1(color)
Fill colour where COND1 holds.
// the oversold counterpart
FILLBOTTOMRGN(30, RSI < 30, RGBA(38,166,120,0.15));
FILLVERTICALRGN(COND1, COLOR1, COND2, COLOR2, …)

Fill the full height of the pane on bars matching a condition.

COND1(condition)
First condition — the bars to shade.
COLOR1(color)
Fill colour where COND1 holds.
COND2(condition)
Next condition, paired with its own colour.
COLOR2(color)
Fill colour where COND2 holds.
// column highlighting: mark a regime across the whole pane
// rather than drawing on the candles themselves
FILLVERTICALRGN(CLOSE > MA(CLOSE, 60), RGBA(38,166,120,0.08),
                1,                     RGBA(239,83,80,0.08));
FLOATRGN(PRICE, WIDTH, COND1, COLOR1, …)

Fill a band of WIDTH pixels along PRICE. A negative WIDTH fills downward; WIDTH may be a series.

PRICE(series)
The line the band hugs.
WIDTH(series)
Band thickness in pixels. Negative fills downward; may vary bar by bar.
COND1(condition)
First condition. Condition/colour pairs follow as in FILLRGN.
COLOR1(color)
Fill colour where COND1 holds.
// the width is a series here, so the band thickens with
// volume — a second dimension on the same line
FLOATRGN(CLOSE, VOL / HHV(VOL, 10) * 15,
         CLOSE > OPEN, RGB(255,0,0),
         1,            RGB(0,255,0));
DRAWGBK(COND, COLOR1, COLOR2, ANGLE)

Paint the whole pane background with a gradient when COND holds anywhere. ANGLE is the gradient angle.

COND(condition)
Holding on ANY bar paints the WHOLE pane — this is not per-bar.
COLOR1(color)
Gradient start colour.
COLOR2(color)
Gradient end colour.
ANGLE(integer)
Gradient angle in degrees.
// a themed backdrop for the pane; pass 1 as the condition
// unless you really want it to appear conditionally
DRAWGBK(1, RGBA(41,98,255,0.10), RGBA(19,23,34,0), 90);

// use DRAWGBK2 if you want only the matching bars shaded
DRAWGBK2(COND, COLOR1, COLOR2, ANGLE)

As DRAWGBK, but the background appears only on the bars where COND holds.

COND(condition)
Which bars get the gradient — per bar, unlike DRAWGBK.
COLOR1(color)
Gradient start colour.
COLOR2(color)
Gradient end colour.
ANGLE(integer)
Gradient angle in degrees.
// highlight only the bars inside a volatility squeeze
SQUEEZE := STD(CLOSE, 20) < LLV(STD(CLOSE, 20), 120) * 1.1;
DRAWGBK2(SQUEEZE, RGBA(94,204,255,0.20), RGBA(94,204,255,0), 90);
DRAWGBK_DIV(COND, COLOR1, COLOR2, COLORTYPE, FILLTYPE)

Split background fill with configurable colour and fill modes.

COND(condition)
Which bars are shaded.
COLOR1(color)
First colour.
COLOR2(color)
Second colour.
COLORTYPE(integer)
How the two colours are applied.
FILLTYPE(integer)
How the region is filled.
// the two extra mode arguments are what separate this from
// DRAWGBK2 — start from 0, 0 and adjust once you can see it
UP := CLOSE > MA(CLOSE, 60);
DRAWGBK_DIV(UP, RGBA(38,166,120,0.15), RGBA(239,83,80,0.15), 0, 0);
DRAWRECTREL(LEFT, TOP, RIGHT, BOTTOM, COLOR)

Rectangle in relative pane coordinates, each 0–999. COLOR 0 leaves it unfilled.

LEFT(integer)
Left edge, in thousandths of pane width.
TOP(integer)
Top edge, in thousandths of pane height.
RIGHT(integer)
Right edge.
BOTTOM(integer)
Bottom edge.
COLOR(color)
Fill colour; 0 leaves the rectangle unfilled.
// coordinates are pane-relative, not prices — the rectangle
// stays put while you pan and zoom
DRAWRECTREL(0, 0, 500, 500, RGB(255,255,0));

// a backdrop for a fixed-position readout
DRAWRECTREL(10, 20, 260, 130, RGBA(19,23,34,0.75));
DRAWTEXT_FIX(ISLASTBAR, 0.03, 0.06, 0, 'stats'), COLORWHITE;