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

ColorParabolic_Alert: ตัวช่วยในการเทรดที่คุณไม่ควรพลาด

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

วันนี้เรามี ColorParabolic ซึ่งเป็นอินดิเคเตอร์ที่มาพร้อมกับสัญญาณเตือนให้คุณได้รู้เมื่อถึงเวลาที่เหมาะสมในการเปิดหรือปิดการเทรด

เราจะพาคุณไปดูการปรับปรุงที่ทำกับโค้ดของอินดิเคเตอร์นี้เพื่อให้สามารถส่งสัญญาณเตือนทางอีเมลและแจ้งเตือนผ่านมือถือได้:

  1. เพิ่มพารามิเตอร์ใหม่ ๆ ในการตั้งค่า

    input uint NumberofBar=1;//จำนวนบาร์สำหรับสัญญาณ
    input bool SoundON=true; //เปิดการแจ้งเตือนเสียง
    input uint NumberofAlerts=2;//จำนวนการแจ้งเตือน
    input bool EMailON=false; //เปิดการส่งสัญญาณทางอีเมล
    input bool PushON=false; //เปิดการส่งสัญญาณไปยังอุปกรณ์มือถือ
    
  2. เพิ่มฟังก์ชันใหม่สามตัวในตอนท้ายของโค้ดอินดิเคเตอร์: BuySignal(), SellSignal() และ GetStringTimeframe()

    //+------------------------------------------------------------------+
    //| ฟังก์ชันสัญญาณซื้อ                                            |
    //+------------------------------------------------------------------+
    void BuySignal(string SignalSirname,      // ชื่อของอินดิเคเตอร์สำหรับอีเมลและการแจ้งเตือน
                   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 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;
          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]*_Point;
          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[],       // ตัวบัฟเฟอร์อินดิเคเตอร์สำหรับสัญญาณขาย
                    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;
       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;
          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]*_Point;
          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));
    //----
      }
    
  3. เพิ่มการเรียกใช้งานฟังก์ชัน BuySignal() และ SellSignal() หลังจากการคำนวณอินดิเคเตอร์ในบล็อก OnCalculate()

    //---     
       BuySignal("ColorParabolic_Alert",BuyBuffer,rates_total,prev_calculated,close,spread);
       SellSignal("ColorParabolic_Alert",SellBuffer,rates_total,prev_calculated,close,spread);
    //---     
    

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

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

Fig1. ColorParabolic_Alert on a chart

Fig1. ColorParabolic_Alert บนกราฟ

Fig.2. The ColorParabolic_Alert indicator. Generating alerts.

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

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

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