sort the array and compare the neighbours
Use array sorting and find if a value is duplicated. Easy with loops.
Rohi Finish:
Hello,
can someone tell me what is the fast and best way to find a duplicated/or more items in array in MQL4 ?
thanks
Use my function.
/**
* Returns most repeated value from array
* @param double array
* @return double
*/
double GetMostRepeatedFromArray(double &arr[])
{
double unique[] = {};
double hits[] = {};
for(int i = 0; i < ArraySize(arr); i++)
{
int index = ArrayFind(unique, arr[i]);
if(index == WRONG_VALUE)
{
int size = ArraySize(unique);
ArrayResize(unique, size+1);
ArrayResize(hits, size+1);
unique[size] = arr[i];
hits[size] = 1;
} else {
hits[index] = hits[index] + 1;
}
}
return(unique[ArrayMaximum(hits)]);
}
int ArrayFind(double &arr[], double value)
{
for(int i = 0; i < ArraySize(arr); i++)
{
if(arr[i] == value) return(i);
}
return(WRONG_VALUE);
}
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
Hello,
can someone tell me what is the fast and best way to find a duplicated/or more items in array in MQL4 ?
thanks