You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
You said that everything should work in MQL4.
But this script can be run in MQL5 too
With exact=True and future time you should return -1
My script also found a strange error:
This error is confirmed by this check:
So I was right about the existence of abnormal situations in your algorithm after all.It's nice that you finally found the error
I will check it out, thank you.
Good evening all. Perhaps I'm misunderstanding something, but still - it's not quite clear what's wrong with the standard function, which has already been suggested at the beginning of Bars(). I've been using it all the time and it hasn't caused any problems. The only thing is that you may encounter "array out of range" or negative value when using TimeCurrent(), but then you need to make a check for it. Examples:
Good evening all. Perhaps I'm misunderstanding something, but still - it's not quite clear what's wrong with the standard function, which has already been suggested at the beginning of Bars(). I've been using it all the time and it hasn't caused any problems. The only thing is that you may encounter "array out of range" or negative value when using TimeCurrent(), but then you need to make a check for it. Examples:
Judging by the number 32000000000 this is also my creation. UINT_MAX is simply shorter and more solid looking. ))
The point is that this variant is more correct, as it turns out:
rather than
there is almost no external difference. But the upper variant repeats very precisely the standard iBarShift function of MQL4
Judging by the number 32000000000, this is also my creation. UINT_MAX simply looks shorter and more solid. ))
The point is that this variant is more correct, as it turns out:
rather than
there is almost no external difference. But the upper variant repeats very precisely the standard iBarShift function of MQL4.
So what's the easiest and the right one?
So what's the easiest and the right thing to do?
So far this variant, but now I want to supplement it to bypass the bug of Bars function freeze, about which I have already reported to Service Desk.
The essence of this bug is that if in Bars function bothstart_time andstop_time are inside one bar or are in the future (to the right of zero bar), then this function hangs for more than 10 seconds.
Maybe I'll make a proper faster but more cumbersome version later.
I have decided to go a different way.
I won't redo iBarShift, but will redo the glitchy Bars feature.
And the new iBars feature will not only bypass the hiccups bug, it will also be faster than the original Bars.
Others will be able to use this feature and the algorithms already in place will work faster.
I just need time. I won't be able to do it until a day later.
I've decided to go a different route.
I won't redo iBarShift, but will redo the glitchy Bars feature.
And the new iBars feature will not only bypass the hiccups bug, it will also be faster than the original Bars.
Others will be able to use this feature and the algorithms already in place will work faster.
I just need time. Won't be able to do it before one day.
Very good! Looking forward to it!
From all the analysis I've done, we can conclude that this full analogue of the iBarShift:
is by far the most correct, and at the same time the fastest and with the simplest and shortest algorithm.
It's nice, but something confuses me...
will have to test it )
The iBars function is quite cumbersome, but I still recommend using it instead of the regular Bars, until MQ fixes the hang-up bug in it.
The iBar hangs when logically it should return 0. As a rule, it returns it for more than 10 seconds. There is no such bug in MQL4.
In the majority of tasks, iBars will work faster than the regular Bars since it will not only avoid the bug, but tries not to use the Bars and SeriesInfoInteger functions whenever possible due to the algorithm of saving previous values.
I have tested this function far and wide. It seems to be a full copy of Bars.
Perhaps it can be done in a more elegant way. If you have a desire, you are welcome. If you find errors, we will fix them.
So...
Then the full analogue of iBarsShift function will have the following form:
And variant without last parameter, which is used in the vast majority of cases will have this form:
Indicator showing the performance of the iBars function compared to the built-in Bars and the iBarShift function from @Alain Verleyen
Function execution time in microseconds.