Histogram Bars not printing, please help

 
//+------------------------------------------------------------------+
//|                                           iFx TREND Detector.mq4 |
//+------------------------------------------------------------------+
//#property copyright   "2005-2014, MetaQuotes Software Corp."
//#property link        "http://www.mql4.com"
#property description "Trend detection with iStochastic & MACD"
#property strict

//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_height  100
//--- plot Signal as Histogram
#property indicator_label1 "Buy"
#property indicator_style1 STYLE_SOLID
#property indicator_width1 5
#property indicator_color1 0x00FF3C        // 0x00FF3C

#property indicator_label2 "Sell"
#property indicator_style2 STYLE_SOLID
#property indicator_width2 5
#property indicator_color2 clrOrangeRed          // 0x0000FF

#property indicator_label3 "Neutral"
#property indicator_style3 STYLE_SOLID
#property indicator_width3 5
#property indicator_color3 0x7D7B78
//--- indicator buffers
double buffer_BuySignal[];
double buffer_SellSignal[];
double buffer_Neutral[];
//--- indicator parameters
int    bar_Start = 0;
double myPoint;
input  group "Time Frames for Indicator"
input  ENUM_TIMEFRAMES TF0 = PERIOD_M5;
input  ENUM_TIMEFRAMES TF1 = PERIOD_M15;
input  ENUM_TIMEFRAMES TF2 = PERIOD_M30;
input  ENUM_TIMEFRAMES TF3 = PERIOD_H1;
input  group "iMACD Short Parameters"
input  ENUM_APPLIED_PRICE MACD_AppiledPrices = PRICE_CLOSE;  // type of price for calculation
input  int                MACD_FastPeriod    = 8;            // MACD Fast EMA period
input  int                MACD_SlowPeriod    = 21;           // MACD Slow EMA period
input  int                MACD_SignalPeriod  = 9;            // MACD for their difference averaging
input  group "iStochastic Parameters"
input  int            Stoch_KPeriod          = 8;               // K-period (number of bars for calculations)
input  int            Stoch_DPeriod          = 5;               // D-period (period of first smoothing)
input  int            Stoch_SlowingPeriod    = 3;               // final smoothing
input  ENUM_STO_PRICE Stoch_AppliedPrices    = STO_CLOSECLOSE;  // stochastic calculation method

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
  // Set Height & #Digit for accuracy of drawing of indicator values for SubWindow
  IndicatorDigits(Digits);
  IndicatorSetInteger(INDICATOR_HEIGHT,125);
//--- //--- indicator buffers mapping drawing settings
  SetIndexStyle(0,DRAW_HISTOGRAM);
  SetIndexBuffer(0,buffer_BuySignal);       // Indicator data to draw
  SetIndexStyle(1,DRAW_HISTOGRAM);
  SetIndexBuffer(1,buffer_SellSignal);      // Indicator data to draw
  SetIndexStyle(2,DRAW_HISTOGRAM);
  SetIndexBuffer(2,buffer_Neutral);         // Indicator data to draw
//--- name for DataWindow and indicator subwindow label
  IndicatorShortName("iFx TrendDetector"); 
  SetIndexLabel(0,"BuySignal");
  SetIndexLabel(1,"SellSignal");
  SetIndexLabel(1,"Neutral");

//--- setting Plotting buffer arrays as timeseries
    ArraySetAsSeries(buffer_BuySignal,true);
    ArraySetAsSeries(buffer_SellSignal,true);
    ArraySetAsSeries(buffer_Neutral,true);
//--- initialize myPoint
    myPoint = Point();
    if(Digits() == 5 || Digits() == 3)
      {
        myPoint *= 10;
      }
    SetIndexDrawBegin(0,MACD_SlowPeriod);
//--- initialization done
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
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 limit = (rates_total - prev_calculated);
    //--- initial zero
    if(prev_calculated < 1)
      {
        ArrayInitialize(buffer_BuySignal,EMPTY_VALUE);
        ArrayInitialize(buffer_SellSignal,EMPTY_VALUE);
        ArrayInitialize(buffer_Neutral,EMPTY_VALUE);
      }
    else
      limit++;
  //+--------------------------------------------------------------------------------------------------------+
  //| Array to calculate TimeShift bars from TF0
  //+--------------------------------------------------------------------------------------------------------+
    datetime TimeShift[];
    if(CopyTime(Symbol(), TF0, 0, rates_total, TimeShift) <= 0)
      return(rates_total);
      ArraySetAsSeries(TimeShift, true);

    datetime MyTime[];
    if(CopyTime(Symbol(), TF0, 0, rates_total, MyTime) <= 0)
      return(rates_total);
      ArraySetAsSeries(MyTime, true);

  //+--------------------------------------------------------------------------------------------------------+
  //| Main Loop to generate Signal
  //+--------------------------------------------------------------------------------------------------------+
    for(int i = limit - 1; i >= 0; i--)
      {
        if(i >= MathMin(20000 - 1, rates_total - 1 - 100))
          continue; //omit some old rates to prevent "Array out of range" or slow calculation
        int BarShift_TF0 = iBarShift(Symbol(), TF0, TimeShift[i]);
        if(BarShift_TF0 < 0)
          continue;
        int BarShift_TF1 = iBarShift(Symbol(), TF1, TimeShift[i]);
        if(BarShift_TF1 < 0)
          continue;
        int BarShift_TF2 = iBarShift(Symbol(), TF2, TimeShift[i]);
        if(BarShift_TF2 < 0)
          continue;
        int BarShift_TF3 = iBarShift(Symbol(), TF3, TimeShift[i]);
        if(BarShift_TF3 < 0)
          continue;
      //+----------------------------------------------------------------------------------------------------+
      //| Declration of Variable from Indicators
      //+----------------------------------------------------------------------------------------------------+
        double Stoch_MainTF0 = iStochastic(_Symbol,TF0,Stoch_KPeriod,Stoch_DPeriod,Stoch_SlowingPeriod,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,BarShift_TF0);
        double Stoch_MainTF1 = iStochastic(_Symbol,TF1,Stoch_KPeriod,Stoch_DPeriod,Stoch_SlowingPeriod,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,BarShift_TF1);
        double Stoch_MainTF2 = iStochastic(_Symbol,TF2,Stoch_KPeriod,Stoch_DPeriod,Stoch_SlowingPeriod,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,BarShift_TF2);
        double Stoch_MainTF3 = iStochastic(_Symbol,TF3,Stoch_KPeriod,Stoch_DPeriod,Stoch_SlowingPeriod,MODE_LWMA,STO_CLOSECLOSE,MODE_MAIN,BarShift_TF3);
        double Stoch_SignalTF0 = iStochastic(_Symbol,TF0,Stoch_KPeriod,Stoch_DPeriod,Stoch_SlowingPeriod,MODE_LWMA,STO_CLOSECLOSE,MODE_SIGNAL,BarShift_TF0);
        double Stoch_SignalTF1 = iStochastic(_Symbol,TF1,Stoch_KPeriod,Stoch_DPeriod,Stoch_SlowingPeriod,MODE_LWMA,STO_CLOSECLOSE,MODE_SIGNAL,BarShift_TF1);
        double Stoch_SignalTF2 = iStochastic(_Symbol,TF2,Stoch_KPeriod,Stoch_DPeriod,Stoch_SlowingPeriod,MODE_LWMA,STO_CLOSECLOSE,MODE_SIGNAL,BarShift_TF2);
        double Stoch_SignalTF3 = iStochastic(_Symbol,TF3,Stoch_KPeriod,Stoch_DPeriod,Stoch_SlowingPeriod,MODE_LWMA,STO_CLOSECLOSE,MODE_SIGNAL,BarShift_TF3);

        double MACD_MainTF0 = iMACD(_Symbol,TF0,MACD_FastPeriod,MACD_SlowPeriod,MACD_SignalPeriod,PRICE_CLOSE,MODE_MAIN,BarShift_TF0);
        double MACD_MainTF1 = iMACD(_Symbol,TF1,MACD_FastPeriod,MACD_SlowPeriod,MACD_SignalPeriod,PRICE_CLOSE,MODE_MAIN,BarShift_TF1);
        double MACD_MainTF2 = iMACD(_Symbol,TF2,MACD_FastPeriod,MACD_SlowPeriod,MACD_SignalPeriod,PRICE_CLOSE,MODE_MAIN,BarShift_TF2);
        double MACD_MainTF3 = iMACD(_Symbol,TF3,MACD_FastPeriod,MACD_SlowPeriod,MACD_SignalPeriod,PRICE_CLOSE,MODE_MAIN,BarShift_TF3);
        double MACD_SignalTF0 = iMACD(_Symbol,TF0,MACD_FastPeriod,MACD_SlowPeriod,MACD_SignalPeriod,PRICE_CLOSE,MODE_SIGNAL,BarShift_TF0);
        double MACD_SignalTF1 = iMACD(_Symbol,TF1,MACD_FastPeriod,MACD_SlowPeriod,MACD_SignalPeriod,PRICE_CLOSE,MODE_SIGNAL,BarShift_TF1);
        double MACD_SignalTF2 = iMACD(_Symbol,TF2,MACD_FastPeriod,MACD_SlowPeriod,MACD_SignalPeriod,PRICE_CLOSE,MODE_SIGNAL,BarShift_TF2);
        double MACD_SignalTF3 = iMACD(_Symbol,TF3,MACD_FastPeriod,MACD_SlowPeriod,MACD_SignalPeriod,PRICE_CLOSE,MODE_SIGNAL,BarShift_TF3);

      //+----------------------------------------------------------------------------------------------------+
      //| BUY
      //+----------------------------------------------------------------------------------------------------+
        if(((Stoch_MainTF0 > Stoch_SignalTF0 && Stoch_MainTF0 < 80) || Stoch_MainTF0 > 80) &&
           ((Stoch_MainTF1 > Stoch_SignalTF1 && Stoch_MainTF1 < 80) || Stoch_MainTF1 > 80) &&
           ((Stoch_MainTF2 > Stoch_SignalTF2 && Stoch_MainTF2 < 80) || Stoch_MainTF2 > 80) &&
           ((Stoch_MainTF3 > Stoch_SignalTF3 && Stoch_MainTF3 < 80) || Stoch_MainTF3 > 80) &&
           MACD_MainTF0 > MACD_SignalTF0 &&
           MACD_MainTF1 > MACD_SignalTF1 &&
           MACD_MainTF2 > MACD_SignalTF2 &&
           MACD_MainTF3 > MACD_SignalTF3)
            {
              buffer_BuySignal[i] = 1; // Store BUY Signal for index [i] Bar
            }
        else
          {
            buffer_BuySignal[i] = EMPTY_VALUE;      // Store EMPTY SIGNAL for index [i] Bar            
          }
      //+----------------------------------------------------------------------------------------------------+
      //| SELL
      //+----------------------------------------------------------------------------------------------------+
        if(((Stoch_MainTF0 < Stoch_SignalTF0 && Stoch_MainTF0 > 20) || Stoch_MainTF0 < 20) &&
           ((Stoch_MainTF1 < Stoch_SignalTF1 && Stoch_MainTF1 > 20) || Stoch_MainTF1 < 20) &&
           ((Stoch_MainTF2 < Stoch_SignalTF2 && Stoch_MainTF2 > 20) || Stoch_MainTF2 < 20) &&
           ((Stoch_MainTF3 < Stoch_SignalTF3 && Stoch_MainTF3 > 20) || Stoch_MainTF3 < 20) &&
           MACD_MainTF0 > MACD_SignalTF0 &&
           MACD_MainTF1 > MACD_SignalTF1 &&
           MACD_MainTF2 > MACD_SignalTF2 &&
           MACD_MainTF3 > MACD_SignalTF3)
            {
              buffer_SellSignal[i] = 1; // Store SELL Signal for index [i] Bar
            }
        else
          {
            buffer_SellSignal[i] = EMPTY_VALUE;      // Store EMPTY SIGNAL for index [i] Bar            
          }
      //+----------------------------------------------------------------------------------------------------+
      //| NO SIGNAL
      //+----------------------------------------------------------------------------------------------------+
        if((buffer_BuySignal[i] != 1) && (buffer_SellSignal[i] != 1))
          {
            buffer_Neutral[i] = 1; // Set indicator at fixed value
          }
        else
          {
            buffer_Neutral[i] = EMPTY_VALUE;
          }
    } // ENF of for ... loop
//--- done
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_maximum 1.0
#property indicator_minimum 0.0
#property indicator_height  100

Add two lines.

There are so many useless descriptions that it should be better organized.

 
Nagisa Unada:

Add two lines.

There are so many useless descriptions that it should be better organized.

Thanks a lot Nagisa, this code I was trying to covert from MQL5 to MAL4. need to used it temporarily, until my MQL5 versions start working perfectly well.

Yes adding these lines helped to run this for now. Let me test it for few days to be sure it is working.

Descriptions are for my understanding, however I realized that I should have removed them while posting on Forum. 

 
Anil Varma:

Descriptions are for my understanding, however I realized that I should have removed them while posting on Forum. 

No, that's not what I'm saying. I'm saying that there are many duplicates and unnecessary lines.

For example, 

ArraySetAsSeries(buffer_BuySignal,true);
ArraySetAsSeries(buffer_SellSignal,true);
ArraySetAsSeries(buffer_Neutral,true);

In MT4, "true" is the default, so these are not necessary.

SetIndexLabel(0,"BuySignal");
SetIndexLabel(1,"SellSignal");
SetIndexLabel(1,"Neutral");

These are duplicate of the label name you wrote in the profile.

myPoint = Point();
if(Digits() == 5 || Digits() == 3)
{
   myPoint *= 10;
}

This is an unused variable.

And so on.

 
Nagisa Unada:

No, that's not what I'm saying. I'm saying that there are many duplicates and unnecessary lines.

For example, 

In MT4, "true" is the default, so these are not necessary.

These are duplicate of the label name you wrote in the profile.

This is an unused variable.

And so on.

Thanks Nagisa for your reply and comments.

1) in MQL5 when use SetIndexBuffer() is used, array is automatically assumed to be as timeseries. I was not aware of MQL4, so just left it there.

2) SetIndexLabel(1,"Neutral"); ... ERROR Noted and thanks for pointing it out.

3) myPoint ... I want to use it in the indicator to handle currency pairs, which have 4/5 decimal OR 2/3 decimal points. However, could not realize how to use it, and hence left in the code as a reminder to do it.

Indicator is working now, thanks to error pointed out by you for indicator_minimum and indicator_maximum. As I have already shifted to MQL5, I am concentrating to serious errors only in MQL4 version.

I would be obelized if you can help me to trace zero_divide error as following line is failing to get MAvalue on different time frame. The error is not frequent but happens some time.

      double EMA_Price  = NormalizeDouble(iMA(_Symbol,PERIOD_M15,MA_Period,0,MODE_SMA,PRICE_CLOSE,i),Digits) ... while I am working on PERIOD_M5 or PERIOD_M30/H1.

 
Anil Varma:

I would be obelized if you can help me to trace zero_divide error as following line is failing to get MAvalue on different time frame. The error is not frequent but happens some time.

      double EMA_Price  = NormalizeDouble(iMA(_Symbol,PERIOD_M15,MA_Period,0,MODE_SMA,PRICE_CLOSE,i),Digits) ... while I am working on PERIOD_M5 or PERIOD_M30/H1.

Zero division is what occurs in division. However, I don't see any division in this program, so I don't know what's going on.

 
Nagisa Unada:

Zero division is what occurs in division. However, I don't see any division in this program, so I don't know what's going on.

I remember one of your suggestion in earlier post. I used if(EMA_Price !=  0) then do the calculation. Hope it should be working. as I told you earlier, this error is not frequent but happens sometimes.

Reason: