加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

MT4中MACD指标

(2012-03-05 00:33:43)
标签:

macd

mt4

指标

模型

ea

财经

分类: 交易成长

写了MACD在MT4的指标,希望对大家有用!

 

效果图如下:

MT4中MACD指标

 

源码如下:

//+------------------------------------------------------------------+
//|                                                         JDMACD.mq4 |
//|                                           Copyright ?2011, iPan. |
//|                                http://blog.sina.com.cn/panqunjun |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2011, iPan."
#property link      "http://blog.sina.com.cn/panqunjun"

//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 White
#property indicator_color2 Yellow
#property indicator_color3 Lime
#property indicator_color4 White

//---- indicator parameters
extern int FastEMA = 12;
extern int SlowEMA = 26;
extern int SignalSMA = 9;
//---- indicator buffers
double DiffBuffer[];
double DeaBuffer[];
double ColumnBuffer0[];
double ColumnBuffer1[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //---- drawing settings
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_HISTOGRAM);
   SetIndexStyle(3, DRAW_HISTOGRAM);
   IndicatorDigits(Digits + 1);
   SetIndexDrawBegin(1, SignalSMA);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0, DiffBuffer);
   SetIndexBuffer(1, DeaBuffer);
   SetIndexBuffer(2, ColumnBuffer0);
   SetIndexBuffer(3, ColumnBuffer1);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("JDMACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
   SetIndexLabel(0, "DIFF");
   SetIndexLabel(1, "DEA");
   SetIndexLabel(2, NULL);
   SetIndexLabel(3, NULL);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Awesome Oscillator                                               |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars = IndicatorCounted();
   double prev, current;
   bool up = true;
  
   if(counted_bars>0) counted_bars--;
   limit = Bars - counted_bars;
  
   for(int i=0; i<limit; i++) {
      DiffBuffer[i] = iMA(NULL, 0, FastEMA, 0, MODE_EMA, PRICE_CLOSE, i) - iMA(NULL, 0, SlowEMA, 0, MODE_EMA, PRICE_CLOSE, i);
   }
   for(i=0; i<limit; i++) {
      DeaBuffer[i] = iMAOnArray(DiffBuffer, Bars, SignalSMA, 0, MODE_EMA, i);
   }
   for(i=0; i<limit; i++) {
      current = DiffBuffer[i] - DeaBuffer[i];
      prev = DiffBuffer[i + 1] - DeaBuffer[i + 1];
      if(current >= prev) up = true;
      if(current < prev) up = false;
      //Print("up=" + up);
      if(!up) {
         ColumnBuffer1[i] = current;
         ColumnBuffer0[i] = 0.0;
      } else {
         ColumnBuffer0[i] = current;
         ColumnBuffer1[i] = 0.0;
      }
   }

   return(0);
  }
//+------------------------------------------------------------------+

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有