#define PI 3.14159265359#define RadToDeg(x) (x)*180/PI
//--- indicator buffersdouble 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) coordinatesChartTimePriceToXY(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 donedouble m=(double)(y2-y1)/(double)(x2-x1)*((double)ChartWidthInPixels()/(double)ChartHeightInPixelsGet());
//Calculate the angle in degreesdouble angle=RadToDeg(MathArctan(m));
return(angle);
}
//+------------------------------------------------------------------+//| The function receives the chart width in pixels |//+------------------------------------------------------------------+int ChartWidthInPixels(constlong chart_ID=0)
{
//--- prepare the variable to get the property valuelong result=-1;
//--- reset the error valueResetLastError();
//--- receive the property valueif(!ChartGetInteger(chart_ID,CHART_WIDTH_IN_PIXELS,0,result))
{
//--- display the error message in Experts journalPrint(__FUNCTION__+", Error Code = ",GetLastError());
}
//--- return the value of the chart propertyreturn((int)result);
}
//+------------------------------------------------------------------+//| The function receives the chart heigth value in pixels |//+------------------------------------------------------------------+int ChartHeightInPixelsGet(constlong chart_ID=0,constint sub_window=0)
{
//--- prepare the variable to get the property valuelong result=-1;
//--- reset the error valueResetLastError();
//--- receive the property valueif(!ChartGetInteger(chart_ID,CHART_HEIGHT_IN_PIXELS,sub_window,result))
{
//--- display the error mesage in Expert journalPrint(__FUNCTION__+", Error Code = ",GetLastError());
}
//--- return the value of the chart propertyreturn((int)result);
}
//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- indicator buffers mappingSetIndexBuffer(0,lwmadiffsmaBuffer);
SetIndexBuffer(1,lwmadiffsmapcBuffer);
SetIndexBuffer(2,bbwidthslopeBuffer);
IndicatorDigits(Digits+2);
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Custom indicator iteration function |//+------------------------------------------------------------------+intOnCalculate(constint rates_total,
constint prev_calculated,
constdatetime &time[],
constdouble &open[],
constdouble &high[],
constdouble &low[],
constdouble &close[],
constlong &tick_volume[],
constlong &volume[],
constint &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 callreturn(rates_total);
}
//+------------------------------------------------------------------+
the bbwidthslopeBuffer was not displayed. What could be wrong here?
the bbwidthslopeBuffer was not displayed. What could be wrong here?