ArraySize of spreads wont loop

 

Confusing how ArraySize doesn't work in a loop.

I am looping the array elements to move all down and update the zero array with the latest spread.

input int Spreads = 8;

int iS[12]; //spreads array
string sS; //spreads

int OnInit()
  {
   ArrayResize(iS,Spreads);
   //Print(ArraySize(iS)); //8
  }

void OnTick()
  {   
   for(int iCnt=ArraySize(iS); iCnt>=0; iCnt--)
     {      
      if(iCnt==0){iS[0]=(int)MarketInfo(NULL,MODE_SPREAD);}
      else{iS[iCnt]=iS[iCnt+1];}
      
      if(iCnt==0){sS=IntegerToString(iS[iCnt])+sS;}
             else{sS=" "+IntegerToString(iS[iCnt])+sS;}
     }
   Comment(sS);
   sS="";
  }


The string should show the spreads like "5 3 1 1 7 4 4 3"

 
 
   for(int iCnt=ArraySize(iS); iCnt>=0; iCnt--){
      
      else{iS[iCnt]=iS[iCnt+1];}

Array exceeded. iCnt is the size of iS. Therefor indexes of iS are [0 … iCnt - 1]

 
William Roeder:

Array exceeded. iCnt is the size of iS. Therefor indexes of iS are [0 … iCnt - 1]

Yes Sir -

Thankx

 
Brian Lillard:

Yes Sir -

Thankx

You also want it to be

for(int iCnt =ArraySize(iSp)-1; ...