//+----------------------------------------------------------------+
//|                  FX_Snipers_Ergodic_CCI_TriggerTSI Signals.mq4 |
//|                             modified by Linuxser for Forex-TSD |
//+----------------------------------------------------------------+
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Magenta
//---- input parameters

extern int pq =2;
extern int pr = 10;
extern int ps = 5;
extern int trigger =3;
extern int       ArrowShift=5;
extern bool sound_alert = false;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,217);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel(0,"UpArrow");
   SetIndexEmptyValue(0,0.0);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,218);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(1,"DownArrow");
   SetIndexEmptyValue(1,0.0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- TODO: add your code here
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit,i;
   double curErgodic=0.0,prevErgodic=0.0,curSignal=0.0,prevSignal=0.0;
   limit=Bars-counted_bars-pq-pr-ps;
   for (i=limit;i>=0;i--)
      {
      curErgodic=iCustom(NULL,0,"FX_Sniper's_Ergodic_CCI_Trigger",pq,pr,ps,trigger,sound_alert,0,i);
      prevErgodic=iCustom(NULL,0,"FX_Sniper's_Ergodic_CCI_Trigger",pq,pr,ps,trigger,sound_alert,0,i+1);
      curSignal=iCustom(NULL,0,"FX_Sniper's_Ergodic_CCI_Trigger",pq,pr,ps,trigger,sound_alert,1,i);
      prevSignal=iCustom(NULL,0,"FX_Sniper's_Ergodic_CCI_Trigger",pq,pr,ps,trigger,sound_alert,1,i+1);
      if ((curErgodic>curSignal)&&(prevErgodic<prevSignal)) ExtMapBuffer1[i]=Close[i]+3*ArrowShift*Point;
      if ((curErgodic<curSignal)&&(prevErgodic>prevSignal)) ExtMapBuffer2[i]=Close[i]-ArrowShift*Point;
      }
//---- TODO: add your code here
   
//----
   return(0);
  }
//+------------------------------------------------------------------+