Slope Direction Line Email

Hello guys, I’m need some help with an indicator that I find very useful. I’m not a programmer and thats why I need one of you to help me out. I have an indicator called the “slope direction line”, and its suppose to send me an email alert every time it changes color. Unfortunately, I have been unable to receive emails from this indicator even though I have my email alerts set correctly trough metatrader (I do receive email from other indicators).

Attached is a copy of the indicator and I just need some help from any of you that can find and correct the coding error so that I can receive emails.

Thank you very much for your help

//+------------------------------------------------------------------+ 
//| HMA.mq4 
//| Copyright � 2006 WizardSerg <[email protected]>, ?? ??????? ForexMagazine #104 
//| [email protected] 
//| Revised by IgorAD,[email protected] |   
//| Personalized by iGoR AKA FXiGoR for the Trend Slope Trading method (T_S_T) 
//| Link: 
//| contact: [email protected]                                                                         
//+------------------------------------------------------------------+
#property copyright "MT4 release WizardSerg <[email protected]>, ?? ??????? ForexMagazine #104" 
#property link      "[email protected]" 

#property indicator_chart_window 
#property indicator_buffers 3 
#property indicator_color2 Blue 
#property indicator_color3 Red 
#property indicator_color1 Orange 
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1

//---- input parameters 
extern int       period=20; 
extern int       method=1;                         // MODE_SMA 
extern int       price=0;                          // PRICE_CLOSE
extern int       EmailON=1;                        // 0 = false    1 = true
extern int       SoundON=1;                        // 0 = false    1 = true
//---- buffers 
double Uptrend[];
double Dntrend[];
double ExtMapBuffer[]; 
double buff[];


//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init() 
{ 
    IndicatorBuffers(3);  
    SetIndexBuffer(1, Uptrend); 
    //ArraySetAsSeries(Uptrend, true); 
    SetIndexBuffer(2, Dntrend); 
    //ArraySetAsSeries(Dntrend, true); 
    //SetIndexBuffer(2, ExtMapBuffer); 
    //ArraySetAsSeries(Uptrend, true);
    SetIndexBuffer(0, ExtMapBuffer); 
    ArraySetAsSeries(ExtMapBuffer, true); 
    
    SetIndexStyle(0,DRAW_LINE);
    SetIndexStyle(1,DRAW_LINE);
    SetIndexStyle(2,DRAW_LINE);
    
    IndicatorShortName("Slope Direction Line("+period+")"); 
    return(0); 
} 

//+------------------------------------------------------------------+ 
//| Custor indicator deinitialization function                       | 
//+------------------------------------------------------------------+ 
int deinit() 
{ 
    // ???? ????? ?????? ?????? 
    return(0); 
} 

//+------------------------------------------------------------------+ 
//| ?????????? ???????                                               | 
//+------------------------------------------------------------------+ 
double WMA(int x, int p) 
{ 
    return(iMA(NULL, 0, p, 0, method, price, x));    
} 

//+------------------------------------------------------------------+ 
//| Custom indicator iteration function                              | 
//+------------------------------------------------------------------+ 
int start() 
{ 
    int counted_bars = IndicatorCounted(); 
    
    if(counted_bars < 0) 
        return(-1); 
                  
    int x = 0; 
    int p = MathSqrt(period);              
    int e = Bars - counted_bars + period + 1; 
    
    double vect[], trend[]; 
    
    if(e > Bars) 
        e = Bars;    

    ArrayResize(vect, e); 
    ArraySetAsSeries(vect, true);
    ArrayResize(trend, e); 
    ArraySetAsSeries(trend, true); 
    
    for(x = 0; x < e; x++) 
    { 
        vect[x] = 2*WMA(x, period/2) - WMA(x, period);        
 //       Print("Bar date/time: ", TimeToStr(Time[x]), " close: ", Close[x], " vect[", x, "] = ", vect[x], " 2*WMA(p/2) = ", 2*WMA(x, period/2), " WMA(p) = ",  WMA(x, period)); 
    } 

    for(x = 0; x < e-period; x++)
     
        ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x);        
    
    for(x = e-period; x >= 0; x--)
    {     
        trend[x] = trend[x+1];
        if (ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1;
        if (ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1;
    
    if (trend[x]>0)
    { Uptrend[x] = ExtMapBuffer[x]; 
      if (trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
      Dntrend[x] = EMPTY_VALUE;
    }
    else              
    if (trend[x]<0)
    { 
      Dntrend[x] = ExtMapBuffer[x]; 
      if (trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
      Uptrend[x] = EMPTY_VALUE;
    }    
    buff[x] = trend[x];          
    
    //Print( " trend=",trend[x]);
    }
    if (EmailON==1 && Dntrend[0] != EMPTY_VALUE &&   Dntrend[1] == EMPTY_VALUE && isNewBar())
    { 
      if (SoundON==1) Alert("SELL signal at Ask=",Ask,", Bid=",Bid,", Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime())," Symbol=",Symbol()," Period=",Period());
      SendMail("SELL signal alert","SELL signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
    }
    if (EmailON==1 && Uptrend[0] != EMPTY_VALUE &&   Uptrend[1] == EMPTY_VALUE && isNewBar()) 
    { 
      if (SoundON==1) Alert("BUY signal at Ask=",Ask,", Bid=",Bid,", Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime())," Symbol=",Symbol()," Period=",Period());
      SendMail("BUY signal alert","BUY signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
    }
    return(0); 
}

bool isNewBar()
{
   static datetime lastbar=0;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
   {
      lastbar=curbar;
      return (true);
   }
   else
   {
      return(false);
   }
}  

 
//+------------------------------------------------------------------+ 

Hi I’ve attached a modified file. I’m not a programmer either but it seems to work right now. I had to change all the array names, otherwise it seemed to interact with the original indicator which I was using to check that I hadn’t destroyed the way the original worked.

I’m also copying the code here

I should add that sometimes you will get a false alert. This is because the original indicator repaints itself up to a point. If you look at where it changes color you will see one part that is painted half and half - half red and yellow, the next bar yellow (for example) and the following bar yellow. So you have one half and half bar and two yellow bars. The alert is sent at the open of the second yellow bar. However, if that bar closes down instead of up by enough to change the slope, the indicator will go back and repaint the half and half bar and the first and second yellow bars to red. I found this out by watching the original indicator on the 1 minute timeframe

//±-----------------------------------------------------------------+
//| HMA.mq4
//| Copyright � 2006 WizardSerg <[email protected]>, ?? ??? ForexMagazine #104
//| <[email protected]>
//| Revised by IgorAD,[email protected] |
//| Personalized by iGoR AKA FXiGoR for the Trend Slope Trading method (T_S_T)
//| Link:
//| contact: <[email protected]>
//±-----------------------------------------------------------------+
#property copyright “MT4 release WizardSerg <[email protected]>, ?? ??? ForexMagazine #104
#property link "[email protected]"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color1 Orange
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1

//---- input parameters
extern int period=20;
extern int method=1; // MODE_SMA
extern int price=0; // PRICE_CLOSE
extern int EmailON=1; // 0 = false 1 = true
extern int SoundON=1; // 0 = false 1 = true
//---- buffers
double Uptrend1[];
double Dntrend1[];
double ExtMapBuffer1[];
double buff1[];

//±-----------------------------------------------------------------+
//| Custom indicator initialization function |
//±-----------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
SetIndexBuffer(1, Uptrend1);
//ArraySetAsSeries(Uptrend1, true);
SetIndexBuffer(2, Dntrend1);
//ArraySetAsSeries(Dntrend1, true);
//SetIndexBuffer(2, ExtMapBuffer1);
//ArraySetAsSeries(Uptrend1, true);
SetIndexBuffer(0, ExtMapBuffer1);
ArraySetAsSeries(ExtMapBuffer1, true);

SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);

IndicatorShortName("Slope Direction Line1("+period+")"); 
return(0); 

}

//±-----------------------------------------------------------------+
//| Custor indicator deinitialization function |
//±-----------------------------------------------------------------+
int deinit()
{
// ??? ??? ??? ???
return(0);
}

//±-----------------------------------------------------------------+
//| ??? ??? |
//±-----------------------------------------------------------------+
double WMA(int x, int p)
{
return(iMA(NULL, 0, p, 0, method, price, x));
}

//±-----------------------------------------------------------------+
//| Custom indicator iteration function |
//±-----------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();

if(counted_bars &lt; 0) 
    return(-1); 
              
int x = 0; 
int p = MathSqrt(period);              
int e = Bars - counted_bars + period + 1; 

double vect1[], trend1[]; 

if(e &gt; Bars) 
    e = Bars;    

ArrayResize(vect1, e); 
ArraySetAsSeries(vect1, true);
ArrayResize(trend1, e); 
ArraySetAsSeries(trend1, true); 

for(x = 0; x &lt; e; x++) 
{ 
    vect1[x] = 2*WMA(x, period/2) - WMA(x, period);        

// Print("Bar date/time: ", TimeToStr(Time[x]), " close: “, Close[x], " vect1[”, x, "] = ", vect1[x], " 2WMA(p/2) = ", 2WMA(x, period/2), " WMA§ = ", WMA(x, period));
}

for(x = 0; x &lt; e-period; x++)
 
    ExtMapBuffer1[x] = iMAOnArray(vect1, 0, p, 0, method, x);        

for(x = e-period; x &gt;= 0; x--)
{     
    trend1[x] = trend1[x+1];
    if (ExtMapBuffer1[x]&gt; ExtMapBuffer1[x+1]) trend1[x] =1;
    if (ExtMapBuffer1[x]&lt; ExtMapBuffer1[x+1]) trend1[x] =-1;

     if (trend1[x]&gt;0)
     { Uptrend1[x] = ExtMapBuffer1[x]; 
       if (trend1[x+1]&lt;0) Uptrend1[x+1]=ExtMapBuffer1[x+1];
       Dntrend1[x] = EMPTY_VALUE;
      }
     else              
     if (trend1[x]&lt;0)
     { 
       Dntrend1[x] = ExtMapBuffer1[x]; 
       if (trend1[x+1]&gt;0) Dntrend1[x+1]=ExtMapBuffer1[x+1];
       Uptrend1[x] = EMPTY_VALUE;
     }    
   buff1[x] = trend1[x];  

 }

if (isNewBar())
{

  if (Dntrend1[0] != 2147483647 && Uptrend1[0] == 2147483647 && Uptrend1[1] == 2147483647 && Uptrend1[2] != 2147483647)
     { 
       if (SoundON==1) Alert("SELL signal at Ask=",Ask,", Bid=",Bid,", Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime())," Symbol=",Symbol()," Period=",Period());
       if (EmailON==1)  SendMail("SELL signal alert","SELL signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
     } 
 
 if (Uptrend1[0] != 2147483647 && Dntrend1[0] == 2147483647 && Dntrend1[1] == 2147483647 && Dntrend1[2] != 2147483647)
     { 
       if (SoundON==1) Alert("Buy signal at Ask=",Ask,", Bid=",Bid,", Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime())," Symbol=",Symbol()," Period=",Period());
       if (EmailON==1)  SendMail("Buy signal alert","Buy signal at Ask="+DoubleToStr(Ask,4)+", Bid="+DoubleToStr(Bid,4)+", Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
     }
 
} 

}

bool isNewBar()
{
// Alert(“in is newwwwwwwwwwwww”);
static datetime lastbar=0;
datetime curbar = Time[0];

if(lastbar!=curbar)
{
lastbar=curbar;

  return (true);

}
else
{

  return(false);

}
}

//±-----------------------------------------------------------------+