Drawing — style helpers

14 functions

These return a value rather than drawing. They are written after a comma, as modifiers on the statement.

RGB(R, G, B)

Colour from three 0–255 components.

R(integer)
Red, 0–255.
G(integer)
Green, 0–255.
B(integer)
Blue, 0–255.
// note the byte order trap: the COLORxxxxxx literal form is
// BLUE-GREEN-RED, whereas RGB() is the familiar red-first order
UP: MA(CLOSE, 5), RGB(38,166,120);

// MACD histogram with explicit two-sided colours
MACD: (DIF - DEA) * 2, COLORSTICK,
      UPCOLOR(RGB(38,166,120)), DOWNCOLOR(RGB(239,83,80));
RGBA(R, G, B, A)

Colour with an alpha channel, A between 0 and 1.

R(integer)
Red, 0–255.
G(integer)
Green, 0–255.
B(integer)
Blue, 0–255.
A(float)
Opacity, 0 fully transparent to 1 fully opaque.
// fills need alpha, or they bury the candles underneath
FILLRGN(CLOSE, MA(CLOSE, 20),
        CLOSE > MA(CLOSE, 20), RGBA(38,166,120,0.15),
        1,                     RGBA(239,83,80,0.15));
UPCOLOR(COLOR)

Colour for the positive side of COLORSTICK, VOLSTICK, UPDOWNDOT and LINEAREA.

COLOR(color)
Colour used on the positive side.
// only meaningful next to one of the two-sided modifiers —
// on a plain line it does nothing
MACD: (DIF - DEA) * 2, COLORSTICK,
      UPCOLOR(RGB(38,166,120)), DOWNCOLOR(RGB(239,83,80));
DOWNCOLOR(COLOR)

Colour for the negative side of the same modifiers.

COLOR(color)
Colour used on the negative side.
// volume bars coloured by the candle's direction
VOLBAR: VOL, VOLSTICK,
        UPCOLOR(RGB(38,166,120)), DOWNCOLOR(RGB(239,83,80));
CSSFONT('14px Inter')

Set a full CSS font string for text drawing.

FONT(string)
A CSS font shorthand, e.g. 'bold 14px Inter'.
// use it when FONTSIZE is not enough — weight and family
// can only be set through the full CSS string
DRAWTEXT(ISLASTBAR, HIGH, 'BREAKOUT'),
         CSSFONT('bold 16px Inter'), COLORYELLOW;
STICKTYPE(TYPE)

Bar rendering style for VOLSTICK.

TYPE(integer)
Which bar style VOLSTICK uses.
// only has an effect alongside VOLSTICK
VOLBAR: VOL, VOLSTICK, STICKTYPE(1);
XMOVE(N)

Shift the drawing N pixels horizontally.

N(integer)
Pixels to move right; negative moves left.
// nudge a label clear of the candle it belongs to
DRAWTEXT(ISLASTBAR, HIGH, 'now'), XMOVE(8), COLORWHITE;
YMOVE(N)

Shift the drawing N pixels vertically. Positive is upward.

N(integer)
Pixels to move up; negative moves down.
// VALIGN picks the anchor, YMOVE fine-tunes the gap —
// use both rather than fighting one of them
DRAWTEXT(CROSS(K, D), LOW, 'buy'),
         COLORGREEN, VALIGN2, YMOVE(6);
LINEDASH(A, B, …)

Dash pattern in pixels — LINEDASH(4, 4) gives an even dashed line.

A(integer)
Dash length in pixels.
B(integer)
Gap length in pixels. Further pairs may follow for a more complex pattern.
// finer control than the plain DOTLINE modifier
MA20: MA(CLOSE, 20), LINEDASH(4, 4), COLORGRAY;
// long dash, short gap, short dash, short gap
REF20: HHV(HIGH, 20), LINEDASH(10, 3, 2, 3), COLORYELLOW;
FIRSTDRAW(0 | 1)

Draw this element beneath (1) or above (0) the rest of the pane.

MODE(integer)
1 draws underneath everything else, 0 on top.
// push a heavy background fill behind the candles, so it
// tints them instead of hiding them
FILLVERTICALRGN(CLOSE > MA(CLOSE, 60), RGBA(38,166,120,0.20)),
                FIRSTDRAW(1);
BACKGROUND(COLOR, BORDERCOLOR, LEFT, RIGHT, TOP, BOTTOM)

Background box behind drawn text. The four margins are in pixels and default to 0, 1, 1, 1.

COLOR(color)
Box fill colour.
BORDERCOLOR(color)
Box border colour.
LEFT(integer)
Left padding in pixels. The four margins default to 0, 1, 1, 1.
RIGHT(integer)
Right padding in pixels.
TOP(integer)
Top padding in pixels.
BOTTOM(integer)
Bottom padding in pixels.
// a label that stays legible over candles of any colour
DRAWTEXT(CROSS(K, D), LOW, 'buy'), COLORWHITE, FONTSIZE12,
         VALIGN2, YMOVE(6),
         BACKGROUND(RGB(38,166,120), RGB(255,255,255), 4, 4, 2, 2);
CKLINE(COLOR, WIDTH, TYPE, DOTTED)

Connector line from a text or icon down to the candle. TYPE 0 solid, 1 dashed; DOTTED is a pattern string.

COLOR(color)
Connector colour.
WIDTH(integer)
Connector width in pixels.
TYPE(integer)
0 solid, 1 dashed.
DOTTED(string)
Dash pattern string, e.g. '3,3'.
// once a label is pushed well clear of the bar, the connector
// is what keeps it obvious which bar it belongs to
DRAWTEXT(CROSS(K, D), LOW, 'buy'), COLORGREEN, VALIGN2, YMOVE(24),
         CKLINE(COLORGREEN, 1, 1, '3,3');
SOUND(NAME)

Requests a sound on the triggering bar. Accepted by the compiler; the browser chart currently has no sound handler attached.

NAME(string)
Name of the sound to request.
// compiles and runs, but stays silent in the browser chart —
// set up an alert instead if you want to be notified
CROSS(MA5, MA20), SOUND('ding');
PLAYSOUND(COND, NAME)

Conditional form of SOUND, with the same caveat.

COND(condition)
When to request the sound.
NAME(string)
Name of the sound to request.
// same silence applies here — the condition is evaluated,
// the sound simply has nowhere to go
PLAYSOUND(CROSS(MA5, MA20), 'ding');