Skip to main content
UT Bot v2 is built on one idea: follow price with a trailing stop whose distance depends on volatility, and flip the trend when price crosses it. Everything on this page comes from the open-source code.

The calculation

1

Measure volatility

Calculate the Average True Range over ATR Period bars:
New to ATR? See ATR and Signal Sensitivity.
2

Set the stop distance

Multiply ATR by the Multipier input:
With the defaults (multiplier 1, ATR period 10), the stop sits one 10-bar ATR away from price.
3

Update the trailing stop

On every bar, compare the price Source (close, by default) with the previous bar’s stop:
4

Detect a trend flip

A Buy signal is generated when the source crosses above the trailing stop. A Sell signal is generated when it crosses below. Both require the bar to be closed:

Why it trails

In an uptrend, the stop follows price upward and never moves down. If price pulls back without crossing the stop, the trend holds. If the pullback is deeper than the stop distance, price crosses the stop and the trend flips to down. Downtrends work the same way in reverse. The Multipier sets how deep a pullback has to be:
  • Higher multiplier: wider stop, fewer trend flips, later signals.
  • Lower multiplier: tighter stop, more trend flips, earlier signals, more whipsaws in choppy markets.
Because the distance is measured in ATR, the stop automatically widens in volatile periods and tightens in quiet ones.

Signal timing

Signals are only generated on confirmed (closed) bars (barstate.isconfirmed). In practice:
  • A Buy or Sell label never appears on the bar that’s still forming. It’s added when that bar closes.
  • Once a label appears, it doesn’t disappear later.
  • The trailing stop line on the current bar does still move with live prices until the bar closes. That’s expected.
This avoids the most common source of disappearing signals. See Confirmed vs Unconfirmed Signals.

Strategy behavior

UT Bot v2 is a TradingView strategy. On each signal it places a simulated market order: The strategy is always in the market after its first signal, reversing on each flip. Orders are only placed within the backtest date range (see Settings). By TradingView’s standard behavior, a market order generated on a bar’s close is filled at the open of the next bar.
The script doesn’t set commission or slippage, so default backtest results don’t include trading costs. Set them under Settings → Properties before reading too much into the results. Backtests describe the past, not the future.
Last modified on November 7, 2026