//+------------------------------------------------------------------+
//|                                      Elliott Wave Oscillator.mq4 |
//|                                                tonyc2a@yahoo.com |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "tonyc2a@yahoo.com"
#property link      ""
#property indicator_buffers 2
#property indicator_separate_window
#property indicator_color1 LawnGreen
#property indicator_color2 Red

//---- buffers
double Buffer1[];
double Buffer2[];
double alertBar;
double prev;
double prev1;
extern int SoundAlertMode = 1;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexBuffer(0,Buffer1);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexBuffer(1,Buffer2);
   SetIndexLabel(0,"EWO");
//----
   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();
   double MA5,MA35;
//---- TODO: add your code here
   for(int i=Bars;i>=0;i--){
      MA5=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,i);
      MA35=iMA(NULL,0,35,0,MODE_SMA,PRICE_MEDIAN,i);
      
      if(Buffer2[i]  > 0) {Buffer1[i]=MA5-MA35;Buffer2[i]=0;}
      if(Buffer1[i]  < 0) {Buffer2[i]=MA5-MA35;Buffer1[i]=0;}

      if(prev != 2 && Buffer2[i] < Buffer1[i] && SoundAlertMode > 0 && Bars>alertBar) {Alert("Elliot Wave new Up wave starting on ",Symbol()," Period ",Period(),"buf1= ",Buffer1[i],"buf2= ",Buffer2[i]," prev = ", prev);alertBar = Bars;prev = 2;}
      if(prev != 1 && Buffer2[i] > Buffer1[i] && Buffer2[i] != 0 && SoundAlertMode > 0 && Bars>alertBar) {Alert("Elliot Wave new Down wave starting on ",Symbol()," Period ",Period(),"buf1= ",Buffer1[i],"buf2= ",Buffer2[i]," prev = ", prev);alertBar = Bars;prev = 1;}
      if(Buffer1[i] >= 0.0005 && Buffer2[i] != 0 && SoundAlertMode > 0 && Bars>alertBar) {Alert("Up wave Hit 0.0005 on ",Symbol()," Period ",Period()," buf1= ",Buffer1[i]," buf2= ",Buffer2[i]);alertBar = Bars;prev = Buffer1[i];}
      if(Buffer2[i] <= -0.0003 && Buffer1[i] != 0 && SoundAlertMode > 0 && Bars>alertBar) {Alert("Down wave Hit -0.0003 on ",Symbol()," Period ",Period()," buf1= ",Buffer1[i]," buf2= ",Buffer2[i]);alertBar = Bars;prev1 = Buffer2[i];}
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+


