The calculation
1
Measure volatility
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.
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.
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.