Script alerts
How a LootScript script reports a trigger: alert() and alertcondition(), frequency, arming, where alerts are delivered, and what script alerts don't support.
A script can tell you that a condition occurred on the live market: a breakout, a delta spike, a line crossover. LootScript provides two functions for that — alert(), which the script calls itself, and alertcondition(), a condition you enable manually.
A trigger enters the same pipeline as the terminal’s other notifications: an entry in the Alerts tape, a sound, and a popup card. All of this is handled locally in the terminal on your computer: alerts work only while the terminal runs and the script is on the chart.
Two ways
alert() |
alertcondition() |
|
|---|---|---|
| Who decides whether to ring | Script code | You: the condition must be armed |
| When it triggers | By the chosen frequency, including on an unclosed bar | Only on bar close, not more than once per bar |
| Text | Any string, can be built from numbers | Fixed text in code |
| Where it’s enabled | Always while the script is on the chart | Checkbox in the Editor console |
If an alert is needed always — use alert(). If a script declares several signals but only some should ring — declare them with alertcondition() and arm the ones you want.
alert(): alert from code
alert(message, freq = alert.freq_once_per_bar_close)message — a string. Insert numbers via str.tostring: "Цена " + str.tostring(close). The text arrives in the notification verbatim; the terminal does not translate or alter it.
Frequency is set by a constant:
| Frequency | When it rings |
|---|---|
alert.freq_once_per_bar_close |
Default. Once, when the bar closed: on the first update of the next bar, using the closed bar’s values |
alert.freq_once_per_bar |
At the first moment the call ran on that bar — even if the bar is still forming. Then silent until the next bar |
alert.freq_all |
On every recalculation of the live bar where the call ran |
Frequency is tracked for each alert() call separately: two calls in one script do not mute each other. Per single recalculation a script sends up to 16 alerts; the rest are dropped.
Example: an alert on a delta spike as soon as it appears on a forming bar.
indicator("Всплеск дельты", overlay = false)
mult = input.float(3.0, "Во сколько раз больше обычного", minval = 1.5, step = 0.5)
base = ta.sma(math.abs(delta.value), 50)
spike = delta.available and math.abs(delta.value) > base * mult
plot(delta.value, "Дельта", style = plot.style_columns, color = delta.value >= 0 ? color.teal : color.red)
if spike {
alert("Всплеск дельты: " + str.tostring(delta.value, "#.##"), freq = alert.freq_once_per_bar)
}Where delta is unavailable, delta.available is false and the alert is silent — see Market data for the rule about na.
alertcondition(): a condition you arm
alertcondition(condition, title, message)condition — a boolean expression, title — the condition’s name, message — the alert text. title and message are literals in code; you cannot build them from numbers. Without message the notification will contain title.
The condition rings only on bar close, not more than once per bar and only if it is armed. Conditions are off by default.
Add the script to the chart
In the Script Editor click Add to chart.
Open the Output tab
In the console under the code select the Output tab. It shows series values on the last bar and the list “Alert conditions (alertcondition) — arm the ones you need”.
Arm the conditions
Check the boxes for the conditions you want notifications for. If the script is on multiple charts each chart has its own list.
History is silent
Alerts only ring on live updates. The first calculation after loading the chart, after switching instruments, or after loading older history is considered history: neither alert() nor alertcondition() fire on past bars. So adding a script to a chart will not produce a batch of notifications for the past.
You can check a condition on history visually: draw its marker with plotshape — it will show every bar where the alert would have fired.
Where an alert goes
Each trigger:
- Is recorded in the Alerts tape with source “Script alert”. The entry contains the message text, the script name and, for
alertcondition(), the condition title. The tape opens in a separate window or a workspace panel; the Sources filter leaves only script alerts. - Plays a sound. It is selected in Settings → Alerts, the Sounds block, the “Script alert” line: a list of sounds and a toggle that mutes the sound.
- Shows a card “Script name: message”.
- Highlights the workspace tab that contains the chart with the script.
Other terminal notifications are described on the Alerts and levels page.
Log: log.*
There is a log for debugging conditions. log.info, log.warning and log.error write a line to the Log tab of the Script Editor console — the same area that shows Problems and Output.
- The log, like alerts, writes only on live updates — it is silent on history.
- Up to 16 lines per bar; the rest are dropped.
- The console keeps the last 256 lines. Older lines are pushed out; their count is shown as “lines pushed out”. The Clear button clears the log.
indicator("Проверка условия", overlay = true)
len = input.int(20, "Канал, баров", minval = 2, maxval = 500)
upper = ta.highest(high, len)[1]
plot(upper, "Верх канала", color = color.teal)
if barstate.islast {
log.info("Закрытие " + str.tostring(close) + ", верх канала " + str.tostring(upper))
}Example: channel breakout
The script draws the channel upper boundary, marks breakouts with a triangle and reports them in two ways: alert() rings always, while the condition “Breakout up” rings only if you armed it.
indicator("Пробой канала с алертом", overlay = true)
len = input.int(20, "Канал, баров", minval = 2, maxval = 500)
upper = ta.highest(high, len)[1]
breakUp = ta.crossover(close, upper)
plot(upper, "Верх канала", color = color.teal)
plotshape(breakUp, "Пробой", style = shape.triangleup, location = location.belowbar, color = color.teal, size = size.small)
if breakUp {
alert("Пробой вверх, цена " + str.tostring(close), alert.freq_once_per_bar_close)
}
alertcondition(breakUp, "Пробой вверх", "Цена закрылась выше канала")The boundary uses a [1] offset — from previous bars; otherwise the current high would always be inside the channel. freq_once_per_bar_close means the alert arrives after the bar closed above the channel, and the triangle on the chart stays exactly where the alert rang. In real scripts you usually keep one of the two methods — both are shown here for comparison.