Pine Script for beginners: write your first indicator
Pine Script is TradingView's purpose-built language for writing custom indicators and strategies. You don't need to be a programmer — start by tweaking existing code and you'll pick it up.
A minimal indicator
Open the Pine Editor at the bottom of the chart and paste this — it draws two EMAs on the main chart:
//@version=6
indicator("My first indicator", overlay=true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
plot(fast, color=color.aqua)
plot(slow, color=color.orange)
Click "Add to chart" and the two lines appear.
Line by line
//@version=6: declares the Pine version, always first;indicator(..., overlay=true): declares an indicator;overlay=truedraws on the main chart (else a separate pane, like MACD);ta.ema(close, 9): a 9-period EMA of the close;plot(...): draws the result on the chart.
Where to go next
The fastest progress is editing existing scripts: change 9 and 21 to your preferred numbers, or add a line to mark crosses. Dig into the official Pine docs and browse community scripts for ideas. When it's ready, you can publish it.
Key takeaways
- Structure: version → indicator() → calculations → plot().
- overlay=true draws on the main chart, false in a separate pane.
- Start by editing existing scripts — that's the fastest path.
Edit and backtest scripts on desktop for faster feedback.
Download the desktop app, free