crossLine

A cross line lets you place a crosshair (both vertical and horizontal line) at a specific point in time and price. It’s like dropping a temporary cursor on the chart to mark an exact candle and level. Very useful for highlighting key points where price reacted.

Syntax

crossLine(time, price, styles?)

Parameters

  • time: The candle time where the cross should appear (for example, time(0) for the current candle).

  • price: The price level where the cross should be drawn (for example, closeC(0) for the current closing price).

  • styles (optional) Settings to control how the cross looks:

    • linecolor: color of the cross lines (e.g., color.yellow)

    • linewidth: thickness of the lines

    • linestyle: solid, dashed, dotted

Return Value

  • string — A unique drawing id.

Example

This script will draw a cross every 50 candles at the current candle close price. We’ll add detailed comments so you understand every step.

//@version=1
init = () => {
    // Place the drawings on the main price chart
    indicator({ onMainPanel: true, format: 'inherit' });
};

onTick = () => {
    // Every 50 candles, place a cross marker
    if (index % 50 === 0) {
        // Get the time of the current candle
        const time_cross = time(0);

        // Get the current candle closing price
        const price_cross = closeC(0);

        // Draw a cross at (time = current candle, price = close price)
        // - Cross color: orange
        // - Line thickness: 2
        // - Line style: dashed
        crossLine(
            time_cross,
            price_cross,
            { linecolor: color.yellow, linewidth: 2 , linestyle: 2 }
        );
    }
};

This will place a neat yellow cross marker every 50 candles, showing exactly where the close price was at that point in time.

Result

Tips

  • Crosses are great to “pin” exact price reactions, like when testing levels or marking trade entries/exits.

  • Use them sparingly, or your chart may look like a grid of crosses.

Warning

Good Practice

Last updated