Download MetaTrader 5

Please "array out of range"

To add comments, please log in or register
Frédéric LEBRE
375
Frédéric LEBRE  

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;}}
Keith Watford
Moderator
10612
Keith Watford  
                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[]

Frédéric LEBRE
375
Frédéric LEBRE  
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));
    
    
   

    
      
Keith Watford
Moderator
10612
Keith Watford  
//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[]

Frédéric LEBRE
375
Frédéric LEBRE  
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.
To add comments, please log in or register