trend_v2_v1





//+------------------------------------------------------------------+
//|                                                    27sen2007.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property  indicator_buffers 1
#property  indicator_color1  Blue


extern int period =20;

double A[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
 SetIndexStyle(0,DRAW_LINE,EMPTY,2,Blue);
   SetIndexBuffer(0,A);
   SetIndexDrawBegin(0,0);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {

   int    counted_bars=IndicatorCounted();
   int   i, j, k, q, limit;
   double X[2][2], Y[2], B[2], x[2][2000], y[2000], a;
  
  limit=Bars-counted_bars;
  for(q=0; q<limit; q++)
   {
     
   ArrayInitialize(X,0);
   ArrayInitialize(Y,0);   
   ArrayInitialize(B,0);   
   ArrayInitialize(x,0);
   ArrayInitialize(y,0);  
//===========================================
for (i=0; i<=period; i++) {
x[0][i]=1;
x[1][i]=i+q;
y[i]=   Close[i+q];
}
//===========================================
  for (k=1; k<=period; k++) {
  for (j=0; j<=1; j++) {
  for (i=0; i<=1; i++) { 
   X[i][j]=x[j][k]*x[i][k]+X[i][j];   
   }
   Y[j]=y[k]*x[j][k]+Y[j];
   }}  
//===========================================  
k=0; 
 j=1; 
  a=X[k][j]/X[k][k];
  for (i=0; i<=3; i++){
  X[i][j]=X[i][j]-X[i][k]*a; 
  }
  Y[j]=Y[j]-Y[k]*a;

//==========================================  
for (k=2; k>=1; k--){
a=0;
for (i=1; i>=k; i--){
a=X[i][k-1]*B[i]+a;
}
B[k-1]=(Y[k-1]-a)/X[k-1][k-1];
}
//=========================================


   A[q]=-B[1];
   }


//}
//=========================================

   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains close prices for each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features: