Download MetaTrader 5

Scripts: CloseAllTrades

To add comments, please log in or register
Add our Twitter channel to friends and follow the news!
MetaQuotes Software Corp.
Moderator
181369
MetaQuotes Software Corp. 2010.08.03 08:19 

CloseAllTrades:

Script closes all opened and pending positions.

Author: Matus German

Lam K
84
Lam K 2010.08.05 15:52  

Really a Great!!

Very short in Programe~~!!!

And will very fast!

MQL4 Comments
16319
MQL4 Comments 2010.09.20 03:08  

I don't understan about EA.

I try it, and it work so fast.

but for multiple order (more than 10 positions)

it work too slow.

How is it..?!

Thanks :)

Matus German
2261
Matus German 2010.10.08 09:56  
in short time a want to come back to MQL and to upgrade it and resolve bugs
virtualreal
113
virtualreal 2011.10.23 22:54  

Hi Matus,

After a Google search, I've found your CloseAllTrades EA and studied it's code. As expected, your EA closes all positions based on the ticket id's from their entries.
However, in your ManagerChampion EA I noticed it was able to close multiple entries in 1 exit order.
AFAIK, it's impossible to merge trade tickets and opening a position in the opposite direction isn't allowed, so I was wondering, how did you perform this trick?

Best regards,

Jim

MQL4 Comments
16319
MQL4 Comments 2011.12.24 10:41  
hello...why i cannot download it?
Matus German
2261
Matus German 2011.12.28 12:17  
nuno_kerenz:
hello...why i cannot download it?

They have deleted the files on server, i had 10 files but now I only can upload 9 files. I pack it in an zip file now, you can download scripts also from my page http://www.mtexperts.net/en/Free/Scripts
dabbler
1103
dabbler 2012.01.15 17:12  
int start()
{
   double total;
   int cnt;
   while(OrdersTotal()>0)
   {
      // close opened orders first
      total = OrdersTotal();
      for (cnt = total ; cnt >=0 ; cnt--)
      {
         if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) 
         {
            switch(OrderType())
            {
               case OP_BUY       :
                  RefreshRates();
                  OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,Violet);break;
                   
               case OP_SELL      :
                  RefreshRates();
                  OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Violet); break;
            }             
         }
      }

BUG 1: The first for loop needs to start at OrdersTotal() -1 since arrays start at position [0].

BUG 2: Not really a bug, as such, but for speed critical code you should not be calling RefreshRates() at all since you are using the MarketInfo function. The RefreshRates() function only applies to Bid/Ask on this chart symbol.

Matus German
2261
Matus German 2012.01.16 11:37  
dabbler:
int start()
{
   double total;
   int cnt;
   while(OrdersTotal()>0)
   {
      // close opened orders first
      total = OrdersTotal();
      for (cnt = total ; cnt >=0 ; cnt--)
      {
         if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)) 
         {
            switch(OrderType())
            {
               case OP_BUY       :
                  RefreshRates();
                  OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,Violet);break;
                   
               case OP_SELL      :
                  RefreshRates();
                  OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Violet); break;
            }             
         }
      }

BUG 1: The first for loop needs to start at OrdersTotal() -1 since arrays start at position [0].

BUG 2: Not really a bug, as such, but for speed critical code you should not be calling RefreshRates() at all since you are using the MarketInfo function. The RefreshRates() function only applies to Bid/Ask on this chart symbol.




it is not big issue, it still will close all trades, but you are right, I will correct it,
Russell Bagby
719
Russell Bagby 2014.09.22 17:17  
Could you tell me how to get it working?
because when I execute on a chart nothing happens.
To add comments, please log in or register