DRAWSEGMENT
DRAWSEGMENT in ProBuilder draws a line segment between two chart points given as bar index and price coordinates, with an optional COLOURED colour.
Syntax
DRAWSEGMENT(x1, y1, x2, y2) COLOURED(R, G, B, a)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x1 | integer | required | X coordinate of the start point, normally a bar index. |
y1 | price | required | Y coordinate of the start point, a price or computed value. |
x2 | integer | required | X coordinate of the end point. |
y2 | price | required | Y coordinate of the end 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
DRAWSEGMENT is an indicator instruction. It draws a straight segment from the start point (x1, y1) to the end point (x2, y2). The x values are bar indices along the horizontal axis and the y values are prices on the vertical axis. Unlike DRAWRAY, the segment ends exactly at its two points and does not extend past them.
The x coordinates typically come from BarIndex, and the y coordinates from prices or indicator values. Because the object is redrawn on each bar, most scripts set DEFPARAM DrawOnLastBarOnly = true so the segment is drawn once. The COLOURED clause is optional and sets colour and transparency.
Examples
Example 1, A single coloured segment (Indicator)
// A semi-transparent red horizontal segment between two fixed points
DRAWSEGMENT(BarIndex-90, close, BarIndex, close) COLOURED(255, 0, 0, 150)
RETURNPreserved from the source idea: a segment drawn between two coordinate pairs, coloured red at partial opacity.
Example 2, Trend segment between two lows (Indicator)
// Connect the two most recent lows within 30 bars
DEFPARAM DrawOnLastBarOnly = true
period = 30
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
DRAWSEGMENT(x1, y1, x2, y2) COLOURED(0, 120, 255)
RETURNThe loop finds two low points and the segment links them as a support line.
Example 3, Segment plus a label (Indicator)
// Segment from the recent high to the current close, with a caption
DEFPARAM DrawOnLastBarOnly = true
hh = Highest[20](high)
DRAWSEGMENT(BarIndex-20, hh, BarIndex, close) COLOURED(200, 120, 0)
DRAWTEXT("range", BarIndex, close) COLOURED(200, 120, 0)
RETURNDRAWSEGMENT and DRAWTEXT combine to mark and annotate the same area.
Common errors and gotchas
- Indicator only.
DRAWSEGMENTdoes nothing in ProScreener, ProOrder or ProBacktest. Keep it in a ProBuilder indicator. - X is a bar index. Passing a price into
x1orx2misplaces the segment. UseBarIndexor offsets from it. - Redraw cost. Without
DrawOnLastBarOnly = true, the segment is drawn on every bar and slows the chart. - Bounded segment. It stops at its endpoints. For a line that extends past the second point use
DRAWRAY.
Related instructions
DRAWLINE, draws a line between two points, close in behaviour toDRAWSEGMENT.DRAWHLINE, a horizontal line at one price level.DRAWVLINE, a vertical line at one bar index.DRAWRAY, extends beyond its second point.COLOURED, sets colour and transparency.DrawOnLastBarOnly, restricts drawing to the last bar for performance.BarIndex, supplies the x coordinates.DRAWTEXT, adds a caption to the segment.
