JBrainTrend1Stop เป็นตัวบ่งชี้แนวโน้มที่มีฟีเจอร์แจ้งเตือน, อีเมล และการแจ้งเตือนผ่านมือถือ
การเปลี่ยนแปลงที่ทำในโค้ดของตัวบ่งชี้เพื่อให้มีการแจ้งเตือน, ข้อความอีเมล และการแจ้งเตือนผ่านมือถือมีดังนี้:
- เพิ่มพารามิเตอร์ใหม่
- เพิ่มฟังก์ชันใหม่สามฟังก์ชันที่ท้ายโค้ดของตัวบ่งชี้: BuySignal(), SellSignal() และ GetStringTimeframe()
- เพิ่มการเรียกฟังก์ชัน BuySignal() และ SellSignal() หลังจากการคำนวณของตัวบ่งชี้ในบล็อก OnCalculate()
- เครื่องมือ Open Range Breakout สำหรับ MetaTrader 5
- ID Lite Info MA – ตัวช่วยวิเคราะห์ Moving Average สำหรับ MetaTrader 5
- Volume Profile + Range v6.0: เครื่องมือวิเคราะห์การซื้อขายใน MetaTrader 5
- BrainTrend1Sig_Alert: สัญญาณแจ้งเตือนสำหรับ MetaTrader 5
- ค้นหา Pin Bar: เครื่องมือวิเคราะห์สำหรับ MetaTrader 5
input uint NumberofBar=1;//จำนวนแท่งสำหรับสัญญาณ input bool SoundON=true; //เปิดใช้งานการแจ้งเตือน input uint NumberofAlerts=2;//จำนวนการแจ้งเตือน input bool EMailON=false; //เปิดใช้งานการส่งสัญญาณทางอีเมล input bool PushON=false; //เปิดใช้งานการส่งสัญญาณไปยังอุปกรณ์มือถือ
//+------------------------------------------------------------------+
//| ฟังก์ชันสัญญาณซื้อ |
//+------------------------------------------------------------------+
void BuySignal(string SignalSirname, // ชื่อของตัวบ่งชี้สำหรับข้อความอีเมลและการแจ้งเตือน
double &BuyArrow[], // บัฟเฟอร์สำหรับสัญญาณแนวโน้มขึ้น
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 BuySignal=false;
bool SeriesTest=ArrayGetAsSeries(BuyArrow);
int index,index1;
if(SeriesTest)
{
index=int(NumberofBar);
index1=index+1;
}
else
{
index=Rates_total-int(NumberofBar)-1;
index1=index-1;
}
if(SellArrow[index1] && SellArrow[index1]!=EMPTY_VALUE && BuyArrow[index] && 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+=_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 &SellArrow[], // บัฟเฟอร์สำหรับสัญญาณแนวโน้มลง
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 SellSignal=false;
bool SeriesTest=ArrayGetAsSeries(SellArrow);
int index,index1;
if(SeriesTest)
{
index=int(NumberofBar);
index1=index+1;
}
else
{
index=Rates_total-int(NumberofBar)-1;
index1=index-1;
}
if(BuyArrow[index1] && BuyArrow[index1]!=EMPTY_VALUE && SellArrow[index] && 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+=_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));
//----
}
//| ฟังก์ชันสัญญาณซื้อ |
//+------------------------------------------------------------------+
void BuySignal(string SignalSirname, // ชื่อของตัวบ่งชี้สำหรับข้อความอีเมลและการแจ้งเตือน
double &BuyArrow[], // บัฟเฟอร์สำหรับสัญญาณแนวโน้มขึ้น
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 BuySignal=false;
bool SeriesTest=ArrayGetAsSeries(BuyArrow);
int index,index1;
if(SeriesTest)
{
index=int(NumberofBar);
index1=index+1;
}
else
{
index=Rates_total-int(NumberofBar)-1;
index1=index-1;
}
if(SellArrow[index1] && SellArrow[index1]!=EMPTY_VALUE && BuyArrow[index] && 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+=_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 &SellArrow[], // บัฟเฟอร์สำหรับสัญญาณแนวโน้มลง
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 SellSignal=false;
bool SeriesTest=ArrayGetAsSeries(SellArrow);
int index,index1;
if(SeriesTest)
{
index=int(NumberofBar);
index1=index+1;
}
else
{
index=Rates_total-int(NumberofBar)-1;
index1=index-1;
}
if(BuyArrow[index1] && BuyArrow[index1]!=EMPTY_VALUE && SellArrow[index] && 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+=_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("JBrainTrend1Stop_Alert",BuyStopBuffer,SellStopBuffer,rates_total,prev_calculated,close,spread);
SellSignal("JBrainTrend1Stop_Alert",SellStopBuffer,BuyStopBuffer,rates_total,prev_calculated,close,spread);
//---
BuySignal("JBrainTrend1Stop_Alert",BuyStopBuffer,SellStopBuffer,rates_total,prev_calculated,close,spread);
SellSignal("JBrainTrend1Stop_Alert",SellStopBuffer,BuyStopBuffer,rates_total,prev_calculated,close,spread);
//---
โดยที่ BuyStopBuffer และ SellStopBuffer คือชื่อของบัฟเฟอร์ของตัวบ่งชี้สำหรับเก็บสัญญาณแนวโน้มขึ้นและลง (เส้นหยุดสำหรับการซื้อและขาย) ค่า 0 หรือ EMPTY_VALUE จะต้องอยู่ในบัฟเฟอร์ของตัวบ่งชี้หากไม่มีแนวโน้มที่เหมาะสม
คาดว่าจะมีการเรียกใช้ฟังก์ชัน BuySignal() และ SellSignal() เพียงครั้งเดียวในบล็อก OnCalculate() ของโค้ดตัวบ่งชี้
ให้วางไฟล์ตัวบ่งชี้ JMA.mq5 ที่ compiled ใน MQL5\Indicators

Fig.1. ตัวบ่งชี้ JBrainTrend1Stop_Alert บนกราฟ

Fig.2. ตัวบ่งชี้ JBrainTrend1Stop_Alert กำลังสร้างการแจ้งเตือน