How to check the OrderProfit() from 3 last closed orders for the current Symbol() in OrdersHistoryTotal() list ?

 
I mean about MQL4 syntax... I need separate values for 3 last closed orders profit or loss...
 
puncher:
I mean about MQL4 syntax... I need separate values for 3 last closed orders profit or loss...

Just use a standard loop with OrderSelect(...,MODE_HISTORY) and filter out the 3 orders. What part of the "MQL4 syntax" don't u understand?

 
gordon:

Just use a standard loop with OrderSelect(...,MODE_HISTORY) and filter out the 3 orders. What part of the "MQL4 syntax" don't u understand?


Can I please any exampled, full MQL syntax?
 
int x;
double prof[3];
for(int i=OrderHistoryTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol())
{
prof[x]=OrderProfit();
x++;
}

if(x>2)break;
}
 
Roger:
int x;
double prof[3];
for(int i=OrderHistoryTotal()-1;i>=0;i--)
{
OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol())
{
prof[x]=OrderProfit();
x++;
}

if(x>2)break;
}

That's assuming the last 3 orders in the history pool are the last 3 closed orders... In previous discussions on the subject the consensus was that it might not always be so.

 
Thank you.
 
double prof[3]; datetime oct[3]
for(int i=OrderHistoryTotal()-1;i>=0;i--) if (
   OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)
&& OrderSymbol()==Symbol() ) {
    for(int x=0; x<=2; x++) if (
        OrderCloseTime()>= oct[x]) {       
        for(int(y=x; y<2; y++) {
           oct[y+1]= oct[y];
          prof[y+1]=prof[y];
        }
         oct[x]=OrderCloseTime();
        prof[x]=OrderProfit();
        break;
}   }


 

Can this be used to check profit (or loss) for buy and sell orders in the same EA for the past month? I want to set lot size depending on whether past monht buy is profitable.

Any advice, thanks.

 
according to dabbler, the order in the list is not necessarily by order close date. See my GetHistoryOrderByCloseTime
Reason: