Indicators & Strategy
Pine Script Basics: Write Your First TradingView Indicator in 15 Minutes
Pine Script is TradingView's purpose-built language for trading; the v6 engine compiles fast, and the community already has 150k+ public scripts. You don't need a programming background — every line below is explained; copy it and it runs.
Open the editor
Open the Pine Editor from the bottom panel, create a blank indicator, and replace the default with:
//@version=6
indicator("Dual EMA", overlay = true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
plot(fast, color = color.purple, title = "EMA 9")
plot(slow, color = color.gray, title = "EMA 21")
crossUp = ta.crossover(fast, slow)
plotshape(crossUp, style = shape.triangleup,
location = location.belowbar, color = color.green)
Line by line
//@version=6: declares v6 syntax — don't omit it;indicator("Dual EMA", overlay = true): this is an indicator (not a strategy);overlay=truedraws it on the main chart rather than a separate pane;ta.ema(close, 9): a 9-period EMA of close, assigned tofast;plot(): draws a series as a line;ta.crossover(fast, slow): true on the bar where fast crosses above slow;plotshapedraws a green triangle below that bar.
Run and save
- Click Add to chart — the two EMAs and cross markers appear immediately;
- Errors show a line number, usually a typo or indentation — Pine is indentation-sensitive;
- Save and name it; the script joins your indicator library, usable on any device you sign in on.
Next
Turning 9/21 into adjustable input.int() parameters is the natural second lesson; to test whether EMA crosses actually make money, swap indicator for strategy — see the backtesting guide.
Tip: on desktop you can tear the Pine Editor into its own window on a second screen — code on the left, result on the right, far comfier than a top/bottom split.