Download MetaTrader 5

Scripts: CloseAllTrades

To add comments, please log in or register
MetaQuotes Software Corp.
Moderator
184307
MetaQuotes Software Corp.  

CloseAllTrades:

Script closes all opened and pending positions.

Author: Matus German

Lam K
84
Lam K  

Really a Great!!

Very short in Programe~~!!!

And will very fast!

MQL4 Comments
16319
MQL4 Comments  

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
2374
Matus German  
in short time a want to come back to MQL and to upgrade it and resolve bugs
virtualreal
113
virtualreal  

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  
hello...why i cannot download it?
Matus German
2374
Matus German  
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  
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
2374
Matus German  
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  
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