how to get today's date? in mql4? - page 2

 
Thirteen:

I don't think that is a correct statement. (Remember: TimeCurrent() returns "the last known server time (time of incoming of the latest quote) . . ..")

How is your question any different from that of the OP? The responses given to the OP also answer your question: one can calculate today's date in MQL (using various methods, including those demonstrated above). Alternatively, you can make a call to the operating system to query the local date/time. However, how is that much different than TimeLocal() (the main difference being time returned in TimeLocal() is modelled in the strategy tester)?


Hi Thirteen,

Putting TimeCurrent() into a Print function prints the Current time of each bar being processed. A different time for each bar in the data history. (See results below)

TimeLocal() has the same modeled "Bar time" result (as you said). All the above coding I compiled and printed produced the same sequential bar time results. Those are not Todays date only. They are Bar Dates which also include Todays Date..

The above codes do produce Today's date as you said, but at the same time they produce every other date in the history of the data set, which I want to exclude. I was looking for only one date, of the final bar on the chart. Or the Bar number of the final bar on the chart, in order to have the EA automatically do some calculations only after it reached the final bar on the chart, after it has populated all of my arrays with the full data set.

The problem is how to produce Today's date (and Today's only), which is what the OP requested and myself. (though he wasn't actually wanting ONLY today's date) Like you said there are ways to do that, but I ran the codes above and none delivered just Today's date or just the final bar on the chart date.

I was unable (after extensive searching over 5 hours) to find any post on any Forex forum or any mql4 documentation, book or tutorials, that had that code or described that function capability. (To produce the date of the final bar on the chart or the identify the final bar on the chart) My goal, was to output the time or bar number of ONLY the last bar on the chart.

The purpose is to perform calculations on the entire data set, one time only, when the final bar on the chart is being processed. If the capability is in MQL4 it is not documented explicitly to my knowledge. I'll do more research, I"m sure there is a way, and I always benefit from more research anyway.

thanks





 
moneycode:


The problem is how to produce Today's date (and Today's only), which is what the OP requested and myself. (though he wasn't actually wanting ONLY today's date) Like you said there are ways to do that, but I ran the codes above and none delivered just Today's date or just the final bar on the chart date.

I think this will do what you want in the Strategy Tester . . .

int deinit()
   {
   Print("Final bar on chart date: ", TimeToStr(Time[0], TIME_DATE) );
   return(0);
   }
 
RaptorUK:

I think this will do what you want in the Strategy Tester . . .


Like a well oiled machine...




Thanks