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

另类CCI指标 CCI_Trigger.mq4

CCI_Trigger指标创建另类CCI曲线。

图表:CCI_Trigger指标

源码:

//+------------------------------------------------------------------+
//|                                                  CCI_Trigger.mq4 |
//|                       Copyright @2007, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property  copyright "Copyright @2007, GideonSmolders(at)gmail.com."
#property  link      "http://www.125808047.com/"

#property  indicator_separate_window
#property  indicator_buffers 6
#property  indicator_color1  LightBlue
#property  indicator_color2  Blue
#property  indicator_color3  LightPink
#property  indicator_color4  Pink
#property  indicator_color5  Yellow
#property  indicator_color6  Green

extern double CCIPeriod= 3;
extern double MainPeriod = 21;
extern double TriggerPeriod = 5;

extern double TriggerMode = MODE_LWMA;   
extern double MainMode = MODE_SMMA;

string signal;
double cci_open[];
double cci_close[];
double cci_openma[];
double cci_closema[];
double TriggerCCI[];
double MainCCI[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   IndicatorBuffers(6);
   
   SetIndexStyle(0,DRAW_NONE,STYLE_SOLID,1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(2,DRAW_NONE,STYLE_SOLID,1);
   SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(4,DRAW_LINE,STYLE_SOLID,1);
   SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,1);
   
   SetIndexBuffer(0,cci_open);
   SetIndexLabel(0,"CCIopen");
   SetIndexBuffer(1,cci_close);
   SetIndexLabel(1,"CCIclose");
   SetIndexBuffer(2,cci_openma);
   SetIndexLabel(2,"CCIopenMA");
   SetIndexBuffer(3,cci_closema);
   SetIndexLabel(3,"CCIcloseMA");
   SetIndexBuffer(4,TriggerCCI);
   SetIndexLabel(4,"Trigger CCI");
   SetIndexBuffer(5,MainCCI);
   SetIndexLabel(5,"Main Line");
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Calculations                                    |
//+------------------------------------------------------------------+
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[])
  {
   int limit;
   int i;
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
//---- main loop
   
//---- done
   for(i=0; i <= Bars; i++) 
   {
   cci_open[i]=iCCI(Symbol(),0,CCIPeriod,PRICE_OPEN,i);
   }
   for(i=0; i <= Bars; i++) 
   { 
   cci_close[i] = iCCI(Symbol(),0,CCIPeriod,PRICE_CLOSE,i);
   }
   for(i=0; i <= Bars; i++) 
   {
   cci_openma[i]=(   iCCI(Symbol(),0,CCIPeriod,PRICE_OPEN,i)+
                  iCCI(Symbol(),0,CCIPeriod,PRICE_CLOSE,i+1)
                )/2;
   }
   for(i=0; i <= Bars; i++) 
   { 
   cci_closema[i] = (   iCCI(Symbol(),0,CCIPeriod,PRICE_OPEN,i)+
                  iCCI(Symbol(),0,CCIPeriod,PRICE_CLOSE,i+1)
                )/2;
   }
   for(i=0; i <= Bars; i++) 
   {   
   TriggerCCI[i]= iMAOnArray(cci_closema,0,TriggerPeriod,0,TriggerMode,i);
   }
   for(i=0; i <= Bars; i++) 
   {
   MainCCI[i]= iMAOnArray(cci_openma,0,MainPeriod,0,MainMode,i+1);
   }

   
   for(i=0; i<=Bars; i++)
   {
      if(MainCCI[i]>cci_openma[i] && MainCCI[i]>cci_close[i] && cci_close[i]<cci_close[i+1]
         && cci_close[i]<cci_open[i] && TriggerCCI[i]<TriggerCCI[i+1])
      signal = "SELL";
      else if (MainCCI[i]<cci_openma[i] && MainCCI[i]<cci_close[i] && cci_close[i]<cci_close[i+1]
               && cci_close[i]>cci_open[i] && TriggerCCI[i]>TriggerCCI[i+1])
      signal = "BUY";
      else
      signal = "NEUTRAL";
 
    IndicatorShortName("CCI: "+signal);
   return(0); }
  return(rates_total);}
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 另类CCI指标 CCI_Trigger.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏