
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 clrBlue
#property indicator_color2 clrRed
#property indicator_minimum 0
#property indicator_maximum 1

extern  int CCIPeriod1=7777;
extern  int CCIPeriod2=2333;
extern  int CCIPeriod3=1300;
extern  int CCIPeriod4=555;
extern  int CCIPeriod5=777;

int extern stochastic1=333;
int extern stochastic2=555;
int extern stochastic3=777;
int extern stochastic4=1333;

extern bool Reduce_Signals=true;
extern int  Ignore_Signals=10;

extern bool AlertsMessage = true;
extern bool AlertsSound = true;
extern bool AlertsEmail = true;

double draw_itl[]; 
double draw_its[];
double Arrow_up[];
double Arrow_dn[]; 
double a01,a02,a03,a04,a05;
double Bar_ok;
string DPA;


int init()
  {
   IndicatorBuffers(4);

   SetIndexBuffer(0,Arrow_up);
   SetIndexStyle(0,DRAW_ARROW,2,2);
   SetIndexArrow(0,233);
   SetIndexBuffer(1,Arrow_dn);
   SetIndexStyle(1,DRAW_ARROW,2,2);
   SetIndexArrow(1,234);
   SetIndexBuffer(2,draw_itl);
   SetIndexBuffer(3,draw_its);


   return(0);
  }
  
  int start()
 {
 int i,
 Counted_bars=IndicatorCounted(); 
 i=Bars-Counted_bars-1; 

 while(i>=0)
 {

a02=iStochastic(NULL,0,stochastic1,stochastic1,1,MODE_SMA,0,MODE_MAIN, i);
a03=iStochastic(NULL,0,stochastic2,stochastic2,1,MODE_SMA,0,MODE_MAIN, i);
a04=iStochastic(NULL,0,stochastic3,stochastic3,1,MODE_SMA,0,MODE_MAIN, i);
a05=iStochastic(NULL,0,stochastic4,stochastic4,1,MODE_SMA,0,MODE_MAIN, i);

if (a02>90 && a03>90 && a04>90 && a05>90) draw_itl[i]=1;
if (a02<10 && a03<10 && a04<10 && a05<10) draw_its[i]=1;



if (iCCI(NULL,0,CCIPeriod1,0,i)<0) draw_itl[i]=EMPTY_VALUE;
if (iCCI(NULL,0,CCIPeriod1,0,i)>0) draw_its[i]=EMPTY_VALUE;

if (iCCI(NULL,0,CCIPeriod2,0,i)<125) draw_itl[i]=EMPTY_VALUE;
if (iCCI(NULL,0,CCIPeriod2,0,i)>-125) draw_its[i]=EMPTY_VALUE;

if (iCCI(NULL,0,CCIPeriod3,0,i)<150) {draw_itl[i]=EMPTY_VALUE;}
if (iCCI(NULL,0,CCIPeriod3,0,i)>-150) {draw_its[i]=EMPTY_VALUE;}

if (iCCI(NULL,0,CCIPeriod4,0,i)<150) {draw_itl[i]=EMPTY_VALUE;}
if (iCCI(NULL,0,CCIPeriod4,0,i)>-150) {draw_its[i]=EMPTY_VALUE;}

if (iCCI(NULL,0,CCIPeriod5,0,i)<150) {draw_itl[i]=EMPTY_VALUE;}
if (iCCI(NULL,0,CCIPeriod5,0,i)>-150) {draw_its[i]=EMPTY_VALUE;}

if (Reduce_Signals)
{
   if (Bar_ok==1)
   {
   if(iCCI(NULL,0,CCIPeriod3,0,i)<150 && iCCI(NULL,0,CCIPeriod4,0,i)<150 && iCCI(NULL,0,CCIPeriod5,0,i)<150) Bar_ok=0;
   }
   
   if (Bar_ok==2)
   {
   if(iCCI(NULL,0,CCIPeriod3,0,i)>-150 && iCCI(NULL,0,CCIPeriod4,0,i)>-150 && iCCI(NULL,0,CCIPeriod5,0,i)>-150) Bar_ok=0;
   }
}
else Bar_ok=0;

if (draw_itl[i]==1 && draw_itl[i+1]==EMPTY_VALUE && Bar_ok==0 ) {Arrow_up[i]=Low[i]-iATR(NULL,0,14,i); Bar_ok=1;}
if (draw_its[i]==1 && draw_its[i+1]==EMPTY_VALUE && Bar_ok==0 ) {Arrow_dn[i]=High[i]+iATR(NULL,0,14,i); Bar_ok=2;}


if (Arrow_up[i]!=EMPTY_VALUE)
{
if (Reduce_Signals)
      {
         int y;
         for (y=Ignore_Signals; y>0; y--)
            { 
               if (Arrow_up[i+y]!=EMPTY_VALUE) Arrow_up[i]=EMPTY_VALUE;
            }
      }
}

if (Arrow_dn[i]!=EMPTY_VALUE)
{
if (Reduce_Signals)
      {
         int y;
         for (y=Ignore_Signals; y>0; y--)
            { 
               if (Arrow_dn[i+y]!=EMPTY_VALUE) Arrow_dn[i]=EMPTY_VALUE;
            }
      }
}

if (Arrow_dn[i] !=EMPTY_VALUE  || Arrow_up[i] !=EMPTY_VALUE)
{
 DPA = StringConcatenate(Symbol(), " at ", TimeToStr(TimeLocal())," Almo SCS");
 if (AlertsMessage) Alert(DPA);
 if (AlertsEmail) SendMail(StringConcatenate(Symbol(), "Almo_SCS"), DPA);
 if (AlertsSound) PlaySound("alert2.wav");
}

i--;
}
   return(0);
  }


