Please "array out of range"

Back to topics list To post a new topic, please log in or register
avatar
31
Pompon83 2016.05.29 22:26
 

Hello, please, is there anyone to help me, my error message is "array out of range".

Here is my code :

 void OnTick()
  {
                for (int i=decalage;i<200;i++)

                     {  if (iCustom(NULL,0,"ZigZag",12,5,3,0,i)!=0) 

                        {pics[j]=iCustom(NULL,0,"ZigZag",12,5,3,0,i);

                        j=j+1;}}

 


avatar
Moderator
3404
GumRai 2016.05.29 22:58 #
 
                for (int i=decalage;i<200;i++)
                     {  if (iCustom(NULL,0,"ZigZag",12,5,3,0,i)!=0) 
                        {pics[j]=iCustom(NULL,0,"ZigZag",12,5,3,0,i);
                        j=j+1;}}

Please show your code that

assigns the initial value for j

sizes the array pics[]

avatar
31
Pompon83 2016.05.29 23:06 #
 
GumRai:

Please show your code that

assigns the initial value for j

sizes the array pics[]

#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

input int   decalage=5;
//input int   profit=50;
//input int   perte=50;
//input int   depassement=5;
double pics[200];
 
double haut,bas;
int j;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

    
             
                for (int i=decalage;i<200;i++)
                     {  if (iCustom(NULL,0,"ZigZag",12,5,3,0,i)!=0) 
                        {pics[j]=iCustom(NULL,0,"ZigZag",12,5,3,0,i);
                        j=j+1;}}
            
 //              for (int i=1;i<199;i++)
      //               {  if (pics[i]>pics[i-1] && pics[i]>pics[i+1] && pics[i]>High[0]) {haut=pics[i];break;}}
    
     //          for (int i=1;i<199;i++)
    //                 {  if (pics[i]<pics[i-1] && pics[i]<pics[i+1] && pics[i]<Low[0]) {bas=pics[i];break;}}
   
    
  //  Comment(DoubleToString(haut)+"    "+DoubleToString(bas));
    
    
   

    
      
avatar
Moderator
3404
GumRai 2016.05.29 23:16 #
 
//Declared Globally
double pics[200];
int j;
                for (int i=decalage;i<200;i++)
                     {  if (iCustom(NULL,0,"ZigZag",12,5,3,0,i)!=0) 
                        {pics[j]=iCustom(NULL,0,"ZigZag",12,5,3,0,i);
                        j=j+1;}}

j will keep increasing and so will soon exceed the size of pics[]



avatar
31
Pompon83 2016.05.29 23:24 #
 
GumRai:

j will keep increasing and so will soon exceed the size of pics[]



thanks a lot, i added j=0; just before the loop and it works.
Back to topics list  

To add comments, please log in or register