大家好!今天我想给大家介绍一下 ColorJFatl_Digit 指标,这个指标的特点是可以发送提醒,并且支持邮件和手机推送通知。
为了实现这些提醒、邮件和推送通知的功能,我们对指标代码进行了一些重要的修改:
- 新增了输入参数:
//---- 提醒的输入变量 input uint NumberofBar=1;// 信号的柱数 input bool SoundON=true;// 启用提醒 input uint NumberofAlerts=2;// 提醒次数 input bool EMailON=false;// 启用邮件发送信号 input bool PushON=false;// 启用发送信号到手机
- 在指标代码末尾新增了三个函数:BuySignal()、SellSignal() 和 GetStringTimeframe()。
//+------------------------------------------------------------------+ //| 买入信号函数 //+------------------------------------------------------------------+ void BuySignal(string SignalSirname,// 用于邮件和推送消息的指标名称 double &ColorArray[],// 颜色索引缓冲区 int ColorIndex,// 生成信号的颜色索引 const int Rates_total,// 当前柱数 const int Prev_calculated,// 上一根柱子的数量 const double &Close[],// 收盘价 const int &Spread[])// 点差 { //--- static uint counter=0; if(Rates_total!=Prev_calculated) counter=0; bool BuySignal=false; bool SeriesTest=ArrayGetAsSeries(ColorArray); int index,index1; if(SeriesTest) { index=int(NumberofBar); index1=index+1; } else { index=Rates_total-int(NumberofBar)-1; index1=index-1; } if(ColorArray[index1]!=ColorIndex && ColorArray[index]==ColorIndex) BuySignal=true; if(BuySignal && counter<=NumberofAlerts) { counter++; MqlDateTime tm; TimeToStruct(TimeCurrent(),tm); string text=TimeToString(TimeCurrent(),TIME_DATE)+" "+string(tm.hour)+":"+string(tm.min); SeriesTest=ArrayGetAsSeries(Close); if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; double Ask=Close[index]; double Bid=Close[index]; SeriesTest=ArrayGetAsSeries(Spread); if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; Bid+=Spread[index]; string sAsk=DoubleToString(Ask,_Digits); string sBid=DoubleToString(Bid,_Digits); string sPeriod=GetStringTimeframe(ChartPeriod()); if(SoundON) Alert("BUY signal \n Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod); if(EMailON) SendMail(SignalSirname+": BUY signal alert","BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod); if(PushON) SendNotification(SignalSirname+": BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod); } //--- } //+------------------------------------------------------------------+
- 在 OnCalculate() 块的指标计算周期后新增了 BuySignal() 和 SellSignal() 函数的调用:
//--- BuySignal("ColorJFatl_Digit_Alert",ColorExtLineBuffer,2,rates_total,prev_calculated,close,spread); SellSignal("ColorJFatl_Digit_Alert",ColorExtLineBuffer,0,rates_total,prev_calculated,close,spread); //---
其中,ColorExtLineBuffer 是用于存储线条颜色的索引的颜色索引缓冲区。
我们假设在指标代码的 OnCalculate() 块中只会调用一次 BuySignal() 和 SellSignal() 函数。
该指标使用了 SmoothAlgorithms.mqh 库中的类(请将其复制到 <terminal_data_folder>\MQL5\Include)。有关这些类的详细使用说明,请参见文章 "在不中断使用额外缓冲区的情况下对价格序列进行平均计算"。

图1. ColorJFatl_Digit_Alert 指标在图表上的表现
图2. ColorJFatl_Digit_Alert 指标生成提醒。
