Download MetaTrader 5

Array out of range

To add comments, please log in or register
Publish your programs in the Market. Make money with your knowledge!
dwijfintech1
11
dwijfintech1 2015.09.03 07:37 

Array out of range  during optimization


double X1[], X2[], beta=0, alfa=0;

int W=60;

  ArraySetAsSeries(X1,true);
  ArraySetAsSeries(X2,true);
  ArraySetAsSeries(Zt,true);
  CopyClose(my_symbol1,_Period,W,1,X1);
  CopyClose(my_symbol2,_Period,W,1,X2);
for(int b=19; b>0; b--)
{
   for ( int a = 38+b; a>b; a-- )
   {
     
     beta+= X2[a]/40*X1[a] ;
    
    
   }
   for ( int a= 38+b; a>b;a--)
   {
     
     alfa+= (X2[a]-beta*X1[a])/40 ;
   
    
   }

   Zt[b]= X2[b]-beta*X1[b]-alfa;

}
Vladimir Karputov
Moderator
46038
Vladimir Karputov 2015.09.03 08:10  

The code in the message you should to embed correctly: Правильно вставляем код на форуме

Your code is incomplete.

Marco vd Heijden
Moderator
4704
Marco vd Heijden 2015.09.03 08:11  
double X1[], X2[], beta=0, alfa=0;

int W=60;

  ArraySetAsSeries(X1,true);
  ArraySetAsSeries(X2,true);
  ArraySetAsSeries(Zt,true);
  CopyClose(my_symbol1,_Period,W,1,X1);
  CopyClose(my_symbol2,_Period,W,1,X2);
for(int b=19; b>0; b--)
{
   for ( int a = 38+b; a>b; a-- )
   {
      
     beta+= X2[a]/40*X1[a] ;
     Print("beta+ ",beta+);
     
   }
   for ( int a= 38+b; a>b;a--)
   {
     
     Print("38+b= "a);
 
     alfa+= (X2[a]-beta*X1[a])/40 ; 
     Print("alfa+ ",alfa+);
     
   }

   Zt[b]= X2[b]-beta*X1[b]-alfa;
   Print("Zt ",Zt[b]);
}

look to see if it shows negative value somewhere.

Also look to use

ArrayResize()
To add comments, please log in or register