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

Coppock.mq4

Coppock指标根据3组特定参数的均线算法在副图创建柱状线。柱状线的零轴上、零轴下、递增、递减分别代表不同的行情走势。

图表:Coppock指标

源码:

//+------------------------------------------------------------------+
//|                                                      Coppock.mq4 |
//|                                     Copyright @2007, Robert Hill |
//+------------------------------------------------------------------+
#property  copyright "Copyright @2007, Robert Hill"
#property link      "http://www.125808047.com"

#property  indicator_separate_window
#property  indicator_buffers 1
#property  indicator_color1  Red
#property  indicator_level1  0

extern string  strROC="ROC Period for lookback";
extern int     RPeriod1=80;
extern string  strType1="Moving Average Types" ;
extern string  str10="0 = SMA, 1 = EMA";
extern string  str11="2 = SMMA, 3 = LWMA";
extern int     RMAMode1=0;
extern string  sep0="----------------------------------";
extern int     RPeriod2=10;
extern string  strType2="Moving Average Types" ;
extern string  str20="0 = SMA, 1 = EMA";
extern string  str21="2 = SMMA, 3 = LWMA";
extern int     RMAMode2=0;
extern string  sep1="----------------------------------";
extern string  strMA="MA input parameters";
extern int     MAPeriod=20;
extern string  strType="Moving Average Types" ;
extern string  strm0="0 = SMA, 1 = EMA";
extern string  strm1="2 = SMMA, 3 = LWMA";
extern int     MAType=0;
extern string  sep2="----------------------------------";
extern bool    UsePercent=false;

double     Coppock[];
double     RateOfChange1[];
double     RateOfChange2[];
double     RateOfChange3[];

int    MAMode;
string strMAType;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexDrawBegin(0,MAPeriod);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);

   SetIndexBuffer(0,Coppock);
   SetIndexBuffer(1,RateOfChange1);
   SetIndexBuffer(2,RateOfChange2);
   SetIndexBuffer(3,RateOfChange3);
   switch(MAType)
     {
      case 1: strMAType="EMA"; MAMode=MODE_EMA; break;
      case 2: strMAType="SMMA"; MAMode=MODE_SMMA; break;
      case 3: strMAType="LWMA"; MAMode=MODE_LWMA; break;
      default: strMAType="SMA"; MAMode=MODE_SMA; break;
     }
   IndicatorShortName( "Coppock (" + RPeriod1 + "," + RPeriod2 + ") " + strMAType+ " (" +MAPeriod + ") ");

   SetIndexLabel(0,"Coppock");
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Coppock                                                          |
//+------------------------------------------------------------------+
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, i;
   double MA_Cur1, MA_Prev1;
   double MA_Cur2, MA_Prev2;
   double ROC1, ROC2;
   int counted_bars=IndicatorCounted();

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

   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for( i=0; i<limit; i++)
     {
      MA_Cur1=iMA(NULL,0,RPeriod1,0,RMAMode1, PRICE_CLOSE,i);
      MA_Prev1=iMA(NULL,0,RPeriod1,0,RMAMode1, PRICE_CLOSE,i+RPeriod1);
      MA_Cur2=iMA(NULL,0,RPeriod2,0,RMAMode2, PRICE_CLOSE,i);
      MA_Prev2=iMA(NULL,0,RPeriod2,0,RMAMode2, PRICE_CLOSE,i+RPeriod2);
      ROC1=MA_Cur1-MA_Prev1;
      ROC2=MA_Cur2-MA_Prev2;
      if (UsePercent)
        {
         RateOfChange1[i]=NormalizeDouble(100 * ROC1/MA_Prev1, 3);
         RateOfChange2[i]=NormalizeDouble(100 * ROC2/MA_Prev2, 3);
        }
      else
        {
         RateOfChange1[i]=NormalizeDouble(ROC1/Point,1);
         RateOfChange2[i]=NormalizeDouble(ROC2/Point,1);
        }
      RateOfChange3[i]=RateOfChange1[i] + RateOfChange2[i];
     }
   for( i=0; i<limit; i++)
     {
      Coppock[i]=iMAOnArray(RateOfChange3,0,MAPeriod,0,MAMode,i);
     }
   return(rates_total);
  }
打赏
版权所有转载请注明标题及链接:峰汇在线 » Coppock.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏