Example scripts
Ten examples ship with the editor. Open one from Open ▾ → Examples, or from the Indicators list under My scripts. Each one is run by an automated test, so a change to the language cannot quietly break it.
| Example | What it shows |
|---|---|
| EMA Cross | Two EMAs with buy and sell markers where they cross. |
| RSI with Bands | RSI in its own pane with overbought and oversold levels. |
| Bollinger Bands | Bands around a moving average, with the space between shaded. |
| MACD Histogram | MACD with a histogram that is brighter while momentum grows. |
| ATR Channel | A moving average with bands a multiple of ATR away. |
| Daily Open | A line at each day's opening price, restarting every day. |
| Higher-Timeframe EMA | An EMA from a higher timeframe, shown only once that timeframe's bar has closed. |
| Swing Pivots | Labels each swing high and low once enough bars have passed to confirm it. |
| Heikin Ashi Candles | Smoothed Heikin Ashi candles in their own pane, built with plotcandle. |
| Inside Bar | Highlights bars that trade entirely inside the previous bar. |
Recipe: Bollinger Bands
//@version=5
indicator("Bollinger Bands", overlay = true)
len = input.int(20, "Length", minval = 1)
mult = input.float(2.0, "Multiplier", minval = 0.1, step = 0.1)
[basis, upper, lower] = ta.bb(close, len, mult)
plot(basis, "Basis", color.orange)
u = plot(upper, "Upper", color.blue)
l = plot(lower, "Lower", color.blue)
fill(u, l, color.new(color.blue, 90))
Recipe: a line at each day's open
//@version=5
indicator("Daily Open", overlay = true)
newDay = dayofmonth != dayofmonth[1]
var float dailyOpen = na
if newDay
dailyOpen := open
plot(dailyOpen, "Daily open", color.yellow, 2, plot.style_linebr)
Recipe: an RSI pane with shaded zones
//@version=5
indicator("RSI with Bands")
len = input.int(14, "Length", minval = 1)
upper = input.int(70, "Overbought")
lower = input.int(30, "Oversold")
value = ta.rsi(close, len)
plot(value, "RSI", color.purple, 2)
hline(upper, "Overbought", color.red, hline.style_dashed)
hline(lower, "Oversold", color.green, hline.style_dashed)
bgcolor(value > upper ? color.new(color.red, 85) : value < lower ? color.new(color.green, 85) : na)