Getting started
Open the Script Editor, type a five-line indicator, see it render on your chart. From zero to a working Delta DSL script in under five minutes.
This page walks you from "I have never written a Delta DSL script" to "I have a custom indicator on my chart" in five minutes. No installs, no SDKs, no key generation. Open the Web App, type, save.
1. Open the Script Editor
Go to /trading/chart-terminal. Click the indicator icon in the top toolbar (the one that opens the indicator catalog) and pick Custom scripts in the left rail. The catalog item + New script opens the Script Editor dialog.
The dialog has three regions:
- Editor — left side, syntax-highlighted, with autocomplete (
Ctrl + SpaceorTab) and inline error markers. - Inputs preview — right side, top. Renders the settings panel your
@inputdeclarations will produce, live as you type. - Output preview — right side, bottom. Mini-chart that runs the script against the last 200 bars of the symbol you have open.
The Editor remembers your script as you type. Saving promotes it to the indicator catalog.
2. Type the smallest possible script
@name "My SMA"
ma = sma(close, 20)
plotLine(ma, color="#F0B90B", width=2)
Three lines:
@namedeclares the display name shown in the indicator catalog and the legend.ma = sma(close, 20)computes a 20-period simple moving average.smareturns a series the same length as the input, somais itself a series.plotLine(ma, color=…, width=…)draws it.
The output preview should now show a yellow line floating along the candles.
3. Add a knob
Hard-coded 20 is fine, but every real indicator wants an adjustable period. Replace the body with:
@name "My SMA"
@input length = input.int(20, "Length", minval=2, maxval=500)
@input clr = input.color("#F0B90B", "Line color")
ma = sma(close, length)
plotLine(ma, color=clr, width=2)
The Inputs preview now shows two controls — a number stepper labelled Length clamped between 2 and 500, and a color picker. Both are wired to the same script with no UI code.
@input declarations always sit at the top of the file, after @name / @pane if you have those.
See Inputs & directives for every input builder and option.
4. Branch on a condition
Suppose you want the line to turn red when price is below the MA and green when above. The iff(cond, a, b) helper is the vector if-then-else:
@name "My SMA"
@input length = input.int(20, "Length", minval=2, maxval=500)
@input upColor = input.color("#0ECB81", "Above color")
@input dnColor = input.color("#F6465D", "Below color")
ma = sma(close, length)
bullMa = mask(ma, close >= ma)
bearMa = mask(ma, close < ma)
plotLine(bullMa, color=upColor, width=2)
plotLine(bearMa, color=dnColor, width=2)
close >= ma is a per-bar boolean series. mask(ma, cond) returns ma where cond is true and NaN elsewhere; the renderer treats NaN as a gap, so each plotLine call paints only the bars where its mask was true. Together the two lines render as a single two-tone trace.
plotLine's color= argument is a single static colour — to paint different segments in different colours you split the source into N masked series, one per colour, and emit N plotLine calls. This is the foundation of every "two-tone" or "N-tone" trace in Delta DSL.
5. Wire an alert
Last step: tell the alert builder to listen for crossover events.
@name "My SMA"
@input length = input.int(20, "Length", minval=2, maxval=500)
@input upColor = input.color("#0ECB81", "Above color")
@input dnColor = input.color("#F6465D", "Below color")
ma = sma(close, length)
bullMa = mask(ma, close >= ma)
bearMa = mask(ma, close < ma)
plotLine(bullMa, color=upColor, width=2)
plotLine(bearMa, color=dnColor, width=2)
plotShape(crossover(close, ma), close, shape="arrowUp", color=upColor, size=8)
plotShape(crossunder(close, ma), close, shape="arrowDown", color=dnColor, size=8)
alertcondition(crossover(close, ma), title="SMA cross up",
message="Price crossed up through SMA on {{symbol}}")
alertcondition(crossunder(close, ma), title="SMA cross down",
message="Price crossed down through SMA on {{symbol}}")
alertcondition does not fire alerts by itself — it declares that this condition is alertable. Hit Save, then open the Alerts panel from the indicator legend (or from /trading/alerts). You'll see two new conditions wired up; pick the channels you want (push / Telegram / in-app), set frequency, done.
See Alerts for the full alert wiring.
6. Save and run on every chart
Hit Save. The script is now in your account's indicator catalog as My SMA. Open it on any chart the way you open a built-in indicator. It runs against whatever symbol and timeframe the chart has loaded. Re-open the Editor any time to tweak.
What you've learned
| Concept | Where it's used in the script |
|---|---|
| Directive | @name |
| Typed input | @input length = input.int(20, "Length", minval=2, maxval=500) |
| Built-in series | close |
| Indicator function | sma(close, length) |
| Vectorised branching | bullMa = mask(ma, close >= ma) / bearMa = mask(ma, close < ma) |
| Per-bar plot | plotLine(bullMa, color=upColor, width=2) |
| Per-bar marker | plotShape(crossover(close, ma), close, shape="arrowUp", color=upColor, size=8) |
| Cross detection | crossover(close, ma) / crossunder(close, ma) |
| Alert wiring | alertcondition(...) |
That's the whole loop. Every script is some combination of these eight ideas — declare inputs, compute series, branch with iff, plot, and (optionally) alert.
Next steps
- Read the language reference for syntax details and the type system.
- Skim the recipes cookbook — chances are someone has already written the indicator you want.
- Browse the drawing reference when you need more than a line on the chart.