Need help to understand this please

 

I need some advice for the below code if you please,

1- for some reason, I get a note of "array out of range " in Mt4 expert journal

2- although Period_MA is external variable and I set it to 20; but when I am testing my code by changing

 for(x=i; x<i+Period_MA; x++)

to

for(x=i; 
x<=i+Period_MA; x++)
the moving average disappear from the chart

would someone help and tell me what is wrong with my code?


   int Counted_Bars = IndicatorCounted();
   int Uncounted_Bars = Bars - Counted_Bars;
   Uncounted_Bars++;
   
   for(int i=0; i<=Uncounted_Bars; i++)
     {
      double Total = 0;
         for(x=i; x<i+Period_MA; x++)
           {
            Total = Total + iClose(NULL,0,x);
           }
           
       Closing_Price_Array[i] = Total / Period_MA;
     }
 

It didn't happen because you changed the code, but because there was a mistake in your code from the beginning.

When the program starts, "Counted_Bars" is zero, so "Uncounted_Bars = Bars".

As a result, when "i = Uncounted_Bars", you get an "array out of range" error.
 
Nagisa Unada:

It didn't happen because you changed the code, but because there was a mistake in your code from the beginning.

When the program starts, "Counted_Bars" is zero, so "Uncounted_Bars = Bars".

As a result, when "i = Uncounted_Bars", you get an "array out of range" error.

How the Counted_Bars is zero and it is = IndicatorCounted () function which returns the amount of bars not changed after the indicator had been launched last?

and when I modify the line of the code and = , I get the moving average widen like below, so I just need to know how it was calculated just by adding an equal sign so that will be the outcome

for(x=i; 
x<=i+Period_MA; x++)

Thank you



 
I tested it with "GBPUSD,H1" just like you did, but nothing like you said happens.

Try showing your MA on 1 minute time frame, and see if the MA updates. Maybe it should not be updated.

"IndicatorCounted()" returns the number of calculated bars. Right after startup, it returns zero because it hasn't calculated anything yet.

Counted_Bars = IndicatorCounted();  //--->  Counted_Bars = 0

Uncounted_Bars = Bars - Counted_Bars;  //--->  Uncounted_Bars = Bars - 0

Uncounted_Bars++;  //--->  Uncounted_Bars = Bars + 1

// When "i = Uncounted_Bars" in the "for loop",

Closing_Price_Array[i] = Total / Period_MA; //--->  Closing_Price_Array[Bars + 1]  --->  array out of range
 
Nagisa Unada:
I tested it with "GBPUSD,H1" just like you did, but nothing like you said happens.

Try showing your MA on 1 minute time frame, and see if the MA updates. Maybe it should not be updated.

"IndicatorCounted()" returns the number of calculated bars. Right after startup, it returns zero because it hasn't calculated anything yet.

when I remove the equal yes, it updates on M1 chart and work fine, I am just trying to understand what the variance that the equal sign did to get this, how it was calculated?

Well I managed to remove the out of array error by adding the below to the code but still when I add the equal in the below line of code

x<=i+Period_MA
I get the same widen MA but when I remove it it works fine, I am trying to understand how the calculation took place to make this variance


   int Counted_Bars = IndicatorCounted();
   Counted_Bars--;
   if(Counted_Bars<Period_MA)
     {Counted_Bars = Period_MA;
      
     }
   int Uncounted_Bars = Bars - Counted_Bars;

   for(int i=Uncounted_Bars; i>=0; i--)
     {
      double Total = 0;
         for(x=i; 
x<=i+Period_MA; x++)
           {
            Total = Total + iClose(Symbol(),0,x);
          
           }
           
       Closing_Price_Array[i] = Total / Period_MA;
     }
 

Hello there, ive facing a problem kind of technical i don't know what it is. i cant access the mql5 website neither on mobile nor on desktop PC. Yet i am login now by using a VPN. I unchecked all of three options under the "Binding to IP address".  It is still not working. 

As we can see in the screenshot, same problem in mobile browser. . Can someone please help me about Thanks

 
Aijaz Khan:

Hello there, ive facing a problem kind of technical i don't know what it is. i cant access the mql5 website neither on mobile nor on desktop PC. Yet i am login now by using a VPN. I unchecked all of three options under the "Binding to IP address".  It is still not working. 

As we can see in the screenshot, same problem in mobile browser. . Can someone please help me about Thanks

This happens when you have some excessive activity, too many friend requests sent, too many market votes etc. or it may just be an automatic IP ban.

Wait for a few hours and it will be back to normal.