外汇论坛 外兔财经

开启左侧

解决Mt4 macd问题

[复制链接]
发表于 2007-9-3 11:07 | 显示全部楼层 |阅读模式
https://www.y2cn.com
把这个文件存为macd.mq4加到/experts/indicators/就是传统的MACD了
//+------------------------------------------------------------------+
//|                                         MACD_ColorHist_Alert.mq4 |
//|                                    Copyright ?2006, Robert Hill |
//|                                                                  |
//+------------------------------------------------------------------+
#property  copyright "Copyright ?2006, Robert Hill"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  Aqua
#property  indicator_color2  Red
#property  indicator_color3  Green
#property  indicator_color4  Red

//---- indicator parameters

extern bool SoundON=true;
extern bool EmailON=false;

extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
//---- indicator buffers
double     ind_buffer1[];
double     ind_buffer2[];
double HistogramBufferUp[];
double HistogramBufferDown[];
int flagval1 = 0;
int flagval2 = 0;
//---- variables

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
//   IndicatorBuffers(3);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+1);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
   SetIndexBuffer(0,ind_buffer1);
   SetIndexDrawBegin(0,SlowEMA);
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(1,ind_buffer2);
   SetIndexDrawBegin(1,SignalSMA);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(2,HistogramBufferUp);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID);
   SetIndexBuffer(3,HistogramBufferDown);
//   SetIndexDrawBegin(2,SlowEMA + SignalSMA);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD("+FastEMA+","+SlowEMA+","+SignalSMA+"";
   SetIndexLabel(0,"MACD";
   SetIndexLabel(1,"Signal";
   SetIndexLabel(2,"Histogram";
   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   double temp;
   
   int counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
   for(int i=0; i<limit; i++)
      ind_buffer1=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
   for(i=0; i<limit; i++)
      ind_buffer2=iMAOnArray(ind_buffer1,Bars,SignalSMA,0,MODE_SMA,i);
//      ind_buffer2 = alpha*ind_buffer1 + alpha_1*ind_buffer2[i+1];

   for(i=0; i<limit; i++)
   {
      HistogramBufferUp = 0;
      HistogramBufferDown = 0;
      temp = ind_buffer1 - ind_buffer2;
      if (temp >= 0)
        HistogramBufferUp = temp;
      else
        HistogramBufferDown = temp;
      
      if (i == 1)
      {
        if (HistogramBufferUp > 0 && HistogramBufferDown[i + 1] < 0)
//        if (HistogramBufferUp >  HistogramBufferUp[i + 1])
        {
// Cross up
         if (flagval1==0)
         {
           flagval1=1;
           flagval2=0;
           if (SoundON) Alert("MACD Crossed up","\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
           if (EmailON) SendMail("MACD Crossed up", "MACD Crossed up, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
        }
        else if (HistogramBufferDown < 0 && HistogramBufferUp[i + 1] > 0)
//        else if (HistogramBufferUp <  HistogramBufferUp[i + 1] )
        {
// Cross down
         if (flagval2==0)
         {
          flagval2=1;
          flagval1=0;
          if (SoundON) Alert("MACD Crossed down","\n Date=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period());
          if (EmailON) SendMail("MACD Crossed down","MACD Crossed Down, Date="+TimeToStr(CurTime(),TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Period());
         }
        }
      }
      
   }
      
//---- done
   return(0);
  }


[ 本帖最后由 peterlong 于 2007-9-3 11:12 编辑 ]
发表于 2007-9-4 10:08 | 显示全部楼层
我试了,是txt文件啊 还是不行啊
 楼主| 发表于 2007-9-5 12:16 | 显示全部楼层

注意一下

1.文件里有几个表情符号,实际上是右括号),在拷贝时会漏掉
2.文件要改存为.mq4格式
发表于 2007-10-30 19:10 | 显示全部楼层



让我来说明一下:

先将代码复制到记事本里面,保存为后缀名为mq4的文件,[注意你用记事本保存的时候需要在保存的文件名输入全名"传统的MACD.mq4",否则会以.txt后缀保存. 并确认保存的目录正确],然后将漏掉的右括号")"加上,将文件复制到mt4安装目录\experts\indicators下.重启软件

[ 本帖最后由 player0702 于 2007-10-30 20:20 编辑 ]
发表于 2007-10-31 10:33 | 显示全部楼层

不行啊

搞不出来啊!~~~~房主能不能直接搞好了的放个在这里啊?
发表于 2007-11-12 00:49 | 显示全部楼层
好东西
发表于 2007-11-14 13:08 | 显示全部楼层
学习
发表于 2007-11-15 11:47 | 显示全部楼层
怎么用啊?可以再详细一些吗?
发表于 2007-11-19 07:08 | 显示全部楼层

本版积分规则

QQ|手机版 Mobile Version|Archiver|关于我们 About Us|联系我们 Contact Us|Y2外汇论坛 外兔财经

GMT+8, 2024-5-2 23:09 , Processed in 0.049135 second(s), 29 queries .

Powered by Discuz! X7.2

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表