Linear regression channel - page 18

 
Here's a compact, fast version of parabolic and linear regression in mql4, but how to get rid of one cycle when calculating the sxxy value I haven't figured out yet.
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrDeepSkyBlue
#property indicator_color2 clrRed
#property indicator_width1 2
#property indicator_width2 2
#property indicator_type1 DRAW_LINE
#property indicator_type2 DRAW_LINE
//================================
extern int p = 2 4;
//================================
double lr[],qr[];
double lwi,mai,fxi;
double ci,cp,sy,sxy,sxxy,lri,qri;
double a1,a2;
int w,n;
//*************************************************
int init()
{
   SetIndexBuffer(0,qr);
   SetIndexBuffer(1,lr);
   //-----------------------
   if (p<3) p=3;
   
   return(0);
}
//*******************************************************************
int start()
{
   int cbi=Bars-IndicatorCounted()-1; if (cbi<0) return(-1);
   if (cbi==0) return(0); if (cbi==1) cbi=0; 
   if (cbi>1)
   { 
      cbi=Bars-p-1;
     
      sy=0; sxy=0; w=0;  
      for(int j=1; j<=p; j++) 
      {
         ci=Open[cbi+p-j];
         sy+=ci; 
         sxy+=j*ci;
         w+=j; 
      }
      cbi--;
      
      a1=6.0/(p*(p+1)*(2*p+1))*(10-15.0/(p+2)); 
      a2=12-15.0/(p+2);
   }
   //----------------------------------------
   for (int i=cbi; i>=0; i--) 
   {
      sxxy=0;
      for (int j=1; j<=p; j++)
         sxxy+=j*j*Open[i+p-j];
      
      ci=Open[i]; 
      cp=Open[i+p];
      
      sxy+=ci*p-sy;
      sy+=ci-cp;
      
      mai=sy/p;
      lwi=sxy/w;
      
      lri=3*lwi-2*mai;
      
      qri=3*mai+a1*sxxy-lwi*a2;
      
      qr[i]=qri;
      lr[i]=lri;
   }
   //----------------------------------------
   return(0);
}
//*********************************************************



 
Yousufkhodja Sultonov:

The indicator works

And where are you looking for happiness now, something from the ceiling again (like mining)?
 
ANG3110:
Here's a compact, fast version of parabolic and linear regression in mql4, but I still haven't figured out how to get rid of one cycle when calculating sxxy value.

What's the point of that?

Try applying this code to calculate the regression elsewhere, say, if you have an array of values - you'll have to go quite deep into the code's workings. And why, if it's more reasonable to do the opposite, the code may not be as efficient, but it's easy to modify.

Personally, my regression class has three virtual functions - to get the number of points and their coordinates, to apply regression - you should declare a class where you overload these functions to the required ones - and immediately get the coefficient of the regression polynomial of any degree from zero to the third. In addition, there are two optional functions - for obtaining weights and the "polar point" (i.e. the point the polynomial must necessarily pass through), but these functions can be omitted, weights will be equated to one, and the polynomial will be calculated without the polar point. It may not be as efficient (both at the expense of internal loops and virtual functions), but it is very flexible, and there is no need to figure it out.

 
Georgiy Merts:

What's the point of that?

Try applying this code to calculate the regression elsewhere, say, if you have an array of values - you'll have to go quite deep into the code's workings. And why, when it's more reasonable to do the opposite, let the code be not so effective, but easily modifiable.

Personally, my regression class has three virtual functions - number of points and their coordinates - to apply regression - I declare a class where these functions must be overloaded and we immediately get the regression polynomial coefficient of any degree from zero to the third. In addition, there are two optional functions - for obtaining weights and the "polar point" (i.e. the point the polynomial must necessarily pass through), but these functions can be omitted, weights will be equated to one, and the polynomial will be calculated without the polar point. It may not be as efficient (both at the expense of internal loops and virtual functions), but it is very flexible, and there is no need to figure it out.

These fast variants, for specific purposes, exactly those where speed is needed, when testing and the position of the end of the regression. If you need coefficients and different degree of polynomial, then I apply this variant.Here array of coefficients in the code - X[]. That is, there is exhaustive information for drawing curves of any depth. If we're talking about the expediency of something, it probably depends on who needs it. I don't use it in trade, only for specific research purposes so far.
#property strict
//********************************************************************
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 clrMediumSlateBlue
#property indicator_width1 2
#property indicator_type1 DRAW_LINE
//================================
extern int p = 120;
extern int m = 2;
//================================
double fx[];
double a[],b[],sx[],x[];
double ci,sum;
int N;
//********************************************************************
int init()
{
   SetIndexBuffer(0,fx);
   //------------------------------------------------
   N=m+1;
  
   if (p<N+2) p=N+2;
  
   ArrayResize(sx,2*N);
   ArrayResize(a,N*N);
   ArrayResize(b,N);
   ArrayResize(x,N);
  
   return(0);
}
//********************************************************************
int start()
{
   int cbi=Bars-IndicatorCounted()-1; if (cbi<0) return(-1);
   if (cbi==0) return(0);
  
   //--------sx-------
   sx[0]=p;
   for(int n=1; n<N*2; n++)
   {
      sum=0;
      for(int j=0; j<p; j++)
         sum+=MathPow(j,n);
      sx[n]=sum;
   } 
   //-------syx--------
   for(int n=0; n<N; n++)
   {
      sum=0;
      for(int j=0; j<p; j++)
      {
         ci=Open[j];
         if (n==0) sum+=ci; else
         sum+=ci*MathPow(j,n);
      }
      b[n]=sum;
   }
   //------Matrix------
   for(int j=0; j<N; j++)
   for(int n=0; n<N; n++)
      a[n+j*N]=sx[n+j];
   //------Gauss-------
   af_Gauss(N,a,b,x);
   //------------------
   for (int j=0; j<p; j++)
   {
      sum=x[0];
      for(int n=1; n<N; n++)
         sum+=x[n]*MathPow(j,n);
        
      fx[j]=sum;
   }
  
   SetIndexDrawBegin(0,Bars-p);
  
   return(0);
}
//***************************************************************
void af_Gauss(int M, double& A[],double& B[], double& X[])
{
   double r,s;
   for(int k=0; k<M-1; k++)
   for(int i=k+1; i<M; i++)
   {
      r=0; if (A[k+k*M]!=0) r=A[k+i*M]/A[k+k*M];
      for(int j=k; j<M; j++)
         A[j+i*M]-=A[j+k*M]*r;
      B[i]-= B[k]*r;
   }
   if (A[M-1+(M-1)*M]!=0) X[M-1]=B[M-1]/A[M-1+(M-1)*M]; else X[M-1]=0;

   for(int i=M-2; i>=0; i--)
   {
      s=0;
      for(int j=i+1; j<M; j++)
         s+=A[j+i*M]*X[j];
      if (A[i+i*M]!=0) X[i]=(B[i]-s)/A[i+i*M]; else X[i]=0;
   }
}
//***************************************************************
 
I am ready to refute the ingrained opinion that polynomials of any degree are lucky and irreplaceable. On real examples of participants I will prove, that polynomials lose by almost all indicators of URM regression (above gave the link), to forget forever about unsinkability of polynomials.
 
Yousufkhodja Sultonov:
I am ready to refute the ingrained opinion that polynomials of any degree are vital and irreplaceable. On real examples of participants I will prove that polynomials lose by almost all indicators of URM regression (above I gave a link) to forget about unsinkability of polynomials forever.

No need, you proved it a long time ago, we believe it.

 
TheXpert:

In return for what? I don't give a shit about him, as long as he doesn't start running around in technical threads, especially regarding pros, talking nonsense and trolling members, mentioning "the club" and other nonsense.

It's just that in this thread his trolling was beautifully translated into self-banning, which I thanked him for.

How can you get past something like that?Here's another one in the club- 11 pages full of crap, shitting with each other, but no one has enough guts to write a normal test - to check and argue their position. And better to just join forces and figure it out at least for themselves. It's called super technical experts on the pros... I can imagine what they write on their pluses.

There is one more club here - the OOP Victims Club with new concepts - it turns out that if inheritance is not used, it is not OOP any more, so there is that rubbish. And they too lack the courage to write a test and check when it is faster - when it is polymorphism and when it is piggyback etc. ...and all the same faces we know from the club of victims of C++.

 
Vladimir Baskakov:
And where do you look for happiness now, again something from the ceiling (like mining)?

There are no recipes for "happiness" anywhere, it is useless to look for it. I am content with what has been achieved. I am proud of the fact that I managed to develop the SDMhttps://www.mql5.com/ru/articles/250 and the "Market Theory" https://www.mql5.com/ru/articles/1825, but, they will be understood in 100 years or more. I said earlier thathttps://www.mql5.com/ru/forum/318795/page17#comment_13020163 indicator is persistently waiting for its time and it has come:


Канал линейной регрессии
Канал линейной регрессии
  • 2019.08.29
  • www.mql5.com
Есть индикатор линейной регрессии. Как встроить его расчет в советник и получить данные на 0 баре или на 1...
 
Yousufkhodja Sultonov:

Nowhere is there a recipe for "happiness

Pity your students, Semko proved this idea untenable a long time ago
 
Dmitry Fedoseev:

If you can find a solution without recursion, it is better than with recursion.

It's OK.
Reason: