A function that return the open price of the current day

 
double open() {
if(Period() > 240) return(0);
int shift = ((Hour()*60) + Minute())/Period();
// if the market open after Midnight then...
while(TimeDay(Time[0]) != TimeDay(Time[shift])) {
shift--;
}
double value = iOpen(Symbol(),0,shift);
return(value);
}
 

Thanks allot Mario, have you tried.

iOpen(Symbol(),PERIOD_D1,0);
 
ubzen:

Thanks allot Mario, have you tried.

Using the daily charts can be problematic if the history for that chart is not being updated because that chart is not currently live. In this case you can use ...

  int iBarShift( string symbol, int timeframe, datetime time, bool exact=false)
 
Daily charts are garbage . . . when is the official start of the day (UTC)?
 

@dabbler: do you have an example in complete code when this would be a problem? Are you saying its wrong because you're off-line and trying to get Today's information? Wouldn't this be the case for any other missing bar (not just D1) while you're off-line (bars for today, or ten years ago).

@RaptorUK: I agree, especially if the brokers definition of Day-Open does not agree with yours. But I read somewhere a while ago, that there's a UTC which does Not-Change. Wouldn't it make sense to convert your Data to this time for Back-Testing purposes? And use something like the Time() in WHRoeders codes to get this time during Live-testing? Note: I've also read that UTC from your computer is dependent on the accuracy of your computer bios time or whatever, perhaps someone can clarify?

 
ubzen:

@dabbler: do you have an example in complete code when this would be a problem? Are you saying its wrong because you're off-line and trying to get Today's information? Wouldn't this be the case for any other missing bar (not just D1) while you're off-line (bars for today, or ten years ago).

Sorry, I didn't mean to imply that what you said was wrong. It just seems to me that there are charts and histories for each timeframe AND for each symbol AND each account. If you are running on an M15 chart and the D1 chart has not been viewed in the last month I am not sure if that history data is actually updated regardless of whether you have a live connection to the trade server.

When trading a particular trading method I have to have 8 charts live in order to get all the data constantly updated. And then I have another 8 in a different profile when I want to change timescale.

If you look in your history folder, and for one of my accounts this is

C:\Program Files\MetaTrader\history\AlpariUK-Classic-1

and look at the dates on the .HST files, they do not all (or even mostly) have today's date. I think the history on a timeframe is only updated when that chart is live. So if your EA is trading on an M15 chart and you want D1 data you need to also have the D1 chart live (displayed) on the same profile (although it doesn't have to be on top).

 
dabbler:

Sorry, I didn't mean to imply that what you said was wrong....

Sorry, I didn't mean to come off fussy. I just wanted to learn something. See my memory is not as good as it used to be :). IFRC, when you're trading M15 and connected to your broker, some amount of D1 data will also be downloaded, I think most brokers default setting is to push something like 1000 Bars (Don't Know Exact#) of every time frame as soon as you connect. So generally it's not the higher timeframe data you've got to worry about, it's the smaller timeframe like only having only 1000 Bars of M1 for example.

Once you dis-connect, all the M15 data will have a corresponding D1 data.

One case where you'll not have D1 data is when you disconnect from the broker, delete all your Old-Data, use Period Converter to make new M15 out of M1 good-quality data downloaded elsewhere. But forget to use period converter to create the D1 data.

 
ubzen:

Sorry, I didn't mean to come off fussy. I just wanted to learn something. See my memory is not as good as it used to be :). IFRC, when you're trading M15 and connected to your broker, some amount of D1 data will also be downloaded, I think most brokers default setting is to push something like 1000 Bars (Don't Know Exact#) of every time frame as soon as you connect. So generally it's not the higher timeframe data you've got to worry about, it's the smaller timeframe like only having only 1000 Bars of M1 for example.

Once you dis-connect, all the M15 data will have a corresponding D1 data.

Happiness is restored to my universe just in time for Christmas :-)

So this undocumented feature seemed worthy of a test. I picked a pair I don't trade, AUDCAD. The .HST data for that was quite old. I opened an explorer window to view the date of those .HST files. On another account I set the chart to M1 AUDCAD, just the one chart. then I changed accounts to the one explorer was looking at. Clearly the terminal downloaded new data but the file dates didn't change. I closed MT4 down and then the M1 HST date did change. I opened MT4 up again and clicked through all the time frames on the AUDCAD chart then closed MT4. Sure enough all time frames then showed updated HST files.

So I conclude that (at least for my broker) any chart (HST data) which has not been looked at is not refreshed. Of course when we are using indicators and EAs we know the history is not valid because we get an error return code. What I have as yet to find is the MT4 equivalent of right clicking on a chart and doing a "refresh" of the data.

Reason: