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

CCI_Angle.mq4

CCI_Angle指标创建另类CCI。

图表:CCI_Angle指标

源码:

//+------------------------------------------------------------------+
//|                                                    CCI_Angle.mq4 |
//|                                                           MrPip  |
//+------------------------------------------------------------------+
#property  copyright "Robert L. Hill aka MrPip"
#property link      "http://www.125808047.com"

#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  LimeGreen
#property  indicator_color2  Yellow
#property  indicator_color3 FireBrick

extern int CCIPeriod=14;
extern double AngleTreshold=15.0;
extern int PrevShift=4;
extern int CurShift=0;

double UpBuffer[];
double DownBuffer[];
double ZeroBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
   IndicatorBuffers(3);

   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2);

   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);

   if(!SetIndexBuffer(0,UpBuffer) &&
      !SetIndexBuffer(1,DownBuffer) &&
      !SetIndexBuffer(2,ZeroBuffer))
      Print("cannot set indicator buffers!");

   IndicatorShortName("CCI_Angle("+CCIPeriod+","+AngleTreshold+","+PrevShift+","+CurShift+")");
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| The angle for LSMA                                               |
//+------------------------------------------------------------------+
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[])
  {
   double fCur, fPrev;
   double fAngle, mFactor;
   int nLimit, i;
   int nCountedBars;
   int ShiftDif;
 
   if(CurShift >= PrevShift)
   {
      Print("Error: CurShift >= PrevShift");
      PrevShift = 6;
      CurShift = 0;      
   }  
         
   nCountedBars = IndicatorCounted();
   if(nCountedBars<0) 
      return(-1);
   if(nCountedBars>0) 
      nCountedBars--;
   nLimit = Bars-nCountedBars;

   mFactor = 1.0;
   ShiftDif = PrevShift-CurShift;
   mFactor /= ShiftDif; 
 
   for(i=0; i<nLimit; i++)
   {
      fCur=iCCI(NULL, 0, CCIPeriod, PRICE_CLOSE, i+CurShift);
      fPrev=iCCI(NULL, 0, CCIPeriod, PRICE_CLOSE, i+PrevShift);
      fAngle = mFactor * (fCur - fPrev)/2;

      DownBuffer[i] = 0.0;
      UpBuffer[i] = 0.0;
      ZeroBuffer[i] = 0.0;
      
      if(fAngle > AngleTreshold)
         UpBuffer[i] = fAngle;
      else if (fAngle < -AngleTreshold)
         DownBuffer[i] = fAngle;
      else ZeroBuffer[i] = fAngle;
   }
   return(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » CCI_Angle.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏