CCI_SoundEmailAlert_mtf_001





//+------------------------------------------------------------------+
//|                                                          CCI.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|mtf2008fxtsd   ki                      http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property link      "Sound & email added by cja" 
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 LightSeaGreen

#property indicator_level1  200
#property indicator_level2  100
#property indicator_level3 -100
#property indicator_level4 -200

#property indicator_levelcolor DarkSlateGray


//---- input parameters
extern int CCIPeriod    =14;
extern int AppliedPrice =0;

extern int CCIHigh=100;
extern int CCILow=-100;

extern int TimeFrame = 0;

extern bool SendEmail = false;
extern bool SoundAlert_ON = false;
extern string SoundFile ="alert2.wav";
extern int MaxBarsToCount   = 1500;

extern string  TimeFrames = "M1;5,15,30,60H1;240H4;1440D1;10080W1;43200MN|0-CurrentTF";
extern string  note_Price = "Price(C O1 H2 3L 4M 5T W6) ModeMa(SMA0,EMA1,SmmMA2,LWMA3)";

int PlayedSoundH = False;
int PlayedSoundL = False;

//---- buffers
double CCIBuffer[];
double RelBuffer[];
double DevBuffer[];
double MovBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;

//---- 3 additional buffers are used for counting.
   IndicatorBuffers(4);
   SetIndexBuffer(1, RelBuffer);
   SetIndexBuffer(2, DevBuffer);
   SetIndexBuffer(3, MovBuffer);
//---- indicator lines
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,CCIBuffer);
   
   SetLevelValue(0,CCIHigh);
   SetLevelValue(1,CCILow);
   SetLevelStyle(2,0,DarkSlateGray);
//---- name for DataWindow and indicator subwindow label
   string Alert1="",Alert2="";
   if(SendEmail==true)Alert1="ON";
   if(SendEmail==false)Alert1="OFF";
   if(SoundAlert_ON==true)Alert2="ON";
   if(SoundAlert_ON==false)Alert2="OFF";
 
    switch(TimeFrame)
   {
      case 1 : string TimeFrameStr= "M1";  break;
      case 5 : TimeFrameStr=        "M5";  break;
      case 15 : TimeFrameStr=       "M15"; break;
      case 30 : TimeFrameStr=       "M30"; break;
      case 60 : TimeFrameStr=       "H1";  break;
      case 240 : TimeFrameStr=      "H4";  break;
      case 1440 : TimeFrameStr=     "D1";  break;
      case 10080 : TimeFrameStr=    "W1";  break;
      case 43200 : TimeFrameStr=    "MN1"; break;
      default : TimeFrameStr= "CurrTF";
   }
   
   short_name="CCI ("+CCIPeriod+") ["+TimeFrameStr+"]|( Sound Alert "+Alert2+" )( Email Alert "+Alert1+")|";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
   if (TimeFrame<Period()) TimeFrame=Period();

//----
   SetIndexDrawBegin(0,CCIPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Commodity Channel Index                                          |
//+------------------------------------------------------------------+
int start()
  {
 
   datetime TimeArray[];
   int    i,limit,y=0,counted_bars=IndicatorCounted();
 
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); 

limit= Bars-counted_bars;
limit= MathMax(limit,TimeFrame/Period());
limit= MathMin(limit,MaxBarsToCount);

   for(i=0,y=0;i<limit;i++)
   {
   if (Time[i]<TimeArray[y]) y++;
/***********************************************************   
   Add your main indicator loop below.  You can reference an existing
      indicator with its iName  or iCustom.
   Rule 1:  Add extern inputs above for all neccesary values   
   Rule 2:  Use 'TimeFrame' for the indicator time frame
   Rule 3:  Use 'y' for your indicator's shift value
 **********************************************************/  
   CCIBuffer[i]=iCCI(NULL,TimeFrame,CCIPeriod,AppliedPrice,y) ; 



   if(CCIBuffer[0]<CCIHigh){PlayedSoundH = False;}
   
   if(CCIBuffer[0]>CCILow){PlayedSoundL = False;}  
   
   if(CCIBuffer[0]>=CCIHigh && PlayedSoundH == False)
   {if(SoundAlert_ON==true)
    PlaySound(SoundFile); 
    if (SendEmail==true)SendMail("CCI  ("+CCIPeriod+") TF["+TimeFrame+"] "+Symbol()+" M"+Period()+"","CCI Xrossed @ Level "+CCIHigh+"\n"+Symbol()+" M"+Period()+"\n"+"Price "+DoubleToStr(Bid,Digits)+"\n"
		     +"Time = "+TimeToStr(TimeLocal(),TIME_SECONDS)+"\n"+"Date = "+TimeToStr(TimeLocal(),TIME_DATE)+"");
		       {
    PlayedSoundH = True;}
    
   if(CCIBuffer[0]<=CCILow && PlayedSoundL == False){if(SoundAlert_ON==true)
    PlaySound(SoundFile); if (SendEmail==true)SendMail("CCI  ("+CCIPeriod+") TF["+TimeFrame+"]"+Symbol()+" M"+Period()+"","CCI Xrossed @ Level "+CCILow+"\n"+Symbol()+" M"+Period()+"\n"+"Price "+DoubleToStr(Bid,Digits)+"\n"
		     +"Time = "+TimeToStr(TimeLocal(),TIME_SECONDS)+"\n"+"Date = "+TimeToStr(TimeLocal(),TIME_DATE)+"");
		       {
    PlayedSoundL = True;}
    }}
    }
//----
   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar


Indicator Curves created:


Implements a curve of type DRAW_LINE

Indicators Used:

Commodity channel index


Custom Indicators Used:

Order Management characteristics:

Other Features:

It plays sound alerts
It sends emails