Close all order at once - Not thru looping opening order

 

i had some check and i knew there is code allow to loop thru all open order and select the type of order to close , delete

however this is time confusing (i.e around 6 txn will took about 3 second) where its not feasible for me

i had see some example where people is closing the deal (i.e 15 deals) on exactly same time (same second)


would appreciate if anyone can guide me thru how to do that

 
lhkoon2013: closing the deal (i.e 15 deals) on exactly same time (same second)


would appreciate if anyone can guide me thru how to do that

Can't be done.

 
lhkoon2013:

i had some check and i knew there is code allow to loop thru all open order and select the type of order to close , delete

however this is time confusing (i.e around 6 txn will took about 3 second) where its not feasible for me

i had see some example where people is closing the deal (i.e 15 deals) on exactly same time (same second)


would appreciate if anyone can guide me thru how to do that

If you use an asynchronous trade request, then about a thousand trade requests can be sent through MQL5 in one second. But even in this case, everything will depend on the speed at which trade orders are executed on the broker's server.

Example of asynchronous orders (one loop, no checks)

//+------------------------------------------------------------------+
//|                                                    Close All.mq5 |
//|                         Copyright © 2016-2022, Vladimir Karputov |
//|                      https://www.mql5.com/en/users/barabashkakvn |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016-2022, Vladimir Karputov"
#property link      "https://www.mql5.com/en/users/barabashkakvn"
#property version   "1.009"
//---
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
CPositionInfo  m_position;                   // trade position object
CTrade         m_trade;                      // trading object
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   m_trade.SetAsyncMode(true);
   for(int i=PositionsTotal()-1; i>=0; i--) // returns the number of current positions
      if(m_position.SelectByIndex(i))     // selects the position by index for further access to its properties
        {
         if(m_position.PositionType()==POSITION_TYPE_BUY)
           {
            if(!m_trade.PositionClose(m_position.Ticket())) // close a position by the specified m_symbol
               Print(__FILE__," ",__FUNCTION__,", ERROR: ","BUY PositionClose ",m_position.Ticket(),", ",m_trade.ResultRetcodeDescription());
           }
         if(m_position.PositionType()==POSITION_TYPE_SELL)
           {
            if(!m_trade.PositionClose(m_position.Ticket())) // close a position by the specified m_symbol
               Print(__FILE__," ",__FUNCTION__,", ERROR: ","SELL PositionClose ",m_position.Ticket(),", ",m_trade.ResultRetcodeDescription());
           }
        }
  }
//+------------------------------------------------------------------+
Documentation on MQL5: Standard Library / Trade Classes / CTrade / SetAsyncMode
Documentation on MQL5: Standard Library / Trade Classes / CTrade / SetAsyncMode
  • www.mql5.com
SetAsyncMode(bool) - CTrade - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
Close_All.mq5  4 kb
 
William Roeder #:

Can't be done.

Next time don't answer instead of giving a such answer. Nothing is impossible in programming especially the person said he saw it somewhere but you are still giving a very discouring answer while you are ignorent 

 
Vladimir Karputov #:

If you use an asynchronous trade request, then about a thousand trade requests can be sent through MQL5 in one second. But even in this case, everything will depend on the speed at which trade orders are executed on the broker's server.

Example of asynchronous orders (one loop, no checks)

thank you , will give it a trial

i am just learning thru online open source and its kind of difficult thing

 
Ugochukwu Mobi #:

Next time don't answer instead of giving a such answer. Nothing is impossible in programming especially the person said he saw it somewhere but you are still giving a very discouring answer while you are ignorent 

yeah, exactly . agree with you

can see most of his replies was on that pattern (in trading term , should call trend following)

guess he was just bored and sitting in pc everyday to finish his day

 
Ugochukwu Mobi #: Next time don't answer instead of giving a such answer. Nothing is impossible in programming especially the person said he saw it somewhere but you are still giving a very discouring answer while you are ignorent 

William answered correctly. It cannot be done. It is physically impossible, even in programming. Unfortunately what the person saw was false! Vladimir took it further and explained it in more detail, but he still mentioned that it cannot be done. So if you don't know or understand this, don't be so quick to jump to conclusions.

 
lhkoon2013 #: yeah, exactly . agree with you can see most of his replies was on that pattern (in trading term , should call trend following) guess he was just bored and sitting in pc everyday to finish his day

Just because William gave a short answer does not invalidate what he wrote. What he wrote is correct, and so is Vladimir. It cannot be done.

What you saw was false or a fluke. There is no way to force all positions to be closed together at once. You always have to loop through them one by one, whether that be in synchronous mode or asynchronous mode.

The asynchronous mode can make it seem faster on the client side (terminal), but the actual execution is still dependant on the server side (the broker).

So I will repeat what William stated: Can't be done.

 
Fernando Carreiro #:

William answered correctly. It cannot be done. It is physically impossible, even in programming. Unfortunately what the person saw was false! Vladimir took it further and explained it in more detail, but he still mentioned that it cannot be done. So if you don't know or understand this, don't be so quick to jump to conclusions.

what makes you think u knew all ?

how much u willing bet for me to show you its done ?

 
lhkoon2013 #:

what makes you think u knew all ?

how much u willing bet for me to show you its done ?

Please show us, we like to learn new things.
 
lhkoon2013 #: how much u willing bet for me to show you its done ?

Please show us how you are going to change the broker's server software.

Reason: