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

CCI_onMA.mq4 指标将CCI算法与均线算法相结合

CCI_onMA指标将CCI算法与均线算法相结合在主图创建均线。

图表:CCI_onMA指标

源码:

//+------------------------------------------------------------------+
//|                                                     CCI_onMA.mq4 |
//+------------------------------------------------------------------+
#property copyright ""
#property link    "http://www.125808047.com/"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 DodgerBlue
#property indicator_width1 2
#property indicator_width2 1

extern int CCI_Period  =14;
extern int CCI_Price   =5;
extern double CCI_multiplier=0.3;

extern int MaPeriod    =14;
extern int MaMetod     =0;
extern int MaPrice     =5;

extern string   note_Price="0C 1O 2H 3L4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";
extern string   MA_Method_="SMA0 EMA1 SMMA2 LWMA3";

double CCIonMABuffer[];
double MA_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|
int OnInit(void)
{
   IndicatorBuffers(2);
   SetIndexBuffer(0, CCIonMABuffer);
   SetIndexBuffer(1, MA_Buffer);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);

   SetIndexLabel(0,"CCIonMA CCI:("+CCI_Period+"|"+CCI_Price+")("+MaPeriod+")");
   SetIndexLabel(1,"MA ("+MaPeriod+")"+MaMetod+","+MaPrice+"");
   IndicatorShortName("CCIonMA "+CCI_Period+";"+MaPeriod+"");

   for(int i=0;i<indicator_buffers;i++)
      SetIndexDrawBegin(i,MathMax (MaPeriod,CCI_Period));
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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    i,limit,    CountedBars=IndicatorCounted();
   if (CountedBars<0) return(-1);
   if (CountedBars>0) CountedBars--;

   limit= Bars-CountedBars;
   limit= MathMax(limit,CCI_Period);
   limit= MathMax(limit,MaPeriod);

   for(i=limit;i>=0;i--)
     {
      double     CCI_val =iCCI(NULL,0,CCI_Period,CCI_Price,i);
      MA_Buffer      [i] =iMA(NULL,0,MaPeriod,0,MaMetod,MaPrice,i);
      CCIonMABuffer  [i] =CCI_val*CCI_multiplier*Point+ MA_Buffer[i];
     }
   return(rates_total);
  }
打赏
版权所有转载请注明标题及链接:峰汇在线 » CCI_onMA.mq4 指标将CCI算法与均线算法相结合
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏