AD优化指标 CHO.mq4-MT4指标-峰汇在线
诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

AD优化指标 CHO.mq4

CHO指标属于AD指标的一种优化。

图表:CHO指标

源码:

//+------------------------------------------------------------------+
//|                                                          CHO.mq4 |
//|                       Copyright @2007, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright @2007, MetaQuotes Software Corp."
#property link      "http://www.125808047.com/"

#property  indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DarkBlue

extern int       SlowPeriod=10;
extern int       FastPeriod=3;
extern int       TypeSmooth=0;

double CHO[];
double AD[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
   string name,smoothString;
   if (TypeSmooth<0 || TypeSmooth>1) TypeSmooth=0;
   if (TypeSmooth==0) smoothString="SMA"; else smoothString="EMA";
   name="Chaikin Oscillator("+SlowPeriod+","+FastPeriod+","+smoothString+")";

   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,CHO);
   SetIndexLabel(0,name);
   SetIndexEmptyValue(0,0.0);
   SetIndexBuffer(1,AD);
   SetIndexEmptyValue(1,0.0);
   IndicatorShortName(name);
   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    counted_bars=IndicatorCounted();
   int limit,i;

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

   if (counted_bars==0) 
      {
      limit=Bars-1;
      for (i=limit;i>=0;i--)
        {
         AD[i]=iAD(NULL,0,i);
        }
      for(i=limit-SlowPeriod;i>=0;i--)
        {
         CHO[i]=iMAOnArray(AD,0,FastPeriod,0,TypeSmooth,i)-iMAOnArray(AD,0,SlowPeriod,0,TypeSmooth,i);
        }
      }

   if (counted_bars>0) 
     {
      limit=Bars-counted_bars;
      for (i=limit;i>=0;i--)
        {
         AD[i]=iAD(NULL,0,i);
        }
      for(i=limit;i>=0;i--)
        {
         CHO[i]=iMAOnArray(AD,0,FastPeriod,0,TypeSmooth,i)-iMAOnArray(AD,0,SlowPeriod,0,TypeSmooth,i);
        }
      }            
   return(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » AD优化指标 CHO.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏