The code in the message you should to embed correctly: Правильно вставляем код на форуме
Your code is incomplete.
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()

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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;
}