MQL4 - automated forex trading   /  

Forum

the most frequent value from a number of buffers?

Back to topics list To post a new topic, please log in or register

avatar
134
MrH 2011.12.13 23:16 

Say you have 10 buffers:

buf1[i] =icustom(0,0,"someIndicator",10,0,i);

buf2[i] =icustom(0,0,"someIndicator",20,0,i);

buf3[i] =icustom(0,0,"someIndicator",30,0,i);

...

buf10[i] =icustom(0,0,"someIndicator",100,0,i);

So it's the same custom indicator, but only its window length is changing from 10 to 100. Assume these 10 values are integers and often close to or equivalent to each other. Say the 10 buffers have the following values: 12,10,8,12,12,4,12,4,12,12. The most frequent element in this list is obviously 12. How would you code this in an efficient way that some summary buffer contains the value of 12 for the current bar?

Contest of Expert Advisors inside an Expert Advisor

Contest of Expert Advisors inside an Expert Advisor

Using virtual trading, you can create an adaptive Expert Advisor, which will turn on and off trades at the real market. Combine several strategies in a single Expert Advisor! Your multisystem Expert Advisor will automatically choose a trade strategy, which is the best to trade with at the real market, on the basis of profitability of virtual trades. This kind of approach allows decreasing drawdown and increasing profitability of your work at the market. Experiment and share your results with others! I think many people will be interested to know about your portfolio of strategies.


avatar
4328
WHRoeder 2011.12.14 14:45 
Assuming the int values range 0 to 100
int count[101]; for(int iCnt=0; iCnt<=100; iCnt++) count[iCnt]=0;
count[ buf1[i] ]++;
count[ buf2[i] ]++;
:
count[ buf10[i] ]++;
int max=0; for(int iCnt=0; iCnt<=100; iCnt++) if (max < count[iCnt]){ 
   max = count[iCnt];
   MostFrequentInt[i] = iCnt;
}
if bufX are really doubles then use
int value = buf1[i]; count[ value ]++;
    value = buf2[i]; count[ value ]++;
:


avatar
134
MrH 2011.12.14 16:23 
WHRoeder:
Assuming the int values range 0 to 100 if bufX are really doubles then use

thx WHRoeder!
Back to topics list  

To add comments, please log in or register