Questions from Beginners MQL5 MT5 MetaTrader 5 - page 623

 
-Aleks-:
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().

 
Good day to all! Please help me find an Expert Advisor. I need a box (box) with setting session time, splitting into three orders in each direction, trailing and stop loss functions. I have already drowned in my search on the open spaces. I'm almost on the edge of a precipice, just a little longer and I'll start learning the language and the editor to write myself!!!! HELP!!!
 
Alexey Kozitsyn:

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().

In other words, we should create an 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 to work, right?
 
-Aleks-:
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 would it be so complicated... Let's go over it again. What is the objective? To get the entire history available for calculations?
 
Alexey Kozitsyn:
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.

 
-Aleks-:

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.

 
Alexey Kozitsyn:

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?

 
-Aleks-:

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.

 
Alexey Kozitsyn:

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.

Didn't pay attention to +1 , thanks, I think it's not a bad option.
 
Can you tell me why this might happen?

double A;
int x, y;

x=100; y=3; A=x/y=33,000