I always use this kind of loop:
int i = ArraySize(array); while(i-->0) sum+=array[i];
To check it use the debugger: https://www.metatrader5.com/en/metaeditor/help/development/debug
- www.metatrader5.com
-
You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
No free help (2017)Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum (2018)We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
No free help (2017) - Was it so hard you couldn't even attempt it? Not tested, not compiled, just typed.
double meanOnArray(const double& array[], int iEnd=EMPTY, int iBeg=0){ if(iEnd == EMPTY) iEnd = ArraySize(array); return sumArray(array, iEnd, iBeg) / (iEnd - iBeg); } double sumArray(const double& array[], int iEnd, int iBeg=0){ double sum=0; while(iEnd > iBeg) sum += array(--iEnd); return sum; }
Not tested, not compiled, just typed.
I always use this kind of loop:
To check it use the debugger: https://www.metatrader5.com/en/metaeditor/help/development/debug
-
You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
No free help (2017)Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum (2018)We're not going to code it for you (although it could happen if you are lucky or the issue is interesting).
No free help (2017) - Was it so hard you couldn't even attempt it? Not tested, not compiled, just typed. Not tested, not compiled, just typed.
Thanks William, I will try yours too later this evening.
Not sure some of your comments would have been necessary if you read my initial request for help; I'm sure they were well addressed there.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I am looking for help with writing a small custom code (MQL4) to sum some elements (about 25 to 35 elements) of an array with 100 elements.
I tried the following code but it did not work and I'm not sure how else to go about it.
for (int iArray = ArraySize(array) - 1; iArray >= 0; iArray--) summation += array[iArray];
The only other choice I have is to sum them manually, that is, sum=var1+var2+...var35. This will work but is clumsy and I can only modify the calculation manually.
Please help, thanks.