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
DRAWRAY(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 a second point that sets the direction. |
y2 | price | required | Y coordinate of the second 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
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)
// 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)
RETURNThe ray starts 40 bars back and continues past the current bar, projecting the slope forward.
Example 2, Rays from period extremes (Indicator)
// 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
RETURNGuarding 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)
// 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)
RETURNBecause both y values are equal, the ray is horizontal and extends to the right of the start point.
Common errors and gotchas
- Indicator only.
DRAWRAYhas 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
x1orx2misplaces the ray. UseBarIndexor offsets from it. - Bounded alternatives. For a line that stops at both points, use
DRAWLINEorDRAWSEGMENTinstead.
Related instructions
DRAWLINE, a line bounded by its two points.DRAWSEGMENT, a segment between two points.DRAWHLINE, a horizontal line at one price.DRAWVLINE, a vertical line at one bar index.COLOURED, sets colour and transparency.DrawOnLastBarOnly, restricts drawing to the last bar for performance.IsLastBarUpdate, runs a block once on the last bar.BarIndex, supplies the x coordinates.
