Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1754
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
The situation is as follows: the X variable stores the index of the bar in the history, we know that when a new bar appears, there is a shift, and therefore X already points to a different bar. How to fix it? The idea: with every new bar we increase the counter (count++) and add it to X. Thus X will always point to the same bar regardless of the offset. But there is a problem - when the EA is initialized the first current bar should not be taken into account. I think it can be easily solved if count is initially just equal to -1. That is, on the current bar after the increment count will be "0", and on the next new bar (when the first shift by 1 bar has happened after initialization) it will be "1". What do you think? Maybe I'm thinking in the wrong place at all?
If it is an indicator, it is sufficient
to all arrays and buffers of the indicator used.
Then the zero bar will become rates_total-1
The situation is as follows: the X variable stores the index of the bar in the history, we know that when a new bar appears, there is a shift, and therefore X already points to a different bar. How to fix it? The idea: with every new bar we increase the counter (count++) and add it to X. Thus X will always point to the same bar regardless of the offset. But there is a problem - when the EA is initialized the first current bar should not be taken into account. I think it can be easily solved if count is initially just equal to -1. That is, on the current bar after the increment count will be "0", and on the next new bar (when the first shift by 1 bar has happened after initialization) it will be "1". What do you think? Maybe I'm thinking in the wrong place at all?
Why go to all that trouble?
It's easier for me)
But the processor is heavier...
But the processor is heavier...
The situation is as follows: The X variable stores the index of the bar in the history, and we know that when a new bar appears, it is shifted and therefore X already points to another bar. How to fix it? The idea: with every new bar we increase the counter (count++) and add it to X. Thus X will always point to the same bar regardless of the offset. But there is a problem - when the EA is initialized the first current bar should not be taken into account. I think it can be easily solved if count is initially just equal to -1. That is, on the current bar after the increment count will be "0", and on the next new bar (when the first shift by 1 bar has happened after initialization) it will be "1". What do you think? Maybe I'm thinking in the wrong place at all?
Not there. There is nothing in X when loading EA/indicator if it is inside the terminal, unless it is an intu or extern or global variable outside the terminal, so something has to be written there first. And then we simply read the changes of the total number of bars (account for the appearance of a new bar).
datetime BarTime;
Greetings. Can you give me a hint? How in mt5 at initialization or at tick to define testing?
So far I found only OnTester(), which is called just before OnDeinit().
@Valeriy Yastremskiy The index is placed in X still in OnInit(). My code looks like this:
The condition with FlagNewBar seems redundant to me.