When you buy something through a single link on our site, we can get the affiliate commission.
I started using Metatrader in about 2008 in 2008.
Unfortunately, this has not changed much despite the onset of MT5.
It means that it still doesn’t have “Cancels each other“Order function – some people, including myself, prefer to call” Order Cancel Order “.
Whatever you call it, we can now easily add this order type with AI in MT5.
You do not need to know how to code.
In this tutorial, I will show why the OCO is so useful and how to use Chat GPT to make your OCO EA easily make for Metreator 5.
https://www.youtube.com/watch?v=piix-05pniw
How does OCO work
“OCO)” (OCO) Trade orders are a type of conditional orders where two pending orders are placed simultaneously, but only one can be brought into action.
When one order is dynamic and filled, the other is automatically canceled.
This can be very useful to take advantage of various business opportunities.
Oko example
Here is an example where you can use OCO order to take advantage of a potential profitable situation.

This pin bar is also a nasty bar, which can indicate the above.
The last time there was a lot of volume, which shows that this trend may end because the traders are guaranteed.
Now I can now enter this trade, but there is no guarantee that the price will decrease as expected.
So I can compile 2 pending orders, one sales range higher than the current price (high blue line) and the sale below the current price (lower blue line).
The first thing that may be is that the price can be left behind before going down.
If the price goes back, I will enter the trade at a better price and make a little more money. The second trade will be canceled and I will not get a duplicate trade.
Even if the price is removed from the damage above the candle and there is much damage, if I enter the current candle, it will be less damage.
Another thing that may be that the price can only go straight down, as is expected. In this case, the cell stop (lower blue line) will be targeted and the withdrawal trade will be canceled.
This pending order will take me to the market if I go in the direction I expect, but does not back down. This is the best in both worlds.
If the price I have not taken the price according to the plan, I will lose less money because the sales limit will be affected instead of the sales stop.
As you can see, the use of OCO order can be extremely useful.
How much money I save from doing this can really increase over time.
MT5 EA Design
Before talking to Chat GPT, we have to take care of how we will design this MT5 EA.
There are only 2 things we have to calculate.
First, there may be other pending trade in the same market, so we have to calculate it and only have to cancel the orders that we mark for cancellation, and not to anyone else.
Second, we only want to cancel the trade in the same chart market with which EA is connected.
This will reject any trade in other markets that contain the same marker.
In Mettrader 5, we can use Comment Field To easily mark the trade that we want to implement OCO logic.
It needs to be a bit of habit because using the comment field, the order has to enter through the right -click menu and not on the one -click button.
But this is not a big deal.
Chat GPT indicating to get OCO in MT5
So this EA’s LI, I am going to present Chat GPT immediately with the following:
Please create an EA for Metreator 5, which is looking for open orders with a comment in the chart market with which EA is connected. When an open order is found with a comment, in the same market on the next tick, cancel all pending orders with similar comments. Do not provide any input, everything should be without the input of the user. Automatically compete with the comment fields.
Copy and paste this indicator without hesitation and use it for yourself.
But remember that if you choose to use this prompt, I’m not responsible for whatever happens.
Chat GPT or any other AI can give you a different result from the model you use, so you always have to check the EA well before using it directly into the account.
Keep reading to learn how to test it.
Make an expert advisor in MT5
Once you get a code from Chat GPT, just kill it Copy Link to the upper right corner of the code window to copy the code.

Then open MT5 and click on it ide Button above

It will open the MQL 5 editor.
Click on Latest Buttons in the upper left corner of the screen.
A window will come with a wizard.
- On the first screen, select: Expert Advisor (Template)
- Click Next
- Give EA a name
- Keep clicking Next Unless you reach the end of the wizard
The rest of the settings do not matter because you are just going to copy from Chat GPT to the code.
When you see the EA template that MT5 has created for you, click anywhere on the screen and IT control+A to select all the text.
Then hit Backspace Or Delete To delete everything on your keyboard.
Hit now Control+v Paste the chat GPT code into an empty area.
Finally, click on Compile Buttons on the upper part of the screen to check the code.
If it sets without mistakes, congratulations!
Go to the installation section below.
Otherwise, use the next section to fix the mistakes.
Tracing defects
Chat GPT cannot be found for the first time.
When you set the code, a good opportunity is that you will find some such mistakes or warnings.

When this happens, using all error messages in MT5, using, easily highlight all error messages Shift+left mouse click And Click right > Copy Copy them.
Then go to Chat GPT and ask to fix it.
For example:

You may have to do it a few times, but it usually detects it.
Remember this is just a syntax test.
Now you have to examine the logic of the program.
Put it in one DEMO Account and tests until you trust the results.
If you are having trouble that you can’t do right, check to see if you are using MT5.
The code of MT4 and MT5 is different, so you can’t use this EA in MT4.
How to install EA
After setting a bar code, go back to the Man MT5 window and see it in Navigator Window
If Navigator The section is not available, then go: See > Navigator To open the window.
Go to Expert Click and drag the EA created on the section and chart.

Once it comes to the chart, you will see the name of the EA in the upper right corner of the chart.
The hat icon must be blue to show this.

If it’s not blue then click on Alloe trading The button in the upper part of the screen to ensure that the EA is activated.
Test the EA
The time has come for you to check your new EA.
Must check this in a demo account, if something goes wrong.
To take the trade, right -click on the chart you want to trade.
Go: Trade > New order

In the field of comments, enter anything you want to identify the order.
It can be something like “999” or what is easy to remember.
Enter details for the underlined order, then open a new pending order and enter The same comment text In the comment field.
Set 2, 2 orders that are very close to the current price, so immediately one of them. Let it be hanged.
You can also see how the EA behaves with the same comments with numerous pending orders.
Try all kinds of strange situations that you can think about working as expected.
Check it unless you are 100 % confident that it is working properly.
More defects tracked
If there are problems with EA’s logic, then return to GPT to do their job.
At some point, you have to start understanding the code, so now it’s a good time to start.
You don’t need to know how to code, but you should know how every part of the code works.
Fortunately, you can get a chatgot to explain it to you.
It’s good enough to explain in fact.
Keep asking questions until you understand how the program works.
Remember that chatigat may sound all professional, but it doesn’t know as much as you think.
Tell him exactly what you want and do not let it enter the logic that it feels good, but not in accordance with what you want.
Like any other skill, the building with Chat GPT can initially be a bit disappointing.
But once you get the execution of it, it’s extremely powerful and helps you build commercial tools you always want.
The final views
So there is a way to make OCO EA for MT5.
But this is just the beginning.
What else can you make?
Use your creativity and let your imagination go wild.
You probably make some amazing… and make it extremely profitable.

