Download MetaTrader 5

Experts: Droneox Equity Guardian

To add comments, please log in or register
MQL5 language supports OpenCL. Try it!
Automated-Trading
Admin
99623
Automated-Trading 2016.02.18 15:50 

Droneox Equity Guardian:

Expert Advisor that will close all orders and disable another Expert Advisor / AutoTrading at desired level.

Author: Yogie Pratama

Roy Meshulam
118
Roy Meshulam 2016.03.02 10:23  
Automated-Trading:

Droneox Equity Guardian:

Author: Yogie Pratama

Change

//close all open trade
int CloseAllTrade() 
  {
   int total=OrdersTotal();
   int t;
   int cnt=0;
   for(cnt=0; cnt<=total; cnt++)
     {
      bool s=OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()==OP_BUY)
         t=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Violet);
      if(OrderType()==OP_SELL)
         t=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Violet);
      if(OrderType()>OP_SELL//pending orders
         t=OrderDelete(OrderTicket());
     }
   return(0);
  }

 to

   for(cnt=total-1; cnt>=0; cnt--)

Yogie Pratama
879
Yogie Pratama 2016.03.02 12:17  

Hello roy,

I think its the same approach,

for(cnt=0; cnt<=total; cnt++), it's select index from 0 - last index. ex: 0,1,2,3,4, until last index

for(cnt=total-1; cnt>=0; cnt--), it's select last index - 0. ex: last index, last index-1, last index-2, until 0

Carl Schreiber
6591
Carl Schreiber 2016.03.02 15:39  
Yogie Pratama:

Hello roy,

I think its the same approach,

for(cnt=0; cnt<=total; cnt++), it's select index from 0 - last index. ex: 0,1,2,3,4, until last index

for(cnt=total-1; cnt>=0; cnt--), it's select last index - 0. ex: last index, last index-1, last index-2, until 0

No it is not!!

If you close order with cnt=0 the order with cnt=1 becomes the order with cnt=0.

Therefore you HAVE to count down!!

In addition to that may be a RefreshRates() might be helpful especially if there are a bit exotic Symbols() that do not have so many ticks!!

Dan Andersson
151
Dan Andersson 2016.03.05 19:09  

Carl, you would have been correct if Yogie would have used the index "cnt" in the OrderSelect statement, like this:

bool s=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); 

 but now he wrote

bool s=OrderSelect(0,SELECT_BY_POS,MODE_TRADES); 

So the order with index zero is selected every time for closing, so that also works just fine. After first Closing, order with index 1 becomes index 0 and is thus deleted next iteration.

in addition, if your broker has a FIFO rule, then the order with index 0 is the oldest, and must be closed before any other, and in that case it would not work to do it your way and count backwards. 

Eleni Anna Branou
3617
Eleni Anna Branou 2017.02.09 15:35  

How can I use this EA with VPS hosting?

It is removed when I am trying to synchronise MT4 environment with VPS. 

To add comments, please log in or register