//+------------------------------------------------------------------+
//|                                             LinearRegression.mq5 |
//|                                                       Joy D Moyo |
//|                                               www.latvianfts.com |
//+------------------------------------------------------------------+
#property copyright "Joy D Moyo"
#property link      "www.latvianfts.com"
#property version   "1.00"
#property description "Linear Regression Indicator"
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_plots   5
#property indicator_type1   DRAW_LINE
#property indicator_type2   DRAW_LINE
#property indicator_type3   DRAW_LINE
#property indicator_type4   DRAW_LINE
#property indicator_type5   DRAW_LINE
#property indicator_style1  STYLE_DASHDOTDOT
#property indicator_style2  STYLE_DASHDOTDOT
#property indicator_style3  STYLE_DASHDOTDOT
#property indicator_style4  STYLE_DASHDOTDOT
#property indicator_style5  STYLE_DASHDOTDOT
#property indicator_color1  clrAqua
#property indicator_color2  clrPeachPuff
#property indicator_color3  clrPeachPuff
#property indicator_color4  clrMagenta
#property indicator_color5  clrMagenta
#property indicator_applied_price PRICE_CLOSE

input int RegressionPeriod = 1000;

int UsedPeriod,RegressionCount;
double RegressionLine[],OverBoughtLine[],OverSoldLine[],UpperExtremeLine[],LowerExtremeLine[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   if(RegressionPeriod<2)
      UsedPeriod = 2;
   else
      if(RegressionPeriod>=Bars(_Symbol,PERIOD_CURRENT))
         UsedPeriod = Bars(_Symbol,PERIOD_CURRENT)-1;
      else
         UsedPeriod = RegressionPeriod;

   SetIndexBuffer(0,RegressionLine,INDICATOR_DATA);
   SetIndexBuffer(1,OverBoughtLine,INDICATOR_DATA);
   SetIndexBuffer(2,OverSoldLine,INDICATOR_DATA);
   SetIndexBuffer(3,UpperExtremeLine,INDICATOR_DATA);
   SetIndexBuffer(4,LowerExtremeLine,INDICATOR_DATA);

   PlotIndexSetString(0,PLOT_LABEL,"Regression Line("+string(UsedPeriod)+")");
   PlotIndexSetString(1,PLOT_LABEL,"OverBought Line("+string(UsedPeriod)+")");
   PlotIndexSetString(2,PLOT_LABEL,"OverSold Line("+string(UsedPeriod)+")");
   PlotIndexSetString(3,PLOT_LABEL,"UpperExtreme Line("+string(UsedPeriod)+")");
   PlotIndexSetString(4,PLOT_LABEL,"LowerExreme Line("+string(UsedPeriod)+")");

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
  {
   double SumX,SumY,SumXY,SumX2,a,b,SumSR,STDResiduals;
   int X;

   if(rates_total<UsedPeriod+1)
      return 0;

   if(RegressionCount!=rates_total)
     {
      PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,rates_total-UsedPeriod-1);
      PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,rates_total-UsedPeriod-1);
      PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,rates_total-UsedPeriod-1);
      PlotIndexSetInteger(3,PLOT_DRAW_BEGIN,rates_total-UsedPeriod-1);
      PlotIndexSetInteger(4,PLOT_DRAW_BEGIN,rates_total-UsedPeriod-1);

      SumSR =0.0;
      STDResiduals =0.0;
      SumX=0.0;
      SumY=0.0;
      SumXY=0.0;
      SumX2=0.0;
      X=0;

      for(int i=rates_total-1-UsedPeriod;i<rates_total-1;i++)
        {
         SumX+=X;
         SumY+=price[i];
         SumXY+=X*price[i];
         SumX2+=MathPow(X,2);
         X++;
        }

      a = (SumX*SumY-UsedPeriod*SumXY)/(MathPow(SumX,2)-UsedPeriod*SumX2);
      b = (SumY-a*SumX)/UsedPeriod;

      X=0;
      for(int i=rates_total-1-UsedPeriod;i<rates_total;i++)
        {
         RegressionLine[i]=b+a*X;
         SumSR += MathPow(price[i]-RegressionLine[i],2);
         X++;
        }

      STDResiduals = NormalizeDouble(MathSqrt(SumSR/(UsedPeriod+1))/MathCos(MathArctan(a*M_PI/180)*M_PI/180),_Digits);

      for(int i=rates_total-1-UsedPeriod;i<rates_total;i++)
        {
         OverBoughtLine[i] = RegressionLine[i]+STDResiduals;
         OverSoldLine[i] = RegressionLine[i]-STDResiduals;
         UpperExtremeLine[i]=RegressionLine[i]+2*STDResiduals;
         LowerExtremeLine[i]=RegressionLine[i]-2*STDResiduals;
        }
      RegressionCount=rates_total;
     }

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



quero que o codigo sempre abra ordens de apenas 0.01 nada de aumentar o lote mesmo caso tenha maior probabilidade de asserto  da analise!
altere isso e me entregue o codigo completo