#property indicator_chart_window


//--- indicator parameters
input int   Sensitivity = 38;  
input bool  PopUp_Alert = true; 

//+------------------------------------------------------------------+
int OnInit(void)
  {
   return(INIT_SUCCEEDED);
  }
int i;
double bufBuy, bufSell;

//+------------------------------------------------------------------+
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[])
{
   i = (prev_calculated < Sensitivity) ? rates_total - Sensitivity-2 : rates_total - prev_calculated;
   if (i <= 0) return(prev_calculated);
   while(i > 0)
   {
      bufBuy   = iCustom(NULL,0,"beforexguru_orig",Sensitivity, false, false,3,i);
      bufSell  = iCustom(NULL,0,"beforexguru_orig",Sensitivity, false, false,4,i);
      if (PopUp_Alert && bufBuy  != EMPTY_VALUE) Alert("Buy  ", _Symbol, ", TF: ", _Period, ", Time: ",TimeToString(Time[i]));
      if (PopUp_Alert && bufSell != EMPTY_VALUE) Alert("Sell ", _Symbol, ", TF: ", _Period, ", Time: ",TimeToString(Time[i]));
      i--;
   }
return(rates_total);
}