DSSBressertSignAlert: สัญญาณการซื้อขายที่คุณไม่ควรพลาดใน MetaTrader 5

Mike 2016.09.19 21:41 87 0 0
ไฟล์แนบ

สวัสดีครับเพื่อนๆ ชาวเทรดเดอร์ทุกคน! วันนี้เราจะมาพูดถึง DSSBressertSignAlert ซึ่งเป็น อินดิเคเตอร์ ที่ช่วยให้คุณสามารถรับสัญญาณการซื้อขายได้อย่างมีประสิทธิภาพใน MetaTrader 5.

อินดิเคเตอร์นี้ใช้ DSSBressert เป็นพื้นฐาน โดยมีฟังก์ชันการแจ้งเตือนต่างๆ เช่น การส่งอีเมล์และการแจ้งเตือนผ่านมือถือ เพื่อให้คุณไม่พลาดทุกโอกาสในการเทรด!

ต่อไปนี้คือการเปลี่ยนแปลงที่ได้ทำในโค้ดอินดิเคเตอร์เพื่อให้สามารถส่งการแจ้งเตือนได้:

  1. เพิ่มพารามิเตอร์ใหม่ในโค้ดอินดิเคเตอร์:
    inputuint NumberofBar=1;//จำนวนบาร์สำหรับสัญญาณinputbool SoundON=true; //เปิดการแจ้งเตือนเสียงinputuint NumberofAlerts=2;//จำนวนการแจ้งเตือนinputbool EMailON=false; //เปิดการส่งสัญญาณทางอีเมล์inputbool PushON=false; //เปิดการส่งสัญญาณไปยังมือถือ
  2. เพิ่มฟังก์ชันใหม่สามตัวในโค้ดอินดิเคเตอร์: BuySignal(), SellSignal() และ GetStringTimeframe():
    //+------------------------------------------------------------------+//| ฟังก์ชันสัญญาณซื้อ                                              |//+------------------------------------------------------------------+void BuySignal(string SignalSirname,      // ชื่ออินดิเคเตอร์สำหรับข้อความอีเมล์และการแจ้งเตือน
                   double &BuyArrow[],        // บัฟเฟอร์อินดิเคเตอร์สำหรับสัญญาณซื้อ
                   constint Rates_total,     // จำนวนบาร์ปัจจุบัน
                   constint Prev_calculated, // จำนวนบาร์ในติกรอบก่อน
                   constdouble &Close[],     // ราคาปิด
                   constint &Spread[])       // สเปรด
      {
    u//---
       staticuint 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;
          doubleAsk=Close[index];
          doubleBid=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);
         }
    
    u//---
      }
    //+------------------------------------------------------------------+//| ฟังก์ชันสัญญาณขาย                                               |//+------------------------------------------------------------------+void SellSignal(string SignalSirname,      // ชื่ออินดิเคเตอร์สำหรับข้อความอีเมล์และการแจ้งเตือน
                    double &SellArrow[],       // บัฟเฟอร์อินดิเคเตอร์สำหรับสัญญาณขาย
                    constint Rates_total,     // จำนวนบาร์ปัจจุบัน
                    constint Prev_calculated, // จำนวนบาร์ในติกรอบก่อน
                    constdouble &Close[],     // ราคาปิด
                    constint &Spread[])       // สเปรด
      {
    u//---
       staticuint 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;
          doubleAsk=Close[index];
          doubleBid=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);
         }
    u//---
      }
    //+------------------------------------------------------------------+//|  การรับช่วงเวลาทางการตลาดในรูปแบบสตริง                               |//+------------------------------------------------------------------+string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
      {
    //----
       return(StringSubstr(EnumToString(timeframe),7,-1));
    //----
      }
    
  3. เพิ่มการเรียกใช้งานฟังก์ชัน BuySignal() และ SellSignal() หลังจากรอบการคำนวณของอินดิเคเตอร์ในบล็อค OnCalculate():
    u//---     
       BuySignal("DSSBressertSignAlert",BuyBuffer,rates_total,prev_calculated,close,spread);
       SellSignal("DSSBressertSignAlert",SellBuffer,rates_total,prev_calculated,close,spread);
    u//---

โดย BuyBuffer และ SellBuffer เป็นชื่อของบัฟเฟอร์อินดิเคเตอร์ที่ใช้เก็บสัญญาณการซื้อและขาย ถ้ามีค่าเป็นศูนย์หรือ EMPTY_VALUE ต้องตั้งค่าให้ถูกต้องในบัฟเฟอร์ของอินดิเคเตอร์

นอกจากนี้ยังใช้คลาสจากไลบรารี SmoothAlgorithms.mqh (คัดลอกไปที่ <terminal_data_folder>\MQL5\Include) ซึ่งได้มีการอธิบายการใช้งานอย่างละเอียดในบทความ "Averaging Price Series for Intermediate Calculations Without Using Additional Buffers".


Fig.1. The DSSBressertSignAlert indicator on the chart

Fig.1. อินดิเคเตอร์ DSSBressertSignAlert บนกราฟ

Fig.2. The DSSBressertSignAlert indicator. Generating alerts.

Fig.2. อินดิเคเตอร์ DSSBressertSignAlert สร้างการแจ้งเตือน.

รายการ
ความคิดเห็น 0