Here is the function without needing to download the EA.
void DayProfit() { double dayprof = 0.0; datetime end = TimeCurrent(); string sdate = TimeToString (TimeCurrent(), TIME_DATE); datetime start = StringToTime(sdate); HistorySelect(start,end); int TotalDeals = HistoryDealsTotal(); for(int i = 0; i < TotalDeals; i++) { ulong Ticket = HistoryDealGetTicket(i); if(HistoryDealGetInteger(Ticket,DEAL_ENTRY) == DEAL_ENTRY_OUT) { double LatestProfit = HistoryDealGetDouble(Ticket, DEAL_PROFIT); dayprof += LatestProfit; } } Print("DAY PROFIT: ", dayprof); }
Hi Keith,
It's purely educational to show how the syntax of HistorySelect works for any new users of MT5 out there. Obviously, you wouldn't need to make each of these variables if you didn't wish.
Thanks,
It would only be educational if the code was correct, but it wasn't. You should not be adding a datetime with an enumeration when they are not compatible.
On MQL4 the time-frame enumeration is in minutes and on MQL5 it is a mix of bit flags and minutes. In neither case is it compatible with the seconds elapsed of a datetime.
The more correct way would be something like this:
datetime start = end - PeriodSeconds( PERIOD_D1 );
But that however, is still questionable.
Hi Keith,
It's purely educational to show how the syntax of HistorySelect works for any new users of MT5 out there. Obviously, you wouldn't need to make each of these variables if you didn't wish.
Thanks,
It is not educational if it is wrong.
You have deleted the relevant post and modified the code.
You should at least admit that your code was wrong.
Hello everyone, I hope you're well,
why not simply use 0 as the starting point, as shown in the documentation here ?
HistorySelect(0,TimeCurrent());
I'm wondering about my message here
Best Reguards,
ZeroCafeine
![Documentation on MQL5: Trade Functions / HistorySelect Documentation on MQL5: Trade Functions / HistorySelect](https://c.mql5.com/36/77/documentation-on-mql5-trade-functions__2.png)
- www.mql5.com
I answer myself, beginner's mistake, and after several reflexions I think that this type of starting time is very good for me now 😉.
string sdate = TimeToString (TimeCurrent(), TIME_DATE); datetime start = StringToTime(sdate);
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Daily Profit Function:
A simple and easy to understand function that calculates todays profit, written to the Expert Journal.
Author: Meta_Work