Navigation:Home > Content >

DynamicRS_3CLines_Alert.mq4

Time: 2015-12-08 | Download file:DynamicRS_3CLines_Alert.mq4

//+------------------------------------------------------------------+
//|                                            DynamicRS_3CLines.mq4 |
//|                                 Copyright © 2007, Nick A. Zhilin |
//|                                                  [email protected] |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, Nick A. Zhilin"
#property link      "[email protected]"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_color2 Aqua
#property indicator_color3 Red
#define SIGNAL_BAR 1
extern bool AlertPossible    = true;
extern bool AlertOnlySound   = false;
extern string Sound          = "alert2.wav";
extern bool SendMailPossible = false;

//---- buffers
double ExtMapBuffer1[];
double TopLine[];
double BottomnLine[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorShortName("DynamicRS_3CLines");
//---- indicators
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,TopLine);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,BottomnLine);

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| DynamicRS                                                        |
//+------------------------------------------------------------------+
int start()
  {
   int i,counted_bars=IndicatorCounted();

//----
   i=Bars-counted_bars-1;
   while(i>=0)
     {
      if(High[i]Low[i+1] && Low[i]>ExtMapBuffer1[i+1])
         {
          ExtMapBuffer1[i]=Low[i];
          TopLine[i]=Low[i];
          BottomnLine[i]=BottomnLine[i+1];
         }
      else
         {
          ExtMapBuffer1[i]=ExtMapBuffer1[i+1];
          if(ExtMapBuffer1[i+1]==TopLine[i+1]) 
             {
              TopLine[i]=ExtMapBuffer1[i+1];
              BottomnLine[i]=BottomnLine[i+1];
             }
          else if(ExtMapBuffer1[i+1]==BottomnLine[i+1]) 
             {
              BottomnLine[i]=ExtMapBuffer1[i+1];
              TopLine[i]=TopLine[i+1];
             }
         }         
      i--;
     }

  //+------------------------------------------------------------------+     
      static int PrevSignal = 0, PrevTime = 0;

	  if(SIGNAL_BAR > 0 && Time[0] <= PrevTime) 
	      return(0);

	  PrevTime = Time[0];

     if (AlertPossible == true) {
	
      {
        if(ExtMapBuffer1[SIGNAL_BAR +1] < TopLine[SIGNAL_BAR +1] && ExtMapBuffer1[SIGNAL_BAR] >= TopLine[SIGNAL_BAR]){
        if (AlertOnlySound) {PlaySound(Sound);} else 
          {
            PrevSignal = 1;
            Alert("DynamicRS_3CLines (", Symbol(), ", ", Period(), ")  -  BUY!!!");PlaySound(Sound);
            if (SendMailPossible) SendMail(Symbol()+ " M"+ Period()+ "DynamicRS_3CLines -  BUY!!!", "");
          }
      }
      }
   
      {
    if(ExtMapBuffer1[SIGNAL_BAR+1] > BottomnLine[SIGNAL_BAR+1] && ExtMapBuffer1[SIGNAL_BAR] <= BottomnLine[SIGNAL_BAR]){
        if (AlertOnlySound) {PlaySound(Sound);} else 
          {
            PrevSignal = -1;
            Alert("DynamicRS_3CLines(", Symbol(), ", ", Period(), ")  -  SELL!!!");PlaySound(Sound);
            if (SendMailPossible) SendMail(Symbol()+ " M"+ Period()+ " DynamicRS_3CLines -  SELL!!!", "");
          }
      }
      }
      }
//+------------------------------------------------------------------+
//----
   return(0);
  }
//+------------------------------------------------------------------+

Recommend