a trading strategy based on Elliott Wave Theory - page 34

 
I have derived a system of equations to find the coefficients of a parabola using the method of least squares. Who remembers the ruler? Or do I have to go into the determinants myself... <br / translate="no">

Here is an algorithm for solving a system of linear equations and implementation in the form of polynomial regression.
If m=1, it's a line,
at m=2 it's a parabola,
if m=3, there's a cube, and so on.
//--------------------------------
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 LightSkyBlue
//-----------------------------------
extern double hours = 24;
extern int m = 2;
extern int i0 = 0;
//-----------------------
double fx[];
double a[10,10],b[10],x[10],sx[20];
double sum; 
int p;
int nn;
//*******************************************
int init() 
{
   IndicatorShortName("at_PR (Din)");
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,fx);
   p=hours*60/Period(); 
   nn=m+1; 
   return(0);
}
//**********************************************************
int start()
{ 
  int i,n,k;
  sx[1]=p+1;
  SetIndexDrawBegin(0,Bars-p+i0);
  //----------------------sx---------------------
  for(i=1; i<=nn*2-2; i++) 
  {
    sum=0.0; 
    for(n=i0; n<=i0+p; n++) {sum+=MathPow(n,i);} 
    sx[i+1]=sum;
  }  
  //----------------------syx--------------------
  for(i=1; i<=nn; i++) 
  {
    sum=0.0; 
    for(n=i0; n<=i0+p; n++) 
    {
      if (i==1) sum+=Close[n]; 
      else 
      sum+=Close[n]*MathPow(n,i-1);
    } 
    b[i]=sum;
  } 
  //===============Matrix========================
  for(int j=1; j<=nn; j++) 
  {
    for(i=1; i<=nn; i++) 
    {
      k=i+j-1; 
      a[i,j]=sx[k];
    }
  }  
  //===============Gauss=========================
  af_Gauss(nn,a,b,x);
  //=============================================
  for (i=i0; i<=i0+p; i++) 
  {
    sum=0; 
    for(k=1; k<=m; k++) sum+=x[k+1]*MathPow(i,k); 
    fx[i]=x[1]+sum;
  } 
  //-------------------------------------------------------------
  return(0);
}
//*************************************************************** 
void af_Gauss(int n, double& a[][],double& b[], double& x[])
{
  int i,j,k,l;
  double q,m,t;

  for(k=1; k<=n-1; k++) 
  {
    l=0; 
    m=0; 
    for(i=k; i<=n; i++) 
    {
      if (MathAbs(a[i,k])>m) {m=MathAbs(a[i,k]); l=i;}
    } 
    if (l==0) return(0);   

    if (l!=k) 
    {
      for(j=1; j<=n; j++) 
      {
        t=a[k,j]; 
        a[k,j]=a[l,j]; 
        a[l,j]=t;
      } 
      t=b[k]; 
      b[k]=b[l]; 
      b[l]=t;
    }  

    for(i=k+1;i<=n;i++) 
    {
      q=a[i,k]/a[k,k]; 
      for(j=1;j<=n;j++) 
      {
        if (j==k) a[i,j]=0; 
        else 
        a[i,j]=a[i,j]-q*a[k,j];
      } 
      b[i]=b[i]-q*b[k];
    }
  }  
  
  x[n]=b[n]/a[n,n]; 
  
  for(i=n-1;i>=1;i--) 
  {
    t=0; 
    for(j=1;j<=n-i;j++) 
    {
      t=t+a[i,i+j]*x[i+j]; 
      x[i]=(1/a[i,i])*(b[i]-t);
    }
  }
  return;
}
//********************************************************************** 


Based on that, you can build both RMS and probability levels and optimise length and extrapolation.
Although with reliable extrapolation it's not all clear to me yet, can someone enlighten me?
If someone paid attention to it? Or maybe I bring it all up for nothing?

 
I have derived a system of equations to find the coefficients of a parabola using the method of least squares. Who remembers the ruler? Or do I have to go into the determinants myself...

Rosh, why is everything so complicated? How are you going to find coefficients if you don't know beforehand that this particular sample contains what you need? In fact you can make everything simpler! Vladislav said at the very beginning that approximation errors show the order of approximation. And I've already written about it. I can repeat it once again. If we have an equation of the following form: y=ax^2+bx+c, then by approximating the sample with the linear regression channel y1=b1X+c1 you actually obtain the coefficient b1 equal to the coefficient b of the initial equation. Then subtracting the linear regression equation from the first equation we get an equation of the form y=ax^2+c2. That is, you can tell from this equation that the top of the parabola will be shifted by c2 against the x-axis. Also take into account the fact that the vertex of the parabola will be in the middle of the sample. If we take the vertex of the parabola at (0,c2), that is the origin of the sample at the vertex of the parabola we will deal with the equation (y-c2)=ax^2. But of course we don't know the 2x parameters a and c2 in this equation. But we do know how they depend on each other c2=y-ax^2. We also know the points of intersection of the parabola with the x-axis. So we have three points on the x-axis - the vertex and the intersection with the x-axis, by which we need to find the desired parabola. Here I see no other way to solve the problem than to find by successive approximation such a and consequently such a parameter c2 , at which the RMS error of approximation by a parabola will be minimal. And then by the known c2 we can also get the parameter c from the very first equation, due to which we have the full equation of the quadratic function. I think this is what takes most of Vladislava's computational time, since everything else can take a less significant part in terms of computational time.
 
Yuri, you are absolutely annoyed for nothing. I really didn't understand your question. I'll answer as you asked: for the problem you are solving - that's the right assessment to be made there.

Good luck and good trends.
 
Vladislav, on the picture you presented, you can see that in the MMLevls_VG indicator MMPeriod parameter is 240. Is it so? You're saying that everything leads to a daily chart. Maybe something I do not understand?
 
Вывел систему уравнений для нахождения коэ-тов параболы по методу наименьших квадратов. Кто помнит линейку? Или самому придется лезть в детерминанты...

Rosh, why is everything so complicated? How are you going to look for coefficients if you don't know in advance that this particular sample has what you need? In fact, you can make everything simpler! Vladislav said at the very beginning that approximation errors show the order of approximation. And I've already written about it. I can repeat it once again. If we have an equation of the following form: y=ax^2+bx+c, then by approximating the sample with the linear regression channel y1=b1X+c1 you actually obtain the coefficient b1 equal to the coefficient b of the initial equation. Then subtracting the linear regression equation from the first equation we get an equation of the form y=ax^2+c2. That is, you can tell from this equation that the top of the parabola will be shifted by c2 against the x-axis. Also take into account the fact that the vertex of the parabola will be in the middle of the sample. If we take the vertex of the parabola at (0,c2), that is the origin of the sample at the vertex of the parabola, we will deal with the equation (y-c2)=ax^2. But of course we don't know the 2x parameters a and c2 in this equation. But we do know how they depend on each other c2=y-ax^2. We also know the points of intersection of the parabola with the x-axis. So we have three points on the x-axis - the vertex and the intersection with the x-axis, by which we need to find the desired parabola. Here I see no other way to solve the problem than to find by successive approximation such a and consequently such a parameter c2 , at which the RMS error of approximation by a parabola will be minimal. And then by the known c2 we can also get the parameter c from the very first equation, due to which we have the full equation of the quadratic function. I think this is what takes most of Vladislava's computational time, since everything else can take less of a computational time.


I don't understand - what are the problems. The parabola equation is sought from the same considerations as the linear regression channel - via MNC. The solution to this system of equations is unambiguous, and it does not require iterations, it is solved head-on.
Zi=Deti/Det , where Zi is the coefficients of the parabola, Det is the matrix determinant, Deti is the matrix determinant obtained by substituting the column of free terms (Ti) into the i column. Similarly, we can apply the same criteria to the resulting curvilinear channel (described unambiguously in the future) - the RMS of the entire sample in the parabola channel is no greater than the RMS of 2/3 of the sample. I'll keep silent about Hurst for now, because I don't have an answer, but I'm about to get around to it :)

HZ I found a 1986 maths reference book, so I'm very clever :)
(Kolmogorov or Demidovich would have been better).
 
I answer as asked: for the kind of problem statement that is being solved - that's the right assessment there.


Thank you, I understand. I don't agree with it, though, and I stand by my opinion.
 
I found a 1986 maths reference book, so I'm getting a lot smarter :)

It's VERY good that there is a simple solution that doesn't require iterations. I'm just a bit rusty on linal too :o(. I'll have to have a look at some books too. Rosh, if you've already worked it out definitively, I think all those interested would also be interested to read the full solution you've already sketched out above. And maybe you can even make it a separate article on Alpari?
 
I started to take pictures from the book, and then I gave up - the quality was not good. Found it through Yandex http://www.exponenta.ru/educat/class/courses/la/theme3/theory.asp#4

And here's a kind of course - http://www.exponenta.ru/educat/class/courses/student/la/examples.asp
 
Вывел систему уравнений для нахождения коэ-тов параболы по методу наименьших квадратов. Кто помнит линейку? Или самому придется лезть в детерминанты...

Here is the algorithm for solving a system of linear equations and the implementation in polynomial regression form.
If m=1 - a line,
at m=2 it's a parabola,
If m=3 - a cube, etc.


Yes, this is exactly what solandr wanted. However, there was a question - to write such a bit tricky code so quickly using my formulas - you need to be a specialist. But I've looked through the code and I've got my own algorithm, at least indexing of matrix terms mirrors my system of equations. Now I see, that ANG3110 has eaten a dog on such things (a branch on a spider I remember) :)
 
Now I see that ANG3110 has eaten the dog on this sort of thing (branch on spider I remember) :)

Indeed, I fully support it!!!
Very nice and a Necessary indicator!
ANG3110, could you explain the code? It's hard to make it out right off the bat. Maybe you have your own blog on the forum, where everything is written about this indicator in detail? Thanks in advance for the information.
Reason: