OPEN-SOURCE SCRIPT

Pineconnector Strategy Template (Connect Any Indicator)

Cập nhật
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?
It’s optimized for Pineconnector, allowing seamless integration with MetaTrader 4 and 5.

This powerful tool gives a lot of power to those who don't know how to code in Pinescript and are looking to automate their indicators' signals on Metatrader 4/5.

IMPORTANT NOTES

Pineconnector is a trading bot software that forwards TradingView alerts to your Metatrader 4/5 for automating trading.
Many traders don't know how to dynamically create Pineconnector-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 Pineconnector alerts dynamically.

Pineconnector doesn't support alerts with multiple Take Profits.
As a workaround, for 2 TPs, I had to open two trades.
It's not optimal, as we end up paying more spreads for that extra trade - however, depending on your trading strategy, it may not be a big deal.

TRADINGVIEW ALERTS

1) You'll have to create one alert per asset X timeframe = 1 chart.
Example: 1 alert for EUR/USD on the 5 minutes chart, 1 alert for EUR/USD on the 15-minute chart (assuming you want your bot to trade the EUR/USD 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) Don't forget to set the Pineconnector webhook URL in the Notifications tab of the TradingView alerts UI.
You’ll find the URL on the Pineconnector documentation website.

EA CONFIGURATION

1) The Pyramiding in the EA on Metatrader must be set to 2 if you want to trade with 2 TPs => as it's opening 2 trades.
If you only want 1 TP, set the EA Pyramiding to 1.
Regarding the other EA settings, please refer to the Pineconnector documentation on their website.

2) In the EA, you can set a risk (= position size type) in %/lots/USD, as in the TradingView backtest settings.

KEY FEATURES

I) Modular Indicator Connection
* plug in 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 it's a MACD , ZigZag , Pivots , higher-highs, lower-lows, or whatever indicator with clear buy and sell conditions.



Important Notes

🔥 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) Customizable Risk Management

- Choose between percentage or USD modes for maximum drawdown.
- Set max consecutive losing days and max losing streak length.

- I used the code from my friend @JosKodify for the maximum losing streak. :) 


Will halt the EA and backtest orders fill whenever either of the safeguards above are “broken”

III) Intraday Risk Management

- Limit the maximum intraday losses both in percentage or USD.
- Option to set a maximum number of intraday trades.
- If your EA gets halted on an intraday chart, auto-restart it the next day.

IV) Spread and Account Filters

- Trade only if the spread is below a certain pip value.
- Set requirements based on account balance or equity.

V) Order Types and Position Sizing

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

Please use the position size from the “Inputs” and not the “Properties” tab.

Reason: The template sends the order on the same candle as the entry signals - at those entry signals candles, the position size isn’t computed yet, and the template can’t then send it to Pineconnector.

However, you can use the position size type (USD, contracts, %) from the “Properties” tab for backtesting.
In the EA, you can define the position size type for your orders in USD or lots or %.

VI) Advanced Take-Profit and Stop-Loss Options

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

VII) Logger

The Pineconnector 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 Pineconnector 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 Pineconnector.
I tested them all, and I checked with the support team what could/can’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 Pineconnector license ID.
* Create your alerts with the Pineconnector webhook URL
* 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 Pineconnector.

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 contract
* Commission Percent: 0.075%
* Slippage: 1 tick
* No margin/leverage used

WHAT’S COMING NEXT FOR YOU GUYS?

I’ll make the same template for ProfitView, then for AutoView, and then for Alertatron.
All of those are free and open-source.
I have no affiliations with any of those companies - I'm publishing those templates as they will be useful to many of you.

Dave
Phát hành các Ghi chú
Version 1.1
Fixed the position size - it was missing from the strategy inputs
educationalpineconnectorPine utilitiesTrend Analysis

Mã nguồn mở

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

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


⭐️ Listed as an Official TradingView Trusted TOP Pine Programmer

📧 Coding/Consulting Inquiries: dave@best-trading-indicator

Telegram: Daveatt

⏩ Course: best-trading-indicator.com

Twitter: twitter.com/bti_trading
Ngoài ra, trên:

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