Start
Quickstart
Write, run and save your first indicator, then turn it into something you would actually trade with.
This page builds one script in four small steps. Run each step to see what changed.
1. The smallest script that draws#
Every script starts with a version line and a declaration. indicator() says this is an indicator; overlay = true puts it on the price chart instead of in its own pane.
//@version=6indicator("My first script", overlay = true)plot(ta.sma(close, 20), "SMA 20", color = color.orange)close is the closing price of each bar. ta.sma(close, 20) averages the last 20 closes. plot() draws the result as a line.
2. Make the length adjustable#
Hard-coded numbers become inputs. Each input.* call adds a field to the indicator's settings, so you can change it without editing code.
//@version=6indicator("Adjustable average", overlay = true)length = input.int(20, "Length", minval = 1)src = input.source(close, "Source")plot(ta.sma(src, length), "SMA", color = color.orange, linewidth = 2)3. Mark the crosses#
Signals are conditions. ta.crossover(a, b) is true on the bar where a moves above b. plotshape draws a marker on those bars.
//@version=6indicator("Cross markers", overlay = true)fast = ta.ema(close, 9)slow = ta.ema(close, 21)plot(fast, "Fast", color = color.teal)plot(slow, "Slow", color = color.red)plotshape(ta.crossover(fast, slow), "Bull cross", style = shape.triangleup, location = location.belowbar, color = color.teal, size = size.small)plotshape(ta.crossunder(fast, slow), "Bear cross", style = shape.triangledown, location = location.abovebar, color = color.red, size = size.small)4. A separate pane#
An oscillator lives in its own pane. Drop overlay = true (it defaults to false) and add reference lines with hline.
//@version=6indicator("RSI with zones")r = ta.rsi(close, 14)plot(r, "RSI", color = color.purple, linewidth = 2)hline(70, "Overbought", color = color.red)hline(30, "Oversold", color = color.teal)Save it, then use it#
In the terminal's editor:
- Add to chart (Ctrl Enter) runs the script on the chart you are looking at.
- Save (Ctrl S) stores it in your account, so it is there next session.
- The indicator's settings (the gear in its legend) show the inputs from step 2.
- Publish shares it. See Publish and sell.
Next, read How a script runs. It explains close[1], var and na, which is where most first scripts go wrong.