//+------------------------------------------------------------------+
//|                                                    IshiCross.mq4 |
//|                                              Copyright 2018, AM2 |
//|                                      http://www.forexsyatems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, AM2"
#property link      "http://www.forexsyatems.biz"
#property version   "1.00"
#property strict
#property indicator_chart_window

#property indicator_buffers 2
#property indicator_color1 Lime        // up arrow
#property indicator_color2 Red         // dn arrow

input int count=1000;
input int upcode=233;
input int dncode=234;
input int shift=1;
input int Tenkan=9;   // Tenkan-sen
input int Kijun=26;   // Kijun-sen
input int Senkou=52;  // Senkou Span B


//--- buffers
double up[];
double dn[];

datetime t=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexBuffer(0,up);
   SetIndexArrow(0,upcode);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1,dn);
   SetIndexArrow(1,dncode);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---
   double a=0,b=0;

   for(int i=0;i<count;i++)
     {
      a=iIchimoku(NULL,0,Tenkan,Kijun,Senkou,3,i);
      b=iIchimoku(NULL,0,Tenkan,Kijun,Senkou,4,i);

      if((a>b && open[i]<a && close[i]>a) || (b>a && open[i]<b && close[i]>b))
        {
         up[i]=low[i]; //cross up zone
        }
      if((a<b && open[i]>a && close[i]<a) || (b<a && open[i]>b && close[i]<b))
        {
         dn[i]=high[i];//cross dn zone
        }
     }

   if(t!=time[0])
     {
      a=iIchimoku(NULL,0,Tenkan,Kijun,Senkou,3,shift);
      b=iIchimoku(NULL,0,Tenkan,Kijun,Senkou,4,shift);

      if((a>b && open[shift]<a && close[shift]>a) || (b>a && open[shift]<b && close[shift]>b))
        {
         Alert(_Symbol+" Cross up zone!!!");
         SendMail(_Symbol,"Cross up zone!!!");
        }
      if((a<b && open[shift]>a && close[shift]<a) || (b<a && open[shift]>b && close[shift]<b))
        {
         Alert(_Symbol+" Cross up zone!!!");
         SendMail(_Symbol,"Cross dn zone!!!");
        }
      t=time[0];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
