How to check the OrderProfit() from 3 last closed orders for the current Symbol() in OrdersHistoryTotal() list ?
- MQL4: Last closed order - I looking for the IDEA
- OrderSelect function question
- MQL4 - OrdersHistoryTotal() - one question
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?
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?
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; }
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.
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.