สวัสดีครับเพื่อนๆ เทรดเดอร์ทุกคน! วันนี้เราจะมาพูดถึง ColorJFatl_Digit ตัวชี้วัดที่มีฟีเจอร์การแจ้งเตือน ส่งอีเมล์ และการแจ้งเตือนผ่านมือถือให้กับเราได้อย่างสะดวกสบาย
ในการปรับปรุงโค้ดของตัวชี้วัดนี้ เราได้เพิ่มฟังก์ชันและพารามิเตอร์ใหม่ๆ เพื่อให้การแจ้งเตือนทำงานได้ดีขึ้น โดยมีการเปลี่ยนแปลงดังนี้:
- เพิ่มพารามิเตอร์สำหรับการแจ้งเตือนใหม่ๆ
//---- ตัวแปรสำหรับการแจ้งเตือน input uint NumberofBar=1; //จำนวนแท่งที่ใช้ในการส่งสัญญาณ input bool SoundON=true; //เปิดการแจ้งเตือนเสียง input uint NumberofAlerts=2; //จำนวนการแจ้งเตือน input bool EMailON=false; //เปิดการส่งสัญญาณผ่านอีเมล์ input bool PushON=false; //เปิดการส่งสัญญาณไปยังมือถือ
- เพิ่มฟังก์ชันใหม่ 3 ฟังก์ชันในส่วนท้ายของโค้ดตัวชี้วัด: 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); } //--- } //+------------------------------------------------------------------+ //| ฟังก์ชันสัญญาณขาย | //+------------------------------------------------------------------+ void SellSignal(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 SellSignal=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) 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); } //--- } //+------------------------------------------------------------------+ //| รับค่า timeframe เป็น string | //+------------------------------------------------------------------+ string GetStringTimeframe(ENUM_TIMEFRAMES timeframe) { //---- return(StringSubstr(EnumToString(timeframe),7,-1)); //---- }
- เพิ่มการเรียกใช้ฟังก์ชัน BuySignal() และ SellSignal() หลังจากรอบการคำนวณของตัวชี้วัดในบล็อก OnCalculate()
//--- 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 คือชื่อของบัฟเฟอร์สีสำหรับเก็บค่า index ของสีในรูปแบบของดัชนี
ส่วนการเรียกใช้ฟังก์ชัน BuySignal() และ SellSignal() จะใช้เพียงครั้งเดียวในบล็อก OnCalculate() ของโค้ดตัวชี้วัด
ตัวชี้วัดนี้ใช้คลาสจากไลบรารี SmoothAlgorithms.mqh (ให้คัดลอกไปที่ <terminal_data_folder>\MQL5\Include) ซึ่งได้มีการอธิบายอย่างละเอียดในบทความ "การเฉลี่ยราคาซีรีส์เพื่อการคำนวณกลางโดยไม่ใช้บัฟเฟอร์เพิ่มเติม".

Fig1. ตัวชี้วัด ColorJFatl_Digit_Alert บนกราฟ
Fig.2. ตัวชี้วัด ColorJFatl_Digit_Alert กำลังสร้างการแจ้งเตือน.
โพสต์ที่เกี่ยวข้อง
- เครื่องมือ Open Range Breakout สำหรับ MetaTrader 5
- เครื่องมือ Flexible Momentum สำหรับ MT5 - ช่วยเทรดได้แม่นยำขึ้น
- ปรับ MACD ให้แม่นยำยิ่งขึ้นด้วยการแจ้งเตือนสัญญาณแบบเรียลไทม์บนมือถือ
- รีวิว X2MA_HTF_Signal_BG อินดิเคเตอร์สำหรับ MetaTrader 5
- WeightOscillator_Alert: อินดิเคเตอร์สำหรับ MetaTrader 5 ที่มีการแจ้งเตือน
