CCI_SoundEmailAlert_mtf

Download script
Author: Copyright � 2004, MetaQuotes Software Corp.
CCI_SoundEmailAlert_mtf

This tool is designed as a custom technical indicator for the MetaTrader trading platform, specifically focused on monitoring the Commodity Channel Index (CCI). The primary purpose of this script is to track price momentum and provide real-time notifications when the market reaches specific intensity levels.

Core Functionality

The indicator calculates the CCI based on user-defined periods and applies it to specific timeframes. Unlike standard indicators that only show a line on your current chart, this script allows for multi-timeframe analysis, meaning it can monitor the technical status of higher timeframes (such as Daily or Weekly) while you are viewing a smaller timeframe (like 1-minute or 5-minute charts).

Key Features & Logic:

  • Customizable Thresholds: The script uses specific "High" and "Low" levels (defaulting to 100 and -100). These act as boundaries; when the CCI line crosses above the high level or below the low level, it signifies that the price is moving significantly away from its average.
  • Intelligent Alert System: To prevent the software from constantly "spamming" notifications, the script includes a logic gate for alerts. It will only trigger a sound or an email once per crossing event. It resets its memory once the price moves back into the neutral zone, ensuring you are notified of new movements rather than repeated signals on the same move.
  • Multi-Channel Notifications: The tool provides three ways to stay informed:
    1. Visual: A dedicated line is drawn in a separate sub-window on your chart.
    2. Audio: It can trigger a specific sound file (e.g., "alert2.wav") immediately when a level is breached.
    3. Email: If enabled, it sends a detailed automated email containing the specific asset name, current price, date, and time of the crossover.
  • Data Processing: The script is optimized to scan through a large history of bars (up to 1500 by default) to ensure that calculations are accurate and synced correctly with the chosen timeframe.

User Experience

From a user perspective, this script acts as an automated "watchman." Instead of needing to constantly stare at the charts to see if the price is becoming overbought or oversold, the tool monitors these conditions in the background across various timeframes and pushes that information to you via sound or email only when significant market action occurs.

Indicators Used
Commodity channel index
Miscellaneous
Implements a curve of type %1It plays sound alertsIt sends emails
11 Views
0 Downloads
0 Favorites
CCI_SoundEmailAlert_mtf
//+------------------------------------------------------------------+
//|                                                          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 = true;
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);
}
//+------------------------------------------------------------------+

Comments