Analogue to iBarShift - page 10

 
Aleksey Vyazmikin:

You mean it's showing Monday? That's what I want... :)

Yeah, well, it's actually strange behaviour for a standard function. After all, we are adjusting the values to its "reference".

The standard function iBarShift of MQL4 returns the number of the left bar (i.e. Saturday in this case), and iBarShift3 returns the number of the right bar (i.e. Monday) when the requested time hits the hole, which is more logical.

 
Nikolai Semko:

Yeah, well, that's actually strange behaviour for a standard function. After all, we are dealing exactly with fitting values to its "benchmark".

The standard function iBarShift of MQL4, when the requested time hits the hole, returns the left bar number (i.e. Saturday in this case), and iBarShift3 returns the right bar number from the hole (i.e. Monday), which makes more sense.

And what will happen if we are now in the hole (real time) and expect to receive information on the bar, what index will be offered to us? I assume it will be "1" in MQL4, while for the third algorithm it will be "0", or no?

I think the MQL4 function has a "don't look ahead" message, which is true to a certain extent - it all depends on the task.

 

Nikolai Semko :

...

I have only one complaint about your option: it is very complicated and slow.

When i posted it (4 years ago) the main goal was accuracy (again), because all other versions i found were wrong (compared to mql4 version).

I know it can be faster.

Try to prove otherwise. Find a single combination of parameters when your function and mine will show different values.

In most cases the function returns the wrong result.

But I haven't implemented the last parameter exact in it, because I don't understand why it is needed at all. I personally have never needed it.

The requirement is to have mql4 version ONLY.

Forum on trading, automated trading systems and testing trading strategies

Analogue to iBarShift

Alain Verleyen, 2018.04.05 00:18

Actually it only shows the opposite, my version is the only one that is correct. (And the original iBarShift1 from this code is correct).

My version was conceived as a standalone function, just like mql4 iBarShift .


PS: Is it necessary to post English version or Russian translation is correct ?

 
vladevgeniy:
Why don't you try my function? There is a solution there that adjusts the start and end of bars in time. It seems to calculate everything correctly. And it is faster in time than version 3 of your fastest one. Or the branch is more important?) Or is there an error there too?) I've been using it for a long time....

Where is it, your function, to try it out?

 
Aleksey Vyazmikin:

And what happens if we are now in a hole (real time) and expect to get information on a bar, what index will be offered to us? I assume it will be "1" in MQL4, while for the third algorithm it will be "0", or no?

I think the MQL4 function has the "don't look ahead" message, which is true to a certain extent - it all depends on the problem.

No. The first one is zero. In real time it works the same way.

 
Aleksey Vyazmikin:

And where is it, your function, to try it out?

It's at the end of page 7.)

int iBarShift(string symbol, ENUM_TIMEFRAMES timeframe, datetime time){
datetime t1 = TimeCurrent()+10000000;
int ps = PeriodSeconds(timeframe);
double div = time/(double)ps;
double mant = div - MathFloor(div);
int ret = Bars(symbol, timeframe, (datetime)(time-(ps*mant)), t1)-1;
return(ret);
}

That might be more convenient.

 
vladevgeniy:
Why don't you try my function? I have a solution that compensates for the beginning and the end of bars in time. It seems to calculate everything correctly. And it is faster in time than the 3rd version of your fastest one. Or the branch is more important?) Or is there an error there too?) I've been using it for a long time....

That's funny ))))

Here is your function:

int iBarShift4(string symbol,ENUM_TIMEFRAMES timeframe,datetime time)
  {
   datetime t1=TimeCurrent()+10000000;
   int ps=PeriodSeconds(timeframe);
   double div=time/(double)ps;
   double mant=div-MathFloor(div);
   int ret=Bars(symbol,timeframe,(datetime)(time-(ps*mant)),t1)-1;
   return(ret);
  }

Since you don't know some mathematical operators, like % - the remainder of division

Let's make some simplification of your function.

It worked:

int iBarShift4(string symbol,ENUM_TIMEFRAMES timeframe,datetime time)
  {
   time-=time%PeriodSeconds(timeframe);
   return(Bars(symbol,timeframe,time,UINT_MAX)-1);
  }

And here is my function:

int iBarShift1(const string Symb,const ENUM_TIMEFRAMES TimeFrame,datetime time)
  {
   return(Bars(Symb,TimeFrame,time+1,UINT_MAX));
  }

Very similar. Really?

Only yours does everything very wrong and is slower at that.

You can try it with this script in MQL4.

Files:
 
Nikolai Semko:

No. The first one is zero. It works the same in real time.

OK - just some algorithm showing me "-1" on future data today....

 
Nikolai Semko:

That's funny ))))


Yeah, well, it does give out inconsistencies.) I'll dig it out ok.

 
vladevgeniy:

Well, yes, it does give out inconsistencies.) I'll dig it out ok.

I've been going around in circles myself. Only now I've figured out the shortest solution.
Reason: