Graphical/probuilder

DRAWVLINE

DRAWVLINE in ProBuilder draws a vertical line at a given bar index, with an optional COLOURED colour and transparency. Syntax, parameters and worked examples.

Syntax

probuilder
DRAWVLINE(x1) COLOURED(R, G, B, a)

Parameters

NameTypeDefaultDescription
x1integerrequiredThe bar index at which the vertical line is drawn.
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

DRAWVLINE runs inside a ProBuilder indicator. It draws a vertical line that spans the chart from top to bottom at the bar index x1. Only an x coordinate is needed, since a vertical line has no start or end price. This makes it convenient for marking a moment in time, such as the bar of the highest high or a session boundary.

The x value is normally a bar index taken from BarIndex. The optional COLOURED clause sets colour and transparency. Because one line covers the full height, most scripts set DEFPARAM DrawOnLastBarOnly = true so it is drawn once rather than on every bar.

Examples

Example 1, Mark the bars of the recent high and low (Indicator)

probuilder
// Green line on the highest bar, red line on the lowest bar over 15 bars
DEFPARAM DrawOnLastBarOnly = true
period = 15
Yhh = Highest[period](high)
Yll = Lowest[period](low)
FOR i = 0 TO period DO
    IF high[i] = Yhh THEN
        Xhh = BarIndex[i]
    ENDIF
    IF low[i] = Yll THEN
        Xll = BarIndex[i]
    ENDIF
NEXT
DRAWVLINE(Xhh) COLOURED(0, 200, 0)
DRAWVLINE(Xll) COLOURED(200, 0, 0)
RETURN

The loop locates the bar indices of the extreme prices, then two vertical lines mark them.

Example 2, A line at a fixed bar offset (Indicator)

probuilder
// A grey vertical line 50 bars back from the current bar
DEFPARAM DrawOnLastBarOnly = true
DRAWVLINE(BarIndex-50) COLOURED(128, 128, 128, 180)
RETURN

A single call marks a bar a fixed distance behind the current one.

Example 3, Vertical line with a caption (Indicator)

probuilder
// Mark the current bar and label it
DEFPARAM DrawOnLastBarOnly = true
DRAWVLINE(BarIndex) COLOURED(0, 100, 255)
DRAWTEXT("now", BarIndex, close) COLOURED(0, 100, 255)
RETURN

DRAWVLINE marks the bar and DRAWTEXT names it.

Common errors and gotchas

  • Indicator only. DRAWVLINE has no effect in ProScreener, ProOrder or ProBacktest. Keep it in a ProBuilder indicator.
  • One argument only. It takes a single bar index x1. For a line between two arbitrary points use DRAWLINE or DRAWSEGMENT.
  • X is a bar index, not a price. Passing a price places the line at the wrong bar. Use BarIndex or an offset from it.
  • Horizontal counterpart. For a level at a fixed price, use DRAWHLINE instead.
  • DRAWHLINE, a horizontal line at one price level, the counterpart of this instruction.
  • DRAWLINE, a line between two arbitrary points.
  • DRAWSEGMENT, a segment between two points.
  • COLOURED, sets colour and transparency.
  • DrawOnLastBarOnly, restricts drawing to the last bar for performance.
  • BarIndex, supplies the x coordinate.
  • Highest, finds a recent high to mark.
  • Lowest, finds a recent low to mark.