Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1466
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
if(i+30<=ArraySize(opens))
Here is the output outside the array
This error is due to inattention. Fixing it does not solve the problem.
How could I create an array of 30 candlestick opening prices to search for highs and lows in it?
ArrayMaximum
ArrayMaximum
Returns index of the maximum value, not the price.
I haven't checked, but it seems to be the way to get indices of minimums and maximums of candlestick openings (opens).
Although you can also get the price at once, but not the indices.
Nowhere have I found an example of an mql loop with a step. This simplifies the whole matter.
Only ChatGPT advised me to write it this way:
I will experiment further. The code works. Thank you.
The "array out of range" error occurs if you don't do ArrayResize.
This error is due to inattention. Fixing it does not solve the problem.
How could I create an array of 30 candlestick opening prices to search for highs and lows in it?
What is the problem? Declare an array temp[] and copy 30 elements into it and look for the index of the minimum/maximum value. And if at the end it is less than 30, it will copy how many are left. And in this case, I'd rather use a while() loop.
What's the problem? Declare an array temp[] and copy 30 elements into it and look for the index of the minimum/maximum value. And if at the end it is less than 30, it will copy how many are left. And in this case, I'd rather use a while() loop.
Yes, you can do that. I'm not thinking straight, so I'm asking for advice.
Yeah, you could do that. I'm not thinking straight, so I'm asking for advice.
In a static array the size is set constant, it cannot be changed, in a dynamic array it can be changed, but the size of the array is set! i.e. the size of the array is known and the indexes of elements from 0 to the end. <= is out of bounds just because the indexes of elements from zero, and the index of the last element is less by one unit of the array size.
Everything is in your hands))))
In a static array the size is set constant and cannot be changed, in a dynamic array it can be changed, but the size of the array is set! i.e. the size of the array is known and the indexes of the elements are from 0 to the end. <= is out of bounds just because the indexes of elements from zero, and the index of the last element is less by one unit of the array size.
Everything is in your hands))))
What do you mean bythat ? Do you think that to copy some number of elements from one array to another, some temp[], you should set the array size before copying ArrayResize(temp, new_size); ?????
Yeah, you could do that. I'm not thinking straight, so I'm asking for advice.
You don't even need a temporary array.
This code
searches for the maximum of 15 remaining elements despite the fact that it is set to search for 20 elements.
So you'd better use the while() loop and not worry about the number of remaining array items.
What do you mean bythat ? Do you think that in order to copy some number of elements from one array to another, some temp[], you should set the array size before copying ArrayResize(temp, new_size); ?????
No of course, I meant that the array size is always known or can be known. And it can and should be controlled for index overrun.