I'm trying to run totals on the closed trade history for all orders that opened after a certain datetime.
I thought I would save program cycles by working backwards through the history, starting from the most recent closed trade and going backwards, like this:
// step backwards through history so only relevant recent history is analyzed.
for(int i=OrdersHistoryTotal();i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue;
if(OrderCloseTime()==0) continue;
// have now hit orders earlier than current trade group, stop analyzing.
if(OrderOpenTime()<earliestOpenOrderTime) break;
// ... do some stuff here
}
The problem is that it seems that the order of the trades in the history is something different than the ticket number or the order open time because I'm breaking out of the for loop before I've analyzed all the trades I want.
Have I made a mistake here or is the only way to do this to cycle through ALL of the trade history?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I'm trying to run totals on the closed trade history for all orders that opened after a certain datetime.
I thought I would save program cycles by working backwards through the history, starting from the most recent closed trade and going backwards, like this:
// step backwards through history so only relevant recent history is analyzed. for(int i=OrdersHistoryTotal();i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) continue; if(OrderCloseTime()==0) continue; // have now hit orders earlier than current trade group, stop analyzing. if(OrderOpenTime()<earliestOpenOrderTime) break; // ... do some stuff here }The problem is that it seems that the order of the trades in the history is something different than the ticket number or the order open time because I'm breaking out of the for loop before I've analyzed all the trades I want.
Have I made a mistake here or is the only way to do this to cycle through ALL of the trade history?
Thank you very much,
Christian