DRAWTRIANGLE
DRAWTRIANGLE in ProBuilder draws a triangle from three vertices given as bar index and price coordinates, with an optional COLOURED colour and transparency.
Syntax
DRAWTRIANGLE(x1, y1, x2, y2, x3, y3) COLOURED(R, G, B, a)Parameters
| Name | Type | Default | Description |
|---|---|---|---|
x1, y1 | integer, price | required | Bar index and price of the first vertex. |
x2, y2 | integer, price | required | Bar index and price of the second vertex. |
x3, y3 | integer, price | required | Bar index and price of the third vertex. |
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
DRAWTRIANGLE runs inside a ProBuilder indicator. It connects three vertices (x1, y1), (x2, y2) and (x3, y3) into a closed triangle. Each x is a bar index on the horizontal axis and each y is a price on the vertical axis, so the vertices can be placed at swing highs, swing lows or the current bar. This suits marking patterns such as wedges or measured moves.
The optional COLOURED clause sets colour and transparency. Because the triangle is redrawn on every bar, scripts usually set DEFPARAM DrawOnLastBarOnly = true so it is drawn once.
Examples
Example 1, Triangle from period extremes (Indicator)
// Vertices at the highest high, the lowest low and the current low
DEFPARAM DrawOnLastBarOnly = true
period = 20
hh = Highest[period](high)
ll = Lowest[period](low)
FOR i = 1 TO period DO
IF high[i] = hh THEN
x1 = BarIndex[i]
ENDIF
IF low[i] = ll THEN
x2 = BarIndex[i]
ENDIF
NEXT
DRAWTRIANGLE(x1, hh, x2, ll, BarIndex, low) COLOURED(200, 120, 120, 255)
RETURNThe loop locates the bars of the extreme prices and the triangle links them to the current low.
Example 2, A fixed triangle marker (Indicator)
// A small blue triangle above the current bar
DEFPARAM DrawOnLastBarOnly = true
DRAWTRIANGLE(BarIndex-1, high, BarIndex+1, high, BarIndex, high + 5 * pointsize) COLOURED(0, 120, 255)
RETURNThree vertices set by offsets from the current bar produce a compact pointer.
Example 3, Filled triangle (Indicator)
// Outline in green, interior filled light green
DEFPARAM DrawOnLastBarOnly = true
DRAWTRIANGLE(BarIndex-5, low, BarIndex, high, BarIndex+5, low) COLOURED(0, 180, 0) FILLCOLOR(200, 255, 200)
RETURNFILLCOLOR shades the interior while COLOURED sets the border.
Common errors and gotchas
- Indicator only.
DRAWTRIANGLEhas no effect in ProScreener, ProOrder or ProBacktest. Keep it in a ProBuilder indicator. - Six values, three vertices. The arguments pair up as three
(x, y)vertices. Miscounting them shifts the shape. - X is a bar index. Passing a price into any x argument misplaces that vertex. Use
BarIndexor offsets from it. - Redraw cost. Without
DrawOnLastBarOnly = true, the triangle is drawn on every bar and slows the chart.
Related instructions
DRAWRECTANGLE, draws a four-corner box.DRAWELLIPSE, draws an ellipse in a bounding box.DRAWLINE, draws a line between two points.COLOURED, sets the outline colour and transparency.FILLCOLOR, sets the interior fill colour.DrawOnLastBarOnly, restricts drawing to the last bar for performance.BarIndex, supplies the x coordinates.Highest, finds a vertex price to use.
