Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 821

 

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.


ruslanzip:
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 ?
 
Roza75:
I have money in my real account but it says here you can only withdraw wages ?
Real account where do you have it?
 
Artyom Trishkin:
Real account where do you have it?
Metatreder 4 application
 
Igor Makanu:

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.


Igor Makanu:

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.

 
The_Sheikh:

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!

 
Artyom Trishkin:

I have the Metatreder 4 app on my phone there
 
Alexey Viktorov:

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.

 
Good day to all forum users! Faced with a problem, the second day headache, I can not figure out how to implement the idea! How to draw a rectangle, a circle, an oval (no matter what figure) at a certain candle, not to redraw in new coordinates. And what if some conditions trigger a figure? Each figure on its own candlestick. I am just recently started studying mql4, so I'm not familiar with charting. I decided yesterday to try to print a square on the 10th bar (as an example). I got one and it's not drawn anymore. Yesterday, I poked and poked the code, and eventually it worked, but the square is constantly erased in its old place and drawn in a new one, then bothered that the output square only once. Hint who knows how to implement it! Or advise where there is a branch on the forum. Aka already read a bunch of information, just more confused! Thanks in advance for the answers!
Reason: