
Artificial Intelligence is still in its early days and there are a lot of bugs to be worked out.
However, one area that I have found it tremendously useful is in the area of creating automated trading robots for trading platforms like MetaTrader 4.
So in this tutorial, I'll show you how I'm using ChatGPT to create custom MT4 EAs. This process can be very fast and for simple EAs, you don't even know how to code.
If you prefer the text version, it's provided below the video.
Tutorial Video
How to Create an EA with ChatGPT
All of these steps should be done in a demo account.
Never use an EA with real money until you're absolutely sure that it's working properly.
Step 1: Have a Trading Strategy
You can get a trading strategy from almost anywhere…books, websites, YouTube or something you just made up.
Ideally, you should have a trading strategy that you've already backtested.
But if you just want to go through the process to see how it works, then just use the example code in the section below.
Step 2: Describe it to ChatGPT
Ask it to create an EA for MT4.
Then explain the rules as clearly as you can to ChatGPT. Write as if you were writing to a friend.
It will generate the code that you need for MT4.
Copy this code from ChatGPT
Step 3: Copy and Paste the Code into MT4
Then open the MetaQuotes Language Editor via the tool bar at the top.
Click the New button to create a new EA.
Select Expert Advisor, give it a name, then leave the rest of the settings blank. Keep hitting the Next button until you get to the end of the wizard.
That will give you a blank EA template.
Click anywhere in the code, then use Control + A to select all of the text. Then hit Backspace to delete all of the default code, then Control + V on your keyboard to paste in the ChatGPT code.
Click on the Compile button to generate the EA.
Step 4: Check for Errors
If there are any errors or warnings in the code, go back and ask ChatGPT to fix them.
It will generate new code.
Repeat step 3 above to start using the new code.
Step 5: Add the EA to a Chart and Start Testing
Once all the errors and warnings are gone, then you're ready to start using the EA.
Go to the main MT4 screen and look for the EA in the Navigator window.
Click and drag your new EA onto the chart.
There should be the name of your EA in the upper right corner of the chart you added it to, next to a happy face.
If the face is sad, click on the AutoTrading button at the top to activate the EA. The happy face shows that the EA is activated.
Now test the EA to see if it's working properly.
Test all of the regular features AND try to “break” the EA by doing things that it might not expect. This will show you how robust it is and will give you confidence in it.
If you have any issues, go back to ChatGPT and work on fixing them.
This may take several tries, but keep at it.
Example Code
If you want to give this a try, here's the example code. Simply copy and paste this prompt into ChatGPT and it will generate the code for this EA.
Important: This is for educational purposes only and should NOT be used in live trading. It's only provided to help you understand how to EA creation process works. There's a very high probability that this strategy will lose money.
“Please create an Expert Advisor for MetaTrader 4 that executes these rules:
Indicators
Short SMA: 2?period simple moving average of Close
Long SMA: 36?period simple moving average of Close
Long Entry
Condition: Short SMA (2) > Long SMA (36)
AND price closes below the Short SMA
Action: Open a buy at the close of that bar
Long Exit
Condition: price closes above the Short SMA
Action: Close the long
Short Entry
Condition: Short SMA (2) < Long SMA (36)
AND price closes above the Short SMA
Action: Open a sell at the close of that bar
Short Exit
Condition: price closes below the Short SMA
Action: Close the short
Position Sizing & Settings
Fixed size: 0.1 lots per trade
No stop?loss, no take?profit, no trailing stops”
Words of Warning
Remember that this is just step 1 in the process of creating a fully or partially automated trading strategy.
If you backtested with AI, you really, really have to double check the results.
Even if you didn't, you still have to check that the code is doing what you expected.
AI can hallucinate, so you have to be extra sure that the EA is doing what you expected before you risk real money.
Never trade the EA live until you're absolutely sure that it's working properly.
Final Tips
I hope that this tutorial will help you create you own tools that improve your trading results.
At the time that this is being written, backtesting with AI is not mature yet.
However, creating EAs for MT4 is very usable, so I would highly recommend learning how to do it.
Even if you never build an EA, you can also build very useful custom indicators that can help you spot trading opportunities and manage parts of your trades.
Have fun!
The post How to Build No-Code MT4 Expert Advisors with ChatGPT appeared first on Trading Heroes.