Drawing — text, numbers & icons
16 functions
DRAWTEXT(COND, PRICE, TEXT)Write TEXT at PRICE on every bar where COND holds.
- COND(condition)
- Which bars get the label.
- PRICE(series)
- The level the text is anchored to.
- TEXT(string)
- What to write. May be built per bar with VARCAT or STRFORMAT.
// a plain marker under the bar
DRAWTEXT(CROSS(K, D), LOW, 'buy'), COLORGREEN, VALIGN2;
// a live readout pinned to the last bar
DRAWTEXT(ISLASTBAR, HIGH,
STRFORMAT('C {0:0.00} chg {1:0.00}%',
CLOSE, (CLOSE - OPEN) / OPEN * 100)),
COLORWHITE, FONTSIZE12, DRAWABOVE;DRAWTEXT_FIX(COND, X, Y, TYPE, TEXT)Write TEXT at a fixed position. X and Y are fractions of the pane (0–1); TYPE 0 left, 1 right, 2 centre.
- COND(condition)
- When to draw. Usually ISLASTBAR — the position does not follow the bars.
- X(float)
- Horizontal position as a fraction of pane width, 0–1.
- Y(float)
- Vertical position as a fraction of pane height, 0–1.
- TYPE(integer)
- Alignment: 0 left, 1 right, 2 centre.
- TEXT(string)
- What to write.
// a heads-up panel in the top-left corner that stays put
// while you pan and zoom
DRAWTEXT_FIX(ISLASTBAR, 0.02, 0.05, 0, 'session high'), COLORGRAY;
DRAWTEXT_FIX(ISLASTBAR, 0.02, 0.12, 0,
VAR2STR(SYSPARAM(4), 2)), COLORWHITE;DRAWTEXT_LINE(COND, PRICE, TEXT, TEXTCOLOR, FONTSIZE, LINETYPE, LINECOLOR)Write TEXT at PRICE together with a horizontal marker line.
- COND(condition)
- Which bars get the label and line.
- PRICE(series)
- The level for both the text and the line.
- TEXT(string)
- What to write.
- TEXTCOLOR(color)
- Colour of the text.
- FONTSIZE(integer)
- Font size in pixels.
- LINETYPE(integer)
- Line style, same codes as VERTLINE.
- LINECOLOR(color)
- Colour of the marker line.
// a labelled level — text and line in one call, so they
// can never drift apart
STOP := LLV(LOW, 10);
DRAWTEXT_LINE(ISLASTBAR, STOP, 'stop', COLORRED, 12, 1, COLORRED);DRAWTEXTREL(X, Y, TEXT)Write TEXT at a relative pane position where X and Y run 0–999 (thousandths of width and height).
- X(integer)
- Horizontal position in thousandths of pane width, 0–999.
- Y(integer)
- Vertical position in thousandths of pane height, 0–999.
- TEXT(string)
- What to write.
// same idea as DRAWTEXT_FIX but on a 0–999 scale and with
// no condition argument — it always draws
DRAWTEXTREL(20, 50, 'top left'), COLORGRAY;
DRAWTEXTREL(20, 950, 'bottom left'), COLORGRAY;DRAWTEXTABS(X, Y, TEXT)Write TEXT at an absolute pixel offset from the pane's top-left corner.
- X(integer)
- Pixels right of the pane's left edge.
- Y(integer)
- Pixels down from the pane's top edge.
- TEXT(string)
- What to write.
// pixel-exact placement — unlike the relative forms this does
// not rescale when the pane is resized, so keep it near a corner
DRAWTEXTABS(10, 10, 'debug'), COLORGRAY, FONTSIZE10;SUPERDRAWTEXT(COND, PRICE, TEXT, DIRECTION, OFFSET)DRAWTEXT with explicit placement: DIRECTION 0 middle, 1 above the price, 2 below; OFFSET shifts it vertically.
- COND(condition)
- Which bars get the label.
- PRICE(series)
- The level the text is anchored to.
- TEXT(string)
- What to write.
- DIRECTION(integer)
- 0 centred on the price, 1 above it, 2 below it.
- OFFSET(integer)
- Extra vertical shift in pixels.
// placement is an argument here rather than a VALIGN modifier,
// which keeps buy and sell symmetric and easy to nudge
SUPERDRAWTEXT(CROSS(K, D), LOW, 'buy', 2, 6), COLORGREEN;
SUPERDRAWTEXT(CROSS(D, K), HIGH, 'sell', 1, 6), COLORRED;DRAWFLAGTEXT(COND, PRICE, TEXT)Semi-transparent tooltip that appears at PRICE only when the crosshair is on a bar satisfying COND. Use \n for line breaks.
- COND(condition)
- Which bars carry a tooltip.
- PRICE(series)
- Where the tooltip is anchored.
- TEXT(string)
- Tooltip contents. \n starts a new line.
// detail on demand — nothing clutters the chart until the
// crosshair lands on a signal bar
SIG := CROSS(MA5, MA20);
DRAWFLAGTEXT(SIG, LOW,
STRFORMAT('entry {0:0.00}\nstop {1:0.00}',
CLOSE, LLV(LOW, 10)));DRAWNUMBER(COND, PRICE, NUMBER, DECIMAL)Write NUMBER at PRICE where COND holds, to DECIMAL decimal places.
- COND(condition)
- Which bars get a number.
- PRICE(series)
- The level the number is anchored to.
- NUMBER(series)
- The value to write.
- DECIMAL(integer)
- Decimal places to show.
// today's percentage change above the bar
DRAWNUMBER(ISLASTBAR, HIGH, (CLOSE - OPEN) / OPEN * 100, 2), DRAWABOVE;
// label every swing high with its price — no VAR2STR needed,
// the formatting is built in
DRAWNUMBER(HIGH >= HHV(HIGH, 20), HIGH, HIGH, 2), COLORYELLOW, DRAWABOVE;DRAWNUMBER_FIX(COND, X, Y, TYPE, NUMBER, DECIMAL)Write NUMBER at a fixed pane position, coordinates and TYPE as DRAWTEXT_FIX.
- COND(condition)
- When to draw — usually ISLASTBAR.
- X(float)
- Horizontal position as a fraction of pane width, 0–1.
- Y(float)
- Vertical position as a fraction of pane height, 0–1.
- TYPE(integer)
- Alignment: 0 left, 1 right, 2 centre.
- NUMBER(series)
- The value to write.
- DECIMAL(integer)
- Decimal places to show.
// a fixed-corner stat block: label on the left, value beside it
DRAWTEXT_FIX(ISLASTBAR, 0.02, 0.05, 0, 'ATR'), COLORGRAY;
DRAWNUMBER_FIX(ISLASTBAR, 0.12, 0.05, 0, EXPMEMA(TR, 14), 2), COLORWHITE;DRAWNUMBER_DIF(COND, STEP, START, COUNT)From the bar where COND holds, label COUNT consecutive bars with an increasing number starting at START, stepping by STEP.
Numbers sit under the low by default; add DRAWABOVE to move the whole run above the high. This is how a nine-count sequence is drawn.
- COND(condition)
- Where the counted run starts.
- STEP(integer)
- How much the number increases per bar.
- START(integer)
- The number on the first bar of the run.
- COUNT(integer)
- How many bars to label.
// a nine-count setup: the run starts when the close first
// falls below the close four bars earlier
DOWN := CLOSE < REF(CLOSE, 4);
SETUP_START := DOWN AND NOT(REF(DOWN, 1));
DRAWNUMBER_DIF(SETUP_START, 1, 1, 9), COLORLIBLUE;
// the mirror image, counted above the highs
UP := CLOSE > REF(CLOSE, 4);
TOP_START := UP AND NOT(REF(UP, 1));
DRAWNUMBER_DIF(TOP_START, 1, 1, 9), COLORRED, DRAWABOVE;DRAWICON(COND, PRICE, ICON)Draw icon number ICON at PRICE where COND holds. ICON may be a number or 'ICO<n>'.
Use 85 for buy markers and 97 for sell markers — signal scanning and alerts key off those numbers.
- COND(condition)
- Which bars get an icon.
- PRICE(series)
- The level the icon is anchored to.
- ICON(integer)
- Icon number 1–117, or the string form 'ICO85'. See the Constants section for the full table.
// the platform-standard buy / sell pair — keep these two
// numbers, or scanning and alerts will not recognise the signal
DRAWICON(CROSS(DIF, DEA), LOW, 85), VALIGN2;
DRAWICON(CROSS(DEA, DIF), HIGH, 97), VALIGN0;
// FILTER stops the marker repeating through one long trend
ENTRY := FILTER(CLOSE > MA(CLOSE, 20), 10);
DRAWICON(ENTRY, LOW, 85);ICON(POSITION, ICON)Modifier form used after a condition: POSITION 1 anchors to the high, 0 to the low.
- POSITION(integer)
- 1 anchors the icon to the high, 0 to the low.
- ICON(integer)
- Icon number, or the string form 'ICO1'.
// a modifier, not a call: the condition comes first and the
// icon follows after the comma
CLOSE > OPEN, ICON(1, 'ICO1'), VALIGN0;
// the DRAWICON equivalent, which reads better when the
// anchor price is not simply the high or the low
DRAWICON(CLOSE > OPEN, HIGH, 1);TIPICON(COND, PRICE, ICON, TEXT)An icon that reveals TEXT as a tooltip on hover.
- COND(condition)
- Which bars get the icon.
- PRICE(series)
- The level the icon is anchored to.
- ICON(integer)
- Icon number, as DRAWICON.
- TEXT(string)
- Tooltip shown on hover.
// the marker stays small; the reasoning lives in the tooltip
SIG := CROSS(MA5, MA20) AND VOL > MA(VOL, 20) * 2;
TIPICON(SIG, LOW, 85,
STRFORMAT('cross on {0:0.0}x volume', VOL / MA(VOL, 20)));DRAWLASTBARICON(PRICE, ICON)Draw an icon at PRICE on the most recent bar only.
- PRICE(series)
- The level the icon is anchored to.
- ICON(integer)
- Icon number, as DRAWICON.
// same as DRAWICON(ISLASTBAR, …) but without the condition —
// use it for "current state" markers rather than signals
DRAWLASTBARICON(HIGH, 1);DRAWLASTBARTEXT(PRICE, TEXT)Write TEXT at PRICE on the most recent bar only.
- PRICE(series)
- The level the text is anchored to.
- TEXT(string)
- What to write.
// a right-edge label that follows the last bar as it moves
DRAWLASTBARTEXT(MA(CLOSE, 20), 'MA20'), COLORYELLOW, ALIGN0;DRAWLASTBARNUMBER(PRICE, NUMBER, PRECISION, COLOR)Write NUMBER at PRICE on the most recent bar, to PRECISION decimals.
- PRICE(series)
- The level the number is anchored to.
- NUMBER(series)
- The value to write.
- PRECISION(integer)
- Decimal places to show.
- COLOR(color)
- Text colour — passed as an argument here, not as a modifier.
// the colour is an argument, so it can differ per line
// without repeating a modifier on each one
DRAWLASTBARNUMBER(HIGH, (CLOSE - OPEN) / OPEN * 100, 2, COLORRED), ALIGN0;
DRAWLASTBARNUMBER(MA(CLOSE, 20), MA(CLOSE, 20), 2, COLORYELLOW), ALIGN0;