보조지표 게시글

Balance of Power 히스토그램 알림: MetaTrader 5에서의 활용

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

작성자: RoboFx

Balance of Power (BOP) 지표는 현재의 추세의 강도와 방향을 나타내는 색상 히스토그램으로, 알림 기능이 포함되어 있어 이메일과 모바일 기기로 푸시 알림을 보낼 수 있습니다. 히스토그램은 과매도 및 과매수 레벨에 대한 입력 파라미터에 따라 색상이 지정되며, 히스토그램의 움직임 방향에 따라 변합니다.

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

  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 &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(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);
         }
    
    //---
      }
    //+------------------------------------------------------------------+
    //| 매도 신호 함수                                             |
    //+------------------------------------------------------------------+
    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(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);
         }
    //---
      }
    //+------------------------------------------------------------------+
    //|  시간프레임을 문자열로 변환하기                               |
    //+------------------------------------------------------------------+
    string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
      {
    //----
       return(StringSubstr(EnumToString(timeframe),7,-1));
    //----
      }
    
  3. OnCalculate() 블록에서 BuySignal() 및 SellSignal() 함수 호출 추가:
    //---     
       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() 블록에서 한 번만 호출될 것으로 가정합니다.

이 지표는 SmoothAlgorithms.mqh 라이브러리의 클래스를 사용하며 (\MQL5\Include에 복사), 이 클래스의 사용법은 "추가 버퍼 없이 중간 계산을 위한 가격 시리즈 평균화"라는 기사에서 자세히 설명되어 있습니다.

원래 이 지표는 MQL5로 작성되었으며, 2013년 2월 7일에 코드 베이스에 처음 게시되었습니다.

Fig1. BalanceOfPower_Histogram_Alert 지표 차트

Fig1. BalanceOfPower_Histogram_Alert 지표 차트

Fig.2 BalanceOfPower_Histogram_Alert 지표 알림 생성

Fig.2 BalanceOfPower_Histogram_Alert 지표 알림 생성.

연관 포스트

댓글 (0)