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?
Nerd Trader #: 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
boolArraySetAsSeries(
constvoid& array[], // массив по ссылкеbool flag // true означает обратный порядок индексации
);
Nerd Trader #: 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?
datetime x=время нужного бара;
int index=iBarShift(_Symbol,0,x);
Nerd Trader #: 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;
FlagNewBar=false;
if(BarTime!=iTime(NULL,0,0))
{
BarTime=iTime(NULL,0,0);
FlagNewBar=true;
}
if(FlagNewBar==true)
{
// И когда тру, делаем что нужно делать когда появился новый бар, //на следующем тике флаг нового бара будет ложь, так как БарТайм время все время существования нулевого бара будет равным
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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.