My own Stochastics in an EA

 

Hi,

 I am trying to recreate the Stochastic so that I can use the crossovers between the main and the Signal line.


This should be the formula: %K = (Current Close - Lowest Low)/(Highest High - Lowest Low) * 100

%D = 3-day SMA of %K


However the results of my code does not match the indicator provided by MQL4. can you help me understand where the error is?

This is the bulk of my indicator.


int start() {

ArraySetAsSeries(ExtMainBuffer,false);
ArraySetAsSeries(ExtSignalBuffer,false);


   
   for (int i = 0; i < Bars-1 ; i++) {
   
    stocaMax = High[iHighest(NULL,0,MODE_HIGH,5,i+1)];
     stocaMin = Low[iLowest(NULL,0,MODE_LOW,5,i+1)];
   
   
   
   ExtHighesBuffer[i]= stocaMax;
   
  ExtLowesBuffer[i]=stocaMin;
  
  
  ExtMainBuffer[i] =((Close[i]-ExtLowesBuffer[i])/(stocaMax-stocaMin))*100;
  
  
    
    
}  

   for(int l=3; l<Bars-1 && !IsStopped(); l++)
     {
      double sum=0.0;
         for( int k=0; k<InpDPeriod; k++)
            sum+=ExtMainBuffer[l-k];
         ExtSignalBuffer[l]=sum/InpDPeriod;
     }
  
 
   

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

return(0);
 }

thanks for your help.