Accelerator Alert





//+------------------------------------------------------------------+
//|                                             AcceleratorAlert.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//|                                     Alerts & Arrows added by cja |
//|  Thanks to mladen for the Arrow code & IgorAD for the Alert code |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005, MetaQuotes Software Corp."
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Black
#property  indicator_color2  Green
#property  indicator_color3  Red
#property  indicator_width2  2
#property  indicator_width3  2


extern bool   PopUP_Alert_ON  = false;
extern bool   SoundAlert_ON   = false;
extern string SoundFile       ="alert2.wav";
extern bool   Show_Arrows     = true;
extern int    Arrow_Size      = 1;
extern int    ArrowUP         = 233;//241
extern int    ArrowDN         = 234;//242
extern int    Arrow_Shift     = 4;

//---- indicator buffers
double     ExtBuffer0[];
double     ExtBuffer1[];
double     ExtBuffer2[];
double     ExtBuffer3[];
double     ExtBuffer4[];

bool       UpTrend=false, DownTrend=false;

int      maxArrows;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(5);
//---- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   IndicatorDigits(Digits+2);
   SetIndexDrawBegin(0,38);
   SetIndexDrawBegin(1,38);
   SetIndexDrawBegin(2,38);
//---- 4 indicator buffers mapping
   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);
   SetIndexBuffer(2,ExtBuffer2);
   SetIndexBuffer(3,ExtBuffer3);
   SetIndexBuffer(4,ExtBuffer4);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("AC");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
//---- initialization done
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
     //ObjectsDeleteAll(0,OBJ_ARROW);
    // ObjectDelete("ACC_BUY");
    // ObjectDelete("ACC-SELL");
       DeleteArrows();
     
//----
   return(0);
  }  
//+------------------------------------------------------------------+
//| Accelerator/Decelerator Oscillator                               |
//+------------------------------------------------------------------+
int start()
  {
   int    limit;
   int    counted_bars=IndicatorCounted();
   double prev,current;
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   //---- macd counted in the 1-st additional buffer
   for(int i=0; i<limit; i++)
      ExtBuffer3[i]=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN,i);
   //---- signal line counted in the 2-nd additional buffer
   for(i=0; i<limit; i++)
      ExtBuffer4[i]=iMAOnArray(ExtBuffer3,Bars,5,0,MODE_SMA,i);
   //---- dispatch values between 2 buffers
   bool up=true;
   for(i=limit-1; i>=0; i--)
     {
      current=ExtBuffer3[i]-ExtBuffer4[i];
      prev=ExtBuffer3[i+1]-ExtBuffer4[i+1];
      if(current>prev) up=true;
      if(current<prev) up=false;
      if(!up)
        {
         ExtBuffer2[i]=current;
         ExtBuffer1[i]=0.0;
        }
      else
        {
         ExtBuffer1[i]=current;
         ExtBuffer2[i]=0.0;
        }
       ExtBuffer0[i]=current;
     }
         
   if (Show_Arrows)
      for (i=0; i<WindowBarsPerChart() ;i++)//Bars for showing total history of signals
         {
            if( ExtBuffer3[i]-ExtBuffer4[i]<ExtBuffer3[i+1]-ExtBuffer4[i+1] 
            && ExtBuffer3[i+1]-ExtBuffer4[i+1]>ExtBuffer3[i+2]-ExtBuffer4[i+2] 
            && Volume[0]>1 && !UpTrend) DrawArrow(i,"up");
            
            if ( ExtBuffer3[i]-ExtBuffer4[i]>ExtBuffer3[i+1]-ExtBuffer4[i+1] 
            && ExtBuffer3[i+1]-ExtBuffer4[i+1]<ExtBuffer3[i+2]-ExtBuffer4[i+2]
            && Volume[0]>1 && !DownTrend)  DrawArrow(i,"down");
         }

    
   if ( current>prev && Volume[0]>1 && !UpTrend)
	{
	if ( PopUP_Alert_ON==true ) Alert(""+Symbol()+" M"+Period()+": ACC Signal for BUY &  "+DoubleToStr(Bid,Digits)+"");
	if(SoundAlert_ON==true)PlaySound(SoundFile); 
	UpTrend=true; DownTrend=false;
	} 
	 	  
	if ( current<prev && Volume[0]>1 && !DownTrend)
	{
	if ( PopUP_Alert_ON==true ) Alert(""+Symbol()+" M"+Period()+": ACC Signal for SELL &  "+DoubleToStr(Bid,Digits)+""); 
	if(SoundAlert_ON==true)PlaySound(SoundFile);
	DownTrend=true; UpTrend=false;
	} 

   //---- done
   return(0);
  }
  
  
void DrawArrow(int i,string type)//Arrow_Size
{
   maxArrows++;
      ObjectCreate("AC_ArrowALERT"+maxArrows,OBJ_ARROW,0,Time[i],0);
      if (type=="up")
         {
            ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_PRICE1,High[i]+((4+Arrow_Shift)*Point));
            ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_ARROWCODE,ArrowDN);
            ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_WIDTH,Arrow_Size);
            ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_COLOR,Red);
         }
      else
         {
            ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_PRICE1,Low[i]-((2+Arrow_Shift)*Point));
            ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_ARROWCODE,ArrowUP);
            ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_WIDTH,Arrow_Size);
            ObjectSet("AC_ArrowALERT"+maxArrows,OBJPROP_COLOR,LimeGreen);
         }
}
void DeleteArrows()
{
   while(maxArrows>0) { ObjectDelete("AC_ArrowALERT"+maxArrows); maxArrows--; }
}






Sample





Analysis



Market Information Used:

Series array that contains tick volumes of each bar
Series array that contains open time of each bar
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:

Implements a curve of type DRAW_NONE
Implements a curve of type DRAW_HISTOGRAM


Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features:

It issuies visual alerts to the screen
It plays sound alerts