002 — Your first indicator
In this lesson, we will create a simple line that follows the closing price.
Complete script
Section titled “Complete script”//@version=6indicator("Close Line", overlay = true)
plot(close, "Close", color = color.blue, linewidth = 2)Copy the complete script into the Pine Editor and add it to a chart.
Line 1: the version annotation
Section titled “Line 1: the version annotation”//@version=6This tells TradingView to compile the script as Pine Script v6. Keep it on the first line.
Line 2: the indicator declaration
Section titled “Line 2: the indicator declaration”indicator("Close Line", overlay = true)Every Pine script needs one declaration statement.
"Close Line"is the indicator’s name.overlay = trueplaces the output in the main price chart.- With
overlay = false, the indicator would normally use a separate pane.
Line 3: the plot
Section titled “Line 3: the plot”plot(close, "Close", color = color.blue, linewidth = 2)The arguments mean:
close: the value to draw on each bar"Close": the plot title shown in settings and the data windowcolor = color.blue: the line colorlinewidth = 2: the line thickness
Modify it
Section titled “Modify it”Try each change separately:
plot(high, "High", color = color.orange, linewidth = 2)plot(low, "Low", color = color.purple, linewidth = 3)You can also plot more than one series:
//@version=6indicator("High and Low", overlay = true)
plot(high, "High", color = color.green)plot(low, "Low", color = color.red)Key idea
Section titled “Key idea”plot() does not draw one fixed line. Pine evaluates the supplied value on every bar. The plotted points are then connected across the chart.