How can I get the last trades results into an expert

 

Hi, I would like to get the last trades profit and loss that my expert had, how can I do that?

Thanks.

 
rodrigosm:

Hi, I would like to get the last trades profit and loss that my expert had, how can I do that?

Thanks.

Use

bool OrderSelect( int index, int select, int pool=MODE_TRADES) 

with pool = MODE_HISTORY

Also use

int OrdersHistoryTotal( ) 
 
 
    for(int iPos=OrdersHistoryTotal()-1; iPos >= 0 ; iPos--) if (
        OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY)      // Only orders w/
    &&  OrderMagicNumber() == Magic.Number                  // my magic number
    &&  OrderSymbol()      == chart.symbol                  // and my pair.
    &&  OrderType()        <= OP_SELL// Avoid cr/bal forum.mql4.com/32363#325360
    ){
        double  profit  = OrderProfit() + OrderSwap() + OrderCommission(),
Reason: