This forum is now read-only. You can discuss you questions on Forums of MQL4.community and MQL5.community

Program check if the last order was a winning order or not?


Back to topics list
avatar
1
koolrafa 2009.09.23 14:15 

Hi!I've been learning meta 4 language and i'd like to know if there's a quick way for the program check if the last order was a winning order or not?

can any one help me please?

thank you

avatar
52
JPS 2009.09.30 18:40 

This is sample code only, but does what you need. There are several ways to do this, but here is probably the easiest.

Try adding magic numbers to your trading EA, and call last closed trade in trade history.

closedProfit will return if last order was +profit or -profit.


double mymagicnumber = 55;

double closedProfit = 0;


int hstTotal = OrdersHistoryTotal();
for(i=0;i<hstTotal;i++)
{ OrderSelect(i, SELECT_BY_POS, MODE_HISTORY );
if ( OrderSymbol()==Symbol() && ( (OrderMagicNumber() == mymagicnumber)))
{closedProfit = closedProfit + OrderProfit();
}
}



Back to topics list