Download MetaTrader 5
To add comments, please log in or register
Do you know that MQL5 has structures?
Frédéric LEBRE
233
Frédéric LEBRE 2016.05.29 20: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;}}
Keith Watford
Moderator
7906
Keith Watford 2016.05.29 20: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[]

Frédéric LEBRE
233
Frédéric LEBRE 2016.05.29 21: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));
    
    
   

    
      
Keith Watford
Moderator
7906
Keith Watford 2016.05.29 21: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[]

Frédéric LEBRE
233
Frédéric LEBRE 2016.05.29 21: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.
/
To add comments, please log in or register