How to let the EA close all opening order of a specific symbol?

phoenix
439

i tried this code

** totalprofit = all profit from floating orders**

if(totalprofit>300)CloseAll();

//------------------

void CloseAll()

{ int spread = MathRound((Ask-Bid)/Point);

int total = OrdersTotal();

for (int cnt = 0 ; cnt < total ; cnt++)

{

OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

if (OrderSymbol()==Symbol())

{

if(OrderType()==OP_BUY)

OrderClose(OrderTicket(),OrderLots(),Bid,spread,Black);

if(OrderType()==OP_SELL)

OrderClose(OrderTicket(),OrderLots(),Ask,spread,Black);

}

}

}

//-----------------------

it's dose'nt work .. what's wrong with it?..pls

anyone know pls help me.. , looking forward for kindly help

thank you

David Michael
735
David Michael  

To close all trade start from latest ID :

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

. Hope this help

[Deleted]  

if you post the EA I can take a look at it. Also, post code within code brackets so that it is easy to read.

Also, look at this line ---> OrderClose(OrderTicket(),OrderLots(),Bid,spread,Bl ack);

it should be ---> OrderClose(OrderTicket(),OrderLots(),Bid,spread,Black);

& this line ---> OrderClose(OrderTicket(),OrderLots(),Ask,spread,Bl ack);

should be ---> OrderClose(OrderTicket(),OrderLots(),Ask,spread,Black);

phoenix
439
phoenix  

here's the new one but still doesn't work

Files:
closeall.mq4  2 kb