Help write a linear regression - page 2

 
kvn писал (а): SO WHERE IS THE MISTAKE [...] ???????
DNA?
 
kvn:
I won't argue about LR. SO WHERE IS THE ERROR IN THE INDICATOR CODE???????
Who the hell knows. No one knows what algorithm you are trying to implement. First write an idea, then formulas, and then an explanation - this piece of code does this and that. And no one will guess.
 
once again
how LR is calculated
//Indicator is calculated using the formula:LR = at+b
//where LR - forecasted "average" closing price,
//t - point in time,(n1 variable in the indicator)Pt - closing price of the last n periods.(Close[n2])
//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}

indicator code above.

It calculates from n=1 to 100 incorrectly, then outputs n=22 and the result is correct, I think the loop is written incorrectly, but I don't know where.
 
It seems to be unsynchronised. For bar n x it takes nn, with the index for y being
n2=n+n1-1 = n+nn-1
There are plenty of regression indicators nearby, e.g. https://forum.mql4.com/ru/10446/page39, if you search for all of them, it is better to browse from the end.
 
I can only deduce a formula:
 
lna01:
It seems to be unsynchronised. For bar n x takes nn, with the index for y being
n2=n+n1-1 = n+nn-1

.And in general
there are a lot of regression indicators nearby, e.g.
https://forum.mql4.com/ru/10446/page39, if you're looking for all of them.
it's better to start at the end.


n1 is not equal to nn but varies from 1 to nn - the period of the indicator.
and n - number of bars to be recalculated (to work faster and without pulling the whole tail)

In general https://forum.mql4.com/ru/10446/page39 is not a linear regression but rather a derivative of the MA.
 
kvn:
lna01:
It seems to be unsynchronised. For bar n x takes nn, with the index for y being
n2=n+n1-1 = n+nn-1

n1 is not equal to nn but varies from 1 to nn - period of the indicator.
and n is the number of bars to be recalculated (to work faster and not to drag the whole tail)

In general https://forum.mql4.com/ru/10446/page39 is not a linear regression but rather a derivative of the MA.
Well, what the heck, let's assume the LR is deliberately shifted by a period. I propose this: replace the tricky expression
b=(1/nn)*(ssm3-a*ssm2);
replace by
b=(1.0/nn)*(ssm3-a*ssm2);
(the main mistake was here).
And if the shift is not needed, replace with
LR=a*nn+b;
to
LR=a+b;
After this, compare what is drawn by this indicator with the one by at_LR0. mq4 and try to find out why it is not a derivative of the MA and how to correctly get rid of the tail.

P.S. Not to bother with the parameters, let the indicators be placed on the hour chart and set the period of your indicator to one more.
 
(the main mistake was here).
THANK YOU so much for the tip. I would not have guessed, it's too bad it's not written in the language manual.
It turns out that wherever one of the variables is an integer, the constant must be written as a fractional number. I'll keep that in mind.
And as for DR or not, it's a private matter.
Put my indicator on the chart and pay attention to the inflection points of the line. It is always the end of the trend and not a bad exit point.
And its intersection with the MA (any) is also nice.

I would be very thankful to receive information about how to make the indicator faster, how to increase MT speed.
And may be someone knows where is the information about the speed of execution of various MT operators (for example, how many clock cycles are executed in different operators of the loop.).
 
kvn:
(the main mistake was here).
THANK YOU so much for the tip. I would not have guessed, it's too bad it's not written in the language manual.
It turns out that wherever one of the variables is an integer, the constant must be written as a fractional number. Got it.
If you're referring to casting, it's described in MQL4 and in all other programming languages.
 
kvn:
Also, I would be very grateful for any information on how to make the turntable faster, how to increase MT speed.
And if anyone knows if there is any information about execution speed of different MT statements (e.g. how many clock cycles different statements are executed).
As far as MT is concerned, it is useful for the user to try to minimise the number of indicator buffers. Operator execution speeds are usually learned independently using Print and GetTickCount operators. Although it would be welcome if someone would digest this and publish an article.
Reason: