보조지표 게시글

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

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

JBrainTrend1Stop은 트렌드 지표로, 알림, 이메일 및 푸시 알림 기능을 제공합니다.

알림, 이메일 메시지 및 푸시 알림을 구현하기 위해 지표 코드에 다음과 같은 변경 사항이 적용되었습니다:

  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[],        // 상승 신호를 위한 지표 버퍼
                   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 신호 Ask=",Ask," Bid=",Bid," currtime=",text," Symbol=",Symbol()," Period=",sPeriod);
          if(EMailON) SendMail(SignalSirname+": BUY 신호 알림","BUY 신호 at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
          if(PushON) SendNotification(SignalSirname+": BUY 신호 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 신호 Ask=",Ask," Bid=",Bid," currtime=",text," Symbol=",Symbol()," Period=",sPeriod);
          if(EMailON) SendMail(SignalSirname+": SELL 신호 알림","SELL 신호 at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
          if(PushON) SendNotification(SignalSirname+": SELL 신호 at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
         }
    //---
      }
    //+------------------------------------------------------------------+
    //|  시간 프레임을 문자열로 변환                               |
    //+------------------------------------------------------------------+
    string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
      {
    //----
       return(StringSubstr(EnumToString(timeframe),7,-1));
    //----
      }
  3. OnCalculate() 블록에서 BuySignal() 및 SellSignal() 함수 호출 추가
    //---    
       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가 존재해야 합니다.

OnCalculate() 블록에서 BuySignal() 및 SellSignal() 함수의 단일 호출만 사용된다고 가정합니다.

JMA.mq5 지표의 컴파일된 파일을 MQL5\Indicators 폴더에 배치하세요.


Fig.1. JBrainTrend1Stop_Alert 지표 차트

Fig.1. JBrainTrend1Stop_Alert 지표 차트

Fig.2. JBrainTrend1Stop_Alert 지표. 알림 생성

Fig.2. JBrainTrend1Stop_Alert 지표. 알림 생성

연관 포스트

댓글 (0)