#property copyright 'yee'
#property link 'https://blog.51cto.com/noican'
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 PaleVioletRed
#property indicator_width1 2
//
//
//
//
//
extern int StdDevLen = 14;
extern int StdDevPrice = PRICE_TYPICAL;
extern int StdDevMaMode = MODE_EMA;
extern int NormalizationPeriod = 50;
//
//
//
//
//
double width[];
double devs[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(2);
SetIndexBuffer(0, width);
SetIndexBuffer(1, devs);
IndicatorShortName(' BB width normalized ('+StdDevLen+')');
return(0);
}
int deinit() { return(0); }
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int i,limit,counted_bars = IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = MathMin(Bars - counted_bars,Bars-1);
//
//
//
//
//
for(i = limit; i >= 0 ; i--)
{
devs[i] = iStdDev(NULL,0,StdDevLen,0,StdDevMaMode,StdDevPrice,i);
double max = devs[ArrayMaximum(devs,NormalizationPeriod,i)];
double min = devs[ArrayMinimum(devs,NormalizationPeriod,i)];
if (max!=min)
width[i] = 100.0*(devs[i] - min) / (max-min);
else width[i] = 0;
}
return(0);
}
|