> ## Documentation Index
> Fetch the complete documentation index at: https://docs.quantnomad.com/llms.txt
> Use this file to discover all available pages before exploring further.

# UT Bot v2 Source Code

> Where to find the open-source Pine Script v6 code for UT Bot v2, how it's structured, its license, and how to make your own copy.

UT Bot v2 is open source. You can read every line of code that produces its trailing stop, signals, alerts, and strategy entries.

| | |
| - | - |
| **Script page** | [UT Bot v2 — ATR Trailing Stop](https://www.tradingview.com/script/lDGmh7ou-UT-Bot-v2-ATR-Trailing-Stop/) |
| **Script type** | Strategy (overlay) |
| **Language** | Pine Script v6 |
| **License** | [Mozilla Public License 2.0](https://mozilla.org/MPL/2.0/) |
| **Author** | © QuantNomad |

## How the code is organized

The script is short and split into clearly marked sections:

| Section | What it does |
| - | - |
| **Inputs** | Defines the [settings](https://docs.quantnomad.com/free-indicators/ut-bot-v2/settings.md): multiplier, ATR period, source, backtest range, and display toggles |
| **Calculations** | Computes ATR, the trailing stop, and the `buy` and `sell` conditions |
| **Plots** | Draws the trailing stop line, trend bar colors, and Buy/Sell labels |
| **Alerts** | Sends `UT Bot Buy` and `UT Bot Sell` alerts once per bar close |
| **Strategy** | Enters long on Buy and short on Sell, within the backtest date range |

The core of the indicator, the trailing stop, is a few lines:

```pine theme={null}
atr = ta.atr(atr_len)
sl_value = mult * atr

tsl_price = 0.0
tsl_price :=  source > tsl_price[1] and source[1] > tsl_price[1] ? math.max(nz(tsl_price[1]), source - sl_value) :
              source < tsl_price[1] and source[1] < tsl_price[1] ? math.min(nz(tsl_price[1]), source + sl_value) :
              source > tsl_price[1] ? source - sl_value :
              source + sl_value
```

A walkthrough is on [How It Works](https://docs.quantnomad.com/free-indicators/ut-bot-v2/how-it-works.md).

## View the source in TradingView

> [!NOTE]
>
> **General TradingView information.** This section describes standard TradingView behavior, not a QuantNomad-specific feature. TradingView updates its interface regularly, so menu names and positions may differ slightly from what you see. When in doubt, check the [TradingView Help Center](https://www.tradingview.com/support/).

> [tab] From the script page
>
> Open the [script page](https://www.tradingview.com/script/lDGmh7ou-UT-Bot-v2-ATR-Trailing-Stop/) and select the **Source code** tab.

> [tab] From your chart
>
> With UT Bot v2 on your chart, hover over its name in the status line and click the **Source code** icon (`{ }`). The code opens in the Pine Editor.

## Make your own copy

**1. Open the source in the Pine Editor**

Follow the steps above.

**2. Create a working copy**

In the Pine Editor, use **Make a copy** from the script name menu. The copy is saved to your own TradingView account.

**3. Edit and add to chart**

Make your changes, save, and click **Add to chart**.

> [!NOTE]
>
> QuantNomad can't support modified versions. If you publish a modified version, follow the terms of the [MPL 2.0 license](https://mozilla.org/MPL/2.0/) and [TradingView's House Rules](https://www.tradingview.com/support/solutions/43000591638-house-rules/).

## Related pages

* [How It Works](https://docs.quantnomad.com/free-indicators/ut-bot-v2/how-it-works.md)
* [Settings & Parameters](https://docs.quantnomad.com/free-indicators/ut-bot-v2/settings.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.