Indicator of tangent of another indicator, but plot displayed empty window

 
#define PI  3.14159265359
#define RadToDeg(x)  (x)*180/PI

//--- indicator buffers
double         lwmadiffsmaBuffer[];
double         lwmadiffsmapcBuffer[];
double         bbwidthslopeBuffer[];

int            BBandPeriod   =20; 


double GetAngle(datetime time1, double price1, datetime time2, double price2)
  {
   int x1,y1,x2,y2;
   
   //convert the (time,price) coordinates to (x,y) coordinates
   ChartTimePriceToXY(0,0,time1,price1,x1,y1);
   ChartTimePriceToXY(0,0,time1,price1,x2,y2);
   // flip Y coordinates because screen point (0,0) s upper-leftmost
   // and not lowre-leftmost as we usually draw the axes on paper
   y1=ChartHeightInPixelsGet()-y1;
   y2=ChartHeightInPixelsGet()-y2;
   //Calculate the slope, notiece the forced casting that need to be done
   double m=(double)(y2-y1)/(double)(x2-x1)*((double)ChartWidthInPixels()/(double)ChartHeightInPixelsGet());
   //Calculate the angle in degrees
   double angle=RadToDeg(MathArctan(m));
   
   return(angle);
  }

//+------------------------------------------------------------------+
//| The function receives the chart width in pixels                  |
//+------------------------------------------------------------------+
int ChartWidthInPixels(const long chart_ID=0)
  {
    //--- prepare the variable to get the property value
    long result=-1;
    //--- reset the error value
    ResetLastError();
    //--- receive the property value
    if(!ChartGetInteger(chart_ID,CHART_WIDTH_IN_PIXELS,0,result))
      {
        //--- display the error message in Experts journal
        Print(__FUNCTION__+", Error Code = ",GetLastError());
      }
    //--- return the value of the chart property
    return((int)result);
  }
  
//+------------------------------------------------------------------+
//| The function receives the chart heigth value in pixels           |
//+------------------------------------------------------------------+
int ChartHeightInPixelsGet(const long chart_ID=0,const int sub_window=0)
  {
    //--- prepare the variable to get the property value
    long result=-1;
    //--- reset the error value
    ResetLastError();
    //--- receive the property value
    if(!ChartGetInteger(chart_ID,CHART_HEIGHT_IN_PIXELS,sub_window,result))
    {
      //--- display the error mesage in Expert journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
    }
    //--- return the value of the chart property
    return((int)result);
  }
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,lwmadiffsmaBuffer);
   SetIndexBuffer(1,lwmadiffsmapcBuffer);
   SetIndexBuffer(2,bbwidthslopeBuffer);
   IndicatorDigits(Digits+2);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 begin=!prev_calculated?rates_total-BBandPeriod-1:rates_total-prev_calculated;
   double bandsUpper, bandsLower, bandsMain, lwma, bbandwidth, tangent;
   double oldBandsUpper, oldBandsLower, oldBandsMain, oldBandsWidth;
   
   for (int i=begin;i>=0;i--)
   //for (int i=1;i<begin;i++)
   {  
      bandsUpper=iBands(NULL,PERIOD_CURRENT,BBandPeriod,2,0,PRICE_CLOSE,MODE_UPPER,i);
      bandsLower=iBands(NULL,PERIOD_CURRENT,BBandPeriod,2,0,PRICE_CLOSE,MODE_LOWER,i);
      bandsMain=iBands(NULL,PERIOD_CURRENT,BBandPeriod,2,0,PRICE_CLOSE,MODE_MAIN,i);
      oldBandsUpper=iBands(NULL,PERIOD_CURRENT,BBandPeriod,2,0,PRICE_CLOSE,MODE_UPPER,i-1);
      oldBandsLower=iBands(NULL,PERIOD_CURRENT,BBandPeriod,2,0,PRICE_CLOSE,MODE_LOWER,i-1);
      oldBandsMain=iBands(NULL,PERIOD_CURRENT,BBandPeriod,2,0,PRICE_CLOSE,MODE_MAIN,i-1);

      bbandwidth=(bandsUpper-bandsLower)/bandsMain*100;
      oldBandsWidth=(oldBandsUpper-oldBandsLower)/oldBandsMain*100;

      bbwidthslopeBuffer[i]=GetAngle(Time[i-1],oldBandsWidth,Time[i],bbandwidth);
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

the bbwidthslopeBuffer was not displayed. What could be wrong here?

Reason: