ATR SMA复合指标

把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);
  }

本博客所有文章如无特别注明均为原创。作者:天泓评测
分享到:更多

相关推荐

发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(0)