DRAWLINE
DRAWLINE in ProBuilder draws a straight line between two chart points given as bar index and price coordinates, with an optional COLOURED colour. Syntax and examples.
Syntax
DRAWLINE(x1, y1, x2, y2) COLOURED(R, G, B, a)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x1 | integer | required | X coordinate of the first point, normally a bar index such as BarIndex. |
y1 | price | required | Y coordinate of the first point, a price or computed value. |
x2 | integer | required | X coordinate of the second point. |
y2 | price | required | Y coordinate of the second point. |
R, G, B | integer | platform default | Optional COLOURED red, green and blue components, 0 to 255. |
a | integer | 255 | Optional alpha (transparency), 0 fully transparent to 255 fully opaque. |
How it works
DRAWLINE runs inside a ProBuilder indicator. On each bar the platform draws a straight line between the two coordinate pairs (x1, y1) and (x2, y2). The x coordinates are bar indices, so BarIndex and BarIndex-1 place the ends at specific bars, while the y coordinates are prices on the vertical axis.
The line spans exactly the two points given, unlike DRAWRAY, which extends beyond them. Because drawing on every bar repeats the same object many times, most scripts prefix the code with DEFPARAM DrawOnLastBarOnly = true so the line is drawn once, on the current bar.
The optional COLOURED clause sets the colour. When it is omitted the platform default colour is used.
Examples
Example 1, Fibonacci pivot lines (Indicator)
// Draw pivot and Fibonacci support/resistance as short horizontal lines
DEFPARAM DrawOnLastBarOnly = true
dh = DHigh(1)
dl = DLow(1)
P = (dh + dl + DClose(1)) / 3
R1 = P + 0.382 * (dh - dl)
S1 = P - 0.382 * (dh - dl)
DRAWLINE(BarIndex-1, P, BarIndex, P) COLOURED(153, 153, 0)
DRAWLINE(BarIndex-1, R1, BarIndex, R1) COLOURED(0, 153, 0)
DRAWLINE(BarIndex-1, S1, BarIndex, S1) COLOURED(153, 0, 0)
RETURNEach line runs from the previous bar to the current bar at a fixed price, so it reads as a short level marker.
Example 2, Connect two recent lows (Indicator)
// Draw a line between the two most recent lowest points over 20 bars
DEFPARAM DrawOnLastBarOnly = true
period = 20
y2 = Lowest[period](low)
FOR i = 0 TO period DO
IF low[i] = y2 THEN
x2 = BarIndex[i]
ELSIF low[i] < y2 THEN
y1 = low[i]
x1 = BarIndex[i]
ENDIF
NEXT
DRAWLINE(x1, y1, x2, y2)
RETURNThe loop locates the bar indices of two low points, then a single DRAWLINE connects them as a trend line.
Example 3, Mark a fixed distance (Indicator)
// A green line from 10 bars back at the low to the current close
DEFPARAM DrawOnLastBarOnly = true
DRAWLINE(BarIndex-10, low[10], BarIndex, close) COLOURED(0, 200, 0, 200)
RETURNA minimal call using literal offsets for the x coordinates and prices for the y coordinates.
Common errors and gotchas
- Indicator only.
DRAWLINEhas no effect in ProScreener, ProOrder or ProBacktest. Keep drawing code in a ProBuilder indicator. - X is a bar index, not a price. A common mistake is passing a price into
x1orx2. The x coordinates locate bars on the horizontal axis, useBarIndexor offsets from it. - Redraw cost. Without
DrawOnLastBarOnly = true, the line is drawn on every historical bar, which slows the chart. Set it once at the top of the script. - Bounded, not infinite.
DRAWLINEstops at its two points. For a line that extends past them useDRAWRAY.
Related instructions
DRAWSEGMENT, draws a line segment between two points, close in behaviour toDRAWLINE.DRAWHLINE, a horizontal line at one price level.DRAWVLINE, a vertical line at one bar index.DRAWRAY, a line that extends beyond its second point.COLOURED, sets the colour and transparency of the line.DrawOnLastBarOnly, restricts drawing to the last bar for performance.BarIndex, supplies the x coordinates.DRAWTEXT, labels the line with text.
