WeightOscillator는 알림 기능을 갖춘 추세 지표로, 이메일과 모바일 푸시 알림을 지원합니다. 이 지표를 사용하면 중요한 거래 신호를 놓치지 않을 수 있습니다.
알림, 이메일 메시지 및 푸시 알림 기능을 구현하기 위해 지표 코드에 다음과 같은 변경 사항이 적용되었습니다:
- 신호 생성 옵션을 위한 열거형이 입력 변수 선언 전에 전역 범위에서 선언되었습니다.//+----------------------------------------------------+
//| 신호 생성 옵션을 위한 열거형 |
//+----------------------------------------------------+
enum ENUM_SIGNAL_MODE
{
MODE_SIGNAL, //돌파 신호
MODE_TREND //돌파 및 추세 신호
}; - 새로운 입력 매개변수가 추가되었습니다.//---- 알림을 위한 입력 변수
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; //모바일 장치로 신호 발송 활성화 - 지표 코드의 끝에 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," 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);
}
else
{
if(SoundON) Alert("상승 추세 신호 Ask=",Ask," Bid=",Bid," currtime=",text," Symbol=",Symbol()," Period=",sPeriod);
if(EMailON) SendMail(SignalSirname+": 상승 추세 신호 알림","BUY 신호 at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
if(PushON) SendNotification(SignalSirname+": 상승 추세 신호 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(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," 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);
}
else
{
if(SoundON) Alert("하락 추세 신호 Ask=",Ask," Bid=",Bid," currtime=",text," Symbol=",Symbol()," Period=",sPeriod);
if(EMailON) SendMail(SignalSirname+": 하락 추세 신호 알림","SELL 신호 at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
if(PushON) SendNotification(SignalSirname+": 하락 추세 신호 at Ask="+sAsk+", Bid="+sBid+", Date="+text+" Symbol="+Symbol()+" Period="+sPeriod);
}
}
//---
}
//+------------------------------------------------------------------+
//| 시간 프레임을 문자열로 가져오기 |
//+------------------------------------------------------------------+
string GetStringTimeframe(ENUM_TIMEFRAMES timeframe)
{
//----
return(StringSubstr(EnumToString(timeframe),7,-1));
//----
} - 지표 계산 사이클이 끝난 후 BuySignal() 및 SellSignal() 함수에 몇 가지 호출을 추가했습니다.//---
BuySignal("WeightOscillator_Alert",ColorBuffer,0,rates_total,prev_calculated,close,spread);
SellSignal("WeightOscillator_Alert",ColorBuffer,4,rates_total,prev_calculated,close,spread);
//---여기서 ColorBuffer는 지표 색상을 저장하기 위한 색상 인덱스 버퍼의 이름입니다. 값 0과 4는 각각 오버바이 및 오버셀 구역에 해당하는 색상의 수입니다.
BuySignal() 및 SellSignal() 함수는 지표 코드의 OnCalculate() 블록에서 한 번만 호출된다고 가정합니다.
이 지표는 SmoothAlgorithms.mqh 라이브러리의 클래스를 사용합니다 (이를 <terminal_data_folder>\MQL5\Include에 복사해야 합니다). 이 클래스의 사용에 대해서는 "추가 버퍼 없이 중간 계산을 위한 가격 시리즈 평균화"라는 기사에서 자세히 설명되어 있습니다.

Fig1. WeightOscillator_Alert 지표 차트

Fig.2. WeightOscillator_Alert 지표. 돌파 신호에 대한 알림 생성

Fig.3. WeightOscillator_Alert 지표. 추세 신호에 대한 알림 생성
연관 포스트