P&F_v2_alerts





//+--------------------------------------------------------------------------------------------+
//|   P&F_v2.mq4
//+--------------------------------------------------------------------------------------------+
#property indicator_chart_window

#property indicator_buffers 5
#property indicator_color1 Blue
#property indicator_color2 Blue
#property indicator_color3 Green
#property indicator_color4 Crimson
#property indicator_color5 EMPTY

extern int BoxSize = 20;
extern int Reversal = 3;

extern int     arrWidth= 0;
extern double  arrDistance= 0.5;

extern int ShowBars = 500;


extern bool    SoundAlert  = true;  
extern bool    BoxAlert    = true;
extern bool    EmailAlert  = false;
extern int     AlertOnBar  = 0;
extern string  soundfile   = "ok.wav";//alert alert2 ok.wav   ...etc

bool   UpTrendAlert=false, DownTrendAlert=false;
datetime alerttag;


double UpTrend[];
double DownTrend[];
double UpSignal[];
double DownSignal[];
double Trend[];

int init()
{
      
   IndicatorBuffers(5);
   
   SetIndexStyle(0,DRAW_LINE);
   SetIndexEmptyValue(0,0.0);
   SetIndexBuffer(0,UpTrend);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexEmptyValue(1,0.0);
   SetIndexBuffer(1,DownTrend);
   
   SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,arrWidth);
   SetIndexArrow(2,233);
   SetIndexEmptyValue(2,0.0);
   SetIndexBuffer(2,UpSignal);
   
   SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,arrWidth);
   SetIndexArrow(3,234);
   SetIndexEmptyValue(3,0.0);
   SetIndexBuffer(3,DownSignal);
   
   SetIndexStyle(4,DRAW_NONE);
   SetIndexEmptyValue(4,0.0);
   SetIndexBuffer(4,Trend);
   
   return(0);
}

int deinit()
{
   return(0);
}

int start()
{
   
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1); //---- check for possible errors
   if(counted_bars>0) counted_bars--; //---- last counted bar will be recounted
   
   for (int i=Bars-counted_bars;i>=0;i--)
   {

      double   Range = 0.0;
      for (int counter=i ;counter<=i+9;counter++) 
               Range += MathAbs(High[counter]-Low[counter]);
               Range /= 10;
               Range=Range*arrDistance;




      if (ShowBars == 0 || (ShowBars > 0 && i <= ShowBars))
      {
         if (Trend[i+1] == 0)
         {
            if (Low[i]+(BoxSize*Point) < High[i])
            {
               DownTrend[i] = Low[i];
               UpTrend[i] = High[i];
               Trend[i] = -1;
               DownSignal[i] = High[i]+Range;
            }
            else
            if (High[i]-(BoxSize*Point) > Low[i])
            {
               DownTrend[i] = Low[i];
               UpTrend[i] = High[i];
               Trend[i] = 1;
               UpSignal[i] = Low[i]-Range;
            }
            else
            {
               DownTrend[i] = DownTrend[i+1];
               UpTrend[i] = UpTrend[i+1];
               Trend[i] = Trend[i+1];
            }
         }
         else
         if (Trend[i+1] == -1)
         {
            if (Low[i]+(BoxSize*Point) < DownTrend[i+1])
            {
               DownTrend[i] = Low[i];
               UpTrend[i] = UpTrend[i+1];
               Trend[i] = Trend[i+1];
            }
            else
            if (High[i] > DownTrend[i+1]+((BoxSize*Point)*Reversal))
            {
               UpTrend[i] = High[i];
               DownTrend[i] = Low[i];
               Trend[i] = 1;
               UpSignal[i] = Low[i]-Range;
            }
            else
            {
               DownTrend[i] = DownTrend[i+1];
               UpTrend[i] = UpTrend[i+1];
               Trend[i] = Trend[i+1];
            }
         }
         else
         if (Trend[i+1] == 1)
         {
            if (High[i]-(BoxSize*Point) > UpTrend[i+1])
            {
                DownTrend[i] = DownTrend[i+1];
                UpTrend[i] = High[i];
                Trend[i] = Trend[i+1];
            }
            else
            if (Low[i] < UpTrend[i+1]-((BoxSize*Point)*Reversal))
            {
               UpTrend[i] = High[i];
               DownTrend[i] = Low[i];
               Trend[i] = -1;
               DownSignal[i] = High[i]+Range;
            }
            else
            {
               DownTrend[i] = DownTrend[i+1];
               UpTrend[i] = UpTrend[i+1];
               Trend[i] = Trend[i+1];
            }
         }
      }
              



//----
   string Message;
	Message = " "+Symbol()+" M"+Period()+" P&F:";
   int b=AlertOnBar;
   if ( UpSignal[b+1]==0.0  && UpSignal[b]!=0.0 && Volume[0]>1 && !UpTrendAlert && alerttag!=Time[0])
	  {
	  if ( BoxAlert )   Alert (Message," signal UP");  
	  if ( SoundAlert ) PlaySound(soundfile);
	  if ( EmailAlert ) SendMail ("From P&F",Message);
	  UpTrendAlert=true; DownTrendAlert=false; alerttag =Time[0];
	  } 
	 	  
	if ( DownSignal[b+1]==0.0 && DownSignal[b]!=0.0 && Volume[0]>1 && !DownTrendAlert && alerttag!=Time[0])
	  {
	  if ( BoxAlert )   Alert (Message," signal DOWN");  
	  if ( SoundAlert ) PlaySound(soundfile);
	  if ( EmailAlert ) SendMail ("From P&F",Message);
	  DownTrendAlert=true; UpTrendAlert=false; alerttag=Time[0];
	  } 	         
//----



   }

   return(0);
}
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar
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

Implements a curve of type DRAW_ARROW
Implements a curve of type DRAW_NONE

Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Other Features:

It plays sound alerts