To test this yourself, put these three functions into a Program and substitute the variable n for h (h or Hour() can be Equal to any Number from 1 to 23).
//Change n to act as variable h, which is a theoretical Hour(). //In other words, if the Hour() == n, then this would be the Starting Candle of that Hour. int n = 0; void PlotLine() { VLineCreate(0, "Theoretical Hourly Start", 0, Time[TheoHourLine(n)],255, 0, 2, 0, 0); } int TheoHourLine(int x = 1) { double h1start = Minute() - 1, h = Hour(); return (h1start + (60 * x)); } //The Function below is just a pre-defined Function to allow V-Lines to be Plotted. bool VLineCreate(const long chart_ID=0, // chart's ID const string name="VLine", // line name const int sub_window=0, // subwindow index datetime time=0, // line time const color clr=clrRed, // line color const ENUM_LINE_STYLE style=STYLE_SOLID, // line style const int width=1, // line width const bool back=false, // in the background const bool selection=true, // highlight to move const bool hidden=true, // hidden in the object list const long z_order=0) // priority for mouse click { //--- if the line time is not set, draw it via the last bar if(!time) time=TimeCurrent(); //--- reset the error value ResetLastError(); //--- create a vertical line if(!ObjectCreate(chart_ID,name,OBJ_VLINE,sub_window,time,0)) { Print(__FUNCTION__, ": failed to create a vertical line! Error code = ",GetLastError()); return(false); } //--- set line color ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); //--- set line display style ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); //--- set line width ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); //--- display in the foreground (false) or background (true) ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); //--- enable (true) or disable (false) the mode of moving the line by mouse //--- when creating a graphical object using ObjectCreate function, the object cannot be //--- highlighted and moved by default. Inside this method, selection parameter //--- is true by default making it possible to highlight and move the object ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); //--- hide (true) or display (false) graphical object name in the object list ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); //--- set the priority for receiving the event of a mouse click in the chart ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); //--- successful execution return(true); }
- galfaria: Now in theory, from hourstart I should be able to Calculate the amount of Minutes that have passed According to
This assumes every bar every exists — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
"Free-of-Holes" Charts - MQL4 Articles (20 June 2006)
No candle if open = close ? - MQL4 programming forumUse iBarShift.
-
What are you trying to do?
How To Ask Questions The Smart Way. (2004)
The XY Problemdatetime today=date(); for(int hour=0; hour < 24; ++hour){ datetime topH1 = today + hour * 3600; VLineCreate(0, "Actual Hourly Start", 0, topH1); }
date/time
Maybe this articles helps you:

- 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
Hello, I am trying to Calculate the Index of the First Candle of the Day within the M1 Time Frame and I feel like I found an error in the MQL System; if anyone knows an explanation or a remedy for this, please let me know.
Now in theory, from hourstart I should be able to Calculate the amount of Minutes that have passed According to any amount of Hours by multiplying it by 60 (which is the Number of Minutes within a Day).
This Chart should show the Correct Values of (h *60); Note that these are based off off the Indices of MQL and the Conditions Above and not Pure Math:
These Numbers start based off hourstart (which is 23:00). Now in theory, it should give me the Time in the Chart, but somewhere around where h == 16, it starts diverging from the Formula in Minutes.
Here are the Numbers I got instead (note, it took a Minute to make this Chart XD):
Around the Points where h == 17, it switches to hh:59, then it devolves further from the Formula by going to 1:58 at x == 21, then it went to 00:58, and then finally at the Point I was trying to Calculate it went to 23:50 Randomly.
Can someonet tell me how the Numbers got screwed up? Is it because of a few Candles missing? I would include an Offset for what I am trying to Calculate but I feel like it doesn't even stay at 23:50, sometimes it goes to 23:48 and such.
Is it intentional? Is it an error? Am I missing something here? I'd really like to know because believe it or not this Conundrum caused me to halt my Forex studies for almost a Year because I felt like I was doing everything wrong since I couldn't get the Right Number, but I think it's not me but a technicality.
Thanks for you help and God Bless :D