
#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 BlueViolet
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
#property indicator_color2 Magenta
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
#property indicator_color3 DarkOrange
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
#property indicator_color4 Red
#property indicator_style4 STYLE_SOLID
#property indicator_width4 2
#property indicator_color5 Green
#property indicator_style5 STYLE_SOLID
#property indicator_width5 2
#property indicator_color6 Yellow
#property indicator_style6 STYLE_SOLID
#property indicator_width6 2

//---- indicator parameters
extern bool MA62_PrAlert=true;
extern bool MA10_PrAlert=false;
extern string PrPip_note="PrPip Tolerance for MA62/10 PrAlerts";
extern double PrPip = 3;

int MA1_Period=10;
int MA1_Method=MODE_SMA;
int MA2_Period=50;
int MA2_Method=MODE_SMA;
int MA3_Period=62;
int MA3_Method=MODE_EMA;
int MA4_Period=150;
int MA4_Method=MODE_EMA;
int MA5_Period=200;
int MA5_Method=MODE_SMA;
int MA6_Period=365;
int MA6_Method=MODE_EMA;

static datetime LastAlert62 = 0, LastAlert10 = 0;

//---- indicator buffers
double MA1[];
double MA2[];
double MA3[];
double MA4[];
double MA5[];
double MA6[];

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {

     return(0);
  }


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   
	//  buffers
	SetIndexBuffer(0,MA1);
	SetIndexBuffer(1,MA2);
	SetIndexBuffer(2,MA3);
	SetIndexBuffer(3,MA4);
	SetIndexBuffer(4,MA5);
	SetIndexBuffer(5,MA6);
		
	// Data Window labels
	SetIndexLabel(0,"SMA10");
	SetIndexLabel(1,"SMA50");
	SetIndexLabel(2,"EMA62");
	SetIndexLabel(3,"EMA150");
	SetIndexLabel(4,"SMA200");
	SetIndexLabel(5,"EMA365");
	}

// function which is called with every tick
int start() {

	   int	iBarsToCalc = Bars - IndicatorCounted();
	if (iBarsToCalc < Bars) iBarsToCalc++;
		
	for (int i=iBarsToCalc-i;i>=0;i--) {
	
		MA1[i]= iMA(NULL,0,MA1_Period,0,MA1_Method,PRICE_CLOSE,i);
		MA2[i]= iMA(NULL,0,MA2_Period,0,MA2_Method,PRICE_CLOSE,i);
		MA3[i]= iMA(NULL,0,MA3_Period,0,MA3_Method,PRICE_CLOSE,i);
		MA4[i]= iMA(NULL,0,MA4_Period,0,MA4_Method,PRICE_CLOSE,i);
		MA5[i]= iMA(NULL,0,MA5_Period,0,MA5_Method,PRICE_CLOSE,i);
		MA6[i]= iMA(NULL,0,MA6_Period,0,MA6_Method,PRICE_CLOSE,i);
		
	   }
 
	   // if price is nearing MA10..........
		   double d0_10 = MA1[0]-Close[0];
		   double d1_10 = MA1[1]-Close[1];
		if (MA10_PrAlert==true && LastAlert10 < Time[0] && (MathAbs(d0_10) <= (PrPip*Point*10)) && (MathAbs(d1_10) > (PrPip*Point*10))) {
			Alert("Price near MA10 on " + Symbol() + Period());
			LastAlert10 = Time[0];
		   }
		
		// if price is nearing MA62..........
		   double d0_62 = MA3[0]-Close[0];
		   double d1_62 = MA3[1]-Close[1];
		if (MA62_PrAlert==true && LastAlert62 < Time[0] && (MathAbs(d0_62) <= (PrPip*Point*10)) && (MathAbs(d1_62) > (PrPip*Point*10))) {
			Alert("Price near MA62 on " + Symbol() + Period());
			LastAlert62 = Time[0];
		   }
		
	}

