ผู้เขียนจริง: วิศวกร วาดาห์ อัตตาร์
วาดาห์ อัตตาร์ เทรนด์ เป็นอินดิเคเตอร์ที่มีฟังก์ชันแจ้งเตือน, อีเมล และการแจ้งเตือนผ่านมือถือ
การเปลี่ยนแปลงที่ได้ทำในโค้ดอินดิเคเตอร์นี้เพื่อเพิ่มฟังก์ชันการแจ้งเตือน, อีเมล และการแจ้งเตือนผ่านมือถือมีดังนี้:
- เพิ่มพารามิเตอร์การตั้งค่าใหม่สำหรับการแจ้งเตือน ดังนี้:
//---- การตั้งค่าสำหรับการแจ้งเตือน 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+=_Point*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+=_Point*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("Waddah_Attar_Trend_Alert",ColorIndBuffer,0,rates_total,prev_calculated,close,spread);
SellSignal("Waddah_Attar_Trend_Alert",ColorIndBuffer,1,rates_total,prev_calculated,close,spread);
//---
โดยที่ ColorIndBuffer คือชื่อของดัชนีสีสำหรับเก็บสีของเส้นเป็นดัชนี, ส่วน 0 และ 1 คือจำนวนสีในดัชนีสี
คาดว่าจะมีการเรียกใช้งานฟังก์ชัน BuySignal() และ SellSignal() เพียงครั้งเดียวในบล็อก OnCalculate() ของโค้ดอินดิเคเตอร์
อินดิเคเตอร์นี้ใช้คลาส SmoothAlgorithms.mqh (ให้คัดลอกไปที่ <terminal_data_folder>\MQL5\Include) โดยการใช้คลาสนี้ได้ถูกอธิบายอย่างละเอียดในบทความ "การเฉลี่ยราคาซีรีส์สำหรับการคำนวณระหว่างโดยไม่ต้องใช้บัฟเฟอร์เพิ่มเติม".

Fig.1. อินดิเคเตอร์วาดาห์ อัตตาร์ เทรนด์ อเลิร์ต บนกราฟ
Fig.2. อินดิเคเตอร์วาดาห์ อัตตาร์ เทรนด์ อเลิร์ต. การสร้างการแจ้งเตือน
โพสต์ที่เกี่ยวข้อง
- เครื่องมือ Master Tools - อินดิเคเตอร์สำหรับ MetaTrader 4
- เครื่องมือ Open Range Breakout สำหรับ MetaTrader 5
- FX Multi-Meter II: เครื่องมือช่วยเทรดที่ครบครันสำหรับนักลงทุน
- สัญญาณข้ามค่าเฉลี่ยเคลื่อนที่ครั้งเดียว - เครื่องมือช่วยเทรดใน MetaTrader 4
- WeightOscillator_Alert: อินดิเคเตอร์สำหรับ MetaTrader 5 ที่มีการแจ้งเตือน
