Trend Linear Regression - TrendLR

Technical Forex Market Indicator

Metatrader Indicator
Trend LR
Metatrader Indicator
Trend LR
Metatrader Indicator
Trend LR
Metatrader Indicator
Trend LR





Trend Linear Regression - TrendLR author of this indicator is Sergej Solujanov in 2008. Trend Linear Regression - TrendLR is very interesting indicator suitable to determine the entry and exit from the market, thus buying and selling and also determines the long-term trend. Indicator uses the principle of linear regression. Linear regression attempts to model the relationship between two variables by fitting a linear equation to observed data. One variable is considered to be an explanatory variable, and the other is considered to be a dependent variable. In linear regression, data are modelled using linear predictor functions, and unknown model parameters are estimated from the data.

Trend Linear Regression - TrendLR MQ4 Code Base (Copy Code)
//-------------------------------------------------------------------
//                                                TrendLinearReg.mq4
//                                 Copyright © 2008 Sergej Solujanov 
//--------------------------------------------------------------------
#property copyright "Copyright © 2008 Sergej Solujanov"
#property link      "irasol@bk.ru"
#property indicator_separate_window

#property indicator_buffers 2
#property indicator_color1 LimeGreen
#property indicator_color2 Red

extern int barsToCount=34;    // Ďĺđčîä 
extern int CountBars = 500;   // Ęîëč÷ĺńňâî áŕđîâ äë˙ ďđîđčńîâęč 

double     buffer0[];
double     buffer1[];
//--------------------------------------------------------------------
int init()
{
   IndicatorShortName(StringConcatenate("TrendLR (",barsToCount,")"));
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,buffer0);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,buffer1);
   return(0);
}

//--------------------------------------------------------------------
int deinit()
{  
   return(0);
}

//--------------------------------------------------------------------
int start()
{
// 
int     counted_bars = IndicatorCounted(); 
double  a, b, c, sumy, sumx, sumxy, sumx2;
double  prev; 
double  current; 
if(Bars <= CountBars + barsToCount+1) return(0);
int   limit=Bars-counted_bars-1;
if (limit>CountBars) limit=CountBars;

for(int shift = limit; shift >= 0; shift--) 
  {
   sumy=0.0; sumx=0.0; sumxy=0.0; sumx2=0.0;

   for(int i=0; i<barsToCount; i++)
   {
      sumy+=Close[i+shift];
      sumxy+=Close[i+shift]*i;
      sumx+=i;
      sumx2+=i*i;
   }
   
   c=sumx2*barsToCount-sumx*sumx;
 if (c==0) c=0.1;
   b=(sumxy*barsToCount-sumx*sumy)/c;
//   a=(sumy-sumx*b)/barsToCount;
   current=-1000*b; 
   prev=current;

   if ((buffer0[shift+1] !=EMPTY_VALUE) || (buffer1[shift+1] !=EMPTY_VALUE))  
      if (buffer1[shift+1] !=EMPTY_VALUE) prev=buffer1[shift+1]; 
       else prev=buffer0[shift+1];
 
   if (current>=prev)  
       {
        buffer0[shift]= current; 
        buffer1[shift]= EMPTY_VALUE;
       }
   else
   if(current<prev)  
      {
       buffer1[shift]= current; 
       buffer0[shift]= EMPTY_VALUE;     
      }
   }
   return(0);
}