Standard Deviation calculation from SMA

 

plz help with this code

 

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_buffers 1
#property indicator_color1 Blue
//---- input parameters
extern int ExtStdDevPeriod=7;
extern int ExtStdDevMAMethod=0;
extern int ExtStdDevAppliedPrice=0;
extern int ExtStdDevShift=0;
extern int Period_ADX = 1;         // Calculated MA period
extern int Period_MA = 2;          // Calculated MA period
//---- buffers
double ExtStdDevBuffer[];
double ADX[];                       // Wert Steigung
double SMA[]; 
double SMA1[];
double SMA2[];                      // SMA
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string sShortName;
     ArraySetAsSeries(SMA,true);
   ArraySetAsSeries(SMA1,true);
   ArraySetAsSeries(SMA2,true);
   
//---- indicator buffer mapping
   SetIndexBuffer(0,ExtStdDevBuffer);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
//---- line shifts when drawing
   SetIndexShift(0,ExtStdDevShift);   
//---- name for DataWindow and indicator subwindow label
   sShortName="StdDev("+ExtStdDevPeriod+")";
   IndicatorShortName(sShortName);
   SetIndexLabel(0,sShortName);
//---- first values aren't drawn
   SetIndexDrawBegin(0,ExtStdDevPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Standard Deviation                                               |
//+------------------------------------------------------------------+
int start()
  {
  
  ///
     ///
     
     int counted_bars;                // Number of counted bars 
   int i; 
        i=Bars-counted_bars-1;           // Index of the first uncounted
   while(i>=0)                      // Loop for uncounted bars
      {
      ADX[i]=((High[1]+Low[1])/2)+(Open[1]-Close[1]); // Value of 0 buffer on i bar
      i--;                          // Calculating index of the next bar
      }
   i=Bars-counted_bars-1; 
   while(i>=0)                      // Loop for uncounted bars
      {
      SMA[i]=iMAOnArray(ADX,0,2,0,MODE_SMA,i);    // Value of 1st buffer on i bar
      i--;                          // Calculating index of the next bar
      }
         i=Bars-counted_bars-1; 
   while(i>=0)                      // Loop for uncounted bars
      {
      SMA1[i]=iMAOnArray(SMA,0,2,0,MODE_SMA,i);    // Value of 1st buffer on i bar
      i--;                          // Calculating index of the next bar
      }
         while(i>=0)                      // Loop for uncounted bars
      {
      SMA2[i]=iMAOnArray(SMA1,0,2,0,MODE_SMA,i);    // Value of 1st buffer on i bar
      i--;                          // Calculating index of the next bar
      }
  
      
      ////
  ///
   int    j,nCountedBars;
   double dAmount,dMovingAverage[];  

      ///
      
      //---- insufficient data
   if(Bars<=ExtStdDevPeriod) return(0);
//---- bars count that does not changed after last indicator launch.
   nCountedBars=IndicatorCounted();
//----Standard Deviation calculation
   i=Bars-ExtStdDevPeriod-1;
   if(nCountedBars>ExtStdDevPeriod) 
      i=Bars-nCountedBars;  
      
   while(i>=0)
     {
      dAmount=0.0;
      dMovingAverage[i]=SMA2[i];
      for(j=0; j<ExtStdDevPeriod; j++)
        {
         
         dAmount+=(Close[0]-dMovingAverage[i])*(Close[0]-dMovingAverage[i]);
        }
      ExtStdDevBuffer[i]=MathSqrt(dAmount/ExtStdDevPeriod);
      i--;
     }
//----
   return(0);
  }

 

i need to  Standard Deviation calculation from SMA2[i]=iMAOnArray(SMA1,0,2,0,MODE_SMA,i)

 

plz help thank you  

Reason: