สวัสดีครับเพื่อนๆ นักเทรดทุกคน! วันนี้เรามาพูดถึง WeightOscillator อินดิเคเตอร์ที่มีฟีเจอร์แจ้งเตือน ซึ่งสามารถส่งอีเมล์และการแจ้งเตือนไปยังมือถือได้อย่างสะดวกสบาย
สำหรับการอัปเดตในเวอร์ชันนี้ เราได้ทำการเปลี่ยนแปลงโค้ดบางส่วนเพื่อเพิ่มฟังก์ชันการแจ้งเตือน อีเมล และการแจ้งเตือนที่ส่งไปยังมือถือดังนี้:
- ประกาศตัวแปรสำหรับตัวเลือกการสร้างสัญญาณของอินดิเคเตอร์ในระดับโกลบอลก่อนที่จะประกาศตัวแปรอินพุต //+----------------------------------------------------+
//| Enumeration for signal generation options |
//+----------------------------------------------------+
enum ENUM_SIGNAL_MODE
{
MODE_SIGNAL, //สัญญาณการเบรก
MODE_TREND //สัญญาณการเบรกและเทรนด์
}; - เพิ่มพารามิเตอร์อินพุตใหม่ //---- ตัวแปรอินพุตสำหรับการแจ้งเตือน
input ENUM_SIGNAL_MODE SignMode=MODE_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 &ColorArray[],// บัฟเฟอร์สี
int ColorIndex,// ดัชนีสีในบัฟเฟอร์สีเพื่อสร้างสัญญาณ
const int Rates_total, // จำนวนบาร์ปัจจุบัน
const int Prev_calculated, // จำนวนบาร์ในติ๊กก่อนหน้า
const double &Close[], // ราคา 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(SignMode==MODE_SIGNAL)
{
if(ColorArray[index1]!=ColorIndex && ColorArray[index]==ColorIndex) BuySignal=true;
}
else
{
if(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+=_Point*Spread[index];
string sAsk=DoubleToString(Ask,_Digits);
string sBid=DoubleToString(Bid,_Digits);
string sPeriod=GetStringTimeframe(ChartPeriod());
if(SignMode==MODE_SIGNAL || (SignMode==MODE_TREND && ColorArray[index1]!=ColorIndex))
{
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);
}
else
{
if(SoundON) Alert("Up Trend signal \n Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod);
if(EMailON) SendMail(SignalSirname+": Up Trend signal alert","BUY signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
if(PushON) SendNotification(SignalSirname+": Up Trend 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[], // ราคา 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(SignMode==MODE_SIGNAL)
{
if(ColorArray[index1]!=ColorIndex && ColorArray[index]==ColorIndex) SellSignal=true;
}
else
{
if(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+=_Point*Spread[index];
string sAsk=DoubleToString(Ask,_Digits);
string sBid=DoubleToString(Bid,_Digits);
string sPeriod=GetStringTimeframe(ChartPeriod());
if(SignMode==MODE_SIGNAL || (SignMode==MODE_TREND && ColorArray[index1]!=ColorIndex))
{
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);
}
else
{
if(SoundON) Alert("Down trend signal \n Ask=",Ask,"\n Bid=",Bid,"\n currtime=",text,"\n Symbol=",Symbol()," Period=",sPeriod);
if(EMailON) SendMail(SignalSirname+": Down trend signal alert","SELL signal at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
if(PushON) SendNotification(SignalSirname+": Down trend 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("WeightOscillator_Alert",ColorBuffer,0,rates_total,prev_calculated,close,spread);
SellSignal("WeightOscillator_Alert",ColorBuffer,4,rates_total,prev_calculated,close,spread);
//---
โดย ColorBuffer คือชื่อของบัฟเฟอร์สีสำหรับเก็บสีของอินดิเคเตอร์ โดยค่าที่ 0 และ 4 คือหมายเลขสีในบัฟเฟอร์นี้ซึ่งอินดิเคเตอร์อยู่ในโซนซื้อมากเกินไปและขายมากเกินไปตามลำดับ
คาดว่า จะมีการเรียกใช้ฟังก์ชัน BuySignal() และ SellSignal() เพียงครั้งเดียวในบล็อก OnCalculate() ของโค้ดอินดิเคเตอร์
อินดิเคเตอร์นี้ใช้คลาสจากไลบรารี SmoothAlgorithms.mqh (ให้คัดลอกไปที่ <terminal_data_folder>\MQL5\Include) โดยการใช้คลาสเหล่านี้ได้ถูกอธิบายอย่างละเอียดในบทความ "Averaging Price Series for Intermediate Calculations Without Using Additional Buffers".

Fig1. อินดิเคเตอร์ WeightOscillator_Alert บนกราฟ

Fig.2. อินดิเคเตอร์ WeightOscillator_Alert การสร้างการแจ้งเตือนสำหรับสัญญาณเบรก

Fig.3. อินดิเคเตอร์ WeightOscillator_Alert การสร้างการแจ้งเตือนสำหรับสัญญาณเทรนด์
โพสต์ที่เกี่ยวข้อง
- เครื่องมือ Open Range Breakout สำหรับ MetaTrader 5
- รีวิว X2MA_HTF_Signal_BG อินดิเคเตอร์สำหรับ MetaTrader 5
- Volume Profile + Range v6.0: เครื่องมือวิเคราะห์การซื้อขายใน MetaTrader 5
- เครื่องมือแสดงความยาวของไส้เทียนใน MT5 สำหรับเทรดเดอร์
- BeginnerAlert: อินดิเคเตอร์ที่ช่วยเทรดเดอร์มือใหม่ใน MetaTrader 5