//+------------------------------------------------------------------+
//|                                               MA_ttaro27_a.mq4   |
//|                                               © 2011, MaryJane   |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2011, MaryJane"
#property  link      "http://forexfactory.com/maryjane"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow    
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2

extern int       MA_Period = 5;
extern string    Method = "0=SMA, 1=EMA, 2=SMMA, 3=LWMA";
extern int       MA_Method = MODE_SMA;
extern string    Price1 = "0=Close, 1=Open, 2=Low, 3=High";
extern string    Price2 = "4=Median, 5=Typical, 6=Weighted";
extern int       MA_Price = PRICE_CLOSE;

double Bull[], Bear[], Neutral[], MA[], C[];
//+------------------------------------------------------------------+
int init()
   {
   IndicatorBuffers(5);
   IndicatorDigits(Digits);

   SetIndexBuffer(0, Neutral);
   SetIndexBuffer(1, Bull);
   SetIndexBuffer(2, Bear);
   SetIndexBuffer(3, MA);
   SetIndexBuffer(4, C);
   
   return(0);
   }
//+------------------------------------------------------------------+
int start()
   {
   int counted_bars = IndicatorCounted();
   if (counted_bars < 0) return(-1);
   if (counted_bars > 0) counted_bars--;
   int limit = Bars - counted_bars;
   
   for(int i = limit; i >= 0; i--)
      {
      MA[i] = iMA(NULL, 0, MA_Period, 0, MA_Method, MA_Price, i);
      C[i] = iClose(NULL, 0, i);
      }       

   for(i = limit; i >= 0; i--)
      {
      Neutral[i] = MA[i]; 
      Bull[i] = MA[i];
      Bear[i] = MA[i];
            
      if ((MA[i] < MA[i+1]) && (C[i] < MA[i])) {Bull[i] = EMPTY_VALUE;}
      else if ((MA[i] > MA[i+1]) && (C[i] > MA[i])) {Bear[i] = EMPTY_VALUE;}
      else {Bull[i] = EMPTY_VALUE; Bear[i] = EMPTY_VALUE;}
      }
    
   return(0);
   }
//+------------------------------------------------------------------+