诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

伍迪CCI指标 CCI woodies.mq4

CCI woodies指标是CCI指标的一种优化。

图表:CCI woodies指标

源码:

//+------------------------------------------------------------------+
//|                                                  CCI woodies.mq4 |
//|                                            Copyright @2005, Gaba |
//+------------------------------------------------------------------+
#property copyright "Copyright @2005, Gaba"
#property link      "http://www.125808047.com"

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color1 Silver
#property indicator_color2 LimeGreen
#property indicator_color3 OrangeRed
#property indicator_color4 Blue
#property indicator_color5 Yellow

#property indicator_minimum -300
#property indicator_maximum  300

#property indicator_level1  200
#property indicator_level2  100
#property indicator_level3 -100
#property indicator_level4 -200
#property indicator_level5 0


extern int fastPeriod  = 6;
extern int slowPeriod  = 14;
extern int histLength  = 500;

double FastBuffer[];    
double SlowBuffer[];    
double HistBuffer[];
double UpTrBuffer[];
double DnTrBuffer[];

int OnInit(void)
{
   string short_name;
   IndicatorBuffers(5);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   short_name="WoodiesCCI("+fastPeriod+","+slowPeriod+")";
   IndicatorShortName(short_name);

   SetIndexStyle(0, DRAW_HISTOGRAM);   
   SetIndexBuffer(0, HistBuffer);
   SetIndexDrawBegin(0, slowPeriod);
   SetIndexLabel(0,"SlowCCI histogram");      
   SetIndexEmptyValue(0, EMPTY_VALUE);  

   SetIndexStyle(1, DRAW_HISTOGRAM);   
   SetIndexBuffer(1, UpTrBuffer);
   SetIndexDrawBegin(1, slowPeriod); 
   SetIndexLabel(1,"UpTrend histogram");           
   SetIndexEmptyValue(1, EMPTY_VALUE);  

   SetIndexStyle(2, DRAW_HISTOGRAM);   
   SetIndexBuffer(2, DnTrBuffer);
   SetIndexDrawBegin(2, slowPeriod);  
   SetIndexLabel(2,"DnTrend histogram");     
   SetIndexEmptyValue(2, EMPTY_VALUE);  

   SetIndexStyle(3, DRAW_LINE,1,3);   
   SetIndexBuffer(3, SlowBuffer);
   SetIndexDrawBegin(3, slowPeriod);     
   SetIndexLabel(3,"SlowCCI("+slowPeriod+")");   
   SetIndexEmptyValue(3, EMPTY_VALUE);  

   SetIndexStyle(4, DRAW_LINE);
   SetIndexBuffer(4, FastBuffer);
   SetIndexDrawBegin(4, slowPeriod);     
   SetIndexLabel(4,"FastCCI("+fastPeriod+")");  
   SetIndexEmptyValue(4, EMPTY_VALUE);  
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   string symbolName;
   int i, shift, checksum, counted_bars=IndicatorCounted();
   double slowCCI=0.0;
   if (Bars<slowPeriod) return(0); 

   if (counted_bars<0) return(-1);

   if (counted_bars>0) counted_bars++;
   int limit=Bars-counted_bars;
   if (counted_bars<1 || checksum!=(histLength+fastPeriod+slowPeriod+Period()) || symbolName!=Symbol())
   {
      for(i=Bars-1; i<=Bars-histLength; i++) 
      {
         FastBuffer[i]=EMPTY_VALUE;    
         SlowBuffer[i]=EMPTY_VALUE;    
         HistBuffer[i]=EMPTY_VALUE;   
         UpTrBuffer[i]=EMPTY_VALUE;    
         DnTrBuffer[i]=EMPTY_VALUE;  
      }
      checksum = histLength+fastPeriod+slowPeriod+Period(); 
      symbolName=Symbol();
      limit = histLength;
   }   
   for (shift=limit; shift>=0; shift--)
   {
      FastBuffer[shift] = iCCI(NULL,0,fastPeriod,PRICE_TYPICAL,shift);
      SlowBuffer[shift] = iCCI(NULL,0,slowPeriod,PRICE_TYPICAL,shift);
      HistBuffer[shift] = SlowBuffer[shift];
      UpTrBuffer[shift] = EMPTY_VALUE;
      DnTrBuffer[shift] = EMPTY_VALUE;         

      int a, up=0, dn=0;
      for (a=0;a<8;a++)
      {  
         slowCCI=iCCI(NULL,0,slowPeriod,PRICE_TYPICAL,shift+a);
         if (slowCCI>0) up++;
         if (slowCCI<=0) dn++;		         
		}
      if (up>=6) UpTrBuffer[shift]=SlowBuffer[shift];
      if (dn>=6) DnTrBuffer[shift]=SlowBuffer[shift];      
   }    
   return(rates_total);
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » 伍迪CCI指标 CCI woodies.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏