Documentation
2. Writing Indicators
- Created
- Jun 16, 2026
- Updated
- Jun 16, 2026
A Pine Script indicator begins with an indicator() declaration and uses plot() and other visual functions to draw values on the chart. This page covers what works in Fractal Chart.
A basic indicator
//@version=6
indicator("My MA", overlay=true)
length = input.int(20, "Length")
ma = ta.sma(close, length)
plot(ma, "MA", color.blue)
overlay=true puts the indicator on the price pane. Leave it out (or set overlay=false) to open a new pane below.
Inputs
All input.* types are supported:
| Input function | Control shown |
|---|---|
input.int / input.float | Number field with optional min/max/step |
input.bool | Checkbox |
input.string | Text field; pass options= for a dropdown |
input.color | Color picker |
input.source | Source selector (close, open, hl2, …) |
input.timeframe | Timeframe picker |
input.symbol | Symbol picker |
input.price | Price field |
input.enum | Dropdown from an enum definition |
input() (bare) | Auto-typed from the default value |
Input values appear in the indicator's Settings panel and can be changed without re-saving the script.
Plots
| Function | What it draws |
|---|---|
plot() | Line, histogram, step-line, area, columns, circles, or other styles set via style=plot.style_* |
plotshape() | A shape (triangle, circle, cross, etc.) on the chart |
plotchar() | A Unicode character at each bar |
plotarrow() | An up/down arrow scaled by the value |
plotcandle() | Custom OHLC candles |
plotbar() | Custom OHLCV bars |
hline() | A fixed horizontal line |
fill() | A fill between two plots or two hlines; supports per-bar color and gradients |
bgcolor() | A background color behind the bars |
barcolor() | Recolor the candles |
Per-bar dynamic colors work in all of the above — pass color= a series expression.
Drawing objects
Pine's drawing functions create persistent objects on the chart. They work the same as on TradingView:
- Lines —
line.new(...)with start/end coordinates, color, style, width, andextend.* - Labels —
label.new(...)with text, style, size, color, and placement - Boxes —
box.new(...)with corner coordinates, border style, and background fill - Polylines —
polyline.new(array_of_chart_points, ...)for multi-segment paths - Linefills —
linefill.new(line1, line2, color)to fill between two lines - Tables —
table.new(position, columns, rows)+table.cell(...)for on-chart data tables
All set_* methods work (set_color, set_xy1, set_text, etc.). Objects are capped at 50 per type per script, matching Pine's limits.
request.security — other symbols and timeframes
//@version=6
indicator("Daily Close on Intraday", overlay=true)
daily_close = request.security(syminfo.tickerid, "D", close)
plot(daily_close, "Daily close", color.orange)
request.security works for:
- Higher timeframe resampling — fetch any timeframe (e.g.
"D","W","60") on the current symbol. - Cross-symbol data — fetch a different instrument (e.g.
"BINANCE:BTCUSDT"). Fractal fetches that symbol's bars from its data provider and injects them automatically. - Tuples — return multiple series at once:
[h, l] = request.security(..., [high, low]). lookaheadcontrol —barmerge.lookahead_off(default, no-repaint) andlookahead_on.
request.security_lower_tf is also supported — it returns an array of intrabar values for each chart bar.
Cross-symbol requests currently have no cap on the number of distinct symbols a script can request. Avoid scripts that fan out to a very large number of symbols at once.
Alerts
//@version=6
indicator("Alert example", overlay=true)
crossed = ta.crossover(close, ta.sma(close, 20))
alert("Price crossed above MA", alert.freq_once_per_bar)
alertcondition(crossed, "MA Cross", "Crossed above 20-bar MA")
alert() and alertcondition() fire through Fractal's alert channels — the same toast/browser/sound/webhook pipeline used by price alerts. They evaluate on the live bar only (not during historical compute). See Alerts.
log.info(), log.warning(), and log.error() are also supported and route into the alert log.
Indicator legend
Each indicator shows an entry in the on-chart legend overlay. Click the settings icon (⚙) in the legend to open the indicator's Settings panel without leaving the chart. Collapse the legend with the arrow button if you need more screen space.
Next steps
Next: Writing Strategies