UT Bot Alerts explained: what the code actually computes
UT Bot Alerts is a free, open-source TradingView script published by QuantNomad in 2020. It adds alerts to "UT Bot" by Yo_adriiiiaan, who credits HPotter for the original code. Because the code is open, nothing has to be guessed. It is about 40 lines and does one thing: it keeps an ATR trailing stop on the close and labels the bar where price crosses it.
What it computes
On every bar (our paraphrase, not the original code):
loss = Key Value x ATR(ATR Period)
price = close (or the Heikin Ashi close, if that option is on)
if price and previous price are both above the previous stop: stop = max(previous stop, price - loss) (can only rise)
else if both are below it: stop = min(previous stop, price + loss) (can only fall)
else (price has just crossed the previous stop): stop = price - loss if price is above it, otherwise price + loss
"Buy" label: the bar where price moves from below the stop to above it
"Sell" label: the reverse
bar colour: green above the stop, red below
Three details many write-ups get wrong:
- There is no moving-average filter. The code compares an EMA of length 1 with the stop. An EMA of length 1 equals the price itself, so the "crossover" is simply price crossing the stop. Every label is a stop flip, so Buy and Sell always alternate.
- The stop line is not drawn. The Alerts version plots only the labels and bar colours. Yo_adriiiiaan's original draws the line.
- The alert conditions "UT Long" and "UT Short" are true on exactly the labelled bars.
What the settings change
- Key Value (default 1): the stop's distance in ATRs. Price must give back roughly Key Value x ATR from its best close before the label flips, so a larger value means fewer flips, each one later. QuantNomad's code declares this input as a whole number, so 1.5 is not available; the original UT Bot defaulted to 3, in steps of 0.5. Guides that disagree about "the default" are describing different scripts.
- ATR Period (default 10): how quickly the stop's width reacts to a change in volatility. ATR is Wilder-smoothed true range of the chart's own candles, even with the Heikin Ashi option on.
- Signals from Heikin Ashi Candles (default off): the script requests the Heikin Ashi close for the same symbol and timeframe, with lookahead off. A Heikin Ashi close is the average of the bar's open, high, low and close, so the option swaps the close for that four-price average. The smoothed Heikin Ashi open is never used.
There is no best setting. A pair that looks good on a chart was usually picked after looking at that chart. What you choose is how many ATRs of give-back you accept before the label changes side.
Does UT Bot Alerts repaint?
- Closed bars: no. Each bar's stop uses only that bar and earlier ones, and the Heikin Ashi request uses the chart's own timeframe with lookahead off, so no later data leaks in. A closed bar's label stays put on reload.
- The live bar: yes, until it closes. The close moves with every tick and the code has no confirmed-bar check, so a label can appear mid-bar and be gone at the close. An alert set to "Once per bar" can fire on such a label; "Once per bar close" waits for the bar to finish.
Heikin Ashi and backtests
UT Bot Alerts places no orders. QuantNomad's separate "UT Bot Strategy" runs the same logic, going long at each Buy label and reversing to short at each Sell. On a normal candle chart the Heikin Ashi option only changes when orders trigger; fills are still at real prices. Synthetic fills come from setting the chart itself to Heikin Ashi candles, unless "Fill orders using standard OHLC" is ticked in the strategy's properties. The published strategy also sets no commission or slippage.
UT Bot vs Supertrend
Both are ATR trailing stops that ratchet with the move, flip when a close crosses them, and have two states with no neutral one. The differences:
- UT Bot hangs its stop from the close; Supertrend uses the bar's midpoint, (high + low) / 2.
- UT Bot Alerts defaults to 1 ATR; Supertrend is usually run at 3, as was the original UT Bot. A tighter stop flips more often.
- Supertrend tracks two bands on every bar; UT Bot keeps one line and restarts it on each flip.
The audit version on TradingView
We rebuilt this stop from scratch and published it free and open source: Taught to Trade - ATR Trailing Stop with Flip Audit. At a distance of 1 and an ATR length of 10 on the close, it draws the same stop and the same flip bars as UT Bot Alerts. It adds what the original leaves out: the stop line drawn on the chart, fractional distances, flips confirmed only once the bar closes, Heikin Ashi computed consistently, and a panel that counts how many flips were undone within a few bars. That last number is the cost of a tight setting, on your own chart.
Where it fails
- Every label is late by construction: roughly Key Value x ATR of give-back from the best close.
- At the default 1 ATR the stop sits about one average bar's range from the close, so an ordinary pullback bar can flip it.
- Two states, no neutral: it is always on one side, trending or not.
- On the live bar, a label and a "Once per bar" alert can vanish before the close.
- The Heikin Ashi option mixes a four-price average with regular-candle ATR; a strategy run on a Heikin Ashi chart fills at prices that never traded unless the standard-OHLC setting is on.
- Many scripts share the name, so two "UT Bot Alerts" with the same settings may not be the same code.
- A Buy label records that price crossed a stop. Treating it as the start of a trend is a different claim, and nothing in the code tests it.
The Teardown Letter
The monthly Teardown Letter takes one popular indicator apart per issue in the same way: what it computes, what follows from the arithmetic, and where it misleads. Issues so far: RSI, MACD, order blocks, Fibonacci and Supertrend. New subscribers get every past issue.
Also explained: VWAP, Supertrend, RSI, UT Bot Alerts