StockWaves
  • Home
  • Global Markets
    Global MarketsShow More
    Trump Pentagon is ‘considering’ about taking fairness stakes in protection contractors, says Lutnick
    Trump Pentagon is ‘considering’ about taking fairness stakes in protection contractors, says Lutnick
    0 Min Read
    Longer-dated US Treasuries, shares tumble as Trump's Fed battle heats up
    Longer-dated US Treasuries, shares tumble as Trump's Fed battle heats up
    0 Min Read
    What to anticipate when Signet Jewelers (SIG) studies Q2 2026 earnings outcomes
    What to anticipate when Signet Jewelers (SIG) studies Q2 2026 earnings outcomes
    3 Min Read
    The Bunzl share value jumps 4% on H1 outcomes. Is it prepared for a resurgence?
    The Bunzl share value jumps 4% on H1 outcomes. Is it prepared for a resurgence?
    4 Min Read
    Trump fires Fed Governor Lisa Prepare dinner, cites mortgage fraud declare
    Trump fires Fed Governor Lisa Prepare dinner, cites mortgage fraud declare
    10 Min Read
  • Investment Strategies
    Investment StrategiesShow More
    Fund supervisor adjustments within the DSP Massive & Mid Cap Fund
    Fund supervisor adjustments within the DSP Massive & Mid Cap Fund
    0 Min Read
    Mutual Fund Perception's September challenge is out!
    Mutual Fund Perception's September challenge is out!
    0 Min Read
    Earnings distribution in schemes of Baroda BNP Paribas Mutual Fund
    Earnings distribution in schemes of Baroda BNP Paribas Mutual Fund
    0 Min Read
    Vikran Engineering IPO: Must you subscribe?
    Vikran Engineering IPO: Must you subscribe?
    0 Min Read
    Why flexi-cap funds go well with most traders
    Why flexi-cap funds go well with most traders
    0 Min Read
  • Market Analysis
    Market AnalysisShow More
    Upcoming IPO: Snehaa Organics IPO to open on August 29; key particulars right here
    Upcoming IPO: Snehaa Organics IPO to open on August 29; key particulars right here
    4 Min Read
    Multibagger inventory underneath ₹60 rallies 10% to 4-week excessive on robust volumes; surges 900% in 5 years
    Multibagger inventory underneath ₹60 rallies 10% to 4-week excessive on robust volumes; surges 900% in 5 years
    3 Min Read
    Earnings Distribution declared by Bandhan Mutual Fund
    Earnings Distribution declared by Bandhan Mutual Fund
    0 Min Read
    How Compounding Works in Mutual Funds
    How Compounding Works in Mutual Funds
    12 Min Read
    Trump’s tariffs on India: Can Narendra Modi plug in Act East coverage with China’s Belt and Street Initiative?
    Trump’s tariffs on India: Can Narendra Modi plug in Act East coverage with China’s Belt and Street Initiative?
    9 Min Read
  • Trading
    TradingShow More
    Hillary Clinton Says Her 2024 Warning Of Troops Patrolling Streets Has Come True In Trump 2.0: ‘I Want I would Been Unsuitable’
    Hillary Clinton Says Her 2024 Warning Of Troops Patrolling Streets Has Come True In Trump 2.0: ‘I Want I would Been Unsuitable’
    3 Min Read
    Gold, Silver And Oil Miners Inventory On Fireplace: High 4 Progress Picks – First Majestic Silver (NYSE:AG), Airthings (OTC:ARTGF)
    Gold, Silver And Oil Miners Inventory On Fireplace: High 4 Progress Picks – First Majestic Silver (NYSE:AG), Airthings (OTC:ARTGF)
    4 Min Read
    Southwest Airways Will Cost Passengers Who Can’t Match In A Single Seat Beginning January – Southwest Airways (NYSE:LUV)
    Southwest Airways Will Cost Passengers Who Can’t Match In A Single Seat Beginning January – Southwest Airways (NYSE:LUV)
    2 Min Read
    Trump Fires Fed Governor Lisa Prepare dinner, Cites ‘False Statements’ On Mortgage Agreements As Motive: ‘Deceitful And Doubtlessly Legal Conduct’
    Trump Fires Fed Governor Lisa Prepare dinner, Cites ‘False Statements’ On Mortgage Agreements As Motive: ‘Deceitful And Doubtlessly Legal Conduct’
    3 Min Read
    Bitcoin Tumbles Amid ETF Outflows; Ethereum, Dogecoin, Solana Crash: Analytics Agency Says ETH Can Make It To ,000 – Grayscale Bitcoin Mini Belief (BTC) Widespread items of fractional undivided useful curiosity (ARCA:BTC)
    Bitcoin Tumbles Amid ETF Outflows; Ethereum, Dogecoin, Solana Crash: Analytics Agency Says ETH Can Make It To $5,000 – Grayscale Bitcoin Mini Belief (BTC) Widespread items of fractional undivided useful curiosity (ARCA:BTC)
    3 Min Read
Reading: Learn how to Get One Cancels the Different (OCO) Orders on MetaTrader 5
Share
Font ResizerAa
StockWavesStockWaves
  • Home
  • Global Markets
  • Investment Strategies
  • Market Analysis
  • Trading
Search
  • Home
  • Global Markets
  • Investment Strategies
  • Market Analysis
  • Trading
Follow US
2024 © StockWaves.in. All Rights Reserved.
StockWaves > Trading > Learn how to Get One Cancels the Different (OCO) Orders on MetaTrader 5
Trading

Learn how to Get One Cancels the Different (OCO) Orders on MetaTrader 5

StockWaves By StockWaves Last updated: May 14, 2025 14 Min Read
Learn how to Get One Cancels the Different (OCO) Orders on MetaTrader 5
SHARE


Contents
How OCO WorksOCO InstanceMT5 EA DesignThe ChatGPT Immediate to Get OCO in MT5Create the Skilled Advisor in MT5TroubleshootingLearn how to Set up the EACheck the EAExtra TroubleshootingUltimate Ideas

Once you purchase one thing via one of many hyperlinks on our website, we could earn an affiliate fee.

I began utilizing MetaTrader again in about 2008.

Sadly, it hasn’t modified a lot, even with the launch of MT5.

Meaning it nonetheless does not have the “One Cancels the Different” order operate. Some folks, together with myself, favor to name this “Order Cancels Order.”

No matter you name it, now we will now simply add this order kind to MT5 with the assistance of AI.

You need not know code. 

On this tutorial, I am going to present why OCO is so helpful and use ChatGPT to simply create your personal OCO EA for MetaTrader 5.

How OCO Works

“One Cancels the Different” (OCO) buying and selling orders are a kind of conditional order the place two pending orders are positioned concurrently, however just one will be executed.

When one of many orders is triggered and stuffed, the opposite is robotically canceled.

This may be very helpful for making the most of completely different buying and selling alternatives.

OCO Instance

Here is an instance the place you should utilize an OCO order to make the most of a doubtlessly worthwhile scenario.

AUDCAD chart

This Pin Bar can also be an Engulfing Bar, which may sign a prime.

The earlier bar had very excessive quantity, displaying that this development may very well be coming to an finish as a result of merchants look like bailing out.

Now I may enter this commerce now, however there isn’t any assure that value will drop as anticipated.

So I can arrange 2 pending orders, one promote restrict above the present value (greater blue line) and a promote cease beneath the present value (decrease blue line).

The very first thing that would occur is value may retrace earlier than shifting again down.

If value does retrace, I’ll enter the commerce at a barely higher value and make a bit of extra money. The second commerce will likely be cancelled and I will not take a replica commerce.

Even when value retraces and hits a cease loss above the candle, the loss will likely be smaller than if I entered on the shut of the present candle.

One other factor that would occur is value may simply head straight down, as anticipated. On this case, the promote cease (decrease blue line) will likely be hit and the retracement commerce will likely be cancelled.

This pending order will get me into the market if goes within the route that I count on, however does not retrace. It is the most effective of each worlds.

If value does not go as I deliberate, I am going to lose much less cash as a result of the promote restrict will get hit as an alternative of this promote cease.

As you’ll be able to see, utilizing a OCO order will be extraordinarily helpful.

The sum of money I save by doing this will actually add up over time.

MT5 EA Design

Earlier than we speak to ChatGPT, we now have to place a bit of thought into how we are going to design this MT5 EA.

There are solely 2 issues that we now have to account for.

First, there may be different pending trades in the identical market, so we must account for that and solely cancel orders that we mark for cancellation, and never any others.

Second, we solely need to cancel trades in the identical market of the chart that the EA is connected to.

This can rule out any trades in different markets that occur to have the identical marker.

In MetaTrader 5, we will use the remark area to simply mark trades that we need to apply the OCO logic to.

It takes a bit of getting used to as a result of as a way to use the remark area, the order must be entered by way of the right-click menu and never the one-click button.

But it surely’s not an enormous deal.

The ChatGPT Immediate to Get OCO in MT5

So for this EA, I will immediate ChatGPT with the next:

Please create an EA for MetaTrader 5 that appears for open orders with a remark available in the market of the chart that the EA is connected to. When an open order is discovered, cancel all pending orders with an identical remark, available in the market of the chart that the EA is connected to. Search for any commerce with a remark and shut the pending orders which have an identical remark. Don’t present an enter area for the remark to be looked for. Robotically match the remark fields.

Be happy to repeat and paste that immediate and use it for your self.

However keep in mind that I am NOT answerable for no matter occurs when you select to make use of that immediate. 

ChatGPT or one other AI would possibly offer you a special consequence than what I acquired, relying on which mannequin you employ, so that you at all times have to check an EA totally earlier than utilizing it in a stay account. 

Preserve studying to learn to check it.

Create the Skilled Advisor in MT5

When you get the code from ChatGPT, merely hit the Copy hyperlink within the higher proper nook of the code window to repeat the code.

Copy link in ChatGPT

Then open MT5 and click on on the IDE button on the prime.

IDE button in MT5

This can open the MQL5 Editor.

Click on on the New button within the higher left nook of the display.

A window will provide you with a wizard.

  • On the primary display, choose: Skilled Advisor (template)
  • Click on Subsequent
  • Give the EA a reputation
  • Preserve clicking Subsequent till you get to the top of the wizard

The remainder of the settings do not matter since you’re simply going to repeat within the code from ChatGPT anyway.

Once you see the EA template that MT5 created for you, click on anyplace on the display and it Management+A to pick out all of the textual content.

Then hit Backspace or Delete in your keyboard to delete all the pieces.

Now hit Management+V to stick the ChatGPT code into the clean space.

Lastly, click on on the Compile button on the highest of the display to verify the code.

If it compiles with out errors, congratulations!

Skip right down to the set up part beneath.

In any other case, use the following part to repair the errors.

Troubleshooting

ChatGPT may not get it proper the primary time.

Once you compile the code, there is a good likelihood that you will get some errors or warnings like this.

MT5 errors

When that occurs, merely spotlight all the error messages in MT5, through the use of Shift+left mouse click on and right-click > copy to repeat them.

Then go over to ChatGPT and ask it to repair it.

For instance:

Telling ChatGPT to fix compile errors

You might need to do that a number of occasions, however it often figures it out finally.

Keep in mind that is just a syntax check.

Now it’s a must to verify the logic of this system.

Put it right into a demo account and check till you are assured within the outcomes.

For those who’re having issues that you simply can’t right, verify to see that you simply’re utilizing MT5.

The code for MT4 and MT5 are completely different, so you can’t use this EA in MT4.

Learn how to Set up the EA

As soon as the code compiles, return to the principle MT5 window and look within the Navigator window.

If the Navigator part just isn’t accessible, then go to: View > Navigator to open the window.

Go to the Skilled Advisors part and click on and drag the EA you created onto the chart.

Add EA to chart

As soon as it’s on the chart, you will see the title of the EA within the higher proper nook of the chart.

The hat icon must be blue to indicate that it is working.

MT5 icon

If it is not blue, then click on the Algo Buying and selling button on the prime of the display to ensure that the EA is activated.

Check the EA

Now it is time to check your new EA.

You’ll want to check this in a DEMO account, simply in case one thing goes fallacious. 

To take a commerce, proper click on on the chart you need to commerce on.

Go to: Buying and selling > New Order

Comment

Within the remark area, enter something you need to determine the order.

It may very well be one thing like “999” or no matter is straightforward to recollect.

Enter the small print for the pending order, then open a brand new pending order and enter the identical remark textual content within the remark area.

To check this rapidly, set 2 orders which can be very near the present value, so one in every of them will get executed straight away.

It’s also possible to see how the EA treats a number of pending orders with the identical remark.

Strive each form of bizarre scenario you’ll be able to consider to make sure that the EA is working as anticipated.

Check it till you might be 100% assured that it is working accurately.

Extra Troubleshooting

If there are points with the logic of the EA, then return to ChatGPT to work them out.

In some unspecified time in the future, you will have to start out understanding the code, so now is an effective time to start out.

You do not have to know code, however you need to understand how every a part of the code works.

Fortunately, you will get ChatGPT to clarify it to you.

It is really fairly good at explaining.

Preserve asking it questions till you perceive how this system works.

Keep in mind that ChatGPT would possibly sound all skilled, however it does not know as a lot as you assume.

Inform it precisely what you need and do not let it insert logic that it thinks is sweet, however is not in keeping with what you need. 

Like another talent, constructing with ChatGPT is usually a little irritating at first.

However when you get the dangle of it, it is extraordinarily highly effective and enable you to construct all of the buying and selling instruments that you have at all times needed.

Ultimate Ideas

In order that’s create an OCO EA for MT5.

However that is just the start.

What else are you able to make?

Use your creativity and let your creativeness run wild.

You would possibly simply create one thing superb…and tremendous worthwhile.

 

 

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.

By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Twitter Copy Link Print
Previous Article 3 high-yield passive earnings shares to think about shopping for proper now 3 high-yield passive earnings shares to think about shopping for proper now
Next Article Shares to purchase in 2025: Aptus Worth, Escorts amongst 5 shares that would give 18-26% return – Brokerage Suggestions Shares to purchase in 2025: Aptus Worth, Escorts amongst 5 shares that would give 18-26% return – Brokerage Suggestions
Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

FacebookLike
TwitterFollow
PinterestPin
InstagramFollow

Subscribe Now

Subscribe to our newsletter to get our newest articles instantly!

Most Popular
Trump Pentagon is ‘considering’ about taking fairness stakes in protection contractors, says Lutnick
Trump Pentagon is ‘considering’ about taking fairness stakes in protection contractors, says Lutnick
August 26, 2025
Hillary Clinton Says Her 2024 Warning Of Troops Patrolling Streets Has Come True In Trump 2.0: ‘I Want I would Been Unsuitable’
Hillary Clinton Says Her 2024 Warning Of Troops Patrolling Streets Has Come True In Trump 2.0: ‘I Want I would Been Unsuitable’
August 26, 2025
How Quick&Up is Powering India’s Diet Revolution – Varun Khanna Explains
How Quick&Up is Powering India’s Diet Revolution – Varun Khanna Explains
August 26, 2025
Adani Ports, ICICI Financial institution, Titan amongst prime picks as PL Capital eyes 12-month Nifty goal of 27,609
Adani Ports, ICICI Financial institution, Titan amongst prime picks as PL Capital eyes 12-month Nifty goal of 27,609
August 26, 2025
Longer-dated US Treasuries, shares tumble as Trump's Fed battle heats up
Longer-dated US Treasuries, shares tumble as Trump's Fed battle heats up
August 26, 2025

You Might Also Like

Why Tapestry Inventory Is Cooling Off Regardless of Coach’s Scorching Streak – Tapestry (NYSE:TPR)
Trading

Why Tapestry Inventory Is Cooling Off Regardless of Coach’s Scorching Streak – Tapestry (NYSE:TPR)

3 Min Read
Reddit, Roblox And Garmin Are Amongst High 10 Massive Cap Gainers Final Week (Oct 28-Nov 1): Are The Others In Your Portfolio?
Trading

Reddit, Roblox And Garmin Are Amongst High 10 Massive Cap Gainers Final Week (Oct 28-Nov 1): Are The Others In Your Portfolio?

0 Min Read
Bitcoin Breaks 6,000, Ethereum, Dogecoin Soar As Crypto Traders Shrug Off Tariff Considerations: Analyst Says This Is Your ‘Final Probability’ To Catch ETH’s Breakout – Grayscale Bitcoin Mini Belief (BTC) Widespread items of fractional undivided helpful curiosity (ARCA:BTC)
Trading

Bitcoin Breaks $116,000, Ethereum, Dogecoin Soar As Crypto Traders Shrug Off Tariff Considerations: Analyst Says This Is Your ‘Final Probability’ To Catch ETH’s Breakout – Grayscale Bitcoin Mini Belief (BTC) Widespread items of fractional undivided helpful curiosity (ARCA:BTC)

3 Min Read
Monte Carlo Simulation in Backtesting: Why All Merchants Want It
Trading

Monte Carlo Simulation in Backtesting: Why All Merchants Want It

13 Min Read

Always Stay Up to Date

Subscribe to our newsletter to get our newest articles instantly!

StockWaves

We provide tips, tricks, and advice for improving websites and doing better search.

Latest News

  • About Us
  • Contact Us
  • Privacy Policy
  • Terms Of Service

Resouce

  • Blockchain
  • Business
  • Economics
  • Financial News
  • Global Markets
  • Investment Strategies
  • Market Analysis
  • Trading

Trending

Trump Pentagon is ‘considering’ about taking fairness stakes in protection contractors, says Lutnick
Hillary Clinton Says Her 2024 Warning Of Troops Patrolling Streets Has Come True In Trump 2.0: ‘I Want I would Been Unsuitable’
How Quick&Up is Powering India’s Diet Revolution – Varun Khanna Explains

2024 © StockWaves.in. All Rights Reserved.

Welcome Back!

Sign in to your account

Not a member? Sign Up