DRAWTEXT
DRAWTEXT in ProBuilder prints a text label on the chart at a bar index and price, with optional font, style, size and COLOURED colour. Syntax and worked examples.
Syntax
DRAWTEXT("text", x1, y1, font, style, size) COLOURED(R, G, B, a)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
"text" | string | required | The text to display, in quotation marks. Variables can be embedded between # symbols. |
x1 | integer | required | Bar index where the text starts. |
y1 | price | required | Price or vertical value where the text is placed. |
font | keyword | Dialog | Optional font: Dialog, Monospaced, Serif, SansSerif. |
style | keyword | Standard | Optional style: Standard, Bold, Italic, BoldItalic. Requires font. |
size | integer | 10 | Optional font size, 10 to 30. Requires font and style. |
R, G, B, a | integer | platform default | Optional COLOURED colour and alpha, 0 to 255 each. |
How it works
DRAWTEXT runs inside a ProBuilder indicator. It prints a string on the chart anchored at (x1, y1), where x1 is a bar index and y1 is a price. It is used to annotate levels, values or conditions. A variable can be shown inside the text by wrapping its name in #, for example "High: #highPrice#" prints the value of highPrice.
The optional font, style and size arguments follow the coordinates, and each later one requires the ones before it. The COLOURED clause sets the text colour and transparency. For a single caption on the current bar, set DEFPARAM DrawOnLastBarOnly = true.
Examples
Example 1, Label the current high (Indicator)
// Print "High Price" at the high of the current bar in red
highPrice = high
DRAWTEXT("High Price", BarIndex, highPrice) COLOURED(255, 0, 0, 255)
RETURNThe label sits at the high of each bar, coloured solid red.
Example 2, Embed a value in the text (Indicator)
// Show the numeric high inside the label, once on the last bar
DEFPARAM DrawOnLastBarOnly = true
highPrice = high
DRAWTEXT("High: #highPrice#", BarIndex, highPrice, SansSerif, Bold, 12) COLOURED(0, 0, 0)
RETURNThe #highPrice# placeholder is replaced by the actual value, shown in bold 12-point SansSerif.
Example 3, Caption a drawn line (Indicator)
// Draw a level and label it
DEFPARAM DrawOnLastBarOnly = true
lvl = Highest[20](high)
DRAWHLINE(lvl) COLOURED(0, 150, 0)
DRAWTEXT("20-bar high", BarIndex, lvl) COLOURED(0, 150, 0)
RETURNDRAWTEXT names the level drawn by DRAWHLINE.
Common errors and gotchas
- Indicator only.
DRAWTEXThas no effect in ProScreener, ProOrder or ProBacktest. Keep it in a ProBuilder indicator. - Optional arguments are ordered. To set
sizeyou must also passfontandstylebefore it. Skipping one shifts the rest. - Variable placeholders use
#. To print a value, wrap the variable name in#. Writing the name plainly prints it as literal text. - X is a bar index. Passing a price into
x1misplaces the text horizontally. UseBarIndex.
Related instructions
DRAWLINE, draws a line thatDRAWTEXTcan annotate.DRAWPOINT, a marker that a label can accompany.DRAWARROWUP, an arrow that a label can accompany.COLOURED, sets the text colour and transparency.DrawOnLastBarOnly, restricts drawing to the last bar.BarIndex, supplies the x coordinate.STRINGFORMAT, builds text strings for display.NUMBERFORMAT, formats a number before embedding it in text.
