Create a sount alert on an indicator

To add comments, please log in or register
Anky Five
17
Anky Five  

Hello traders,

I would like to create a sound alert on an indicator I use when the price closes under or below the indicator lines.

It is a volatility indicator :

//+------------------------------------------------------------------+
//|                                                    Guppy CBL.mq4 |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_width1 1
#property indicator_width2 1

//---- input parameters
extern int    LookbackBars      = 100;
extern int    CountbackSteps    = 2;
extern bool   UseClose          = true;
extern bool   UseAlert          = true;

//---- indicator buffers
double UpBuffer[];
double DnBuffer[];

//+------------------------------------------------------------------+
int init()  {
//+------------------------------------------------------------------+
  IndicatorBuffers(2);
  SetIndexStyle(0,DRAW_LINE);
  SetIndexStyle(1,DRAW_LINE);
  SetIndexBuffer(0,UpBuffer);
  SetIndexBuffer(1,DnBuffer);

  string short_name="GuppyCBL("+CountbackSteps+")";
  IndicatorShortName(short_name);
  IndicatorDigits(5);
  if (StringFind(Symbol(),"JPY") >= 0)
    IndicatorDigits(3);
  SetIndexLabel(0,"Guppy Hi");
  SetIndexLabel(1,"Guppy Lo");

  return(0);
}

//+------------------------------------------------------------------+
int start()   {
//+------------------------------------------------------------------+
  int startbar = MathMin(Bars-CountbackSteps-2,LookbackBars);
  for (int i=startbar; i>=0; i--)   {
    int j=i, c=0;
    double HH=High[i], LL=Low[i];
    while (c<CountbackSteps && j<i+10 && j<startbar)  {
      j++;
      if (Low[j]<LL) c++;
      HH=MathMax(HH,High[j]);
      LL=MathMin(LL,Low[j]);
    }  
    if (High[i]==HH)
      DnBuffer[i]=Low[j];
    else
      DnBuffer[i]=DnBuffer[i+1];
    if (DnBuffer[i]!=EMPTY_VALUE && DnBuffer[i+1]!=EMPTY_VALUE)  
      DnBuffer[i]=MathMax(DnBuffer[i],DnBuffer[i+1]);  
    if (UseClose)
      double val=Close[i];
    else
      val=Low[i];    
    if (val<=DnBuffer[i])
      DnBuffer[i]=EMPTY_VALUE;  

    j=i; c=0;
    HH=High[i]; LL=Low[i];
    while (c<CountbackSteps && j<i+10 && j<startbar)  {
      j++;
      if (High[j]>HH) c++;
      LL=MathMin(LL,Low[j]);
      HH=MathMax(HH,High[j]);
    }  
    if (Low[i]==LL)
      UpBuffer[i]=High[j];
    else
      UpBuffer[i]=UpBuffer[i+1];
    if (UpBuffer[i]!=EMPTY_VALUE && UpBuffer[i+1]!=EMPTY_VALUE)  
      UpBuffer[i]=MathMin(UpBuffer[i],UpBuffer[i+1]);  
    if (UseClose)
      val=Close[i];
    else
      val=High[i];    
    if (val>=UpBuffer[i])
      UpBuffer[i]=EMPTY_VALUE;  
  }
  return(0);    
}

Thanks for any help :-)

To add comments, please log in or register