Long time ago I wrote linear regression indicators in MQL3, started rewriting them in 4, they don't work. Specialists please help me to write or correct a mistake.
And a similar one: hyperbolic regression (can't find the error either)
//+------------------------------------------------------------------+ //| гиперболическая регрессия.mq4 | //| Copyright © 2008, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" //#property indicator_chart_window #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 Red //---- input parameters extern int nn=21; //---- buffers double ExtMapBuffer1[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ExtMapBuffer1); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); //---- double barr, as, bs,cs,ds,e, f,k,LR,ExtMapBuffer1[]; int n,n1; // Индикатор Гиперболической Регресии for (barr=0;barr<=100;barr++){ for (n=1;n<=nn;n++){ n1=barr+n-1; as=as+1/n; bs=bs+1/(n*n); cs=cs+Close[n1]; ds=ds+Close[n1]/n; } e=nn*bs-as*as; f=cs*bs-ds*as; k=nn*ds-as*cs; f=f/e; k=k/e; LR = f+k/nn; as=0; bs=0; cs=0; ds=0; ExtMapBuffer1[n]=LR; } //---- return(0); } //+------------------------------------------------------------------+
Search for https://www.mql5.com/ru/code
https://forum.mql4.com/ru/10446/page13
Thanks, interesting, but where did I mess up the indicator?
kvn:
Thanks, interesting, but where did I mess up the indicator?
That's right -messed up.
Thanks, interesting, but where did I mess up the indicator?
Rosh:
That's right -I messed up.
kvn:
Thanks, interesting, but where did I mess up the indicator?
Thanks, interesting, but where did I mess up the indicator?
That's right -I messed up.
You're literate, aren't you? Then tell me where. And thank you very much.
kvn:
Literate, eh? Then tell me where, and thank you very much.
There has been a lot of information on this topic here. I can only give you a general idea: the equation of the sum of standard deviations from the approximating curve with as many given parameters as you want. Then the partial derivatives of each parameter are found and equated to zero. From the resulting system of linear equations all necessary parameters are found. The algorithm, as you can see, is simple, and not at all creative to do it.
Rosh:
That's right -messed up.
kvn:
Thanks, interesting, but where did I mess up the indicator?
Thanks, interesting, but where did I mess up the indicator?
That's right -messed up.
Literate, eh? Then tell me where, and thank you very much.
What you say is not exactly linear regression. The LR technique is described in my indicator.
//Indicator is built using the formula:LR = at+b
//where LR - forecasted "average" price of closing,
//t - point in time,Pt - closing price of the last n periods.
//a = (n*SUMM(t*Pt) -SUMM(t)*SUMM(Pt))/(n*SUMM(t^2) - (SUMM(t))^2) - angle tangent of the regression line,
//b = 1/n*(SUMM(Pt) - a*SUMM(t)), - horizontal shift}
But when I execute it, first I get wrong data (when n=1-100,) and then n=22 and correct values come out. There is a small error somewhere and I can't find it.
I suspect the error is in the loop operator.
//Indicator is built using the formula:LR = at+b
//where LR - forecasted "average" price of closing,
//t - point in time,Pt - closing price of the last n periods.
//a = (n*SUMM(t*Pt) -SUMM(t)*SUMM(Pt))/(n*SUMM(t^2) - (SUMM(t))^2) - angle tangent of the regression line,
//b = 1/n*(SUMM(Pt) - a*SUMM(t)), - horizontal shift}
But when I execute it, first I get wrong data (when n=1-100,) and then n=22 and correct values come out. There is a small error somewhere and I can't find it.
I suspect the error is in the loop operator.
Although I don't like wikipedia, but I am providing a link to it on the subject of linear regression. I also found this on a certain blog - http://cmacfm.mazoo.net/archives/000936.html
I won't argue about LR. SO WHERE IS THE ERROR IN THE INDICATOR CODE???????
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