The DRAWRAY function in ProBuilder language is used to plot a ray on a chart. A ray is a line segment that starts at a specified point and extends infinitely in one direction. This function is particularly useful for highlighting trends or potential levels of support and resistance on a price chart.
DRAWRAY(x1, y1, x2, y2) COLOURED(R, G, B, a)
The DRAWRAY function requires four coordinates: x1 and y1 define the starting point of the ray, while x2 and y2 indicate the direction in which the ray extends. The ray will extend towards the direction of the second point from the first point. The COLOURED function is optional and can be used to specify the color and transparency of the ray using RGB color values and an alpha (transparency) value.
To demonstrate the use of DRAWRAY, consider plotting two trend lines based on the highest high and lowest low over a certain period:
defparam drawonlastbaronly = true
period = 70
if islastbarupdate then
y2 = lowest[period](low)
yy2 = highest[period](high)
// Find the bar index of the highest high and lowest low for the period
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
// Find the bar index of the highest high and lowest low for half the period
for i = 0 to round(period/2) do
if low[i] < y2 then
y1 = low[i]
x1 = barindex[i]
else
y1 = low
x1 = barindex
endif
if high[i] > yy2 then
yy1 = high[i]
xx1 = barindex[i]
else
yy1 = high
xx1 = barindex
endif
next
// Plot the two half segments (rays)
DRAWray(x1, y1, x2, y2) coloured(255, 10, 10)
DRAWray(xx1, yy1, xx2, yy2) coloured(255, 10, 10)
endif
This example sets up two rays based on dynamic calculations of highs and lows over a specified period and half of that period. The rays are colored red with RGB values (255, 10, 10).
This function is a powerful tool in technical analysis for visualizing and extending key levels or trends directly on trading charts.