trendLine

Draw a simple line between two chart points to highlight a trend (for example, from a swing low to a swing high). You can also style the line and (optionally) show a small label on it. The function returns an id so you can update or delete the drawing later.

Syntax

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

Parameters

  • fromPoint { time, price }: A point object with time and price, e.g. newPoint(time, price). This is where the line starts.

  • toPoint { time, price }: A point object with time and price. This is where the line ends.

  • styles (optional) Visual options for the line. Common fields you might use:

    • linecolor: line color (supports named colors like color.blue or RGBA via color.rgba(r,g,b,a))

    • linewidth: line thickness (number)

    • linestyle: line style (number; e.g., solid/dashed)

    • extendRight / extendLeft: keep the line extending beyond your points (boolean)

    • showLabel: show the text label if you pass text (boolean) (Full list available in BasicLineToolOverrides.)

  • text string (optional): A short label that appears on the line (set styles.showLabel = true to display it).

Helper you’ll use

  • newPoint(time, price) → returns a { time, price } point for drawing tools. Use it to build fromPoint and toPoint.

Return Value

  • string — The unique drawing id. Save this if you plan to update or delete the line later with updateDrawingById(id, newData) or deleteDrawingById(id).

Example

Create a blue upward trend line from an older low to a newer high, extend it to the right, and add a label:

Result

Tips

  • Need a custom color? Use color.rgba(r, g, b, a) like color.rgba(0, 128, 255, 0.9) for semitransparent lines.

  • Keep your labels short (a word or two) so they don’t clutter the chart.

  • Save the returned id if you’ll move or remove the line later with updateDrawingById or deleteDrawingById.

Warning

Good Practice

Last updated