Problem with iBarShift - page 2

 
crystal7: I don't want to post all my code here, but the problem is : my indicator do not take in count the bar which are "plate", I mean the when OHLC are all the same on a candle..
  1. No one asked you to! We asked you to post your iBarShift related code and the results.
  2. iBarShift DOES NOT CARE ABOUT the OHLC of the candle. That was your ORIGINAL post. What your indicator does with a plate candle is irrelevant.
 

I think your problem maybe in not realising that iBarShift(Symbol(),Period(),FindBar4Time) has a default parameter exact defaulting to false. From the documentation.

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.

All iBarShift does is loop through Time[] data series until Time[i]<FindBar4Time then checks if FindBar4Time equals Time[i+1] for exact match on the open time.

The loop idea is speculation if might work faster if it used a binary chop but we are not concernd with those details.

 
crystal7:

Thank you, yes I'm wrong, with that logic.

I don't want to post all my code here, but the problem is : my indicator do not take in count the bar which are "plate", I mean the when OHLC are all the same on a candle..

My way to declare my variable datetime is good, because the indicator work well, but because of that problem, it doesn't return the good value on certain pairs on certains periods of time.

My broker is FxOpen ECN, on demo account, find some plate candle with your broker or download FxOpen and try the code I gave you and you will see, the print for the 2 variables ShiftBars1 and ShiftBars2 are not the same.

Give me what you have find please...

Thanks

I ran your code . . .

2012.10.04 10:03:11 crystal7_Test2 USDCHF,M5: Bar de USDCHF : 1006

2012.10.04 10:03:11 crystal7_Test2 USDCHF,M5: Bar de EURUSD : 1008


I get a difference of 2 bars because there is a difference of 2 bars . . . USDCHF probably has a few M5 bars missing here and there, would you like me to find the missing bars ?

Here they are . . .

I have the 00:00 bar, and the 00:05 bar, but the next bar is 00:20 so the missing bars are 00:10 & 00:15 . . . . . iBarShift() is correct.

 
RaptorUK:

I ran your code . . .

2012.10.04 10:03:11 crystal7_Test2 USDCHF,M5: Bar de USDCHF : 1006

2012.10.04 10:03:11 crystal7_Test2 USDCHF,M5: Bar de EURUSD : 1008


I get a difference of 2 bars because there is a difference of 2 bars . . . USDCHF probably has a few M5 bars missing here and there, would you like me to find the missing bars ?

Here they are . . .

I have the 00:00 bar, and the 00:05 bar, but the next bar is 00:20 so the missing bars are 00:10 & 00:15 . . . . . iBarShift() is correct.

Thank you


Allright iBarShift() is correct.But it's not usefull, because if i want to use SetIndexDrawBegin() the indicator will not be the same for all the pairs(it will not begin at the same time) and it will give me a wrong value for some of them.

How can I rule this problem?

 
crystal7: i want to use SetIndexDrawBegin() the indicator will not be the same for all the pairs(it will not begin at the same time)

Index draw begin prevents drawing line when there isn't enough bars to calculate the result. E.g. SMA(10) can not start until there are 10 bars.

You are over complicating it. drawbegin is a constant depending on your parameters.

You loop is for (int iBar = Bars - 1 - IndicatorCounted(); iBar >= 0; iBar--){ ... }

Indicator draws on all valid bars. Depending on how much history a pair has, of course it will not begin at the same time.

 
Ickyrus:

I think your problem maybe in not realising that iBarShift(Symbol(),Period(),FindBar4Time) has a default parameter exact defaulting to false. From the documentation.

All iBarShift does is loop through Time[] data series until Time[i]<FindBar4Time then checks if FindBar4Time equals Time[i+1] for exact match on the open time.

The loop idea is speculation if might work faster if it used a binary chop but we are not concernd with those details.

Well, from my experience the behaviour differs from the documented one. It could easily lead to a failure if you rely on documentation.

With the exact option set, it returns (-1) only if the candle is missing completely, like weekends.

In case there is a candle, then the exact option makes no difference and the function returns index of a candle for ANY time that fits into the candle (not only open time).


Correct me if you find I am wrong.

 
Ovo:

Well, from my experience the behaviour differs from the documented one. It could easily lead to a failure if you rely on documentation.

With the exact option set, it returns (-1) only if the candle is missing completely, like weekends.

In case there is a candle, then the exact option makes no difference and the function returns index of a candle for ANY time that fits into the candle (not only open time).


Correct me if you find I am wrong.

I think you are wrong, do you have a script to demonstrate your point ?
 
RaptorUK:
I think you are wrong, do you have a script to demonstrate your point ?

I think if you are not able to test it yourself, you do not need it.

int start() {
  string result = "";
  for (datetime time = TimeCurrent(); time > (TimeCurrent() - (PERIOD_W1 * 60)); time = time - (PERIOD_H4 * 60) ) {
      int ndx1 = iBarShift(Symbol(), PERIOD_H4, time, true);
      int ndx2 = iBarShift(Symbol(), PERIOD_H4, time, false);
      result = result + TimeToStr(time) + "   " +ndx1 + "   " + ndx2 + "\n";
  }
  Comment(result);
  return(0);
}
 
Ovo:

I think if you are not able to test it yourself, you do not need it.

If the alleged problem lies in your code them me writing the code won't find the problem . . .
 
Ovo:

Well, from my experience the behaviour differs from the documented one. It could easily lead to a failure if you rely on documentation.

With the exact option set, it returns (-1) only if the candle is missing completely, like weekends.

In case there is a candle, then the exact option makes no difference and the function returns index of a candle for ANY time that fits into the candle (not only open time).


Correct me if you find I am wrong.

Looks like you are correct, I have used iBarShift extensively but I guess I have only looked for bar start times before . . . thanks for the heads up.
Reason: