TradingView.To Strategy Template (with Dyanmic Alerts)

Hello traders,

If you're tired of manual trading and looking for a solid strategy template to pair with your indicators, look no further.
This Pine Script v5 strategy template is engineered for maximum customization and risk management.
Best part?
This Pine Script v5 template facilitates the dynamic construction of TradingView.TO alerts, sparing users the time and effort of mastering the TradingView.TO syntax and manually create alert commands.

This powerful tool gives much power to those who don't know how to code in Pinescript and want to automate their indicators' signals via TradingView.TO bot.


TradingView.TO is a trading bot software that forwards TradingView alerts to your brokers (examples: Binance, Oanda, Coinbase, Bybit, Metatrader 4/5, ...) for automating trading.
Many traders don't know how to create TradingView.TO dynamically-compatible alerts using the data from their TradingView scripts.

Traders using trading bots want their alerts to reflect the stop-loss/take-profit/trailing-stop/stop-loss to break options from your script and then create the orders accordingly.

This script showcases how to create TradingView.TO alerts dynamically.


1) You'll have to create one alert per asset X timeframe = 1 chart.
Example: 1 alert for BTC/USDT on the 5 minutes chart, 1 alert for BTC/USDT on the 15-minute chart (assuming you want your bot to trade the BTC/USDT on the 5 and 15-minute timeframes)

2) Select the Order fills and alert() function calls condition

3) For each alert, the alert message is pre-configured with the text below

Please leave it as it is.
It's a TradingView native variable that will fetch the alert text messages built by the script.

4) TradingView.TO uses webhook technology - setting a webhook URL from the alerts notifications tab is required.


I) Modular Indicator Connection
* plug your existing indicator into the template.
* Only two lines of code are needed for full compatibility.

Step 1: Create your connector

Adapt your indicator with only 2 lines of code and then connect it to this strategy template.

To do so:

1) Find in your indicator where the conditions print the long/buy and short/sell signals.
2) Create an additional plot as below

I'm giving an example with a Two moving averages cross.

Please replicate the same methodology for your indicator, whether a MACD , ZigZag, Pivots , higher-highs, lower-lows or whatever indicator with clear buy and sell conditions.

indicator("Supertrend", overlay = true, timeframe = "", timeframe_gaps = true)

atrPeriod = input.int(10,    "ATR Length", minval = 1)
factor =    input.float(3.0, "Factor",     minval = 0.01, step = 0.01)

[supertrend, direction] = ta.supertrend(factor, atrPeriod)

supertrend := barstate.isfirst ? na : supertrend
bodyMiddle = plot(barstate.isfirst ? na : (open + close) / 2, display = display.none)
upTrend =    plot(direction < 0 ? supertrend : na, "Up Trend",   color = color.green, style = plot.style_linebr)
downTrend =  plot(direction < 0 ? na : supertrend, "Down Trend", color = color.red,   style = plot.style_linebr)

fill(bodyMiddle, upTrend,   color.new(color.green, 90), fillgaps = false)
fill(bodyMiddle, downTrend, color.new(color.red,   90), fillgaps = false)

buy  = ta.crossunder(direction, 0)
sell = ta.crossunder(direction, 0)

//////// CONNECTOR SECTION //////// 

Signal = buy ? 1 : sell ? -1 : 0
plot(Signal, title = "Signal", display = display.data_window)

//////// CONNECTOR SECTION //////// 

[b]Important Notes[/b]

🔥 The Strategy Template expects the value to be exactly 1 for the bullish signal and -1 for the bearish signal

Now, you can connect your indicator to the Strategy Template using the method below or that one.

Step 2: Connect the connector

1) Add your updated indicator to a TradingView chart
2) Add the Strategy Template as well to the SAME chart
3) Open the Strategy Template settings, and in the Data Source field, select your 🔌Connector🔌 (which comes from your indicator)

Note it doesn’t have to be named 🔌Connector🔌 - you can name it as you want - however, I recommend an explicit name you can easily remember.

From then, you should start seeing the signals and plenty of other stuff on your chart.

🔥 Note that whenever you update your indicator values, the strategy statistics and visuals on your chart will update in real-time

II) BOT Risk Management:

- Max Drawdown:
Mode: Select whether the max drawdown is calculated in percentage (%) or USD.
Value: If the max drawdown reaches this specified value, set a value to halt the bot.

- Max Consecutive Days:
Use Max Consecutive Days BOT Halt: Enable/Disable halting the bot if the max consecutive losing days value is reached.

- Max Consecutive Days: Set the maximum number of consecutive losing days allowed before halting the bot.

- Max Losing Streak:
Use Max Losing Streak: Enable/Disable a feature to prevent the bot from taking too many losses in a row.

- Max Losing Streak Length: Set the maximum length of a losing streak allowed.
Margin Call:

- Use Margin Call: Enable/Disable a feature to exit when a specified percentage away from a margin call to prevent it.
Margin Call (%): Set the percentage value to trigger this feature.

- Close BOT Total Loss:
Use Close BOT Total Loss: Enable/Disable a feature to close all trades and halt the bot if the total loss is reached.

- Total Loss ($): Set the total loss value in USD to trigger this feature.
Intraday BOT Risk Management:

- Intraday Losses:
Use Intraday Losses BOT Halt: Enable/Disable halting the bot on reaching specified intraday losses.
Mode: Select whether the intraday loss is calculated in percentage (%) or USD.

- Max Intraday Losses (%): Set the value for maximum intraday losses.
Limit Intraday Trades:

- Use Limit Intraday Trades: Enable/Disable a feature to limit the number of intraday trades.

- Max Intraday Trades: Set the maximum number of intraday trades allowed.
Restart Intraday EA:

III) Order Types and Position Sizing

- Choose between market or limit orders.
- Set your position size directly in the template.

Please use the position size from the “Inputs” and not the “Properties” tab.
I know it's redundant. - the template needs this value from the "Inputs" tab to build the alerts, and the Backtester needs it from the "Properties" tab.

IV) Advanced Take-Profit and Stop-Loss Options

- Choose to set your SL/TP in either USD or percentages.
- Option for multiple take-profit levels and trailing stop losses.
- Move your stop loss to break even +/- offset in USD for “risk-free” trades.

V) Miscellaneous:
Retry order openings if they fail.

Order Types:
Select and specify order type and price settings.

Position Size:
Define the type and size of positions.

Leverage settings, including margin type and hedge mode.

Limit trades to specific sessions.

Limit trades to a specific date range.

Trades Direction:
Direction: Specify the market direction for opening positions.

VI) Logger

The TradingView.TO commands are logged in the TradingView logger.
You'll find more information about it in this TradingView blog post.


1) Transform your indicator into a TradingView.TO trading bot more easily than before
Connect your indicator to the template
Create your alerts
Set your EA settings

2) Save Time
Auto-generated alert messages for TradingView.TO.
I tested them all and checked with the support team what could/couldn’t be done.

3) Be in Control
Manage your trading risks with advanced features.

4) Customizable
Fits various trading styles and asset classes.


* Make sure you have your TradingView.TO account
* If there is any issue with the template, ask me in the comments section - I’ll answer quickly.


1) I connected this strategy template to a dummy Supertrend script.
I could have selected any other indicator or concept for this script post.
I wanted to share an example of how you can quickly upgrade your strategy, making it compatible with TradingView.TO.

2) The backtest results aren't relevant for this educational script publication.
I used realistic backtesting data but didn't look too much into optimizing the results, as this isn't the point of why I'm publishing this script.
This strategy is a template to be connected to any indicator - the sky is the limit. :)

3) This template is made to take 1 trade per direction at any given time.
Pyramiding is set to 1 on TradingView.

The strategy default settings are:

* Initial Capital: 100000 USD
* Position Size: 1%
* Commission Percent: 0.075%
* Slippage: 1 tick
* No margin/leverage used

👨‍💻 Need help you with your FTMO/TopStep verif?

⭐️ Listed as TradingView Trusted Pine Programmer

📧 dave@best-trading-indicator

Telegram: Daveatt

⏩ Course: best-trading-indicator.com

Twitter: twitter.com/bti_trading
Mã nguồn mở

Với tinh thần TradingView, tác giả của tập lệnh này đã xuất bản nó dưới dạng mã nguồn mở, vì vậy các nhà giao dịch có thể hiểu và xác minh nó. Chúc mừng tác giả! Bạn có thể sử dụng mã này miễn phí, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?