Scripts: CloseAllTrades

 

CloseAllTrades:

Script closes all opened and pending positions.

Author: Matus German

 

Really a Great!!

Very short in Programe~~!!!

And will very fast!

 

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 :)

 
in short time a want to come back to MQL and to upgrade it and resolve bugs
 

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

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

 
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,
 
Could you tell me how to get it working?
because when I execute on a chart nothing happens.
 

This is a great script and very fast in action. Amazing tool, Thanks!

Reason: