CandleSizeAlert

Author: Copyright � 2006, Robert Hill
CandleSizeAlert
Price Data Components
Series array that contains open prices of each barSeries array that contains close prices for each bar
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
CandleSizeAlert
//compile//
//+------------------------------------------------------------------+
//|                                              CandleSizeAlert.mq4 |
//|                         Copyright © 2008, Robert Hill            |
//|                                                                  |
//| Will send alert when a candle meets the size criteria entered   |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2006, Robert Hill"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 Red
#property indicator_width1  2
#property indicator_width2  2

extern bool AlertON=true;
extern int CandleSize = 50;

double Bull[];
double Bear[];
int flagval1 = 0;
int flagval2 = 0;
double   myPoint;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//   IndicatorBuffers(5);
   SetIndexStyle(0, DRAW_ARROW, EMPTY);
   SetIndexArrow(0, 233);
   SetIndexBuffer(0, Bull);
   SetIndexStyle(1, DRAW_ARROW, EMPTY);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, Bear);

     myPoint = SetPoint(Symbol());

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 

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


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   double myOpen, myClose, myDif;
   int limit, i, counter;
   double tmp=0;
   double Range, AvgRange;
   datetime tc;
   
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   limit=Bars-counted_bars;
   
   for(i = 0; i <= limit; i++) {
   
      counter=i;
      Range=0;
      AvgRange=0;
      for (counter=i ;counter<=i+9;counter++)
      {
         AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]);
      }
      Range=AvgRange/10;
       
      myOpen = iOpen(NULL, 0, i);
      myClose = iClose(NULL, 0, i);
      myDif = NormalizeDouble(MathAbs(myOpen - myClose) / myPoint, 4);
       
      Bull[i] = 0;
      Bear[i] = 0;
      if (myDif > CandleSize)
      {
        if (myOpen > myClose)
        {
         if (i == 0 && flagval1==0)
         {
           flagval1=1;
           flagval2=0;
           tc = TimeCurrent();
           if (AlertON) Alert("Large BEAR candle","\n Time=",TimeToStr(tc,TIME_DATE)," ",TimeHour(tc),":",TimeMinute(tc),"\n Symbol=",Symbol()," Period=",Period());
         }
         Bear[i] = High[i] + Range*0.75;
        }
        else if (myOpen < myClose)
        {
         if (i == 0 && flagval2==0)
         {
          flagval2=1;
          flagval1=0;
          tc = TimeCurrent();
          if (AlertON) Alert("Large Bull candle","\n Date=",TimeToStr(tc,TIME_DATE)," ",TimeHour(tc),":",TimeMinute(tc),"\n Symbol=",Symbol()," Period=",Period());
         }
         Bull[i] = Low[i] - Range*0.75;
        }
      }
   }

   return(0);
}

double SetPoint(string mySymbol)
{
   double mPoint, myDigits;
   
   myDigits = MarketInfo (mySymbol, MODE_DIGITS);
   if (myDigits < 4)
      mPoint = 0.01;
   else
      mPoint = 0.0001;
   
   return(mPoint);
}

Comments