This is One Cancels the Other script. OCO orders are not available in MT4 but they are standard on other platforms. To get this functionality in MT4 one can run this script.
The script will be put in
MetatraderInstall/experts/scripts folder and after restart of Metatrader it
will be available in Navigator/Scripts.
With default parameters it opens two pending stop orders, one for
sell and one for buy. This is also known as Straddle and very
popular among News Trades. One have a possibility to
change order type, set Slippage and Expiration. Also
when StopLoss and/or TakeProfits are set to different value than 0
this value will be used during sending orders. Moreover, the script allows for adjusting stop loss and take profits by dragging them with mouse.
One should note, that setting pending orders require that they
are put in minimum distance from a market price, Ask for BUYSTOP
and Bid for SELLSTOP. This minimum price is different among
brokers and can be found in Symbol Properties as Stops level.
Most of brokers have value 5 which means that a BUYSTOP can be
put with minimum distance of 6 pips above Ask, and SELLSTOP 6
pips below Bid. In case that orders are set too close then
'ERROR #130 : invalid stops' message is put.
The script has following inputs:
extern double BuyOrderOffset = 15; // 15 pips above the market (buy stop order)
extern double SellOrderOffset = -15; // 15 pips below the market (sell stop order)
extern double BuyLots = 1.0; // Buy position size
extern double SellLots = 1.0; // Sell position size
// Trailing stop
extern double StartTrail = 60; // Start trail after so many pips
extern double TrailingStop = 50; // 0 deactivates Trailing Stop
extern double TrailStep = 1; // With which increments TS moves
// Break Even
extern int GainForBE = 50; // How many pips will trigger Break Even. 0 deactivates.
extern int PipsBE = 10; // Level at which Break Even will be put
// Standard SL and TP
extern int StopLoss = 35; // 0 deactivates Hard Stop Loss
extern int TakeProfit = 75; // 0 deactivates Hard Take Profit
extern datetime Expiration = D'15/7/2020 12:00'; // At what time pending orders should expire
extern int Slippage = 1; // Allow entry slippage
extern color BUY_Color = Blue; // Buy line color
extern color SELL_Color = Red; // Sell line color
extern color SL_TP_Color = Orange; // Stop loss and take profit lines color
extern color BE_Color = Green; // Break even lines color
extern int Magic = 20110315;
Magic is a special number to be used as a tag to identify both orders from the same pair. Usually you donít need to bother about it, however when you would like to put more than one straddle on a single pair (on different MT4 charts), then you should set this number to be different for each straddle. A straddle is identified by symbol name and magic.