CCI_SoundEmailAlert_mtf_001
Download scriptThis script is a specialized trading tool designed for the MetaTrader platform. It utilizes the Commodity Channel Index (CCI), which is a momentum-based technical indicator used to identify when an asset is overbought, oversold, or experiencing significant price fluctuations relative to its average.
Core Functionality
The primary purpose of this script is to monitor price movements across specific timeframes and notify the user automatically when the CCI reaches predetermined "extreme" levels. Instead of requiring a trader to watch the screen constantly, the script acts as an automatedsentinel that triggers alerts based on mathematical thresholds.
Key Features and Logic:
-
Multi-Timeframe Analysis: The script is capable of analyzing data from different timeframes (such as M1, H1, D1, etc.). It allows users to observe trends on a larger scale while potentially viewing their current active chart, ensuring that price actions are viewed in the proper context.
-
Customizable Thresholds: Users can define what constitutes a "high" or "low" signal. By default, it monitors when the CCI exceeds specific levels (e.g., 100 or -100), but these can be adjusted to suit different trading strategies or volatile assets.
-
Automated Notification System: One of the most prominent features of this script is its integrated alert system. When the CCI crosses the defined high or low thresholds, the script can perform three actions simultaneously:
- Visual/Audio Feedback: It can play a specific sound file on your computer to grab your attention instantly.
- Email Alerts: It can automatically send an email containing the current price, the specific timeframe, and the exact time of the crossover.
- Status Tracking: The script includes internal logic to ensure it doesn't "spam" alerts; it remembers if a signal has already been triggered so that you only receive a notification at the moment the threshold is breached.
-
Performance Optimization: To keep the trading platform running smoothly, the script includes limits on how many historical bars it processes at once, ensuring that the calculations do not cause unnecessary lag or slow down your software.
Summary for the User
In simple terms, this tool serves as an automated alert system. It watches the Commodity Channel Index for you across various timeframes and "pings" you via sound or email the moment the market enters a state of high momentum or potential reversal, allowing for more responsive and informed trading decisions.
//+------------------------------------------------------------------+
//| 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);
}
//+------------------------------------------------------------------+
Comments