//+------------------------------------------------------------------+
//|                                                        Bulls.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Bulls Power"
#property strict

//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 clrLimeGreen
#property indicator_width1 4
#property indicator_color2 clrRed
#property indicator_width2 4
//--- input parameter
input int InpBullsPeriod = 13;
//--- buffers
double huu[],hdd[],bull[];
struct sGlobalStruct
{
   double ma;
   string short_name;
};
sGlobalStruct glo;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit(void)
{
   IndicatorBuffers(3);
   IndicatorDigits(_Digits);

   SetIndexBuffer(0,huu);SetIndexStyle(0,DRAW_HISTOGRAM); SetIndexLabel(0,glo.short_name);
   SetIndexBuffer(1,hdd);SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexLabel(1,glo.short_name);
   SetIndexBuffer(2,bull);
 
   glo.short_name="Bulls("+IntegerToString(InpBullsPeriod)+")";
   IndicatorShortName(glo.short_name);
}
//+------------------------------------------------------------------+
//| Bulls Power                                                      |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int i=rates_total-prev_calculated+1; if (i>=rates_total) i=rates_total-1; 

   //
   //
   //

   for (; i>=0 && !_StopFlag; i--)
   {
      glo.ma  = iMA(NULL,0,InpBullsPeriod,0,MODE_EMA,PRICE_CLOSE,i);
      bull[i] = high[i]-glo.ma;
      huu[i]  = (bull[i]>0) ? bull[i] : EMPTY_VALUE;
      hdd[i]  = (bull[i]<0) ? bull[i] : EMPTY_VALUE;
   }
return(rates_total);
}
//+------------------------------------------------------------------+
