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 likecolor.blueor RGBA viacolor.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 passtext(boolean) (Full list available inBasicLineToolOverrides.)
text
string(optional): A short label that appears on the line (setstyles.showLabel = trueto display it).
Helper you’ll use
newPoint(time, price) → returns a
{ time, price }point for drawing tools. Use it to buildfromPointandtoPoint.
Return Value
string — The unique drawing
id. Save this if you plan to update or delete the line later withupdateDrawingById(id, newData)ordeleteDrawingById(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)likecolor.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
idif you’ll move or remove the line later withupdateDrawingByIdordeleteDrawingById.
Warning
Your points must include both
timeandprice. If they’re missing or invalid, the drawing won’t be created (the API validates points before drawing).If you pass
textbut forgetshowLabel: trueinstyles, the label won’t appear.
Good Practice
Snap
fromPoint/toPointto meaningful pivots (e.g., recent swing high/low) for clearer trend visualization.Use
extendRight: trueto project the trend forward—great for seeing where price reacts next.Keep style settings consistent across your scripts (same
linewidth,linestyle) so charts look clean and familiar.
Last updated