rayLine

Draw a line that starts at one point and keeps going to the right. Use it to project a level or trend into the future (for example, a line that begins at a pivot and extends forward). You can style the line and (optionally) show a short label. The function gives you an id so you can update or delete it later.

Syntax

rayLine(fromPoint, toPoint, styles?, text?)

Parameters

  • fromPoint { time, price } Point where the ray begins. Build it with newPoint(time, price). If you pass text and want to see it, set styles.showLabel = true.

  • toPoint { time, price } A second point that sets the ray’s direction (the ray goes through this point and continues to the right).

  • styles (optional) Look & feel for the line. Common fields include: linecolor, linewidth, linestyle, extendLeft, extendRight, showLabel, textcolor, etc. Colors can be named (like color.blue) or RGBA via color.rgba(r,g,b,a). See BasicLineToolOverrides and the color helpers.

  • text string (optional) Short label attached at the start point. Set styles.showLabel = true to display it.

Helper you’ll use

  • newPoint(time, price) → returns a { time, price } point.

Return Value

  • string — Unique drawing id. Use it with updateDrawingById(id, data) or deleteDrawingById(id).

Example

//@version=1

init = () => {
    // Configure the indicator:
     // - format: 'inherit' → use the chart’s format (price, decimals, etc.)
    indicator({ onMainPanel: true, format: 'inherit' });
};

onTick = () => {
    // --- Condition to control when to draw ---
    // index is the bar counter. We check "index % 100 === 0":
    // → Only every 100th bar will trigger the drawing.
    if (index % 100 === 0) {
        // time(10), low(10) = 10 bars ago → starting point of the ray (older pivot).
        const start = newPoint(time(10), low(10));

        // time(0), low(0) = current bar’s low → end point, where the ray passes through.
        const end = newPoint(time(0), low(0));

        // --- Draw the ray line ---
        // Style options:
        // - linecolor: red (taken from color set:contentReference[oaicite:1]{index=1})
        // - linewidth: 2 → thicker line
        // - showLabel: true → display a text label on the chart
        // Label: "Support Ray"
        rayLine(
            start,
            end,
            { linecolor: color.red, linewidth: 2, showLabel: true },
            'Support Ray'
        );
    }
};

This draws one tidy ray and simply moves it as new candles arrive—no clutter. rayLine takes two points; the line begins at the first and extends right through the second.

Result

Tips

  • Use a meaningful start like a swing high/low to make the projection intuitive.

  • Prefer named colors (color.blue, color.red) for consistency; switch to color.rgba(...) only when you need transparency.

  • Save the returned id and update it each tick to avoid stacking many drawings. Use updateDrawingById.

Warning

Good Practice

Last updated