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

 

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

 

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();
}
}

Reason: