iBarShift at no standard graph ... - page 2

 
deVries:

 you tested   "2013.02.25 09:05" i assume

 

if you change date to 24 like  "2013.02.24 09:05"   you will get it
  

Yes,  I tested with 25th,  today,  there were no bars around 9 am yesterday as it was Sunday,  neither was there a H1 bar with an open time of 9:05 this morning.
 
deVries:


your english is good 

only how we understand what is written is sometimes different

if i have problems with a function and wants to know what it does

then the answer will be mostly given to me with a short testing program 


yes, I am doing it....

for today´s setup:  2013.02.25 09:05 return StartShift1 and StartShift2 the same value, different -1

mql ignore last parameter true or false....

Fce. iBarShift() will not solution for my problem: Does exist bar with exact open time? Maybe compare open time each bars, compare datetime value... 

 

 

modify code:

I using iBarShift(..., true) - if bar with exact open time exist - it must the same value datetime - therefore next step: compare datetime values...

it is ok 

#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern string  testdate="2013.02.25 09:05";
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   return(0);
  }
int deinit()
  {
   Comment("");
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----


  datetime time=StrToTime(testdate);
  //int StartShift1 = iBarShift(NULL,0,time, false);
  int StartShift2 = iBarShift(NULL,0,time, true);
  if(Time[StartShift2]==StrToTime(testdate)) Comment("Test for " + testdate, ": Bar exist!" );
  else Comment("Test for " + testdate, ": Bar with exact open time not exist!" );
  
   return(0);
  }
 
endy5:

modify code:

I using iBarShift(..., true) - if bar with exact open time exist - it must the same value datetime - therefore next step: compare datetime values...

it is ok 


Another solution
//+------------------------------------------------------------------+
//|                                               BarShiftTESTER.mq4 |
//|                                          Copyright 2013, deVries |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern string  testdate="2013.02.25 09:05";
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   Comment("");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----


datetime time=StrToTime(testdate);
int opentime = -1;
for(int i=0;opentime<Time[i];i++)
 {
  if(time > Time[i])break;
  if(time == Time[i])opentime = i;
 }



Comment("opentime    ",opentime,"  ",i);



//----
   return(0);
  }
//+------------------------------------------------------------------+
 

It seems the Documentation got screwed up in translation . . . Google translation from the Russian

 

"Search bar at the time. The function returns the offset of the bar, which owns the specified time. If for the time bar is missing (the "hole" in the history), the function returns, depending on the parameterexact , -1 or offset the nearest bar. "

 

it is in fact nothing to do with the opening time of the bar. 

 
I think it mean not "hole", but before the earliest or after the latest bar, then it will return -1 if use "exact".
 
ray:
I think it mean not "hole", but before the earliest or after the latest bar, then it will return -1 if use "exact".
No,  it means "hole".  
 

I believe this topic duplicates this one https://www.mql5.com/en/forum/141486/page2

 
And just to muddy the waters some more iBarShift doesn't match documentation. - MQL4 forum
Reason: