Your first script
1Your first script
Step by step: open the LootScript editor, write a two-line indicator, add it to a chart, read errors, and find the script file. Second example: a channel with settings.
On this page you’ll go from an empty editor to your own indicator on a chart: you’ll write a two-line script, see how the editor catches errors, learn where the file lives, and add a settings window. You’ll need an open chart and scripts enabled — if they’re not in the indicators window, read How to enable scripts.
Open the editor
Open the indicators window
On the chart panel, click the ƒ button — its tooltip says “Indicators”.
Launch the editor
Click Editor… next to the search field or New script at the bottom of the window. To open an existing script, find it under My scripts and click the pencil Edit script in its row (or select the row and press Ctrl+E).
Find the buttons you need
The editor opens in a separate window with its own taskbar button — you can move it to a second monitor. At the top — a dropdown list of scripts and the New, Save, and Add to chart buttons; at the bottom — the Problems, Log, and Output tabs.
The editor remembers the chart panel whose indicators window you opened it from — it will add the script there. If you open the editor another way, the script goes to the active chart panel.
Write an indicator
The New button (Ctrl+N) creates a script from a template — a moving average with one setting:
indicator("Без названия", overlay = true)
length = input.int(20, "Length", minval = 1)
plot(ta.ema(close, length), "EMA", color = color.orange)Replace the text with the shortest working indicator — a simple 20-bar moving average:
indicator("Мой первый индикатор", overlay = true)
plot(ta.sma(close, 20), "Средняя 20", color = color.orange)What’s here:
indicator(...)— the declaration, a required first line of any script. The name goes to the My scripts list and the chart legend.overlay = truedraws over candles; withoverlay = falsethe indicator gets its own chart panel below the chart.ta.sma(close, 20)— the average of closing prices over the last 20 bars.plot(...)— draws a line: one value per bar. The second argument is the line’s name in settings,coloris the color.
The script runs for each bar in order, from the oldest to the current one. The first 19 bars don’t have enough history for the average, so the line doesn’t start at the left edge — that’s normal. The editor shows how many bars this “warm-up” takes in the status bar at the bottom.
As you type, the editor suggests function and constant names, shows function parameters after an opening parenthesis, and shows a description when you hover over a name. You can bring up the suggestion list manually with Ctrl+Space.
Save and add to chart
- Save (Ctrl+S) writes the script to the scripts folder. While there are unsaved changes, a dot
•appears before the file name in the window title. - Add to chart (Ctrl+Enter) checks the script, saves it, and places it on the chart panel. The editor panel will show: “Мой первый индикатор” added to chart.
Done: a line on the chart, the indicator’s name in the legend. The indicator is saved in the layout and returns after the terminal restarts.
How the editor shows errors
The script is checked automatically — a moment after you stop typing. The result is visible in the editor header: compiling…, then ok · 12 ms or, if something’s wrong, errors: 1 or warnings: 1.
Try making a mistake: type ta.smaa instead of ta.sma. The error is underlined with a wavy line, the counter in the header shows errors: 1, and the Problems tab gets a line with the error code, explanation, and position:
LS2002 Неизвестное имя «ta.smaa» — проверьте написание или объявите его выше Стр 3:6Double-clicking the line moves the cursor to the error. Every error has a permanent code like LS####, and the text immediately suggests how to fix it. Common errors are covered in Compile and runtime errors.
A script with errors won’t go on the chart: Add to chart responds with “Script with errors can’t be placed on the chart — see Problems” and moves the cursor to the first error. In the indicators window, such a script is marked with a red badge showing the error count instead of the Script badge.
There are also runtime errors — for example, a loop that doesn’t finish in the allotted time. Then the script stops, and the reason appears on the Output tab: “Script stopped: …”. Other indicators and the terminal keep working.
Editing a script that’s already on a chart
While you edit, the chart keeps showing the version you added. As soon as a working version that differs from the chart appears in the editor, two things happen:
- the editor panel shows an Update indicator button;
- the indicator’s legend on the chart shows an update icon.
Either one saves the script and replaces it on every chart where it’s placed. Add to chart for a script that’s already added somewhere does the same — it updates all copies instead of adding a second one. The editor header shows how many panels will get the new version with an on charts: N badge.
Where the files live
On Windows, scripts are stored in %APPDATA%\TradingTerminal\scripts\, one .loot file per script. It’s plain text — you can open it in any editor, copy it, back it up. The folder is outside the installation folder, so terminal updates don’t touch it.
The file name comes from the title at first save: spaces become underscores, Cyrillic is preserved. “Мой первый индикатор” becomes Мой_первый_индикатор.loot.
When the folder is first created, six starter scripts are placed in it — Two moving averages, RSI with zones, Volume impulse, Cumulative delta, Interest vs price, and Funding rate annualized. They’re in the My scripts section; they’re handy to open and study.
Second example: a channel with settings
Let’s make the script more useful: a channel from an average and two boundaries at a distance of a few standard deviations. We’ll put the period, width, and price source into settings, and highlight the upper and lower boundaries in red when price breaks out of them.
indicator("Канал вокруг средней", overlay = true)
length = input.int(20, "Период", minval = 2)
mult = input.float(2.0, "Ширина в сигмах", minval = 0.1, step = 0.1)
src = input.source(close, "Источник")
basis = ta.sma(src, length)
dev = mult * ta.stdev(src, length)
upper = basis + dev
lower = basis - dev
plot(basis, "Середина", color = color.gray)
plot(upper, "Верх", color = close > upper ? color.red : color.teal)
plot(lower, "Низ", color = close < lower ? color.red : color.teal)What’s new:
- Each
input.*call becomes a row in the indicator’s settings window, in the order it’s written.minvalprevents entering a period below two, andstep = 0.1means the width field shows one decimal place. input.sourcebecomes a dropdown list of series:close,open,hl2,volume, and others.- The boundary colors are expressions, so they’re calculated on every bar separately.
Add the script to the chart and double-click its row in the legend (or click the settings icon there). On the Inputs tab there are your three settings: change the period and the lines recalculate immediately. Values are remembered for this indicator on this chart; the Defaults button restores the values written in the code. On the Style tab — the average’s color and each line’s thickness; on the Visibility tab — checkboxes to hide any of the three lines. The boundary colors have no setting: the script chooses them on every bar.
Next
https://docs.lootx.trade/en/loot/first-script