//+------------------------------------------------------------------+
//|                                                       EoLife.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers   4
#property indicator_color1    Blue
#property indicator_color2    Red

#property indicator_color3    Red
#property indicator_color4    Blue

#define	LONG         1
#define	SHORT        -1
#define	FLAT         0

extern int     CCI_period           =  40;
extern int     CCI_applied_price    =  5;
extern int     WPR_period           =  14;

extern int     ArrowDistance        =  50;
extern int     UpArrowCode          =  233;
extern int     UpArrowSize          =  0;
extern color   UpArrowColor         =  Blue;

extern int     DnArrowCode          =  234;
extern int     DnArrowSize          =  0;
extern color   DnArrowColor         =  Red;
//---- buffers
double UpBuf[];         //buffer 0
double DownBuf[];       //buffer 1

double HighSwingBuf[];  //buffer 2
double LowSwingBuf[];   //buffer 3

int   GuppyHistTrend;
int   lsh,lsl;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle     (0, DRAW_ARROW,EMPTY, UpArrowSize,UpArrowColor);
   SetIndexArrow     (0, UpArrowCode);
   SetIndexBuffer    (0, UpBuf);
   
   SetIndexStyle     (1, DRAW_ARROW,EMPTY, DnArrowSize,DnArrowColor);
   SetIndexArrow     (1, DnArrowCode);
   SetIndexBuffer    (1, DownBuf);
   
   SetIndexBuffer    (2, HighSwingBuf);
   SetIndexStyle     (2, DRAW_ARROW, EMPTY,2,Red);
   SetIndexArrow     (2, 159);
   
   SetIndexBuffer    (3, LowSwingBuf);
   SetIndexStyle     (3, DRAW_ARROW, EMPTY,2,Blue);
   SetIndexArrow     (3, 159);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int      counted_bars=IndicatorCounted();
   int      GuppyHist;
   double   HAO,HAC;
   bool     HA_UP,AO_UP;
   double   up,dn,slope,GuppyW,GuppyEdge,AO,AOp,AOpp, ATR_UP,ATR_DN,ATR_MID,Gann,Gannp,Gannpp,PSar;
//----
   
   if       (counted_bars>0) counted_bars--;
   int      limit=Bars-counted_bars;
   
   for      (int i=0;i<limit;i++)
   {

   double CCI  =  iCCI(NULL,0,CCI_period,CCI_applied_price,i);
   double CCI2 =  iCCI(NULL,0,CCI_period,CCI_applied_price,i+1);

   double ST1  =  iStochastic(NULL,0,5,3,2,MODE_SMA,0,MODE_MAIN,i);
   double ST2  =  iStochastic(NULL,0,5,3,2,MODE_SMA,0,MODE_MAIN,i+1);
   double ST3  =  iStochastic(NULL,0,5,3,2,MODE_SMA,0,MODE_MAIN,i+2);
   double ST4  =  iStochastic(NULL,0,5,3,2,MODE_SMA,0,MODE_MAIN,i+3);

   double WPR1 =  iWPR(NULL,0,WPR_period,i);
   double WPR2 =  iWPR(NULL,0,WPR_period,i+1);


   /* HAO=iCustom(NULL,0,"Heiken Ashi",2,i);
      HAC=iCustom(NULL,0,"Heiken Ashi",3,i);
      Print(HAO);

      ATR_UP=iCustom(NULL,0,"ATR_Channel",0,i);
      ATR_DN=iCustom(NULL,0,"ATR_Channel",1,i);
      ATR_MID=iCustom(NULL,0,"ATR_Channel",2,i);

      AO=iMACD(NULL,0,5,34,5,PRICE_CLOSE,MODE_MAIN,i);
      AOp=iMACD(NULL,0,5,34,5,PRICE_CLOSE,MODE_MAIN,i+1);
      AOpp=iMACD(NULL,0,5,34,5,PRICE_CLOSE,MODE_MAIN,i+2);

      Gann=iCustom(NULL,0,"###Gann_HiLo_Activator_v2###",10,0,i);
      Gannp=iCustom(NULL,0,"###Gann_HiLo_Activator_v2###",10,0,i+1);
      Gannpp=iCustom(NULL,0,"###Gann_HiLo_Activator_v2###",10,0,i+2);
      PSar=iSAR(NULL,0,0.02,0.2,i);

      if (AO>AOp){AO_UP=true;} else AO_UP=false; */

   // Setting down arrow signal----------------------------   

   if ((CCI<0 && WPR2>-82 && WPR1<-82 && Close[i]<Open[i]))
      {
         DownBuf[i]        =  High[i] +Point*ArrowDistance; 
         UpBuf[i]          =  EMPTY_VALUE;
         lsh               =  LastSwingHigh(i);
         HighSwingBuf[i]   =  High[lsh];
      } 
   else 
      {
         DownBuf[i]        =  EMPTY_VALUE;
         lsh               =  LastSwingHigh(i);
         //HighSwingBuf[i] =  EMPTY_VALUE;
      }
      
   // Setting up arrow signal------------------------------
   if ((CCI>0 && WPR2<-18 && WPR1>-18 && Close[i]>Open[i]))
      {
         UpBuf[i]          =  Low[i] -Point*ArrowDistance; 
         DownBuf[i]        =  EMPTY_VALUE;
         lsl               =  LastSwingLow(i);
         LowSwingBuf[i]    =  Low[lsl];
      } 
   else
      {
         UpBuf[i]          =  EMPTY_VALUE;
         lsl               =  LastSwingLow(i);
         //LowSwingBuf[i]  =  EMPTY_VALUE;
      }
   
   
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
// internal custom functions
//+------------------------------------------------------------------+

int   LastSwingLow(int st)
      {
      double swing=st;
      
      for   (int i=st; i<=Bars; i++)
            
            if (Low[i+1]>Low[i]){swing=i; break;}
      return(swing);
      }

//+------------------------------------------------------------------+
int   LastSwingHigh(int st)
      {
      double swing=st;

      for   (int i=st; i<=Bars; i++)

            if (High[i+1]<High[i]){swing=i; break;}
      return(swing);
      }
//+------------------------------------------------------------------+      