Help code this line: Close[i] > ‘x’ number of bars please - page 2

 
lippmaje:

Ok, thank you very much sir, will this code and update you

 

Use limit to copy only the minimal required indicator buffer part:

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   ArraySetAsSeries(open, true); ArraySetAsSeries(close, true);
   ArraySetAsSeries(high, true); ArraySetAsSeries(low, true);

   int limit = rates_total-prev_calculated;
   if (prev_calculated==0) limit = rates_total-1;
 
   CopyBuffer(MA_HIGH_handle,0,0,limit+1,MA_HIGH);
   CopyBuffer(MA_TP_handle,  0,0,limit+1,MA_TP);
   CopyBuffer(MA_LOW_handle, 0,0,limit+1,MA_LOW);

   for (int i = limit; i >= 0; i--)
     {
      int index=ArrayMaximum(high,i,11);
      double highestHigh=high[index]; // highest high of the 11 bars at i

      index=ArrayMinimum(low,i,11);
      double lowestLow=low[index];

      index=ArrayMinimum(close,i,11);
      double lowestClose=close[index];

      up[i] = EMPTY_VALUE; dn[i] = EMPTY_VALUE;
      ...
    }
  return rates_total;
}
Reason: