Graphical/probuilder

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

probuilder
DRAWTRIANGLE(x1, y1, x2, y2, x3, y3) COLOURED(R, G, B, a)

Parameters

NameTypeDefaultDescription
x1, y1integer, pricerequiredBar index and price of the first vertex.
x2, y2integer, pricerequiredBar index and price of the second vertex.
x3, y3integer, pricerequiredBar index and price of the third vertex.
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

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)

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

The loop locates the bars of the extreme prices and the triangle links them to the current low.

Example 2, A fixed triangle marker (Indicator)

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

Three vertices set by offsets from the current bar produce a compact pointer.

Example 3, Filled triangle (Indicator)

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

FILLCOLOR shades the interior while COLOURED sets the border.

Common errors and gotchas

  • Indicator only. DRAWTRIANGLE has 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 BarIndex or offsets from it.
  • Redraw cost. Without DrawOnLastBarOnly = true, the triangle is drawn on every bar and slows the chart.