Logistic regression is a simple but effective machine learning method used to predict the probability of certain outcomes—like whether the market will move up or down—by analyzing historical patterns in the data. It does this by looking at past price movements and identifying patterns that often lead to specific results.
We’ll walk through a widely-used open-source Logistic Regression script from TradingView, and show you step-by-step how to automate it easily with PineConnector.
By the end, you’ll have a fully automated trading strategy, no coding experience required!
Implementing on PineConnector
1. Head to the script’s TradingView page
Machine Learning: Logistic Regression Strategy →
2. Click use on chart
Just below the chart, click “Use on chart” to run the strategy on your TradingView chart.
3. Access source code
After clicking “Use on chart”, you will be redirected to your charts with the strategy attached. Now, click on the Source code icon which is the curly brackets { }
to access the code.
4. Create working copy
You should see the Pine Editor opening with the source code revealed. Now, click “create a working copy”.
5. Save duplicated script
Once a working copy is created, click save.
You can use the default name, or rename it as you’d like.
6. Convert code to v5
Since the script is coded in PineScript version 4, let’s convert it to v5 so that we are leveraging on the latest PineScript architecture.
You will see a pop-up comparing the version 4 and 5 code. Click Apply.
7. Review code
If we dive into the code, from Lines 150 to 154, we can see that alerts are already created for buy and sell instances. Now, we just have to create the alert, and configure the appropriate message, as per PineConnector’s syntax to initiate the buy and sell respectively.
8. Create alert
In your desired symbol (such as EURUSD, BTCUSD, US100, etc) and timeframe (1 minute, 15 minutes, 1 hour, 1 day, etc), create a TradingView alert by pressing on Alert in the header, or press ALT+A (Windows) or Option+A (Mac).
9. Configure alert
In the header, we can see that we are creating the alert on EURUSD and on the 1 minute timeframe. Now, select “Machine Learning: Logistic Regression” as the Condition, and select “Buy”.
In the middle section, configure Trigger to be Once Per Bar Close.
At the bottom, let’s configure the alert message whereby:
- 70123456789 should be your License ID found in your PineConnector Portal
- buy → we are looking to initiate a buy when buy conditions are met as per the coded strategy
- {{ticker}} is a dynamic variable, though it will be EURUSD for this case as we are creating the alerts for EURUSD (more on this later!)
- risk=1 → risking 1 unit as per your Volume Type set in the EA
Assuming your actual License ID is 7262999151957, the alert message you should use is:
7262999151957,buy,{{ticker}},risk=1
Alternatively, you can hard-code the ticker or if the ticker used on TradingView does not match your broker’s - any is fine!:
7262999151957,buy,EURUSD,risk=1
7262999151957,buy,{{ticker}}-micro,risk=1
7262999151957,buy,EURUSD-micro,risk=1
In the Notifications tab, setup the PineConnector webhook URL:
https://webhook.pineconnector.com
Now, we do the same for the same symbol and timeframe (EURUSD, 1 minute for this example), but for Sell triggers.
10. (Optional) Watchlist Alerts
This feature is available for TradingView Premium plan and higher, where Premium users are entitled to 2 watchlist alerts.
Lean more about TradingView’s Watchlist Alerts.
Instead of creating alerts based on individual symbols, you can create alerts based on watchlists. In this example, we have an “FX” watchlist where trigger on any of the 53 symbols will result in an alert.
To create alerts based on the watchlist-level instead of symbol-level, simply select your watchlist of choice.
11. Verify alerts
Once you have created the alerts, you should be able to see them in the Alerts tab, where the upper row is a watchlist alert for the FX watchlist, and the bottom alert is a symbol-level alert for EURUSD.
12. Adjust EA settings
In your PineConnector EA that is running on your MT4/5 terminal you may want to consider using the following setting:
On — Hedging When a sell signal is received, open buy positions will be closed followed by a corresponding sell position opening, and vice-versa
Learn more about Close on Reverse EA Setting here.
On this page