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

 
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);
     }
  }
//========================================================================
 
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))
 
RaptorUK:

Your first OrderSelect() will fail . . .

. . . should be . . .


Good one. Thanks

Never post when hungry.

 
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

 
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?

 
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.
 
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?

 
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
 

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 ?

 
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.
Reason: