Help write a linear regression - page 7

 

Agreed. Checked the error accumulates in my version too with a huge array of minutiae. So before using this algorithm too, I shift X to 0. Because of the lack of squares, the error accumulates more slowly.

Although what am I trying to convince you :). You can use any algorithm, the main thing is to find the rake and know not to step on it.

 

The easiest and very fastest method that can be implemented in MQL4 is to draw a line through two points calculated using the formula LRMA = 3*LWMA - 2*SMA.


In general, you should calculate


1. normal MA

2. Straight LWMA

3. reverse LWMA


There is no problem with the first two, i.e. to calculate the last value for the 0-th bar using iMA() is like two fingers on the pavement to get the value of the last point using the above formula.


But to calculate the value of the third one - reverse LWMA, we need to reverse the price series array and apply iMAOnArray() with MODE_LWMA value to it. Substitute this value into the above formula instead of LWMA and obtain the initial (first) point.


Connect the two points with a line segment and get a linear regression, but without correlation coefficients.


Note: the conventional MA does not need to be recalculated in the opposite direction for the starting point, as its value is independent of the direction in which it is counted.

 
Reshetov >> :

The easiest and very fastest method that can be implemented in MQL4 is to draw a line through two points calculated using the formula LRMA = 3*LWMA - 2*MA.


In general, it needs to be calculated.


1. the normal MA

2. Straight LWMA

3. reverse LWMA


There is no problem with the first two, i.e. to calculate the last value for the 0-th bar using iMA() is like two fingers on the pavement to get the value of the last point using the above formula.


But to calculate the value of the third one - reverse LWMA, reverse the price series array and apply iMAOnArray with the MODE_LWMA value to it. Substitute this value into formula above instead of LWMA and obtain the initial (first) point.


Connect the two points with a line segment and get a linear regression, but without correlation coefficients.


Note: the conventional MA does not need to be recalculated in the opposite direction for the starting point, as its value is independent of which way to count.


And with what lag are the points taken, or does it make no difference?

I take it that if you draw a straight line in the way you describe, it should coincide with the linear regression in this thread (only the calculation is faster)?

 
Urain >> :


1. what is the lag of the points, or does it make no difference?

2. I take it that if you draw the line by your method it should coincide with the linear regression in this thread (only the calculation is faster)?

1. I do not understand the humour in the first question, as the calculation is based on the number of bars, i.e. price series points

2. On the second question you got it right as there is a mathematical proof of LRMA.

 
Reshetov >> :

1. I do not understand the humour in the first question, since the calculation is performed using the number of bars, i.e. price series points

Then I didn't understand the formula at all, (about what with the subtraction from LWMA-SMA=inverse of LWMA I knew long ago)

The initial value is calculated through LWMA, the final value through inverse LWMA and I assume that lag is equal to period ???

 
Urain >> :

Then I didn't understand the formula at all, (about what with subtracting from LWMA-SMA=inverse LWMA I knew long ago)

This is the first time I've heard about it. But, if it is really so, then the value of the first point (beginning of the period) can be found by the formula: LRMA_BEGIN = 3*LWMA - 5*SMA


We have to check.

 
Reshetov >> :

This is the first time I have heard of this. If this is indeed the case, then the value of the first point (beginning of the period) can be found using the formula: LRMA = 3*LWMA - 5*SMA


>> Check it.

So LWMA has a decreasing coefficient, the inverse LWMA has an increasing coefficient and the sum of them equals SMA.

(in the sense of the arithmetic mean of (LWMA+ inverse LWMA)*0.5).

 
Urain >> :

( about what if you subtract from LWMA-SMA = inverse of LWMA )

inverse LWMA= LWMA-2*(LWMA-SMA); this is more accurate.

And above it is schematic, meaning to subtract means to put an equal segment in the opposite direction from SMA.

Simplified, the inverse of LWMA=2*SMA-LWMA;