iBarShift at no standard graph ...

 

Hi,

I have graph, when bars start no standard time, example: TF 15min: xx:05; xx:20; etc.

I wrote easy code script:

int start()
  {
  datetime time=StrToTime("2013.02.25 09:00");
  int StartShift = iBarShift(NULL,0,time, true);
  Alert(StartShift);
  return(0);
  }

 Why function iBarShift don´t return value "-1"? It return others value (16), see image. I have no bars at start time 9:00 ...?

 

 
endy5:

Hi,

I have graph, when bars start no standard time, example: TF 15min: xx:05; xx:20; etc.

I wrote easy code script:

 Why function iBarShift don´t return value "-1"? It return others value (16), see image. I have no bars at start time 9:00 ...?

 

Maybe it is getting it's data from the standard US30 M15 chart rather than your offline chart,  why didn't you give it a non standard timeframe ? like M14 ?
 
endy5:

Hi,

I have graph, when bars start no standard time, example: TF 15min: xx:05; xx:20; etc.

I wrote easy code script:

 Why function iBarShift don´t return value "-1"? It return others value (16), see image. I have no bars at start time 9:00 ...?

 

int iBarShift(string symbol, int timeframe, datetime time, bool exact=false)
Search for bar by open time. The function returns bar shift with the open time specified. If the bar having the specified open time is missing, the function will return -1 or the nearest bar shift depending on the exact.
Parameters:
symbol  -  Symbol the data of which should be used to calculate indicator. NULL means the current symbol.
timeframe  -  Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
time  -  value to find (bar's open time).
exact  -  Return mode when bar not found. false - iBarShift returns nearest. true - iBarShift returns -1.

datetime time=StrToTime("2013.02.25 09:00");
  int StartShift = iBarShift(NULL,0,time, true);
  Alert(StartShift);

 Last parameter iBarShift   true

The bar you found is timing   8:50 till  9:05

iBarShift does 

 Search for bar by open time   option false return nearest

                                                  option true only barnumber if time for search is included in bar 

 

AS you can see good reading gives you the answer  and sometimes i have trouble with it

 

Maybe, I don´t understand english well...

last parameter (true) =  I want bar with exactly open time (9:00) or return "-1"

When was last parameter false - I understand why mql return bar open time 8:50 (nearest bar)

 
endy5:

Maybe, I don´t understand english well...

last parameter (true) =  I want bar with exactly open time (9:00) or return "-1"

When was last parameter false - I understand why mql return bar open time 8:50 (nearest bar)


Search for bar by open time. The function returns bar shift with the open time specified.

If the bar having the specified open time is missing, the function will return -1

 or the nearest bar shift depending on the exact.

Your bar is not missing the specified open time  so it is not returning -1

and if you choose exact as false  it gives always the nearest barshift with your time chosen 

with option true you get -1 if there is no bar on chart with specified open time included 

//+------------------------------------------------------------------+
//|                                               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 StartShift1 = iBarShift(NULL,0,time, false);
  int StartShift2 = iBarShift(NULL,0,time, true);
  Comment("StartShift1    ",StartShift1,"    StartShift2    ",StartShift2);



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

 Short program for testing to see what iBarShift is doing.....

 
endy5: last parameter (true) =  I want bar with exactly open time (9:00) or return "-1"

You have a M15 bar at 8:50:00 through 9:04:59. That includes 09:00. The last parameter is thus irrelevant.

Had the bar not exist, then the last parameter would affect the return value. iBarShift(NULL,0, 0, false) == Bars - 1 while iBarShift(NULL,0, 0, true) = -1

 

So when the documentation says  "Search for bar by open time. The function returns bar shift with the open time specified."  it doesn't actually mean open time ?  

If the attached EA is on a H1 chart there will be no bar with an open time of 9:05 so I would expect StartShift1 to give a valid bar number and StartShift2 to give -1   

 
endy5:

Maybe, I don´t understand english well...

last parameter (true) =  I want bar with exactly open time (9:00) or return "-1"

When was last parameter false - I understand why mql return bar open time 8:50 (nearest bar)


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 

 
RaptorUK:

So when the documentation says  "Search for bar by open time. The function returns bar shift with the open time specified."  it doesn't actually mean open time ?  

If the attached EA is on a H1 chart there will be no bar with an open time of 9:05 so I would expect StartShift1 to give a valid bar number and StartShift2 to give -1   


Yes we all learn answering questions Simon,

but testing time  "2013.02.24 09:05" gives value for StartShift1 and returns   -1  for StartShift2

 
deVries:


Yes we all learn answering questions Simon,

but testing time  "2013.02.24 09:05" gives value for StartShift1 and returns   -1  for StartShift2

Not on my H1 chart it doesn't . . . I get a value of 7 for StartShift1 and StartShift2
 
RaptorUK:
Not on my H1 chart it doesn't . . . I get a value of 7 for StartShift1 and StartShift2

 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
  

Reason: