Download MetaTrader 5

Closing orders, easy steps to use it in your EA - page 2

To add comments, please log in or register
What is MetaQuotes ID? Find that out from the article!
Daniel Petrovai
440
Daniel Petrovai 2014.03.07 08:15  
thrdel:

You need help with closing orders with your EA?

.........

2. Copy/paste the function at the end of your code.

3.Call the function when you need it.

Have any questions ? Ask away.

Enjoy.

Here is what I think it's an improved version for closing all orders placed by an EA :
//========================================================================

void CloseThisSymbolAll()
  {
   int trade;
   for(trade=OrdersTotal()-1;trade>=0;trade--)
     {
      if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
        {
         Print("Error: ",ErrorDescription(GetLastError()));
         return;
        }
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber) continue;
         if(OrderType()==OP_BUY)
            {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,slip,Blue))
            ErrorDescription(GetLastError());
         if(OrderType()==OP_SELL)
            {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,slip,Red))
            ErrorDescription(GetLastError());
            }
         if(OrderType()==OP_BUYLIMIT ||OrderType()==OP_SELLLIMIT ||
         OrderType()==OP_BUYSTOP||OrderType()==OP_SELLSTOP)
            {
            if(!OrderDelete(OrderTicket(),Blue))
            ErrorDescription(GetLastError());
            }
        }
      Sleep(1000);
     }
  }
//========================================================================
Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.03.07 08:44  
thrdel:
Here is what I think it's an improved version for closing all orders placed by an EA :

Your first OrderSelect() will fail . . .

   for(trade=OrdersTotal();trade>=0;trade--)
     {
      if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))

. . . should be . . .

   for(trade = OrdersTotal() - 1; trade >= 0; trade--)
     {
      if(!OrderSelect(trade,SELECT_BY_POS,MODE_TRADES))
Daniel Petrovai
440
Daniel Petrovai 2014.03.07 09:55  
RaptorUK:

Your first OrderSelect() will fail . . .

. . . should be . . .


Good one. Thanks

Never post when hungry.

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.03.07 09:59  
thrdel:


Good one. Thanks

Never post when hungry.

You are welcome

I'm always hungry been trying to lose weight since August 2012, so far have lost 60lbs, on the home straight now

Daniel Petrovai
440
Daniel Petrovai 2014.03.07 10:16  
RaptorUK:

You are welcome

I'm always hungry been trying to lose weight since August 2012, so far have lost 60lbs, on the home straight now


Now, that is something to be proud of. Really? 60 lbs ? It's time to sell the method and make some real money !

You do have the before (and after) pictures, right?

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.03.07 10:19  
thrdel:


Now, that is something to be proud of. Really? 60 lbs ? It's time to sell the method and make some real money !

You do have the before (and after) pictures, right?

sorry, no pictures . . . the method is very simple, eat less calories + have some determination + keep track of progress daily.
Daniel Petrovai
440
Daniel Petrovai 2014.03.07 22:22  
RaptorUK:
sorry, no pictures . . . the method is very simple, eat less calories + have some determination + keep track of progress daily.


Yeah, as easy as get a good idea + write a good EA + keep counting profits.

Easier said than done. Where did you get the determination from?

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.03.07 23:27  
thrdel:


Yeah, as easy as get a good idea + write a good EA + keep counting profits.

Easier said than done. Where did you get the determination from?

I got some inspiration from a BBC Horizon program titled, "East, Fast and Live Longer" the rest was just me deciding to no longer put it off till tomorrow, I'm doing it once then maintaining my weight at a healthy level. It's about quality of life as I get older, getting older happens to us all
Ian Venner
2584
Ian Venner 2014.03.08 04:14  

I used to love that show when I was in England I'm glad to hear they are still producing it, do they still have panorama and world in action ?

Simon Gniadkowski
Moderator
18001
Simon Gniadkowski 2014.03.08 09:00  
SDC:

I used to love that show when I was in England I'm glad to hear they are still producing it, do they still have panorama and world in action ?

Panorama yes, not sure about World in Action.
12
To add comments, please log in or register