Graphical/probuilder

DRAWRAY

DRAWRAY in ProBuilder draws a ray that starts at one point and extends infinitely through a second point, with an optional COLOURED colour. Syntax and examples.

Syntax

probuilder
DRAWRAY(x1, y1, x2, y2) COLOURED(R, G, B, a)

Parameters

NameTypeDefaultDescription
x1integerrequiredX coordinate of the start point, normally a bar index.
y1pricerequiredY coordinate of the start point, a price or computed value.
x2integerrequiredX coordinate of a second point that sets the direction.
y2pricerequiredY coordinate of the second point.
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

DRAWRAY runs inside a ProBuilder indicator. It draws a half-line that starts at (x1, y1) and passes through (x2, y2), then continues past that second point without stopping. The direction depends on the order of the pairs: if (x1, y1) is to the right of (x2, y2), the ray extends to the left, and vice versa.

This distinguishes DRAWRAY from DRAWLINE and DRAWSEGMENT, which end at their two points. As with other drawing objects, scripts set DEFPARAM DrawOnLastBarOnly = true so the ray is drawn once. The COLOURED clause is optional.

Examples

Example 1, A single projected trend line (Indicator)

probuilder
// Ray from a swing low projected forward through the current low
DEFPARAM DrawOnLastBarOnly = true
DRAWRAY(BarIndex-40, low[40], BarIndex, low) COLOURED(0, 120, 255)
RETURN

The ray starts 40 bars back and continues past the current bar, projecting the slope forward.

Example 2, Rays from period extremes (Indicator)

probuilder
// Two red rays built from the highest high and lowest low over a period
DEFPARAM DrawOnLastBarOnly = true
period = 70
IF IsLastBarUpdate THEN
    y2 = Lowest[period](low)
    yy2 = Highest[period](high)
    FOR i = 0 TO period DO
        IF low[i] = y2 THEN
            x2 = BarIndex[i]
        ENDIF
        IF high[i] = yy2 THEN
            xx2 = BarIndex[i]
        ENDIF
    NEXT
    x1 = BarIndex
    y1 = low
    xx1 = BarIndex
    yy1 = high
    DRAWRAY(x1, y1, x2, y2) COLOURED(255, 10, 10)
    DRAWRAY(xx1, yy1, xx2, yy2) COLOURED(255, 10, 10)
ENDIF
RETURN

Guarding the calculation with IsLastBarUpdate runs the loop only once. Each ray is anchored at a period extreme and projected through the current bar.

Example 3, Horizontal ray as an open-ended level (Indicator)

probuilder
// A grey ray at a fixed price extending to the right
DEFPARAM DrawOnLastBarOnly = true
DRAWRAY(BarIndex-10, close[10], BarIndex, close[10]) COLOURED(128, 128, 128)
RETURN

Because both y values are equal, the ray is horizontal and extends to the right of the start point.

Common errors and gotchas

  • Indicator only. DRAWRAY has no effect in ProScreener, ProOrder or ProBacktest. Keep it in a ProBuilder indicator.
  • Direction depends on point order. Swapping the two points reverses the direction the ray extends. Check which pair is the anchor.
  • X is a bar index. Passing a price into x1 or x2 misplaces the ray. Use BarIndex or offsets from it.
  • Bounded alternatives. For a line that stops at both points, use DRAWLINE or DRAWSEGMENT instead.