//+------------------------------------------------------------------+
//|                                                        Bears.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Blue

//---- input parameters
extern int BBPeriod=13;
//---- buffers
double BBUP[], BBDOWN[], avg[];

double val;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
   
   IndicatorBuffers(3);
   IndicatorDigits(Digits);
//---- indicator line
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,BBUP);
   
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexBuffer(1,BBDOWN);
   
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2, avg);
   
//---- name for DataWindow and indicator subwindow label
   short_name="Bull Bears("+BBPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----

   return(0);
  }
//+------------------------------------------------------------------+
//| Bears Power                                                      |
//+------------------------------------------------------------------+
int start()
  {
   int i,k,counted_bars=IndicatorCounted();
//----
   if(Bars<=BBPeriod) return(0);
//----
   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++;
   //for(i=0; i<limit; i++)
   //   TempBuffer[i]=iMA(NULL,0,BearsPeriod,0,MODE_EMA,PRICE_CLOSE,i);
//----
   i = limit;
   while(i>=0)
     {      
      //val = High[i] +  Low[i] - 2*iMA(NULL,0,BBPeriod,0,MODE_EMA,PRICE_CLOSE,i) ;
      val = High[i]  - iMA(NULL,0,BBPeriod,0,MODE_EMA,PRICE_CLOSE,i) + Low[i] - iMA(NULL,0,BBPeriod,0,MODE_EMA,PRICE_CLOSE,i);
      if (val <= 0.0){
         BBDOWN[i] = val;
         BBUP[i] = 0;      
      } else {
         BBDOWN[i] = 0;  
         BBUP[i] = val;         
      }
      i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+