Can give me an example how to extract current date from copytime?
Sample ? I thought you can do this yourself ;D
datetime dt1[1]; if (CopyTime (_Symbol, PERIOD_D1, 0, 1, dt1) == 1) { Print(TimeToString (dt1 [0], TIME_DATE| TIME_SECONDS)); }
The problem with your first code is this : when using today date March 04, 2013, your code returned string 2013.3.4, while it should be string 2013.03.04.
Sample ? I thought you can do this yourself ;D
The problem with your first code is this : when using today date March 04, 2013, your code returned string 2013.3.4, while it should be string 2013.03.04.
Thanks for the comment.
Other than copytime is there any other methods?
Thanks for the comment.
Other than copytime is there any other methods?
Yes, it's called LOL ...
string LOL = TimeToString (TimeCurrent(), TIME_DATE); Print (StringToTime(LOL));
being lazy is no good, doshur ;D
Yes, it's called LOL ...
being lazy is no good, doshur ;D
this is the reason why i asked this question. to develop one trade a day code. i can easily use new bar tactics but if EA got restarted, it will trade again.
here u go...
static bool OneTrade; OneTrade = true; string CurrDate = TimeToString(TimeCurrent(), TIME_DATE); HistorySelect(StringToTime(CurrDate), TimeCurrent()); for(int i = HistoryDealsTotal() - 1; i >= 0; i--) { Ticket = HistoryDealGetTicket(i); Entry = HistoryDealGetInteger(Ticket, DEAL_ENTRY); if(Entry == DEAL_ENTRY_IN) { OneTrade = false; } }
this is the reason why i asked this question. to develop one trade a day code. i can easily use new bar tactics but if EA got restarted, it will trade again.
here u go...
You can also remove the messing about with strings stuff . . .
#define SECONDSINADAY 86400 static bool OneTrade; datetime Midnight, StartOfNewYear; Midnight = TimeCurrent() - ( TimeCurrent()%SECONDSINADAY ); // midnight today as a datetime OneTrade = true; HistorySelect(Midnight, TimeCurrent()); // just history between Midnight and now for(int i = HistoryDealsTotal() - 1; i >= 0; i--) { Ticket = HistoryDealGetTicket(i); Entry = HistoryDealGetInteger(Ticket, DEAL_ENTRY); if(Entry == DEAL_ENTRY_IN) { OneTrade = false; } }
You can also remove the messing about with strings stuff . . .
let me compress the code a little
static bool OneTrade; OneTrade = true; HistorySelect(TimeCurrent() - (TimeCurrent()%86400), TimeCurrent()); // just history between Midnight and now for(int i = HistoryDealsTotal() - 1; i >= 0; i--) { Ticket = HistoryDealGetTicket(i); Entry = HistoryDealGetInteger(Ticket, DEAL_ENTRY); if(Entry == DEAL_ENTRY_IN) { OneTrade = false; } }
https://www.mql5.com/en/docs/basis/operations/mathoperation
smart use of %

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
I'm trying to get the current date without the time using this code
are there any simpler ways of getting the current date only?