ChatGPT automated trading tutorial, helping you achieve automated investment and financial management
March 6, 2023
ExplainThis currently offers ChatGPT integration consulting services. Whether you want to integrate ChatGPT API into an existing platform or use ChatGPT API to develop customized applications for your business, please fill out this form. We are happy to assist your company and products. 🙂。 👉 《ChatGPT API Integration Service Request》form
💡 Disclosures: the Content is for informational purposes only, and should not be relied upon when making any investment decision
Impressive Results
Take a quick look at the effectiveness of the strategies I asked ChatGPT to write for me. The above two are completely different strategies, and with some parameter adjustments, both have achieved good results in Bitcoin trading. How was this achieved? Let us break it down step by step
If you encounter any problems during implementation, please feel free to create an issue on Github. We will regularly respond to questions in the issue section in TheExplainthis/ChatGPT-Trading-Bot
How to train ChatGPT
First, I had ChatGPT come up with ten possible trading strategies for me, as follows:
- A momentum trading strategy based on price and volume data
- A mean reversion strategy using Bollinger Bands and RSI indicators
- A trend following strategy using moving averages and MACD indicator
- A breakout trading strategy based on support and resistance levels
- A pairs trading strategy using cointegration analysis
- A news-based trading strategy using sentiment analysis on financial news
- An arbitrage trading strategy using cross-market analysis
- A swing trading strategy using candlestick patterns and chart analysis
- A quantitative trading strategy based on statistical models and machine learning algorithms
- A position trading strategy using fundamental analysis and value investing principles
Now input the following to
Give me pipescript code with version 4 running on TradingView for {trading strategy}
to ChatGPTGive me pipescript code with version 4 running on TradingView for A momentum trading strategy based on price and volume data.
Copy the following codes from ChatGPT:
For the second line of the code, sometimes ChatGPT will give you
study
and you need to change it tostrategy
Buy/Sell Signal Adjustment.
- Sometimes ChatGPT will give you the code for the entry and exit
if buy_signal alert("Buy Signal") if sell_signal alert("Sell Signal")
- You have to change the code to the following in order to trigger it on backtest
if buy_signal strategy.entry("Buy", strategy.long) if sell_signal strategy.entry("Sell", strategy.short)
- Sometimes ChatGPT will give you the code for the entry and exit
After Buy, Sell, Buy Exit, Sell Exit, you need to add the parameter
alert_message
so that there will be no error when setting up Notification later.if long_bb and long_ma and macd_above_signal and time >= start_time strategy.entry("Buy", strategy.long, alert_message="Buy") if short_bb and short_ma and macd_below_signal and time >= start_time strategy.entry("Sell", strategy.short, alert_message="Sell") if exit_bb or exit_ma strategy.exit('Buy Exit', 'Buy', alert_message="Buy_Exit") strategy.exit('Sell Exit', 'Sell', alert_message="Sell_Exit")
⚠️ Sometimes ChatGPT gives you code that doesn't work, so ask him a few more times or throw him an error message
Adjust the parameters to get the best results, as shown below.
Automated Process
Token acquisition
Login to Binance
After login, there is an
API Management
on the left side, enter it and pressCreate
on the top right corner.then you will get
API Key
andSecret Key
Project Settings
Fork Github project: 1.
- Register/Login to GitHub
- Go to ChatGPT-Trading-Bot
- click
Star
Support Developer - click
Fork
to copy all the code to your own repository
Deploy space registration (free space): 1.
Register/login to Heroku
There is a
New
->Create new app
at the top right. 3.App Name:
Enter this App Name
, Region:Europe
4.press
Create app
⚠️ There are two limitations when choosing a deployment platform: Coinan requires an IP location if you need to trade contracts, and Coinan's API has regional restrictions, such as the IP is not available in the US.
Project Implementation
Environment variable setting
Click
Settings
->Reveal Config Vars
. 2. 2. To add environment variables, add.- API Key. key:
API_KEY
value:[obtained from step 1 above]
- API SECRET KEY. key:
API_SECRET_KEY
value:[obtained from step 1 above]
- PASSPHRASE -> The purpose is that TradingView can be used as a Token when playing Request to Server, to avoid allowing everyone to play API key:
PASSPHRASE
value: `User generated, will be used again in step 4
- API Key. key:
Deployment steps
1. Use Terminal to enter the folder where
ChatGPT-Trading-Bot
is located 2.ls
to see if the folder is the same as the followingProcfile; Procfile; ``demo; src; main.py; runtime.txt; README.md; README.en.md; requirements.txt;
3. install Heroku cli 4. Deploy, see the process at the bottom of the Deploy page - First login to Heroku, in Terminal type in
jsx $ heroku login
After pressing Enter, it will open the browser and ask for a login, which will be successful. - To add a new location, in Terminal enter.
jsx $ heroku git:remote -a [your App Name]
5. Push the repo to Heroku and enter in Terminaljsx $ git push heroku main
6.6. After successful deployment, your URL column will be in
Settings
->Domains
7. Click on the link and you will see
Hello, World!
. 8. 8. Terminal enterheroku logs --tail
and find the place where "My IP" is and copy the IP down. For examplejsx 2023-03-05T13:38:36.171417+00:00 app[web.1]: My IP: 54.78.178.135
9. Go back to Binance, click
Edit restrictions
-> underIP access restrictions
and checkRestrict access to trusted IPs (Recommended)
-> and add the IPs from the previous step to it. 10. Check theEnable Futures
box above. 11. 11. ClickSave
⚠️ The free version of Heroku will hibernate if no one sends a request within 30 minutes, so the next step is required.
CronJob Scheduled Send Request
Register/login to cron-job.org
Go to the top right of the back panel and select
CREATE CRONJOB
.Title
enterChatGPT-Trading-Bot
, the URL of the previous stepThe next step will be typed every
5 minutes
. 5.Press
CREATE
Trading View Alert Settings
1. Under TradingView Strategy Tester
, select your strategy and press the icon of the alarm clock 2. Under Settings
the Message format is as follows.
{ "passphrase": "PASSPHRASE for environment setting", "symbol": "Currency to be traded", "leverage": the number of leverage, "quantity": the quantity to be traded, "time": "{{time}}", "close": {{close}}, "message": {{strategy.order.alert_message}} }
Example.
{ "passphrase": "Zw'4Tx^5/]f/pN>}fx*9m6<X,fxLx;x(", "symbol": "BTCUSDT", "leverage": 10, "quantity": 0.002, "time": "{{time}}", "close": {{close}}, "message": {{strategy.order.alert_message}} }
> 👉 Explanation: The contract trade is set to BTCUSDT
with a leverage of 10
times and a quantity of 0.002
bitcoins.
Notifications Settings
1. Webhook URL setting: URL in Heroku (
Settings
->Domains
) +/webhook
For example.
https://chatgpt-trading-bot.herokuapp.com/webhook
Q & A
How to test if the automated stringing is on?
You can open a real-time Alert on TradingView, for example, if the current currency price is 25000, set an Alert to cross 25000 and then let it trigger quickly, but because it is triggered instantly, not by strategy, so
"message": {{strategy.order.alert_message }}
can be changed to"message": "Buy"
, otherwise the message will be empty. 2.must set the quantity of each transaction can not be a ratio?
For example, if
max_quantity_ratio
is set to 0.01, it means 1% of assets.How do I debug the code if there is an error?
You can input
heroku logs --tail
in Terminal to confirm the error first, if you can't solve it by yourself, you can send Issue