# Array out of range

11

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;

}
Moderator
61150

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

Moderator
5301

```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()`