kit1c2000: example would be: 1,3,1,4,7,2,6,1 the answer would be 1. I am new here so please go easy on me.
- My normal response would be:
You have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.but you asked nicely and the problem isn't trivial. - Not Compiled, Not tested.
int example[] = { 1,3,1,4,7,2,6,1}; Print("the answer is "+Mode(example)); : int Mode(int& arr[], int nElem=WHOLE_ARRAY, int iBeg=0){ // Modifies arr if(nElem == WHOLE_ARRAY) nElem = ArraySize(arr) - iBeg; int curVal = arr[iBeg], curCnt = 0, mode, maxCount = 0; ArraySort(arr, nElem, iBeg); for(int iLimit = iBeg + nElem; iBeg < iLimit; iBeg++){ if(arr[iBeg] == curVal){ curCnt++; continue; } if(curCnt > maxCount){ maxCount = curCnt; mode = curVal; } curCnt = 1; curVal = Arr[iBeg]; } if(curCnt > maxCount){ maxCount = curCnt; mode = curVal; } return(mode); } int ModeCons(int conArr[], int nElem=WHOLE_ARRAY, int iBeg=0){ // Constant array if(nElem == WHOLE_ARRAY) nElem = ArraySize(conArr) - iBeg; int temp[]; ArrayResize(temp, nElem); ArrayCopy(temp, conArr, 0, iBeg, nElem); return(Mode(temp, nElem, 0) {
Not Compiled, Not tested.
WHRoeder:
- My normal response would be:
You have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.but you asked nicely and the problem isn't trivial. - Not Compiled, Not tested. Not Compiled, Not tested.
Thanks for your code. It works like a charm.
Your help is much appreciated.
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,
I want to sort a group of numbers and find how many times a number has occurred or the most frequent number.
The numbers are pulled from a chart.
example would be: 1,3,1,4,7,2,6,1
the answer would be 1.
I don't know what the range would be but I know how many numbers in the group.
Java's hashmap can solve this nicely but I don't think there's such data type in mql4.
I am new here so please go easy on me.