how to carry out an OCO(one cancel the other) command in MT4? for example: i sell eur vs usd at 1.39500,then i set a sell oco,limitprice(takeprofit) at 1.4050,stopprice(stoploss) at 1.39000,how can i make system hit stoploss(stopprice) level while it automatic cancel another takeprofit order.
how to editor this program?
There are no native OCO orders in MT4 of a kind comparable to other trading platforms. You can't place two pending orders and have one automatically cancelled when the other gets filled. However, MT4 does provide a subset of this functionality catering specifically for stop-losses and profit targets: when opening a position you can set a s/l and t/p on it - see OrderSend() - and have the position automatically closed at whichever of these prices gets hit first. The s/l and t/p are tied to the specific opening order: if that is manually closed, its s/l and t/p are automatically cancelled. The s/l and t/p aren't listed independently as pending orders in MT4 - though that's effectively what they are.
If you want full OCO functionality, then you have to synthesise it yourself through code. For example, if you are trading some sort of breakout strategy where you have a sell-stop and a buy-stop, and you want the second of the orders to be cancelled when the first gets filled, then you have to continually monitor both orders in your code and do an OrderDelete() when the first of the orders gets filled.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
how to carry out an OCO(one cancel the other) command in MT4? for example: i sell eur vs usd at 1.39500,then i set a sell oco,limitprice(takeprofit) at 1.4050,stopprice(stoploss) at 1.39000,how can i make system hit stoploss(stopprice) level while it automatic cancel another takeprofit order.
how to editor this program?