for(n=i0;n<=i0+p;n++) { if(mi==1) sum+=Close[n]; else sum+=Close[n]*MathPow(n,mi-1);
i0 is the shift so Close[n] make sense. If i0==99 why is your sum multiples of 99, 9801 etc.- I posted my general implementation 3 days ago: Fitting a parabola - MQL4 forum
-
i0 is the shift so Close[n] make sense. If i0==99 why is your sum multiples of 99, 9801 etc.
- I posted my general implementation 3 days ago: Fitting a parabola - MQL4 forum
Thanks for your answer.
Well I m not sure why it multiplies. As i said before i just found the code and altered it. I didnt go through how the regression is calculated.
The only change i ve made is that i placed the code in a i_Regr_i function and i added the real_shift.
So in the Start() in the while() loop i call something like
i_Regr_i(degree, kstd, bars, shift, i)
athanfx2013.10.10 10:36
Hi
i ve worked on some regression code i ve found and i altered it so to create a different version of it.
Although it seems to work as part of an indincator, when i m backtesting it the results are totally different! I really cant find where the problem is. Any ideas/help?
I am not sure what all that is you have coded, you should comment your code when you post it, anyway it looks like too much code to me, this is all it takes to code a regression line.
//+-------------------------------------------------------------+ //| testing least squares regression line | //| SDC 2013 | //+-------------------------------------------------------------+ int start() { double a,b,y,n,x,sumx,sumx2,sumxy,sumy,y1,y2; int begin = 10; //bar shift of first bar (oldest) int end = 0; //bar shift of end bar (newest) //---- vals for least squares regression for(int i=begin; i>=end;i--) { y = Close[i]; //-- loop through closes x=i; //-- bars by chart index n++; //-- number of bars in line sumx += x; //-- sum of bars in line sumy += y; //-- sum of close prices sumxy += (x*y); //-- sum of bars*close sumx2 += (x*x); //-- sum of bars squared } //---- slope(b) intercept(a) b = (n*sumxy-sumx*sumy)/(n*sumx2-sumx*sumx); a = (sumy - (b*sumx))/n; //---- insert bar numbers into equation y1 = a+b*begin; y2 = a+b*end; //test equation with a trendline ObjectCreate("LSR1",OBJ_TREND,0,Time[begin],y1,Time[end],y2); //---- return(0); }
I am not sure what all that is you have coded, you should comment your code when you post it, anyway it looks like too much code to me, this is all it takes to code a regression line.
Thanks for your answer I ll try your code.
The way i ve created is so that it uses buffer not object to draw regression. I do that cause what i want to achieve is to draw on every buffer[i] of the very last part of the regression line (where regression line ends).
I m not sure how to do that so backtest will give same results with simple chart with this indicator
you can bar shift my code easily just use the begin and end variables, i was think about making an indicator like you described let me know if it was useful
you can bar shift my code easily just use the begin and end variables, i was think about making an indicator like you described let me know if it was useful
Yes in theory my code already did this but i ll try yours and let you know. It would be usefull cause you all current regressions indicators show you the current situation and not the past
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
i ve worked on some regression code i ve found and i altered it so to create a different version of it.
Although it seems to work as part of an indincator, when i m backtesting it the results are totally different! I really cant find where the problem is. Any ideas/help?
Here is the code: