Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 821
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
Please pay attention to my question. I am writing an indicator that makes some calculations and saves them in an array (not a time series) of the same size as the number of candlesticks in the chart. Originally, I thought that if I have 2000 candlesticks in the chart in the terminal parameters, then at appearance of a new one, the first one will take the value of the second one, the second one - the third one, etc. Therefore, when getting prev_calculated equal to zero, I recalculate the entire array, otherwise only the last bar will do. But I found out that with every new candle the value of rates_total increases and becomes higher than the limit of 2000.
Hence, there is no sense in recalculating the array.
But why does it happen because the terminal sets exactly 2000 candlesticks?
When the terminal closes, the number of bars becomes 2000 again and starts increasing again when new candles appear.
Afternoon . Could you give me a hint? How would the code for the condition be: If the account balance has increased or decreased, then execute the function
//Declare a variable outside of functions:
double Balance=AccountBalance();
//Add to the tick/calculation function:
if (Balance!=AccountBalance())
{
Balance=AccountBalance();
MyFunction(); // <-- Your function
}
I have money in my real account but it says here you can only withdraw wages ?
Real account where do you have it?
because this is how the terminal works
So this is normal behaviour and not an error? Because some basic custom indicators are written without taking this factor into account and do full recalculation at every prev_calculated==0.
this solution is only for the tester, what happens if i overload the terminal? what if i run a second EA on this account?
you need to work with the orders history, there are no open orders with our magician - check the profit of the last order in the history
Reload? Or reload? If it is the latter, the behaviour of the EA will not change. If you launch a second EA, the algorithm will be executed similarly, without errors.
What the author needs to work with, depends on the task he has set himself. The way he posed the question, I answered it. I was not more specific in my question.
Please pay attention to my question. I am writing an indicator that makes some calculations and saves them in an array (not a time series) of the same size as the number of candlesticks in the chart. Originally, I thought that if I have 2000 candlesticks in the chart in the terminal parameters, then at appearance of a new candlestick, the first one will take the value of the second one, the second one - the third one, etc. Therefore, when getting prev_calculated equal to zero, I recalculated the entire array, or only the last bar. But I found out that with every new candle the value of rates_total increases and becomes higher than the limit of 2000.
Hence, there is no sense in recalculating the array.
But why does it happen so when the terminal sets exactly 2000 candlesticks?
When the terminal closes, the number of bars becomes 2000 again and starts increasing again when new candles appear.
//Declare a variable outside of functions:
double Balance=AccountBalance();
//Add to the tick/calculation function:
if (Balance!=AccountBalance())
{
Balance=AccountBalance();
MyFunction(); // <-- Your function
}
Thank you so much, it worked!
Metatreder 4 application
Forum on trading, automated trading systems & strategy testing
Any questions for beginners on MQL4, help and discussion on algorithms and codes
Artyom Trishkin, 2019.04.28 16:55
Real account where do you have it?And why try to figure out how it works internally? Well, if you want to write your own function, it's probably more convenient to sort and take the value of one of the outermost indexes. But it will hardly be faster than the built-in function. Plus, the built-in function allows you to search for a value within the designated index limits. So, simple sorting will not work. So, we will have to copy part of the array into an intermediate array and sort it already and take the required value from it, but array copying is not a very "cheap" function.
You need to understand so that your brain can develop. Yesterday I sat for a long time and made sketches, it seems that it is possible to do without sorting on the principle of enumeration, but we still need variables that will store values, and even more we can return the value at once, not the index, which simplifies the work. You can better make your own functions in the range and different modifications to save calculations. The built-in functions lack many details. But built-in functions are very fast, I don't understand what it's related to, maybe they are written in C++, as I write my functions very carefully, taking into account all the details: speed, quality, code savings, implement modifications that reduce the number of checks and passes within functions, but for some reason built-in functions still bypass speed, not quality, but I'm addressing to forum community with this question long ago.