//+------------------------------------------------------------------+
//|                                               STOCH-ALARM.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
// This program uses Zerolag SYOCH crossing 80 and 20 % to trigger a signal//
#property link      "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Yellow
#property indicator_color2 Magenta


extern bool Alarmset=true;
extern string Set="Set the # times you want";
extern int Alarmtimesbuy=2;
extern int Alarmtimessell=2;
extern int period=4;
extern double volfac=1.5;


double upbuffer[500];
double dnbuffer[500];
int sep,ba,sa;//b=Buy thresh s=Sell thresh.

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
      SetIndexStyle(0,DRAW_ARROW,2);
      SetIndexArrow(0,233);//This is buy signal
      SetIndexBuffer(0, upbuffer);

      SetIndexStyle(1,DRAW_ARROW,2);
      SetIndexArrow(1,234);
      SetIndexBuffer(1,dnbuffer);
      if(Symbol()=="EURUSD"){sep=4;}
      if(Symbol()=="USDCHF"){sep=3;}
      if(Symbol()=="USDJPY"){sep=3;}
      if(Symbol()=="GBPUSD"){sep=3;}
      if(Symbol()=="EURJPY"){sep=20;}
      if(Symbol()=="GBPJPY"){sep=12;}
      if(Symbol()=="AUDUSD"){sep=3;}
      if(Symbol()=="USDCAD"){sep=12;}
      return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
   {
     return(0);
   }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
// int    counted_bars=IndicatorCounted();

int start()
{   
double ax0[500],ax1[500],ax2[500];
double ax3[500],ax4[500];
int xdown,xup;
   for(int cnt=500;cnt>=0;cnt--)
   {
    
    ax0[cnt]=iCustom(NULL,0,"T3MA",period,volfac,0,cnt);
    ax1[cnt+1]=iCustom(NULL,0,"T3MA",period,volfac,0,cnt+1);
    ax2[cnt+2]=iCustom(NULL,0,"T3MA",period,volfac,0,cnt+2);
    
    ax3[cnt]=iCustom(NULL,0,"T3MA",15,0.7,0,cnt);//trend  not yet implemented
    ax4[cnt+1]=iCustom(NULL,0,"T3MA",15,0.7,0,cnt+1);
    double trendup=ax3[cnt]-ax4[cnt+1];//+ = up  - = down    
    
    if(ax0[cnt]-ax1[cnt+1]<0 && ax1[cnt+1]-ax2[cnt+2]>0){xdown=1;} else {xdown=0;}
    if((ax0[cnt]-ax1[cnt+1])>0 && (ax1[cnt+1]-ax2[cnt+2])<0){xup=1;} else {xup=0;}
    
    
    
    if(xdown==1){dnbuffer[cnt+1]=High[cnt+1]+(sep*Point);}
    if(xup==1){upbuffer[cnt+1]=Low[cnt+1]-(sep*Point);}
    }
    {
    
       if(xup==1 && Alarmset){ Alert (Symbol()," ",Period(),"  STOCH-ALARM 3  >> BUY ");}
       
       if(xdown==1 && Alarmset){ Alert (Symbol()," ",Period(),"  STOCH-ALARM 3  >> SELL ");}
     }       
    
     
      
   //Comment("Angle of T3MA=",actualslope," Degrees","  Point   ",Point); 
return(0);

}