Navigation:Home > Content >

Linear_Regression.mq4

Time: 2017-02-08 | Download file:Linear_Regression.mq4

//+------------------------------------------------------------------+
//|                                            Linear Regression.mq4 |
//|                Copyright © 2006, tageiger, aka fxid10t@yahoo.com |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, tageiger, aka fxid10t@yahoo.com"
#property link      "http://www.metaquotes.net"
#property indicator_chart_window
//----
extern int period=0;

/*default 0 means the channel will use the open time from "x" bars back on which ever time period 
the indicator is attached to.  one can change to 1,5,15,30,60...etc to "lock" the start time to a specific 
period, and then view the "locked" channels on a different time period...*/

extern int window_size=400;   // bars back regression begins


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
{
   return(0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  { 
  ObjectDelete("Regression Line");
 return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
  int start()
  {//refresh chart
  
   ObjectDelete("Regression Line");

   //linear regression calculation
   int start.bar = window_size;
   int end.bar   = 0;
   int n = start.bar - end.bar + 1;
   
   //---- calculate price values
   double value = iClose(Symbol(),period,end.bar);
   double a,b,c;
   double sumy  = value;
   double sumx  = 0.0;
   double sumxy = 0.0;
   double sumx2 = 0.0;
   
   for(int i=1; i        

Recommend