//+------------------------------------------------------------------+
//|                                     T.S.V._Bullish & Bearish.mq4 |
//|                                                    Sergey_T.S.V. |
//|                                                       &&&&&&&&&& |
//+------------------------------------------------------------------+
#property copyright "Sergey_T.S.V."
#property  indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  Blue
#property indicator_color2  Red
#property indicator_width1  4
#property indicator_width2  4
#property indicator_minimum 0
#property indicator_maximum 1

//
//
//
//
//

extern int MaPeriod = 15;
extern int MaShift  = 1;
extern int MaMode   = MODE_LWMA;

//
//
//
//
//

double trend[];
double Up[];
double Dn[];

//
//
//
//
//

int init()
{
   IndicatorBuffers(3);
   SetIndexBuffer(0,Up);  SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(1,Dn);  SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(2,trend);
return(0);
}

//
//
//
//
//

int start()
{
   int counted_bars  = IndicatorCounted(); 
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
          int limit = MathMin(Bars - counted_bars,Bars-1);

   //
   //
   //
   //
   //

   for(int i = limit; i >= 0; i--)
   {
      trend[i] = trend[i+1];
      Up[i] = EMPTY_VALUE;
      Dn[i] = EMPTY_VALUE;
      if (Close[i]>iMA(NULL,0,MaPeriod,MaShift,MaMode,PRICE_HIGH,i+1)) trend[i] = 1;
      if (Close[i]<iMA(NULL,0,MaPeriod,MaShift,MaMode,PRICE_LOW, i+1)) trend[i] =-1;
      if (trend[i] == 1) Up[i] = 1;
      if (trend[i] ==-1) Dn[i] = 1;
   }
return(0);
}