line

This adds a line on your chart that moves with your data. It’s the most common way to show things like moving averages, signals, or any custom calculation. For example, you can plot a 14-period moving average or draw your custom indicator line on top of price.

Syntax

plot.line(title, value, color, plottype?, id?)

Parameters

  • title string — Name of the line (shown in settings).

  • value number — The number you want to plot (for example: close, sma, rsi).

  • color string — Line color, like "red" or "rgba(0,255,0,0.5)".

  • plottype number (optional) — How the line is drawn (usually just leave it as default).

    • plottype- number, one of the following:

      • 0- line

      • 1- histogram

      • 3- cross

      • 4- area

      • 5- columns

      • 6- circles

      • 7- line with breaks

      • 8- area with breaks

      • 9- step line

  • id string (optional) — Custom identifier (helpful if you want to link it later, for example with filledArea).

Return Value

{ value: number; id: string } — Echoes the value and the final id assigned to the plot.

Example

Result

Tips

  • Give lines clear names like “Fast MA” or “RSI Signal” so users know what they see.

  • If you only need one line, don’t worry about id. If you want to connect it with another plot (like filling the area between two lines), give it a custom id.

Warning

Good Practice

Last updated