Graphical/probuilder

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

probuilder
DRAWLINE(x1, y1, x2, y2) COLOURED(R, G, B, a)

Parameters

NameTypeDefaultDescription
x1integerrequiredX coordinate of the first point, normally a bar index such as BarIndex.
y1pricerequiredY coordinate of the first point, a price or computed value.
x2integerrequiredX coordinate of the second point.
y2pricerequiredY coordinate of the second point.
R, G, Bintegerplatform defaultOptional COLOURED red, green and blue components, 0 to 255.
ainteger255Optional 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)

probuilder
// 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)
RETURN

Each 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)

probuilder
// 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)
RETURN

The 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)

probuilder
// 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)
RETURN

A minimal call using literal offsets for the x coordinates and prices for the y coordinates.

Common errors and gotchas

  • Indicator only. DRAWLINE has 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 x1 or x2. The x coordinates locate bars on the horizontal axis, use BarIndex or 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. DRAWLINE stops at its two points. For a line that extends past them use DRAWRAY.
  • DRAWSEGMENT, draws a line segment between two points, close in behaviour to DRAWLINE.
  • 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.