Hello. If you don't know beforehand how many elements will be in the array, how do you declare the array so that the array increases with each new element?
Hello. If you don't know beforehand how many elements will be in the array, how do you declare the array so that the array increases with each new element?
Hello, I use an Expert Advisor ILAN 2.0, can you advise how to make an automatic stop EA after closing all orders, I need it, say before the release of important news that he brought the transaction to a logical end and no longer trade.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hello. If you don't know beforehand how many elements will be in the array, how do you declare the array so that the array increases with each new element?
An example to make it clearer:
for(int i=0; i<1000; i++)
{
if(A[i]<B[i])
HighA[i]=A[i];
}
Print(">>>>>>>>>>>..ArraySize(HighA)= ",ArraySize(HighA));
Hello. If you don't know beforehand how many elements will be in the array, how do you declare the array so that the array increases with each new element?
An example to make it clearer:
for(int i=0; i<1000; i++)
{
if(A[i]<B[i])
HighA[i]=A[i];
}
Print(">>>>>>>>>>>..ArraySize(HighA)= ",ArraySize(HighA));
You should read the documentation more often.
I've read and tried but I get an "array out of range" error. In the example it looked like this:
for(int i=0; i<1000; i++)
{
if(A[i]<B[i])
{
countHlines++;
ArrayResize(HighA,countHlines);
HighA[i]=A[i];
}
}
Print(">>>>>>>>>>>..ArraySize(HighA)= ",ArraySize(HighA));
I've read and tried but I get an "array out of range" error. On the example it looked like this:
for(int i=0; i<1000; i++)
{
if(A[i]<B[i])
{
countHlines++;
ArrayResize(HighA,countHlines);
HighA[i]=A[i];
}
}
Print(">>>>>>>>>>>..ArraySize(HighA)= ",ArraySize(HighA));
When condition A[i] < B[i] is not fulfilled, the array size remains unchanged and the loop counter is incremented. That's why it is out of range.
Try it this way.
for(int i=0; i<1000; i++)
{
if(A[i]<B[i])
{
int size = ArraySize(HighA);
ArrayResize(HighA, size+1);
HighA[size]=A[i];
}
}
Print(">>>>>>>>>>>..ArraySize(HighA)= ",ArraySize(HighA));
When the A[i] < B[i] condition is not satisfied, the array size remains unchanged and the loop counter is incremented. That's why it is out of bounds.
Try it this way.
for(int i=0; i<1000; i++)
{
if(A[i]<B[i])
{
int size = ArraySize(HighA);
ArrayResize(HighA, size+1);
HighA[size]=A[i];
}
}
Print(">>>>>>>>>>>..ArraySize(HighA)= ",ArraySize(HighA));
I've read and tried but I get an "array out of range" error. In the example it looked like this:
for(int i=0; i<1000; i++)
{
if(A[i]<B[i])
{
countHlines++;
ArrayResize(HighA,countHlines);
HighA[i]=A[i];
}
}
Print(">>>>>>>>>>>..ArraySize(HighA)= ",ArraySize(HighA));
Well that would work faster
double HighA[];
for(int i=0; i<1000; i++)
{
if(A[i]<B[i])
{
countHlines++;
ArrayResize(HighA,countHlines);
HighA[countHlines-1]=A[i];
}
}
Print(">>>>>>>>>>>..ArraySize(HighA)= ",ArraySize(HighA));
// Вариант №2
int countHlines=-1;
double HighA[];
for(int i=0; i<1000; i++)
{
if(A[i]<B[i])
{
countHlines++;
ArrayResize(HighA,countHlines+1);
HighA[countHlines]=A[i];
}
}
Print(">>>>>>>>>>>..ArraySize(HighA)= ",ArraySize(HighA));
Well, it will work faster that way
double HighA[];
for(int i=0; i<1000; i++)
{
if(A[i]<B[i])
{
countHlines++;
ArrayResize(HighA,countHlines);
HighA[countHlines-1]=A[i];
}
}
Print(">>>>>>>>>>>..ArraySize(HighA)= ",ArraySize(HighA));
// Вариант №2
int countHlines=-1;
double HighA[];
for(int i=0; i<1000; i++)
{
if(A[i]<B[i])
{
countHlines++;
ArrayResize(HighA,countHlines+1);
HighA[countHlines]=A[i];
}
}
Print(">>>>>>>>>>>..ArraySize(HighA)= ",ArraySize(HighA));
Thank you, I see! It will be faster because of ArraySize, does it slow it down somehow?
Not much, but it's clear and error-proof.