Download MetaTrader 5
To add comments, please log in or register
All articles are available from MetaTrader 5. Contribute your own one!
strontiumDog
263
strontiumDog 2014.07.31 06:49 

Hello

I've searched around and I've not found a script for MT4 specifically which closes all trades on all charts immediately at whatever price.  Has anyone got one?

This will help with testing EAs which work in strategies which work across multiple charts per terminal.

Thanks

qjol
3243
qjol 2014.07.31 11:39  
strontiumDog:


Close All Trades In All Charts Simultaneously Immediately 

I've searched around and I've not found


because there isn't

never was and never will

Daniel Petrovai
440
Daniel Petrovai 2014.08.01 03:01  
strontiumDog:

Hello

I've searched around and I've not found a script for MT4 specifically which closes all trades on all charts immediately at whatever price.  Has anyone got one?

This will help with testing EAs which work in strategies which work across multiple charts per terminal.

Thanks


Are you looking to close all orders placed by the EA on all symbols or do you want to close all orders regardless of who opened them ?

If you're looking to close one symbol regardless of who opened the order :

 

If you want to close all symbols, same function without the symbol condition :

 

void CloseAll()
  {
   int trade=0;
   closed=false;
   double price=0.0;
   for(trade=OrdersTotal()-1;trade>=0;trade--)
     {
      if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))//if order select fails
        {
         Print("Order select failed in CloseAll() with error : "+(string)GetLastError());//tell me the error
         break;
        }
      // else if order select didn't fail
      else
        {
         price=0.0;
         if(OrderType()==OP_BUY)
           {
            price=Bid;
           }
         else
         if(OrderType()==OP_SELL)
           {
            price=Ask;
           }
         else
           {
            continue;
           }
         closed=OrderClose(OrderTicket(),OrderLots(),price,slip,Blue);
         if(!closed)
           {
            Print("Close order failed with error : "+(string)GetLastError());//tell me the error
           }
        }
     }
  }

 I believe you get the idea.

Note that pending orders have to be deleted not closed (Use OrderDelete() instead of OrderClose() ) .

qjol
3243
qjol 2014.08.01 03:17  

@ thrdel your code doesn't do what strontiumDog wants

he want to close all the orders "Simultaneously Immediately"

so with your code ("or any code")  it's not gonna happen

B.T.W 

you don't need to write:

 

      else
        {
            price=0.0;
            if(OrderType()==OP_BUY)
              {
               price=Bid;
              }
            else
            if(OrderType()==OP_SELL)
              {
               price=Ask;
              }
            else
              {
               continue;
              }
         closed=OrderClose(OrderTicket(),OrderLots(),price,slip,Blue);

 

you can simple write

 

      else
        {
         closed=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slip,Blue);
Daniel Petrovai
440
Daniel Petrovai 2014.08.01 08:27  
qjol:

@ thrdel your code doesn't do what strontiumDog wants

he want to close all the orders "Simultaneously Immediately"

so with your code ("or any code")  it's not gonna happen

Hi qjol:,

Long time, how are we ?

Sure one cannot close " all orders simultaneously immediately " but hey, one can only assume he meant ASAP.

In regards to  using OrderClosePrice(), I will test it  to see if it works. So far I only used OrderClosePrice() after selecting the order from history .

If it works , it's new for me.

whroeder1
13641
whroeder1 2014.08.01 11:52  
thrdel: If it works , it's new for me.
OCP() works fine, has for years.
It's value is set at the OrderSelect, and doesn't update, just like Bid/Ask is without a RefreshRates.
/
To add comments, please log in or register