Questions from Beginners MQL5 MT5 MetaTrader 5 - page 623
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
No, I need it not in the tester, but when the terminal really runs on a chart - it will work there only if the history contains less than the maximum number of bars, or am I wrong?
And in real time rates_total and Bars() will increase when the indicator is running. You won't be able to get rates_total in OnInit(), because the parameter is not passed to the function. You must check history in any case in OnCalculate().
And in real time rates_total and Bars() will increase when the indicator is running. You won't be able to get rates_total in OnInit(), because the parameter is not passed to the function. The history should be checked in any case in OnCalculate().
I.e. we have to make a separate indicator, where we check for the number of bars and if everything is OK, then fill the chart buffer with one, and then wait in the EA until we get one from the indicator, and only then continue working, right?
Of course not... Why make it so complicated... Let's do it again. What is the goal? To get all the history available for calculation?
The situation is that for the EA to work properly, it needs to calculate the history once. So, it happens that when you turn on the terminal with this EA, there is history and, accordingly, initialization and calculation are performed, but this history may not be all of it and a new one will be loaded after connection to the terminal.
I think that we can trace the connection with the terminal and then, if it is available, check for changes of the last bar in HLCO and if it is available, we wait, and if it is not available within x seconds, we perform the calculation.
The situation is that for the EA to work properly, it needs to calculate the history once. So, it happens that when you turn on the terminal with this EA, there is history and, accordingly, initialization and calculation are performed, but this history may not be all of it, and a new one will be loaded after connection to the terminal.
I think that we can trace the connection with the terminal and then, if it is available, check for changes of the last bar by HLCO and if it is available, we wait, but if it is not available within x seconds, we perform the calculation.
Does the Expert Advisor use any custom indicators?
For example, you can do the following: you check the size of the history through Bars(). Then see if Bars() > prev_bars+1 (the size of the history on the previous tick) - then you reset all of the saved data and do a complete recalculation of the Expert Advisor from zero. This construction should be inserted first in OnTick().
No need to bother with the connection to the terminal, pauses, etc. The simplest option is often the best.
Does the Expert Advisor use any custom indicators?
For example, you can do this: check the size of the history via Bars(). Then see if Bars() > prev_bars+1 (the size of the history on the previous tick) - then you reset all of the saved data and do a complete recalculation of the Expert Advisor from zero. This construction should be inserted first in OnTick().
No need to bother with the connection to the terminal, pauses, etc. The simplest variant is most often the best.
The Expert Advisor uses a lot of things, including indicators.
I understand that the suggested variant will recalculate on every bar, or am I wrong?
The Expert Advisor uses a lot of things, including indicators.
I understand that this variant will be recalculated on every bar, or am I wrong?
No, why on every bar? The Expert Advisor will be recalculated completely only if more than 1 bar is added to the history! If 1 bar is added (a new bar is formed), the complete recalculation will not be performed.
If you use indicators, and they have global variables, then they must be zeroed when you run them for the first time. Otherwise, artifacts may appear on the chart / indicators may be displayed incorrectly.
No, why on each one? A full recalculation of the EA will only happen if more than 1 bar has been added to the story! If 1 bar is added (a new bar is formed), there will be no complete recalculation.
If you use indicators, and they have global variables, then they must be zeroed when you run them for the first time. Otherwise, artifacts may appear on the chart / indicators may be displayed incorrectly.
double A;
int x, y;
x=100; y=3; A=x/y=33,000