#property copyright "Copyright 2016, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 PaleGreen
#property indicator_color2 Yellow
#property indicator_color3 Aqua
#property indicator_color4 Red
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 1

extern int FastEMA = 5;
extern int SlowEMA = 6;
extern int RSIPeriod = 7;
extern bool Alerts = 0;
double ma_fast[];
double ma_slow[];
double arrow_up[];
double arrow_down[];

double trend[];

int a = 0;
int old = 0;
double delta_ma = 0.0;
extern double delta = 0.0;
 datetime alertshow;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  IndicatorBuffers(5);
   SetIndexStyle(0, DRAW_LINE,0 );
   SetIndexBuffer(0, ma_fast);
   SetIndexStyle(1, DRAW_LINE,0);
   SetIndexBuffer(1, ma_slow);
   SetIndexStyle(2, DRAW_ARROW, 0);
   SetIndexArrow(2, 233);
   SetIndexBuffer(2, arrow_up);
   SetIndexEmptyValue(2, 0.0);
   SetIndexStyle(3, DRAW_ARROW, 0);
   SetIndexArrow(3, 234);
   SetIndexBuffer(3, arrow_down);
   SetIndexEmptyValue(3, 0.0);

   SetIndexBuffer(4, trend);


   return (0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   return (0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars = IndicatorCounted();
   double irsi_1 = 0;
   int limit;
   bool c = FALSE;
   double price_10 = 0;
   if (counted_bars < 0) return (-1);
   if (counted_bars > 0) counted_bars--;
   if(counted_bars==0) limit = Bars-(FastEMA+SlowEMA+1);
   else                limit = Bars-counted_bars; 
   
     for (int i = limit; i >= 0; i--) 
      {
      double atr = iATR(NULL,0,25,i);
      
      ma_fast[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      ma_slow[i] = iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i);
      irsi_1 = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, i);
      delta_ma = ma_fast[i] - ma_slow[i];
       if (delta_ma > delta*Point && irsi_1 > 50.0)trend[i] = +1;// this is up condition a = 1
       if (delta_ma < delta*Point && irsi_1 < 50.0) trend[i] = -1;
      if( trend[i+1] == -1 && trend[i] == +1 )
        {
         arrow_up[i] = Low[i] - atr;// a=1 should be up_arrow 
         c= TRUE;
         price_10 = Ask;
         } 
      if( trend[i+1] == +1 && trend[i] == -1 )
           {
           arrow_down[i] = High[i] + atr;
            c = TRUE;
            price_10 = Bid;
            }

   }

//----
   return(0);
  }
//+------------------------------------------------------------------+


