Download MetaTrader 5

How write "If last trade was winning"....

To add comments, please log in or register
Have you developed a profitable strategy? Launch your trading signal and make profit from it!
Forex Trader
114255
Forex Trader 2007.10.08 17:37 
In an EA, how can I write " If last trade was winning " (for this pair) then....

Thx for help.

Jo
Forex Trader
114255
Forex Trader 2007.10.08 18:09  
Here is one way:

This finds the newest closed trade and if it was a winner, then do your stuff


double newestTime;
int ticket, newestTicket;


for(int i = OrdersHistoryTotal() - 1; i >=0 i++){

     ticket = OrderSelect(i, SELECT_BY_POS, MODE_HISTORY );

     if(OrderSymbol() == Symbol()){
          if(OrderCloseTime() > newestTime){
          newestTime = OrderCloseTime();
          newestTicket = ticket;
     }
}

OrderSelect(newestTicket, SELECT_BY_TICKET, MODE_HISTORY);
if(OrderProfit() > 0) {
     ... do stuff
}





To add comments, please log in or register