#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
extern int EMA_Period=13;
extern int EMA_Band=13;
extern int CCI_Period=14;
extern double CCI_UpLevel=40;
extern double CCI_DnLevel=-40;
extern bool UseAlert=true;
extern bool SendEmail=false;
extern int Repeat=3;
extern int Periods=5;
int Crepeat=0;
int AlertTime=0;
int Bar=0;
int DotPip=7;
//---- buffers
double BuyBuffer[];
double SellBuffer[];
double CciCurrent=0, CciPrevious=0;
double EmaCurrent=0;
double EmaUpBand=0;
double EmaDnBand=0;
double LastState[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
Crepeat=Repeat;
IndicatorBuffers(3);
//---- indicators
SetIndexStyle(0,DRAW_ARROW,EMPTY);
SetIndexArrow(0,233);
SetIndexBuffer(0, BuyBuffer);
SetIndexStyle(1,DRAW_ARROW,EMPTY);
SetIndexArrow(1,234);
SetIndexBuffer(1, SellBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
RefreshRates();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if (counted_bars<0) return (-1);
if (counted_bars>0) counted_bars--;
limit=(Bars-counted_bars)-1;
LastState[0]=0;
for(int i=limit; i>=0; i--) {
CciCurrent=iCCI(NULL,0,CCI_Period,PRICE_TYPICAL,i);
CciPrevious=iCCI(NULL,0,CCI_Period,PRICE_TYPICAL,(i+1));
EmaCurrent=iMA(NULL,0,EMA_Period,0,MODE_EMA,PRICE_CLOSE,i);
EmaUpBand=EmaCurrent+EMA_Band*Point;
EmaDnBand=EmaCurrent-EMA_Band*Point;
if (High[i]>=EmaDnBand && Low[i]<=EmaDnBand && CciCurrent>CCI_DnLevel && CciCurrent<CCI_UpLevel) {
BuyBuffer[i]=Low[i]-DotPip*Point;
LastState[0]=1;
}
else {
BuyBuffer[i]=0;
}
if (High[i]>=EmaUpBand && Low[i]<=EmaUpBand && CciCurrent>CCI_DnLevel && CciCurrent<CCI_UpLevel) {
SellBuffer[i]=High[i]+DotPip*Point;
LastState[0]=-1;
}
else {
SellBuffer[i]=0;
}
}
if (SellBuffer[Bar]>0) Alerts(0,1,0,0);
else if (BuyBuffer[Bar]>0) Alerts(1,0,0,0);
else Alerts(0,0,0,0);
//----
return(0);
}
void Alerts(int _buy, int _sell, int _exitbuy, int _exitsell) {
string AlertStr="";
AlertStr="";
string CurDate="";
CurDate=TimeToStr(CurTime(),TIME_DATE|TIME_MINUTES);
//Alert system
if (UseAlert)
{
if (_buy==1)
{
if (Crepeat==Repeat)
{
AlertTime=0;
}
if (Crepeat>0 && (CurTime()-AlertTime)>Periods)
{
if (_buy==1) {
AlertStr=AlertStr+"Attention! EmaCci Buy Signal"+" Ask="+DoubleToStr(Ask,Digits)+" at "+CurDate;
Alert(Symbol()," ",Period(), ": ",AlertStr);
if (SendEmail)
{
SendMail(Symbol()+" "+Period()+ ": ",Symbol()+" "+Period()+": "+AlertStr);
}
Crepeat=Crepeat-1;
AlertTime=CurTime();
}
}
}
if (_sell==1)
{
if (Crepeat==Repeat)
{
AlertTime=0;
}
if (Crepeat>0 && (CurTime()-AlertTime)>Periods)
{
if (_sell==1) {
AlertStr=AlertStr+"Attention! EmaCci Sell Signal "+" Bid="+DoubleToStr(Bid,Digits)+" at "+CurDate;
Alert(Symbol()," ",Period(), ": ",AlertStr);
if (SendEmail)
{
SendMail(Symbol()+" "+Period()+ ": ",Symbol()+" "+Period()+": "+AlertStr);
}
Crepeat=Crepeat-1;
AlertTime=CurTime();
}
}
}
if (_exitsell==1)
{
if (Crepeat==Repeat)
{
AlertTime=0;
}
if (Crepeat>0 && (CurTime()-AlertTime)>Periods)
{
if (_exitsell==1) {
AlertStr=AlertStr+"Attention! Please check to close sell; ";
Alert(Symbol()," ",Period(), ": ", AlertStr);
if (SendEmail)
{
SendMail(Symbol()+" "+Period()+ ": ",Symbol()+" "+Period()+": "+AlertStr);
}
Crepeat=Crepeat-1;
AlertTime=CurTime();
}
}
}
if (_exitbuy==1)
{
if (Crepeat==Repeat)
{
AlertTime=0;
}
if (Crepeat>0 && (CurTime()-AlertTime)>Periods)
{
if (_exitbuy==1) {
AlertStr=AlertStr+"Attention! Please check to close buy; ";
Alert(Symbol()," ",Period(), ": ",AlertStr);
if (SendEmail)
{
SendMail(Symbol()+" "+Period()+ ": ",Symbol()+" "+Period()+": "+AlertStr);
}
Crepeat=Crepeat-1;
AlertTime=CurTime();
}
}
}
if (_exitbuy==0 && _exitsell==0 && _buy==0 && _sell==0)
{
Crepeat=Repeat;
AlertTime=0;
}
}
//
//----
return;
}
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
extern int EMA_Period=13;
extern int EMA_Band=13;
extern int CCI_Period=14;
extern double CCI_UpLevel=40;
extern double CCI_DnLevel=-40;
extern bool UseAlert=true;
extern bool SendEmail=false;
extern int Repeat=3;
extern int Periods=5;
int Crepeat=0;
int AlertTime=0;
int Bar=0;
int DotPip=7;
//---- buffers
double BuyBuffer[];
double SellBuffer[];
double CciCurrent=0, CciPrevious=0;
double EmaCurrent=0;
double EmaUpBand=0;
double EmaDnBand=0;
double LastState[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
Crepeat=Repeat;
IndicatorBuffers(3);
//---- indicators
SetIndexStyle(0,DRAW_ARROW,EMPTY);
SetIndexArrow(0,233);
SetIndexBuffer(0, BuyBuffer);
SetIndexStyle(1,DRAW_ARROW,EMPTY);
SetIndexArrow(1,234);
SetIndexBuffer(1, SellBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
RefreshRates();
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if (counted_bars<0) return (-1);
if (counted_bars>0) counted_bars--;
limit=(Bars-counted_bars)-1;
LastState[0]=0;
for(int i=limit; i>=0; i--) {
CciCurrent=iCCI(NULL,0,CCI_Period,PRICE_TYPICAL,i);
CciPrevious=iCCI(NULL,0,CCI_Period,PRICE_TYPICAL,(i+1));
EmaCurrent=iMA(NULL,0,EMA_Period,0,MODE_EMA,PRICE_CLOSE,i);
EmaUpBand=EmaCurrent+EMA_Band*Point;
EmaDnBand=EmaCurrent-EMA_Band*Point;
if (High[i]>=EmaDnBand && Low[i]<=EmaDnBand && CciCurrent>CCI_DnLevel && CciCurrent<CCI_UpLevel) {
BuyBuffer[i]=Low[i]-DotPip*Point;
LastState[0]=1;
}
else {
BuyBuffer[i]=0;
}
if (High[i]>=EmaUpBand && Low[i]<=EmaUpBand && CciCurrent>CCI_DnLevel && CciCurrent<CCI_UpLevel) {
SellBuffer[i]=High[i]+DotPip*Point;
LastState[0]=-1;
}
else {
SellBuffer[i]=0;
}
}
if (SellBuffer[Bar]>0) Alerts(0,1,0,0);
else if (BuyBuffer[Bar]>0) Alerts(1,0,0,0);
else Alerts(0,0,0,0);
//----
return(0);
}
void Alerts(int _buy, int _sell, int _exitbuy, int _exitsell) {
string AlertStr="";
AlertStr="";
string CurDate="";
CurDate=TimeToStr(CurTime(),TIME_DATE|TIME_MINUTES);
//Alert system
if (UseAlert)
{
if (_buy==1)
{
if (Crepeat==Repeat)
{
AlertTime=0;
}
if (Crepeat>0 && (CurTime()-AlertTime)>Periods)
{
if (_buy==1) {
AlertStr=AlertStr+"Attention! EmaCci Buy Signal"+" Ask="+DoubleToStr(Ask,Digits)+" at "+CurDate;
Alert(Symbol()," ",Period(), ": ",AlertStr);
if (SendEmail)
{
SendMail(Symbol()+" "+Period()+ ": ",Symbol()+" "+Period()+": "+AlertStr);
}
Crepeat=Crepeat-1;
AlertTime=CurTime();
}
}
}
if (_sell==1)
{
if (Crepeat==Repeat)
{
AlertTime=0;
}
if (Crepeat>0 && (CurTime()-AlertTime)>Periods)
{
if (_sell==1) {
AlertStr=AlertStr+"Attention! EmaCci Sell Signal "+" Bid="+DoubleToStr(Bid,Digits)+" at "+CurDate;
Alert(Symbol()," ",Period(), ": ",AlertStr);
if (SendEmail)
{
SendMail(Symbol()+" "+Period()+ ": ",Symbol()+" "+Period()+": "+AlertStr);
}
Crepeat=Crepeat-1;
AlertTime=CurTime();
}
}
}
if (_exitsell==1)
{
if (Crepeat==Repeat)
{
AlertTime=0;
}
if (Crepeat>0 && (CurTime()-AlertTime)>Periods)
{
if (_exitsell==1) {
AlertStr=AlertStr+"Attention! Please check to close sell; ";
Alert(Symbol()," ",Period(), ": ", AlertStr);
if (SendEmail)
{
SendMail(Symbol()+" "+Period()+ ": ",Symbol()+" "+Period()+": "+AlertStr);
}
Crepeat=Crepeat-1;
AlertTime=CurTime();
}
}
}
if (_exitbuy==1)
{
if (Crepeat==Repeat)
{
AlertTime=0;
}
if (Crepeat>0 && (CurTime()-AlertTime)>Periods)
{
if (_exitbuy==1) {
AlertStr=AlertStr+"Attention! Please check to close buy; ";
Alert(Symbol()," ",Period(), ": ",AlertStr);
if (SendEmail)
{
SendMail(Symbol()+" "+Period()+ ": ",Symbol()+" "+Period()+": "+AlertStr);
}
Crepeat=Crepeat-1;
AlertTime=CurTime();
}
}
}
if (_exitbuy==0 && _exitsell==0 && _buy==0 && _sell==0)
{
Crepeat=Repeat;
AlertTime=0;
}
}
//
//----
return;
}
Ed