//+------------------------------------------------------------------+ //| KVNLinearRegression.mq4 | //| Copyright © 2008, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "KVN" #property link "http://www.ktu.aknet.kg" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Blue //---- input parameters extern int nn=21; //---- buffers double LR1[]; int n,n1=1,n2; double ssm1,ssm2,ssm3,ssm4,a,b,LR; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,LR1); //---- return(0); } //+------------------------------------------------------------------+ //| ïîëüçîâàòåëüñêèé èíäèêàòîð //Èíäèêàòîð ñòðîèòñÿ ïî ôîðìóëå:LR = at+b //ãäå LR - ïðîãíîçèðóåìàÿ "ñðåäíÿÿ" öåíà çàêðûòèÿ, //t - ìîìåíò âðåìåíè,Pt - öåíû çàêðûòèÿ çà n ïîñëåäíèõ ïåðèîäîâ. //a = (n*ÑÓÌÌÀ (t*Pt) - ÑÓÌÌÀ(t)*CÓÌÌÀ(Pt))/(n*ÑÓÌÌÀ(t^2) - (ÑÓÌÌÀ(t))^2) - òàíãåíñ óãëà íàêëîíà ëèíèè ðåãðåññèè, //b = 1/n*(ÑÓÌÌÀ(Pt) - a*ÑÓÌÌÀ(t)), - ñìåùåíèå ïî ãîðèçîíòàëè} //+------------------------------------------------------------------+ int start() { n=0; while(n<100){ ssm1=0; ssm2=0; ssm3=0; ssm4=0; n1=1; while(n1<=nn) { n2=n+n1-1; ssm1=ssm1+n1*Close[n2]; ssm2=ssm2+n1; ssm3=ssm3+Close[n2]; ssm4=ssm4+n1*n1; n1++; } a=(nn*ssm1-ssm2*ssm3)/(nn*ssm4-ssm2*ssm2); b=(1.0/nn)*(ssm3-a*ssm2); LR=a*nn+b; LR1[n]=LR; n++; } //---- 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: