problem in time[] array of OnCalculate() function

 

hello

I checked the values of time[] array of OnCalculate() function of a indicator in two different timeframe , H4 and D1 .

I've put this code in OnCalculate() function in both timeframe H4 and D1 :

int difference=(int)time[2]-(int)time[1];

it is verey strange for me that the difference value in both is equal by 86400 ! 

As far as I know, the difference between two consecutive times at H4 must be 14,400  and at D1 must be 86400.

or it's wrong. 

 

The code is correct but the early H4 history is not for some reason.

Disable autoscroll and press the home key in H4 and you will see that the early H4 bars are the same as D1 bars. Very strange!

 
mahmoodi1072: As far as I know, the difference between two consecutive times at H4 must be 14,400  and at D1 must be 86400.

or it's wrong. 

That 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 forum 2010.06.06

 

thanks 

I've checked this code on 5 different timeframe :

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---

   string comment;
for (int i=0;i<20;i++) //for example check for 20 candle
{
   comment+=StringFormat("time[%d] - time[%d] = %d \n",i+1,i,(int)time[i+1]-(int)time[i]);
}
Comment(comment);

//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

and have attached 5 picture of result chart. 

Is it normal result in H4?

Files:
M1.jpg  417 kb
M5.jpg  426 kb
H1.jpg  422 kb
H4.jpg  432 kb
Daily.jpg  430 kb
 
pooya mahmoodi:

thanks 

I've checked this code on 5 different timeframe :

and have attached 5 picture of result chart. 

Is it normal result in H4?

As I have already said

Keith Watford:

The code is correct but the early H4 history is not for some reason.

Disable autoscroll and press the home key in H4 and you will see that the early H4 bars are the same as D1 bars. Very strange!

 
Keith Watford:

As I have already said

thanks dear Keith

sorry , but I don't understand.

I did your suggestion.

Do you mean that this is something like a bug ?

 
pooya mahmoodi:

thanks dear Keith

sorry , but I don't understand.

I did your suggestion.

Do you mean that this is something like a bug ?

What don't you understand?

Did you see that the H4 chart early bars were actually D! bars?

It is not a bug, it is the broker's early H4 history that is incorrect for some reason.

 
Keith Watford:

What don't you understand?

Did you see that the H4 chart early bars were actually D! bars?

It is not a bug, it is the broker's early H4 history that is incorrect for some reason.

As you said “ it is the broker's early H4 history that is incorrect for some reason.” And the term “incorrect for some reason!” Is the part that make me confused. For which reason ??
Anyway thanks about your time and your answer.🌺
 
mahmoodi1072:
As you said “ it is the broker's early H4 history that is incorrect for some reason.” And the term “incorrect for some reason!” Is the part that make me confused. For which reason ??
Anyway thanks about your time and your answer.🌺

If I knew the reason, I would state the reason.

I don't know the reason, so I said "For some reason".

Ask your broker why.

 
Keith Watford:

If I knew the reason, I would state the reason.

I don't know the reason, so I said "For some reason".

Ask your broker why.

thank you
Reason: