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.
IMPORTANT NOTES
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.
TRADINGVIEW ALERTS
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 {{strategy.order.alert_message}}
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.
KEY FEATURES
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.
- 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: Leverage settings, including margin type and hedge mode.
Session: Limit trades to specific sessions.
Dates: 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.
WHY YOU MIGHT NEED THIS TEMPLATE
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.
REQUIREMENTS
* 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.
BACKTEST RESULTS FROM THIS POST
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