I saw a thread at https://www.mql5.com/en/forum/154009...mment_12753469 for today and yesterday's profit calculations, it is working for me and his codes are as follows :-
I tried to work on monthly (m0, m1 and m2), quarterly (q0, q1, q2, q3) and yearly (y0 and y1) through internet searching, but cannot find the answers, could you please help to provide me the correct codes ? (FYI, I don't have programming background, I just do a try and error to get the answers)
Inserted Code
//TodayProfit double TodayProfit(){ double profit = 0; for(int j = 0; j<OrdersHistoryTotal(); j++){ if(OrderSelect(j, SELECT_BY_POS, MODE_HISTORY) == TRUE){ if(OrderType() > 1){ continue; } if(TimeToStr(TimeCurrent(), TIME_DATE) == TimeToStr(OrderCloseTime(), TIME_DATE)){ profit += OrderProfit() + OrderSwap() + OrderCommission(); } } } return(profit); } //Yesterday Profit double YesterdayProfit(){ datetime yesterday = TimeCurrent() - 60 * 60 * 24; string time_yyyy_MM_dd = TimeToString(yesterday, TIME_DATE); double profit = 0; for(int i = 0; i < OrdersHistoryTotal(); i++){ if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)){ if(time_yyyy_MM_dd == TimeToStr(OrderCloseTime(), TIME_DATE)){ profit += OrderProfit() + OrderSwap() + OrderCommission(); } } } return(profit); }
I tried to work on monthly (m0, m1 and m2), quarterly (q0, q1, q2, q3) and yearly (y0 and y1) through internet searching, but cannot find the answers, could you please help to provide me the correct codes ? (FYI, I don't have programming background, I just do a try and error to get the answers)