|
炒外汇论坛
这一篇叫:我的布林
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Black
#property indicator_color3 Black
//---- indicator parameters
extern int BP=60;
extern int BS=0;
extern double BD=2;
//---- buffers
double MB[];
double UB[];
double LB[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_LINE,0,2,Blue);
SetIndexBuffer(0,MB);
SetIndexStyle(1,DRAW_LINE,0,2,Black);
SetIndexBuffer(1,UB);
SetIndexStyle(2,DRAW_LINE,0,2,Black);
SetIndexBuffer(2,LB);
//----
SetIndexDrawBegin(0,BP+BS);
SetIndexDrawBegin(1,BP+BS);
SetIndexDrawBegin(2,BP+BS);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Bollinger Bands |
//+------------------------------------------------------------------+
int start()
{
int i,k,counted_bars=IndicatorCounted();
double deviation;
double sum,oldval;
//----
if(Bars<=BP) return(0);
//---- initial zero
if(counted_bars<1)
for(i=1;i<=BP;i++)
{
MB[Bars-i]=EMPTY_VALUE;
UB[Bars-i]=EMPTY_VALUE;
LB[Bars-i]=EMPTY_VALUE;
}
//----
int limit=Bars-counted_bars;
if(counted_bars>0) limit++;
for(i=0; i<limit; i++)
MB=iMA(NULL,0,BP,BS,0,0,i);
//----
i=Bars-BP+1;
if(counted_bars>BP-1) i=Bars-counted_bars-1;
while(i>=0)
{
sum=0.0;
k=i+BP-1;
oldval=MB;
while(k>=i)
{
sum+=MathAbs(Close[k]-oldval);
k--;
}
deviation=sum/BP*BD;
UB=oldval+deviation;
LB=oldval-deviation;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+ |
|