//+------------------------------------------------------------------+ //| R-Squared_v1.mq5 | //| Copyright © 2006, TrendLaboratory | //| http://finance.groups.yahoo.com/group/TrendLaboratory | //| E-mail: igorad2003@yahoo.co.uk | //+------------------------------------------------------------------+ //---- author of the indicator #property copyright "Copyright © 2006, TrendLaboratory" //---- author of the indicator #property link "http://finance.groups.yahoo.com/group/TrendLaboratory" //---- indicator version number #property version "1.00" //---- drawing indicator in a separate window #property indicator_separate_window //---- two buffers are used for calculation of drawing of the indicator #property indicator_buffers 2 //---- two plots are used #property indicator_plots 2 //+----------------------------------------------+ //| R-Squared_v1 indicator drawing parameters | //+----------------------------------------------+ //---- drawing indicator 1 as a line #property indicator_type1 DRAW_LINE //---- MediumVioletRed color is used as the color of the indicator basic line #property indicator_color1 clrMediumVioletRed //---- line of the indicator 1 is a continuous curve #property indicator_style1 STYLE_SOLID //---- thickness of line of the indicator 1 is equal to 1 #property indicator_width1 1 //---- displaying the indicator line label #property indicator_label1 "R-Squared_v1" //+----------------------------------------------+ //| Signal line drawing parameter | //+----------------------------------------------+ //---- drawing the indicator 2 as a line #property indicator_type2 DRAW_LINE //---- MediumSlateBlue color is used for the indicator signal line #property indicator_color2 clrMediumSlateBlue //---- the indicator 2 line is a continuous curve #property indicator_style2 STYLE_SOLID //---- indicator 2 line width is equal to 1 #property indicator_width2 1 //---- displaying the indicator line label #property indicator_label2 "Signal" //+----------------------------------------------+ //| Parameters of displaying horizontal levels | //+----------------------------------------------+ #property indicator_level1 50.0 #property indicator_levelcolor clrLimeGreen #property indicator_levelstyle STYLE_DASHDOTDOT //+----------------------------------------------+ //| Declaration of constants | //+----------------------------------------------+ #define RESET 0 // the constant for getting the command for the indicator recalculation back to the terminal //+----------------------------------------------+ //| Indicator input parameters | //+----------------------------------------------+ input uint nLength = 12; // indicator period input uint MA_Period = 5; // moving average period input ENUM_MA_METHOD MA_Method = MODE_SMA; // moving average smoothing method input ENUM_APPLIED_PRICE MA_Price = PRICE_WEIGHTED; // price constant input uint Smooth = 14; // moving period input int Shift = 0; // Horizontal shift of the indicator in bars //+----------------------------------------------+ //---- declaration of dynamic arrays that //---- will be used as indicator buffers double IndBuffer[]; double SignalBuffer[]; //---- declaration of integer variables for the indicators handles int MA_Handle; //---- declaration of the integer variables for the start of data calculation int min_rates_,min_rates_total,Length; double SumX,SumX2; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //---- initialization of variables of the start of data calculation min_rates_=int(MathMax(MathMax(MA_Period,nLength),Smooth)); Length=int(nLength); min_rates_total=int(min_rates_+Length+Smooth); SumX=0; for(int i=0; irates_total || prev_calculated<=0) // checking for the first start of the indicator calculation { limit=rates_total-min_rates_; // starting index for the calculation of all bars } else limit=rates_total-prev_calculated; // starting index for calculation of new bars //---- to_copy=MathMin(limit+Length,rates_total); //---- copy newly appeared data into the arrays if(CopyBuffer(MA_Handle,0,0,to_copy,MA)<=0) return(RESET); //---- main loop of the indicator calculation for(bar=limit; bar>=0 && !IsStopped(); bar--) { SumY=0; for(int i=0; i