DPO_alert





//+------------------------------------------------------------------+
//|                                  Detrended Price Oscillator.mq4  |
//|                                       Ramdass - Conversion only  |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//----
extern int x_prd = 14;
extern int CountBars = 300;
extern bool AlertsEnabled  = true;
extern bool AlertAfterBarClose = true;
extern string AlertsSound = "alert.wav";
//---- buffers
double dpo[];
datetime AlertTime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, dpo);
//---- name for DataWindow and indicator subwindow label
   short_name = "DPO(" + x_prd + ")";
   IndicatorShortName(short_name);
   SetIndexLabel(0, short_name);
//----
   if(CountBars >= Bars) 
   CountBars = Bars;
   SetIndexDrawBegin(0, Bars - CountBars + x_prd + 1);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| DPO                                                              |
//+------------------------------------------------------------------+
int start()
  {
   int i, counted_bars=IndicatorCounted();
   double t_prd;
//----
   if(Bars <= x_prd) 
       return(0);
//---- initial zero
   if(counted_bars < x_prd)
     {
       for(i = 1; i <= x_prd; i++) 
           dpo[CountBars-i] = 0.0;
     }
//----
   i = CountBars - x_prd - 1;
   t_prd = x_prd / 2 + 1;
//----
   while(i >= 0)
     {
       dpo[i] = iMA(NULL, 0, 1, 0, MODE_SMA, PRICE_CLOSE, i) - iMA(NULL, 0, x_prd, t_prd, MODE_SMA, PRICE_CLOSE, i);
       i--;
     }
     
if (AlertsEnabled  && AlertTime != Time[0]&& Volume[0]>1) 
		{
	
			if ((AlertAfterBarClose  && (dpo[i+1] > 0 && dpo[i+2] <= 0) || (dpo[i+1] < 0 && dpo[i+2] >= 0)) ||
		      (!AlertAfterBarClose  && (dpo[i] > 0 && dpo[i+1] <= 0) || (dpo[i] < 0 && dpo[i+1] >= 0))  )
			{

				AlertTime = Time[0];
				Alert("DPO Cross 0 ", Symbol(), " M", Period());

		    if (StringLen(AlertsSound) > 0)
					PlaySound(AlertsSound);
			}
		}
	
	 
 		         
   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar
Series array that contains tick volumes of each bar


Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features:

It issuies visual alerts to the screen
It plays sound alerts