//+------------------------------------------------------------------+
//|                                                          map.mq4 |
//|                                     Copyright © 2010, Nick Bilak |
//|        http://metatrader.50webs.com/         beluck[at]gmail.com |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2010, Nick Bilak"
#property link      "http://metatrader.50webs.com/"

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Yellow
#property indicator_color2 Red
#property indicator_color3 Yellow
#property indicator_color4 Red
#property indicator_color5 Yellow
#property indicator_color6 Red
#property indicator_minimum 0
#property indicator_maximum 4
//---- input parameters
extern string indicator1="___MACD___";
extern int MacdFast=5;
extern int MacdSlow=34;
extern int MacdSig=5;
extern int MacdPrice=0;
/*
PRICE_CLOSE 0 Close price. 
PRICE_OPEN 1 Open price. 
PRICE_HIGH 2 High price. 
PRICE_LOW 3 Low price. 
PRICE_MEDIAN 4 Median price, (high+low)/2. 
PRICE_TYPICAL 5 Typical price, (high+low+close)/3. 
PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4. 
*/
extern string indicator2="___Stochastic___";
extern int StochK=5;
extern int StochD=3;
extern int StochS=3;
extern int StochSmooth=0;
/*
MODE_SMA 0 Simple moving average, 
MODE_EMA 1 Exponential moving average, 
MODE_SMMA 2 Smoothed moving average, 
MODE_LWMA 3 Linear weighted moving average. 
*/
extern int StochPrice=0; // 0 - Low/High or 1 - Close/Close.
extern string indicator3="___MA___";
extern int MaMethod=0; //0 - sma, 1 -ema, 2 - smma, 3 - lwma
extern int MaPrice=0;
extern int MaPeriod=21;

//---- buffers
double s0[],s1[],s2[],s3[],s4[],s5[];

int init()  {
   SetIndexLabel(0,"MACD cross");
   SetIndexLabel(1,"MACD cross");
   SetIndexLabel(2,"Stochastic cross");
   SetIndexLabel(3,"Stochastic cross");
   SetIndexLabel(4,"MA cross");
   SetIndexLabel(5,"MA cross");
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexStyle(2,DRAW_ARROW);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexStyle(5,DRAW_ARROW);
   SetIndexEmptyValue(0,0);
   SetIndexEmptyValue(1,0);
   SetIndexEmptyValue(2,0);
   SetIndexEmptyValue(3,0);
   SetIndexEmptyValue(4,0);
   SetIndexEmptyValue(5,0);
   SetIndexArrow(0,167);
   SetIndexArrow(1,167);
   SetIndexArrow(2,167);
   SetIndexArrow(3,167);
   SetIndexArrow(4,167);
   SetIndexArrow(5,167);
   SetIndexBuffer(0,s0);
   SetIndexBuffer(1,s1);
   SetIndexBuffer(2,s2);
   SetIndexBuffer(3,s3);
   SetIndexBuffer(4,s4);
   SetIndexBuffer(5,s5);
   ArrayInitialize(s0,0);
   ArrayInitialize(s1,0);
   ArrayInitialize(s2,0);
   ArrayInitialize(s3,0);
   ArrayInitialize(s4,0);
   ArrayInitialize(s5,0);
   IndicatorDigits(0);

   return(0);
}

int start()  {

	int i,j,s;
   int counted_bars=IndicatorCounted();
   int shift,limit;
   
   if (counted_bars<0) return(-1);
   if (counted_bars>0) counted_bars--;
   limit=Bars-10;
   if(counted_bars>=1) limit=Bars-counted_bars-1;
   if (limit<0) limit=0;
   double i11,i12,i21,i22,i31,i32;
   for (shift=limit; shift>=0; shift--)   {
      i11=iMACD(NULL,0,MacdFast,MacdSlow,MacdSig,MacdPrice,MODE_MAIN,shift+1);
      i12=iMACD(NULL,0,MacdFast,MacdSlow,MacdSig,MacdPrice,MODE_SIGNAL,shift+1);
      i21=iStochastic(NULL,0,StochK,StochD,StochS,StochSmooth,StochPrice,MODE_MAIN,shift+1);
      i22=iStochastic(NULL,0,StochK,StochD,StochS,StochSmooth,StochPrice,MODE_SIGNAL,shift+1);
      i31=iMA(NULL,0,MaPeriod,0,MaMethod,MaPrice,shift+1);
      i32=Close[shift+1];
      if (MaPrice==PRICE_OPEN) i32=Open[shift+1];
      if (MaPrice==PRICE_HIGH) i32=High[shift+1];
      if (MaPrice==PRICE_LOW) i32=Low[shift+1];
      if (MaPrice==PRICE_MEDIAN) i32=(High[shift+1]+Low[shift+1])/2.0;
      if (MaPrice==PRICE_TYPICAL) i32=(High[shift+1]+Low[shift+1]+Close[shift+1])/3.0;
      if (MaPrice==PRICE_WEIGHTED) i32=(High[shift+1]+Low[shift+1]+Close[shift+1]+Open[shift+1])/4.0;
      s0[shift]=0;
      s1[shift]=0;
      s2[shift]=0;
      s3[shift]=0;
      s4[shift]=0;
      s5[shift]=0;
      if (i11>i12) s0[shift]=1; //1
      if (i11<i12) s1[shift]=1;
      if (i21>i22) s2[shift]=2; //2
      if (i21<i22) s3[shift]=2;
      if (i31<i32) s4[shift]=3; //3
      if (i31>i32) s5[shift]=3;
	}
	
   return(0);
}

