把ATR进行SMA,这属于复合指标
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
extern int PeriodNumber=21;
//---- buffers
double OHLCBuffer1[];
double OHLCBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- 1 additional buffer used for counting.
IndicatorBuffers(2);
IndicatorDigits(Digits);
//---- indicator line
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,OHLCBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,OHLCBuffer2);
//---- name for DataWindow and indicator subwindow label
short_name="Bogie-ATR_SMA-IND-v1";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int i,counted_bars=IndicatorCounted();
//----
if(Bars<=Period()) return(0);
//----
int limit=Bars-counted_bars;
if(counted_bars>0) limit++;
for(i=0; i<limit; i++)
OHLCBuffer2[i]=iATR(NULL,PERIOD_D1,PeriodNumber,i);
//----
i=Bars-counted_bars-1;
while(i>=0)
{
OHLCBuffer1[i]=iMAOnArray(OHLCBuffer2,Bars,PeriodNumber,0,MODE_SMA,i);
i--;
}
//----
return(0);
}
发表评论