Download MetaTrader 5

How to write _If one buy order is closed, then go to "CloseAllBuy()".

To add comments, please log in or register
The entire history on a single page!
Pars1985 2016.01.21 09:10 


Please advise the code.

   if ((OrderType()==OP_BUY) && OP_BUY==Close)






I would like:

If one buy is closed by StopLoss, then go to "CloseAllBuy()".


Thank you 

whroeder1 2016.01.21 14:29  
  1. OrderSelect loop through history; find the last closed order (OrderCloseTime) for the pair.
  2. Determine if the close price is near the SL.
  3. OrderSelect loop through open orders; find any that were opened before the last close time for that pair and close them.
In the presence of multiple orders (one EA multiple charts, multiple EA's, manual trading) you must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
Edi Dimitrovski
Edi Dimitrovski 2016.01.24 23:31  


void yourFunc() {
 if ( lastSellCounts > sellCounts ) flag_StopNewSells = true;
 if ( flag_StopNewSells ) flag_StopNewSells = CloseAllSell(); // bool as success return false;
 if ( flag_StopNewSells ) { lastSellCounts = 0; sellCounts = 0; } // add new++ when opened new...
 /* similar for buy.. */
 /* finish remained tasks.. */
To add comments, please log in or register