Your look back is period. So when IndicatorCounted == 0, i is Bars-1 and k goes to Bars+period-2 which does not exist and script/EA fails. 4002
Array index is out of range
int counted = IndicatorCounted(); int i = Bars - counted -1; while(i>=0){ double sum = 0; for(int k = i ; k <= i+period -1 ; k++){ sum = sum + Close[k];
Handle look back properly int counted = IndicatorCounted(); int i = Bars - MathMax(period, counted) -1; while(i>=0){
What do you think happens when you try to assign a value to a zero length array? double mmh[]; : mmh[i] = sum / period;
- After loop i equals -1 close[i] does not exist
- Why are you calculating SMA for all bars, when you only look at two values (current ones?)
- Check your return codes (OrderSend) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
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 have problems with my code, it's don't work, Normally it have to take long or short after crossing MA. Can you tell me where my code is bad please. thanks