Navigation´╝ÜHome > Content >

s_SilverTrend_Signal_Alert.mq4

Time: 2015-07-27 | Download file:s_SilverTrend_Signal_Alert.mq4

//+------------------------------------------------------------------+
//| SilverTrend_Signal.mq4 
//| Ramdass - Conversion only
//+------------------------------------------------------------------+
#property copyright "SilverTrend  rewritten by CrazyChart"
#property link      "http://viac.ru/"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Violet
#define SIGNAL_BAR 1

//---- input parameters
extern int RISK=3;
extern int CountBars=350;
extern int SSP=9;
 extern bool UseSound=true;
extern bool AlertSound=true;
extern string SoundFileBuy ="tada.wav";
extern string SoundFileSell="email.wav";
extern bool SendMailPossible = false;
bool SoundBuy  = False;
bool SoundSell = False;

//---- buffers
double val1[];
double val2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,233);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexArrow(1,234);
   SetIndexBuffer(0,val1);
   SetIndexBuffer(1,val2);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| SilverTrend_Signal                                               |
//+------------------------------------------------------------------+
int start()
  {   
   if (CountBars>=Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars+SSP);
   SetIndexDrawBegin(1,Bars-CountBars+SSP);
   int i,shift,counted_bars=IndicatorCounted();
   int i1,i2,K;
   double Range,AvgRange,smin,smax,SsMax,SsMin,price;
   bool uptrend,old;
//----
   
   if(Bars<=SSP+1) return(0);
//---- initial zero
   if(counted_bars=0; shift--) 
{ 

	Range=0;
	AvgRange=0;
	for (i1=shift; i1<=shift+SSP; i1++)
		{AvgRange=AvgRange+MathAbs(High[i1]-Low[i1]);
		}
	Range=AvgRange/(SSP+1);

SsMax=High[shift]; SsMin=Low[shift]; 
   for (i2=shift;i2<=shift+SSP-1;i2++)
        {
         price=High[i2];
         if(SsMax=price)  SsMin=price;
        }
 
smin = SsMin+(SsMax-SsMin)*K/100; 
smax = SsMax-(SsMax-SsMin)*K/100; 
	val1[shift]=0;
	val2[shift]=0;
	if (Close[shift]smax)
		{
		uptrend = true;
		}
   if (uptrend!=old && uptrend==true) {val1[shift]=Low[shift]-Range*0.5;}
   if (uptrend!=old && uptrend==false) {val2[shift]=High[shift]+Range*0.5;}
   old=uptrend;

}
//+------------------------------------------------------------------+ 
        string  message  =  StringConcatenate("s_SilverTrend_Signal (", Symbol(), ", ", Period(), ")  -  BUY!!!" ,"-" ,TimeToStr(TimeLocal(),TIME_SECONDS)); 
        string  message2 =  StringConcatenate("s_SilverTrend_Signal (", Symbol(), ", ", Period(), ")  -  SELL!!!","-"  ,TimeToStr(TimeLocal(),TIME_SECONDS)); 
               
        if (val1[SIGNAL_BAR] != EMPTY_VALUE && val1[SIGNAL_BAR] != 0 && SoundBuy)
         {
         SoundBuy = False;
            if (UseSound) PlaySound (SoundFileBuy);
               if(AlertSound){         
               Alert(message);                             
               if (SendMailPossible) SendMail(Symbol(),message); 
            }              
         } 
      if (!SoundBuy && (val1[SIGNAL_BAR] == EMPTY_VALUE || val1[SIGNAL_BAR] == 0)) SoundBuy = True;  
            
  
     if (val2[SIGNAL_BAR] != EMPTY_VALUE && val2[SIGNAL_BAR] != 0 && SoundSell)
         {
         SoundSell = False;
            if (UseSound) PlaySound (SoundFileSell); 
             if(AlertSound){                    
             Alert(message2);             
             if (SendMailPossible) SendMail(Symbol(),message2); 
             }            
         } 
      if (!SoundSell && (val2[SIGNAL_BAR] == EMPTY_VALUE || val2[SIGNAL_BAR] == 0)) SoundSell = True; 
      
       //+------------------------------------------------------------------+  
   return(0);
  }
//+------------------------------------------------------------------+

Recommend