for(int i = 1; i<limit; i++) { buffer[i] = iClose(NULL, 0, i); //Placeholder in first for loop interation for(int a = 1; a<4; a++) { { buffer[i] = buffer[i] + iClose(NULL, 0, i+a); } buffer[i] = buffer[i]/5.0; }
your for loop will only have 3 iterations. This means that you are adding 4 values and then dividing by 5
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
As an exercise to learn MQL4, I'm writing a custom indicator which just replicates the Simple Moving Average, but without using the builtin iMA() function. The code below paints the indicator onto the chart, but every part of the line except the ending is showing extremely low values. For instance, on the AUD/CAD chart, which is usually, 0.80-0.90, the SMA line is around 0.20-0.30.
The line moves up and down in-sync with the price, and the very last bar seems to have an accurate reading (as the SMA spikes towards the current price at that point), but everything else is low. I've exhausted every possible reason for why this may be happening, and nothing is changing it. Can somebody help me to figure out what is going wrong?