- 显示:
- 1458
- 等级:
- 已发布:
- 2018.11.05 10:19
-
需要基于此代码的EA交易或指标吗?请在自由职业者服务中订购 进入自由职业者服务
真实作者: Iin Zulkarnainn
Iin_MA_Signal 信号量指标具有警报、电子邮件和推送通知功能。
已对指标代码进行了以下修改,以便实施警报、电子邮件和推送通知:
- 引入了新的输入参数
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 &BuyArrow[], // 指标当中买入信号的缓存区 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(BuyArrow); int index; if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; if(NormalizeDouble(BuyArrow[index],_Digits) && BuyArrow[index]!=EMPTY_VALUE) 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); } //--- } //+------------------------------------------------------------------+ //| 卖出信号函数 | //+------------------------------------------------------------------+ void SellSignal(string SignalSirname, // 电子邮件和推送消息的指标名称文本 double &SellArrow[], // 指标当中卖出信号的缓存区 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 SellSignal=false; bool SeriesTest=ArrayGetAsSeries(SellArrow); int index; if(SeriesTest) index=int(NumberofBar); else index=Rates_total-int(NumberofBar)-1; if(NormalizeDouble(SellArrow[index],_Digits) && SellArrow[index]!=EMPTY_VALUE) SellSignal=true; if(SellSignal && 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("SELL signal \n Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod); if(EMailON) SendMail(SignalSirname+": SELL signal alert","SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod); if(PushON) SendNotification(SignalSirname+": SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod); } //--- } //+------------------------------------------------------------------+ //| 获取时间帧的字符串 | //+------------------------------------------------------------------+ string GetStringTimeframe(ENUM_TIMEFRAMES timeframe) { //---- return(StringSubstr(EnumToString(timeframe),7,-1)); //---- }
- 在 OnCalculate() 模块中的指标计算循环之后,添加了一对 BuySignal() 和 SellSignal() 函数的调用
//--- BuySignal("Iin_MA_Signal_Alert",BuyBuffer,rates_total,prev_calculated,close,spread); SellSignal("Iin_MA_Signal_Alert",SellBuffer,rates_total,prev_calculated,close,spread); //---
其中 BuyBuffer 和 SellBuffer 用于存储买入和卖出信号的指标缓冲区名称。 指标缓冲区中的空值必须设置为零或 EMPTY_VALUE。
假设在指标代码的 OnCalculate() 模块中仅调用 BuySignal() 和 SellSignal() 函数一次。
图例 1. 图表上的 Iin_MA_Signal_Alert
图例 2. Iin_MA_Signal_Alert. 生成警报
由MetaQuotes Ltd译自俄语
原代码: https://www.mql5.com/ru/code/21911