MQL5:
I'm trying to write a function to close by sequence.
There is no error after compilation, but it does not run.
I could not figure out why. Could you help?
Thank you!
Closing by order sequence.
i.e.
Deal 1 + Deal 2 has profited - close
Deal 3 + Deal 4 has profited - close
5 + 6
7 + 8
9 + 10
and so on ...
Deal 1 has the smallest order number and is opened at the earliest time.
Deal 10 has the biggest order number and is opened at the latest time.
I'm trying to write a function to close by sequence.
There is no error after compilation, but it does not run.
I could not figure out why. Could you help?
Thank you!
Closing by order sequence.
i.e.
Deal 1 + Deal 2 has profited - close
Deal 3 + Deal 4 has profited - close
5 + 6
7 + 8
9 + 10
and so on ...
Deal 1 has the smallest order number and is opened at the earliest time.
Deal 10 has the biggest order number and is opened at the latest time.
Inserted Code
void CloseBySequence() { datetime from=0; datetime to=TimeCurrent(); HistorySelect(from,to); double Minimum_Profit=5.00; ulong ticket; uint x; double trades[][2]; uint total=HistoryDealsTotal(); if(total>1) { ArrayResize(trades,total); for(x=total-1;x>=0;x--) { if((ticket=HistoryDealGetTicket(x))>0) { trades[x][0]=HistoryDealGetInteger(ticket,DEAL_ORDER); trades[x][1]=HistoryDealGetDouble(ticket,DEAL_PROFIT) +HistoryDealGetDouble(ticket,DEAL_COMMISSION) +HistoryDealGetDouble(ticket,DEAL_SWAP); } } ArraySort(trades); x=0; while(x<total-1) { double profit=trades[x][1]+trades[x+1][1]; if(profit>=Minimum_Profit) { if(HistoryDealSelect((int)trades[x][0])) if(!trade.PositionClose(PositionGetSymbol(x))) Print("Error closing (Deal 1/2) #",IntegerToString(OrderGetTicket(x))," Error code ",GetLastError()); if(HistoryDealSelect((int)trades[x+1][0])) if(!trade.PositionClose(PositionGetSymbol(x))) Print("Error closing (Deal 2/2) #",IntegerToString(OrderGetTicket(x))," Error code ",GetLastError()); } x+=2; } } }