诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

CCI水平线报警指标 CCI_Sound_Email.mq4

CCI_Sound_Email指标在当CCI穿越设定的水平线时发出声音报警或发送邮件报警,具体需要哪种报警功能将对应开关设为true即可。

图表:CCI_Sound_Email指标

源码:

//+------------------------------------------------------------------+
//|                                              CCI_Sound_Email.mq4 |
//|                       Copyright @2004, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright @2004, MetaQuotes Software Corp."
#property link      "http://www.125808047.com/"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 LightSeaGreen

extern int CCIPeriod=14;
extern bool SendEmail = false;
extern bool SoundAlert_ON = false;
extern string SoundFile ="alert2.wav";
extern int CCIHigh=100;
extern int CCILow=-100;
int PlayedSoundH = False;
int PlayedSoundL = False;

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

   IndicatorBuffers(4);
   SetIndexBuffer(1, RelBuffer);
   SetIndexBuffer(2, DevBuffer);
   SetIndexBuffer(3, MovBuffer);

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,CCIBuffer);
   
   SetLevelValue(0,CCIHigh);
   SetLevelValue(1,CCILow);
   SetLevelStyle(2,0,DarkSlateGray);

   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";
   
   short_name="CCI( "+CCIPeriod+" ) [ Sound Alert "+Alert2+" ] [ Email Alert "+Alert1+" ]";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);

   SetIndexDrawBegin(0,CCIPeriod);
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Commodity Channel Index                                          |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int    i,k,counted_bars=IndicatorCounted();
   double price,sum,mul;
   if(Bars<=CCIPeriod) return(0);

   if(counted_bars<1)
     {
      for(i=1;i<=CCIPeriod;i++) CCIBuffer[Bars-i]=0.0;
      for(i=1;i<=CCIPeriod;i++) DevBuffer[Bars-i]=0.0;
      for(i=1;i<=CCIPeriod;i++) MovBuffer[Bars-i]=0.0;
     }

   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;

   for(i=0; i<limit; i++)
      MovBuffer[i]=iMA(NULL,0,CCIPeriod,0,MODE_SMA,PRICE_TYPICAL,i);

   i=Bars-CCIPeriod+1;
   if(counted_bars>CCIPeriod-1) i=Bars-counted_bars-1;
   mul=0.015/CCIPeriod;
   while(i>=0)
     {
      sum=0.0;
      k=i+CCIPeriod-1;
      while(k>=i)
       {
         price=(High[k]+Low[k]+Close[k])/3;
         sum+=MathAbs(price-MovBuffer[i]);
         k--;
       }
      DevBuffer[i]=sum*mul;
      i--;
     }
   i=Bars-CCIPeriod+1;
   if(counted_bars>CCIPeriod-1) i=Bars-counted_bars-1;
   while(i>=0)
     {
      price=(High[i]+Low[i]+Close[i])/3;
      RelBuffer[i]=price-MovBuffer[i];
      i--;
     }

   i=Bars-CCIPeriod+1;
   if(counted_bars>CCIPeriod-1) i=Bars-counted_bars-1;
   while(i>=0)
     {
      if(DevBuffer[i]==0.0) CCIBuffer[i]=0.0;
      else CCIBuffer[i]=RelBuffer[i]/DevBuffer[i];
      i--;
     }
   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  "+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  "+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(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » CCI水平线报警指标 CCI_Sound_Email.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏