보조지표 게시글

ColorXdinMA_Alert: 메타트레이더 5를 위한 알림 지표

첨부파일
17111.zip (22.91 KB, 다운로드 0회)

작성자: dimeon

ColorXdinMA는 알림 기능이 포함된 트렌드 이동 평균 지표로, 이메일 및 모바일 푸시 알림을 제공합니다.

이 지표에 알림, 이메일 메시지 및 푸시 알림 기능을 구현하기 위해 다음과 같은 코드 변경이 이루어졌습니다:

  1. 지표 신호 생성 옵션을 위한 열거형(enum)을 입력 변수 선언 전에 전역 범위로 선언했습니다.
    //+----------------------------------------------------+
    //| 신호 생성 옵션을 위한 열거형  |
    //+----------------------------------------------------+
    enum ENUM_SIGNAL_MODE
      {
        MODE_SIGNAL,  //돌파 신호
        MODE_TREND    //돌파 및 트렌드 신호
      };
  2. 새로운 입력 매개변수를 도입했습니다.
    //---- 알림을 위한 입력 변수
    input ENUM_SIGNAL_MODE SignMode=MODE_SIGNAL; //신호 생성 모드
    input uint NumberofBar=1;                    //신호 생성을 위한 바 수
    input bool SoundON=true;                     //알림 활성화
    input uint NumberofAlerts=2;                     //알림 수
    input bool EMailON=false;                    //신호 이메일 발송 활성화
    input bool PushON=false;                     //모바일 기기로 신호 전송 활성화
  3. 지표 코드 끝에 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(SignMode==MODE_SIGNAL)
         {
          if(ColorArray[index1]!=ColorIndex && ColorArray[index]==ColorIndex) BuySignal=true;
         }
       else
         {
          if(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(SignMode==MODE_SIGNAL || (SignMode==MODE_TREND && ColorArray[index1]!=ColorIndex))
            {
             if(SoundON) Alert("BUY 신호 Ask=",Ask," Bid=",Bid," 현재시간=",text," 심볼=",Symbol()," 주기=",sPeriod);
             if(EMailON) SendMail(SignalSirname+": BUY 신호 알림","BUY 신호 at Ask="+sAsk+", Bid="+sBid+", 날짜="+text+" 심볼="+Symbol()+" 주기="+sPeriod);
             if(PushON) SendNotification(SignalSirname+": BUY 신호 at Ask="+sAsk+", Bid="+sBid+", 날짜="+text+" 심볼="+Symbol()+" 주기="+sPeriod);
            }
          else
            {
             if(SoundON) Alert("상승 트렌드 신호 Ask=",Ask," Bid=",Bid," 현재시간=",text," 심볼=",Symbol()," 주기=",sPeriod);
             if(EMailON) SendMail(SignalSirname+": 상승 트렌드 신호 알림","BUY 신호 at Ask="+sAsk+", Bid="+sBid+", 날짜="+text+" 심볼="+Symbol()+" 주기="+sPeriod);
             if(PushON) SendNotification(SignalSirname+": 상승 트렌드 신호 at Ask="+sAsk+", Bid="+sBid+", 날짜="+text+" 심볼="+Symbol()+" 주기="+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(SignMode==MODE_SIGNAL)
         {
          if(ColorArray[index1]!=ColorIndex && ColorArray[index]==ColorIndex) SellSignal=true;
         }
       else
         {
          if(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(SignMode==MODE_SIGNAL || (SignMode==MODE_TREND && ColorArray[index1]!=ColorIndex))
            {
             if(SoundON) Alert("SELL 신호 Ask=",Ask," Bid=",Bid," 현재시간=",text," 심볼=",Symbol()," 주기=",sPeriod);
             if(EMailON) SendMail(SignalSirname+": SELL 신호 알림","SELL 신호 at Ask="+sAsk+", Bid="+sBid+", 날짜="+text+" 심볼="+Symbol()+" 주기="+sPeriod);
             if(PushON) SendNotification(SignalSirname+": SELL 신호 at Ask="+sAsk+", Bid="+sBid+", 날짜="+text+" 심볼="+Symbol()+" 주기="+sPeriod);
            }
          else
            {
             if(SoundON) Alert("하락 트렌드 신호 Ask=",Ask," Bid=",Bid," 현재시간=",text," 심볼=",Symbol()," 주기=",sPeriod);
             if(EMailON) SendMail(SignalSirname+": 하락 트렌드 신호 알림","SELL 신호 at Ask="+sAsk+", Bid="+sBid+", 날짜="+text+" 심볼="+Symbol()+" 주기="+sPeriod);
             if(PushON) SendNotification(SignalSirname+": 하락 트렌드 신호 at Ask="+sAsk+", Bid="+sBid+", 날짜="+text+" 심볼="+Symbol()+" 주기="+sPeriod);
            }
         }
    //---
      }
    //+------------------------------------------------------------------+
    //| 시간 프레임을 문자열로 얻기 |
    //+------------------------------------------------------------------+
    string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
      {
    //----
       return(StringSubstr(EnumToString(timeframe),7,-1));
    //----
      }
  4. 지표 계산 주기 후 BuySignal() 및 SellSignal() 함수를 호출하는 코드를 추가했습니다.
    //---    
       BuySignal("ColorXdinMA_Alert",ColorXdinMA,1,rates_total,prev_calculated,close,spread);
       SellSignal("ColorXdinMA_Alert",ColorXdinMA,2,rates_total,prev_calculated,close,spread);
    //--- 

ColorXdinMA는 지표 색상을 저장하기 위한 색상 인덱스 버퍼의 이름입니다. 1과 2는 각각 이동 평균이 상승 또는 하락할 때의 색상 수를 나타냅니다.

지표 코드의 OnCalculate() 블록에서 BuySignal() 및 SellSignal() 함수는 각각 한 번만 호출됩니다.

이 지표는 SmoothAlgorithms.mqh 라이브러리의 클래스를 사용합니다. 라이브러리 파일을 <terminal_data_folder>\MQL5\Include에 복사해야 합니다. 클래스 사용 방법은 "추가 버퍼 없이 중간 계산을 위한 가격 시계열 평균화" 기사에서 자세히 설명되어 있습니다.

Fig1. ColorXdinMA_Alert 차트 지표

Fig1. ColorXdinMA_Alert 차트 지표

Fig.2. ColorXdinMA_Alert 지표. 돌파 신호 알림 생성

Fig.2. ColorXdinMA_Alert 지표. 돌파 신호 알림 생성

Fig.3. ColorXdinMA_Alert 지표. 트렌드 신호 알림 생성

Fig.3. ColorXdinMA_Alert 지표. 트렌드 신호 알림 생성

연관 포스트

댓글 (0)