Try to specify ArrayResizeandArraySetAsSeriesforvariablesLR_line[],Sup_line[]andRes_line[].
void LinearRegressionChannel(bool Use_Close,int barsToCount,datetime q, double w )
{
Use_Close = true;
barsToCount=50;
double LR_line[];
double Sup_line[];
double Res_line[];
ArrayResize(LR_line,50);
ArrayResize(Sup_line,50);
ArrayResize(Res_line,50);
ArraySetAsSeries(LR_line,false);
ArraySetAsSeries(Sup_line,false);
ArraySetAsSeries(Res_line,false);
// variablesdouble a,b,c,
sumy=0.0,
sumx=0.0,
sumxy=0.0,
sumx2=0.0,
h=0.0,l=0.0;
int x;
// calculate linear regressionfor(int i=0; i<barsToCount; i++)
{
sumy+=Close[i];
sumxy+=Close[i]*i;
sumx+=i;
sumx2+=i*i;
}
c=sumx2*barsToCount-sumx*sumx;
if(c==0.0)
{
Alert("Error in linear regression!");
return;
}
// Line equation
b=(sumxy*barsToCount-sumx*sumy)/c;
a=(sumy-sumx*b)/barsToCount;
// Linear regression line in bufferfor(x=0;x<barsToCount;x++)
LR_line[x]=a+b*x;
// Use PRICE_CLOSE for support-resistanceif (Use_Close)
for(x=0;x<barsToCount;x++)
{
if(Close[x]-LR_line[x] > h) h = Close[x]-LR_line[x];
if(LR_line[x] - Close[x]> l) l = LR_line[x] - Close[x];
}
// Use HIGH - LOWelsefor(x=0;x<barsToCount;x++)
{
if(High[x]-LR_line[x] > h) h = High[x]-LR_line[x];
if(LR_line[x] - Low[x]> l) l = LR_line[x] - Low[x];
}
// Drawing support - resistance lines if (h>l)
{
for(x=0;x<barsToCount;x++)
{
Sup_line[x]=a-h+b*x;
Res_line[x]=a+h+b*x;
}
}
else
{
for(x=0;x<barsToCount;x++)
{
Sup_line[x]=a-l+b*x;
Res_line[x]=a+l+b*x;
}
}
/*
LR_line[x] = 0.0;
Sup_line[x] = 0.0;
Res_line[x] = 0.0;
*/
q=Time[49];
w=LR_line[49];
/* chart can't have two or more objects with same name
these are two decisions for resolve this problem
1. Create LRC in OnInit and set coordinats Time[49],LR_line[49],Time[1],LR_line[1]
by call ObjectSetDouble() here
2. Delete LRC before it create
*/ObjectDelete(0, "LRC"); // method 2 if(!ObjectCreate(0,"LRC",OBJ_TREND,0,Time[49],LR_line[49],Time[1],LR_line[1]))
{ Print(" can not draw LRC: ", GetLastError());};
return;
}
// also delete line in OnDeinitvoidOnDeinit(constint reason)
{
ObjectDelete(0, "LRC"); // method 2
}
intOnInit()
{
return(INIT_SUCCEEDED);
}
Where is bars or candles in chart?
file you attached work , and i modified mine as same as it, but still dont work.
as you can see in last pic.i posted above, the time OR CANDLE IS true,
but the value for price, that must be equal to " LR_line[] " is always zero.
stil same problem.
Try to specify ArrayResize and ArraySetAsSeries for variables LR_line [], Sup_line [] and Res_line [].
:-)
what a mistake, problem solved, thank you,
thank for all freind's help.