在MT4上使用双线MACD指标源码

在MT4上使用双线MACD指标源码MACD指标是股票交易中经典的一款技术分析指标,该指标由两条曲线和柱线组成。基本用法:MACD金叉:DIFF由下向上突破DEA,为买入信号。MACD死叉:DIFF由上向下突破DEA,为卖出信号。MACD绿转红:MACD值由负变正,市场由空头转为多头。MACD红转绿:MACD值正转负,市场多头转空头。DIFF与DEA均为正值,即都在零轴线以上时,大势属于多头市场,DIFF向上突破DEA,可以做买入信号。DIFF与DEA均为负值,即都在零轴线以下时,大势属于空头市场,DIFF向下跌破DEA,可做卖出信号。DE

大家好,又见面了,我是你们的朋友全栈君。

MACD指标是股票交易中经典的一款技术分析指标,该指标由两条曲线和柱线组成。

基本用法:MACD金叉:DIFF由下向上突破DEA,为买入信号。MACD死叉:DIFF由上向下突破DEA,为卖出信号。MACD绿转红:MACD值由负变正,市场由空头转为多头。MACD红转绿:MACD值正转负,市场多头转空头。DIFF与DEA均为正值,即都在零轴线以上时,大势属于多头市场,DIFF向上突破DEA,可以做买入信号。DIFF与DEA均为负值,即都在零轴线以下时,大势属于空头市场,DIFF向下跌破DEA,可做卖出信号。DEA在盘整局面失误率高,配合RSI及KDJ指标可以适当弥补缺点。

效果如下:
在这里插入图片描述
源代码:

#property copyright "Copyright 2021,EATrader."

#property link "https://www.mql5.com/"

#property description "关注公众号:从零开始学EA交易"

                       "\n微信号:XQH20200705"

#property icon "\\Images\\001.ico"

#property version "1.00"

#property strict

#property indicator_separate_window

#property indicator_buffers 4

#property indicator_plots 4

//--- plot DIF

#property indicator_label1 "DIF"

#property indicator_type1 DRAW_LINE

#property indicator_color1 clrSilver

#property indicator_style1 STYLE_SOLID

#property indicator_width1 1

//--- plot DEA

#property indicator_label2 "DEA"

#property indicator_type2 DRAW_LINE

#property indicator_color2 clrYellow

#property indicator_style2 STYLE_SOLID

#property indicator_width2 1

//--- plot macd hist+

#property indicator_label3 "Macd+"

#property indicator_type3 DRAW_HISTOGRAM

#property indicator_color3 clrRed

#property indicator_style3 STYLE_SOLID

#property indicator_width3 1

//--- plot macd hist-

#property indicator_label4 "Macd-"

#property indicator_type4 DRAW_HISTOGRAM

#property indicator_color4 clrAqua

#property indicator_style4 STYLE_SOLID

#property indicator_width4 1





input int FastEMA = 12;

input int SlowEMA = 26;

input int MACDEMA = 9;





//--- indicator buffers

double         DIFBuffer[];

double         DEABuffer[];

double         MacdHistBuffer[];

double         MacdHistBuffer1[];

double w=0;

double w1=0;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int OnInit()

  { 
   

//--- indicator buffers mapping

   SetIndexBuffer(0,DIFBuffer);

   SetIndexBuffer(1,DEABuffer);

   SetIndexBuffer(2,MacdHistBuffer);

   SetIndexBuffer(3,MacdHistBuffer1);



   SetIndexEmptyValue(2,EMPTY_VALUE);

   SetIndexEmptyValue(3,EMPTY_VALUE);



   for(int i=0; i<4; i++)

      SetIndexDrawBegin(i,SlowEMA+MACDEMA);



   IndicatorDigits(Digits);



   IndicatorShortName("MACD("+(string)FastEMA+","+(string)SlowEMA+","+(string)MACDEMA+")");



   if(FastEMA<0 || SlowEMA<0 || MACDEMA<0)

      return(INIT_FAILED);



   w = 2.0/(MACDEMA + 1);

   w1= 1.0-w;



//---

   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 i,limit=0;

   if(rates_total<=0) return(0);

   if(prev_calculated<=0) limit=rates_total-1;

   else limit=rates_total-prev_calculated+1;

   double hst=0.0;

   for(i=limit; i>=0; i--)

     { 
   

      if(i==rates_total-1) continue;

      DIFBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);

      DEABuffer[i]=w*DIFBuffer[i]+w1*DEABuffer[i+1];

      hst = 2.0*(DIFBuffer[i]-DEABuffer[i]);

      if(hst>=0)

        { 
   

         MacdHistBuffer[i]=hst;

         MacdHistBuffer1[i]=EMPTY_VALUE;

        }

      else

        { 
   

         MacdHistBuffer1[i]=hst;

         MacdHistBuffer[i]=EMPTY_VALUE;

        }



     }



//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

工欲善其事,必先利其器,交易最重要的是遵守规则,严格执行。关注公众号,学习MQL入门到精通EA教程,学习更多EA编程,畅写属于自己的EA,锻造属于自己的神兵利器。
在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/139285.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • jquery ajax实例代码_jquery ajax详解

    jquery ajax实例代码_jquery ajax详解Jquery在异步提交方面封装的很好,直接用AJAX非常麻烦,Jquery大大简化了我们的操作,不用考虑浏览器的诧异了。推荐一篇不错的jQueryAjax实例文章,忘记了可以去看看,地址为:http://www.cnblogs.com/yeer/archive/2009/07/23/1529460.html和http://www.w3school.com.cn/jquery/

    2022年8月16日
    3
  • vs2008激活、序列号

    vs2008激活、序列号参考:VS2008简体中文正式版序列号(到期解决办法)​​​​​​​链接:https://pan.baidu.com/s/1xKXW3h585jYOU26EdINsIg提取码:a1wu复制这段内容后打开百度网盘手机App,操作更方便哦…

    2022年7月20日
    25
  • Web安全-一句话木马

    Web安全-一句话木马概述在很多的渗透过程中,渗透人员会上传一句话木马(简称Webshell)到目前web服务目录继而提权获取系统权限,不论asp、php、jsp、aspx都是如此,那么一句话木马到底是什么呢?先来看看最简单的一句话木马:&amp;amp;amp;amp;amp;amp;amp;lt;?php@eval($_POST[‘attack’])?&amp;amp;amp;amp;amp;amp;amp;gt;【基本原理】利用文件上传漏洞,往目标网站中上传一句话木马,然后你就

    2022年5月11日
    35
  • python中的set(),zip()以及map()函数

    python中的set(),zip()以及map()函数set、zip和map函数均为python的内置函数。(1)set()用法:set(interable)用来创建一个无序不重复元素的集合。可以对其进行集合的一系列操作,例如求差集、并集和补集,利

    2022年7月5日
    17
  • 2019年日历假期添加

    2019年日历假期添加

    2021年11月27日
    44
  • pycharm选中一行代码快捷键_python代码自动对齐

    pycharm选中一行代码快捷键_python代码自动对齐在写代码的时候,经常为了对齐代码而烦恼,强大的pycharm为我们提供了一个代码自动对齐功能,而且可以使用快捷键完成。快捷键组合是:Ctrl+Alt+L将光标置于需要调整的代码行,或者选择一个区域,按下快捷键,代码就可以自动对齐啦!…

    2022年8月27日
    38

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号