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
DRAWVLINE(x1) COLOURED(R, G, B, a)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x1 | integer | required | The bar index at which the vertical line is drawn. |
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
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)
// 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)
RETURNThe 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)
// A grey vertical line 50 bars back from the current bar
DEFPARAM DrawOnLastBarOnly = true
DRAWVLINE(BarIndex-50) COLOURED(128, 128, 128, 180)
RETURNA single call marks a bar a fixed distance behind the current one.
Example 3, Vertical line with a caption (Indicator)
// Mark the current bar and label it
DEFPARAM DrawOnLastBarOnly = true
DRAWVLINE(BarIndex) COLOURED(0, 100, 255)
DRAWTEXT("now", BarIndex, close) COLOURED(0, 100, 255)
RETURNDRAWVLINE marks the bar and DRAWTEXT names it.
Common errors and gotchas
- Indicator only.
DRAWVLINEhas 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 useDRAWLINEorDRAWSEGMENT. - X is a bar index, not a price. Passing a price places the line at the wrong bar. Use
BarIndexor an offset from it. - Horizontal counterpart. For a level at a fixed price, use
DRAWHLINEinstead.
Related instructions
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.
