สัญญาณจากลูกศร Semaphore ที่ใช้ตัวบ่งชี้ DeMarker แบบคลาสสิก ช่วยในการออกสัญญาณเมื่อเข้าหรือออกจากโซนซื้อขายที่มากเกินไปหรือขายมากเกินไป โดยมาพร้อมกับฟีเจอร์การแจ้งเตือน การส่งอีเมล และการแจ้งเตือนผ่านมือถือ
ในการพัฒนาสัญญาณนี้ มีการปรับปรุงโค้ดของตัวบ่งชี้เพื่อเพิ่มฟังก์ชันการแจ้งเตือน การส่งข้อความทางอีเมล และการแจ้งเตือนแบบพุช:
- เพิ่มพารามิเตอร์ใหม่ในโค้ดของตัวบ่งชี้:
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)); //---- }
- เพิ่มการเรียกใช้ฟังก์ชัน BuySignal() และ SellSignal() หลังจากรอบการคำนวณตัวบ่งชี้ในบล็อก OnCalculate()
BuySignal("iWPRSign",BuyBuffer,rates_total,prev_calculated,close,spread); SellSignal("iWPRSign",SellBuffer,rates_total,prev_calculated,close,spread);
โดยที่ BuyBuffer และ SellBuffer เป็นชื่อของบัฟเฟอร์ที่ใช้ในการเก็บสัญญาณซื้อและขาย ซึ่งค่าที่ว่างในบัฟเฟอร์จะต้องถูกตั้งเป็นศูนย์หรือ EMPTY_VALUE
คาดว่าจะมีการเรียกใช้ฟังก์ชัน BuySignal() และ SellSignal() เพียงครั้งเดียวในบล็อก OnCalculate() ของโค้ดตัวบ่งชี้

Fig.1. สัญญาณเตือนจาก iDeMarkerSignAlert บนกราฟ

Fig.2. ตัวบ่งชี้ iDeMarkerSignAlert กำลังสร้างสัญญาณเตือน