หน้าแรก ตัวชี้วัดทางเทคนิค โพสต์

BalanceOfPower_Histogram_Alert - ตัวช่วยเทรดด้วยสัญญาณใน MetaTrader 5

ไฟล์แนบ
16403.zip (22.71 KB, ดาวน์โหลด 0 ครั้ง)

ผู้เขียนจริง: RoboFx

วันนี้เรามาทำความรู้จักกับ Indicator Balance of Power (BOP) ที่จะช่วยให้การเทรดของคุณง่ายขึ้นด้วยรูปแบบ histogram แสดงถึงความแข็งแกร่งและทิศทางของแนวโน้มในขณะนี้ พร้อมฟีเจอร์การแจ้งเตือนทั้งอีเมลและการแจ้งเตือนผ่านมือถือ!

Histogram จะถูกจัดสีตามค่าพารามิเตอร์ที่ป้อนสำหรับระดับที่ซื้อเกินและขายเกิน และทิศทางการเคลื่อนไหวของ histogram ด้วยกัน

ในการพัฒนา indicator นี้ได้มีการปรับแต่งโค้ดเพื่อให้รองรับฟังก์ชันแจ้งเตือน อีเมล และการส่งการแจ้งเตือนผ่านมือถือ โดยมีการเปลี่ยนแปลงดังนี้:

  1. เพิ่มพารามิเตอร์ใหม่สำหรับการแจ้งเตือน:
    //---- ตัวแปรสำหรับแจ้งเตือน 
    input uint NumberofBar=1;                    //จำนวนบาร์สำหรับสัญญาณ
    input bool SoundON=true;                    //เปิดใช้งานการแจ้งเตือน
    input uint NumberofAlerts=2;                 //จำนวนการแจ้งเตือน
    input bool EMailON=false;                    //เปิดใช้งานการส่งสัญญาณทางอีเมล
    input bool PushON=false;                    //เปิดใช้งานการส่งสัญญาณไปยังมือถือ
    
  2. เพิ่มฟังก์ชันใหม่สามฟังก์ชันในตอนท้ายของโค้ดของ indicator: BuySignal(), SellSignal() และ GetStringTimeframe()
    //+------------------------------------------------------------------+
    //| ฟังก์ชัน Buy signal                                               |
    //+------------------------------------------------------------------+
    void BuySignal(string SignalSirname,// ชื่อของ indicator สำหรับข้อความอีเมลและการแจ้งเตือน
                   double &ColorArray[],// ตัวเก็บสี
                   int ColorIndex,// ดัชนีสีในตัวเก็บสีเพื่อสร้างสัญญาณ
                   const int Rates_total,     // จำนวนบาร์ปัจจุบัน
                   const int Prev_calculated, // จำนวนบาร์ใน tick ก่อนหน้า
                   const double &Close[],     // ราคาปิด
                   const int &Spread[])       // 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);
         }
    
    //---
      }
    //+------------------------------------------------------------------+
    //| ฟังก์ชัน Sell signal                                             |
    //+------------------------------------------------------------------+
    void SellSignal(string SignalSirname,      // ชื่อของ indicator สำหรับข้อความอีเมลและการแจ้งเตือน
                    double &ColorArray[],       // ตัวเก็บสี
                    int ColorIndex,             // ดัชนีสีในตัวเก็บสีเพื่อสร้างสัญญาณ
                    const int Rates_total,     // จำนวนบาร์ปัจจุบัน
                    const int Prev_calculated, // จำนวนบาร์ใน tick ก่อนหน้า
                    const double &Close[],     // ราคาปิด
                    const int &Spread[])       // 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 GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
      {
    //----
       return(StringSubstr(EnumToString(timeframe),7,-1));
    //----
      }
    
  3. เพิ่มการเรียกใช้ฟังก์ชัน BuySignal() และ SellSignal() หลังจากการคำนวณ indicator ในบล็อก OnCalculate()
    //---     
       BuySignal("BalanceOfPower_Histogram_Alert",ColorIndBuffer,0,rates_total,prev_calculated,close,spread);
       SellSignal("BalanceOfPower_Histogram_Alert",ColorIndBuffer,7,rates_total,prev_calculated,close,spread);
    //---
    

ซึ่ง ColorIndBuffer คือชื่อของตัวเก็บสีสำหรับเก็บสีของเทียนในรูปแบบของดัชนี

โดยคาดว่าการเรียกใช้ฟังก์ชัน BuySignal() และ SellSignal() จะมีเพียงหนึ่งครั้งในบล็อก OnCalculate() ของโค้ด indicator นี้

Indicator นี้ยังใช้คลาสจาก SmoothAlgorithms.mqh (กรุณาคัดลอกไปที่ <terminal_data_folder>\MQL5\Include) ซึ่งมีการอธิบายการใช้งานคลาสอย่างละเอียดในบทความ "การเฉลี่ยซีรีส์ราคาเพื่อการคำนวณกลาง โดยไม่ใช้บัฟเฟอร์เพิ่มเติม".

โดย indicator นี้ถูกเขียนขึ้นใน MQL5 และถูกเผยแพร่ครั้งแรกใน Code Base เมื่อวันที่ 07.02.2013.

Fig1. ตัวชี้วัด BalanceOfPower_Histogram_Alert บนกราฟ

Fig1. ตัวชี้วัด BalanceOfPower_Histogram_Alert บนกราฟ

Fig.2. ตัวชี้วัด BalanceOfPower_Histogram_Alert สร้างการแจ้งเตือน

Fig.2. ตัวชี้วัด BalanceOfPower_Histogram_Alert สร้างการแจ้งเตือน.

โพสต์ที่เกี่ยวข้อง

ความคิดเห็น (0)