【漂亮的MT5双线MACD指标[源码]】双色交叉变色  热门

| 发表于 2026-1-28 19:31:31 | 显示全部楼层 |复制链接
最后由 m1800 于 2026-1-28 19:34 编辑

漂亮的MT5双线MACD指标,交叉变色.附源码.

多多点赞,会变好看,多多留言,会变有钱.

屏幕截图 2026-01-28 192544.png
屏幕截图 2026-01-28 192630.png
  1. //+------------------------------------------------------------------+
  2. //|                                                   MACDDouble.mq5 |
  3. //|                   Copyright 2009-2026, MetaQuotes Software Corp. |
  4. //|                                              http://www.mql5.com |
  5. //+------------------------------------------------------------------+
  6. #property copyright   "2009-2026, MetaQuotes Software Corp."
  7. #property link        "http://www.mql5.com"
  8. #property description "Moving Average of Oscillator Double Line"
  9. #property description "MACD Double Line"
  10. #include <MovingAverages.mqh>
  11. //--- indicator settings
  12. #property indicator_separate_window
  13. #property indicator_buffers 7
  14. #property indicator_plots   3
  15. #property indicator_label1  "MACD"
  16. #property indicator_type1   DRAW_COLOR_HISTOGRAM
  17. #property indicator_color1  clrLime,clrRed
  18. #property indicator_width1  3
  19. #property indicator_label2  "DIF"
  20. #property indicator_type2   DRAW_COLOR_LINE
  21. #property indicator_color2  clrDodgerBlue,clrMagenta
  22. #property indicator_style2  STYLE_SOLID
  23. #property indicator_width2  2
  24. #property indicator_label3  "DEA"
  25. #property indicator_type3   DRAW_LINE
  26. #property indicator_color3  clrYellow
  27. #property indicator_style3  STYLE_DOT
  28. #property indicator_width3  1
  29. //--- input parameters
  30. input int                InpFastEMAPeriod = 12;       // Fast EMA period
  31. input int                InpSlowEMAPeriod = 26;       // Slow EMA period
  32. input int                InpSignalSMAPeriod = 9;      // Signal SMA period
  33. input ENUM_APPLIED_PRICE InpAppliedPrice = PRICE_CLOSE; // Applied price
  34. //--- indicator buffers
  35. double                   ExtMACDBuffer[];
  36. double                   ExtMACDColorBuffer[];
  37. double                   ExtDifBuffer[];
  38. double                   ExtDifColorBuffer[];
  39. double                   ExtDeaBuffer[];
  40. double                   ExtSignalBuffer[];
  41. double                   ExtFastMaBuffer[];
  42. double                   ExtSlowMaBuffer[];
  43. //--- MA handles
  44. int                      ExtFastMaHandle;
  45. int                      ExtSlowMaHandle;
  46. //+------------------------------------------------------------------+
  47. //| Custom indicator initialization function                         |
  48. //+------------------------------------------------------------------+
  49. void OnInit()
  50.   {
  51. //--- indicator buffers mapping
  52.    SetIndexBuffer(0, ExtMACDBuffer, INDICATOR_DATA);
  53.    SetIndexBuffer(1, ExtMACDColorBuffer, INDICATOR_COLOR_INDEX);
  54.    SetIndexBuffer(2, ExtDifBuffer, INDICATOR_DATA);
  55.    SetIndexBuffer(3, ExtDifColorBuffer, INDICATOR_COLOR_INDEX);
  56.    SetIndexBuffer(4, ExtDeaBuffer, INDICATOR_DATA);
  57.    SetIndexBuffer(5, ExtFastMaBuffer, INDICATOR_CALCULATIONS);
  58.    SetIndexBuffer(6, ExtSlowMaBuffer, INDICATOR_CALCULATIONS);
  59.    IndicatorSetInteger(INDICATOR_DIGITS, _Digits + 2);
  60. //--- sets first bar from what index will be drawn
  61.    PlotIndexSetInteger(0, PLOT_DRAW_BEGIN, InpSlowEMAPeriod + InpSignalSMAPeriod - 2);
  62. //--- name for DataWindow and indicator subwindow label
  63.    IndicatorSetString(INDICATOR_SHORTNAME, "MACD Double Line(" + string(InpFastEMAPeriod) + "," + string(InpSlowEMAPeriod) + "," + string(InpSignalSMAPeriod) + ")");
  64.    PlotIndexSetString(0, PLOT_LABEL, "MACD");
  65.    PlotIndexSetString(1, PLOT_LABEL, "DIF");
  66.    PlotIndexSetString(2, PLOT_LABEL, "DEA");
  67. //--- get MAs handles
  68.    ExtFastMaHandle = iMA(NULL, 0, InpFastEMAPeriod, 0, MODE_EMA, InpAppliedPrice);
  69.    ExtSlowMaHandle = iMA(NULL, 0, InpSlowEMAPeriod, 0, MODE_EMA, InpAppliedPrice);
  70. //--- initialization done
  71.   }
  72. //+------------------------------------------------------------------+
  73. //|  Moving Average of Oscillator                                    |
  74. //+------------------------------------------------------------------+
  75. int OnCalculate(const int rates_total,
  76.                 const int prev_calculated,
  77.                 const datetime &time[],
  78.                 const double &open[],
  79.                 const double &high[],
  80.                 const double &low[],
  81.                 const double &close[],
  82.                 const long &tick_volume[],
  83.                 const long &volume[],
  84.                 const int &spread[])
  85.   {
  86.    if(rates_total < InpSignalSMAPeriod)
  87.       return(0);
  88. //--- not all data may be calculated
  89.    int calculated = BarsCalculated(ExtFastMaHandle);
  90.    if(calculated < rates_total)
  91.      {
  92.       Print("Not all data of ExtFastMaHandle is calculated (", calculated, "bars ). Error", GetLastError());
  93.       return(0);
  94.      }
  95.    calculated = BarsCalculated(ExtSlowMaHandle);
  96.    if(calculated < rates_total)
  97.      {
  98.       Print("Not all data of ExtSlowMaHandle is calculated (", calculated, "bars ). Error", GetLastError());
  99.       return(0);
  100.      }
  101. //--- we can copy not all data
  102.    int to_copy;
  103.    if(prev_calculated > rates_total || prev_calculated < 0)
  104.       to_copy = rates_total;
  105.    else
  106.      {
  107.       to_copy = rates_total - prev_calculated;
  108.       if(prev_calculated > 0)
  109.          to_copy++;
  110.      }
  111. //--- get Fast EMA buffer
  112.    if(IsStopped())
  113.       return(0); //Checking for stop flag
  114.    if(CopyBuffer(ExtFastMaHandle, 0, 0, to_copy, ExtFastMaBuffer) <= 0)
  115.      {
  116.       Print("Getting fast EMA is failed! Error", GetLastError());
  117.       return(0);
  118.      }
  119. //--- get SlowSMA buffer
  120.    if(IsStopped())
  121.       return(0); //Checking for stop flag
  122.    if(CopyBuffer(ExtSlowMaHandle, 0, 0, to_copy, ExtSlowMaBuffer) <= 0)
  123.      {
  124.       Print("Getting slow SMA is failed! Error", GetLastError());
  125.       return(0);
  126.      }
  127. //---
  128.    int i, limit;
  129.    if(prev_calculated == 0)
  130.       limit = 0;
  131.    else
  132.       limit = prev_calculated - 1;
  133. //--- the main loop of calculations
  134.    for(i = limit; i < rates_total; i++)
  135.      {
  136.       //--- calculate Dif
  137.       ExtDifBuffer[i] = ExtFastMaBuffer[i] - ExtSlowMaBuffer[i];
  138.      }
  139. //--- calculate Signal
  140.    SimpleMAOnBuffer(rates_total, prev_calculated, 0, InpSignalSMAPeriod, ExtDifBuffer, ExtDeaBuffer);
  141.    for(i = limit; i < rates_total; i++)
  142.      {
  143.       if(i == 0)
  144.         {
  145.          ExtDifColorBuffer[i] = 0;
  146.         }
  147.       else
  148.          if(ExtDifBuffer[i] > ExtDeaBuffer[i])
  149.            {
  150.             ExtDifColorBuffer[i] = 0;
  151.            }
  152.          else
  153.            {
  154.             ExtDifColorBuffer[i] = 1;
  155.            }
  156.      }
  157. //--- calculate MACD
  158.    for(i = limit; i < rates_total && !IsStopped(); i++)
  159.      {
  160.       ExtMACDBuffer[i] = (ExtDifBuffer[i] - ExtDeaBuffer[i]) * 2;
  161.       if(i == 0)
  162.         {
  163.          ExtMACDColorBuffer[i] = 0;
  164.         }
  165.       else
  166.          if(ExtMACDBuffer[i] > ExtMACDBuffer[i - 1])
  167.            {
  168.             ExtMACDColorBuffer[i] = 0;
  169.            }
  170.          else
  171.            {
  172.             ExtMACDColorBuffer[i] = 1;
  173.            }
  174.      }
  175. //--- OnCalculate done. Return new prev_calculated.
  176.    return(rates_total);
  177.   }
  178. //+------------------------------------------------------------------+
复制代码
filetype

MACDDouble.ex5

14.66 KB, 下载次数: 46, 下载积分: 活跃度 -5  [下载]

评分
  • 1
  • 2
  • 3
  • 4
  • 5
平均分:5    参与人数:3    我的评分:未评 下载时遇到问题?
举报

评论 使用道具

精彩评论21

peterzhu2004
DDD
| 发表于 2026-1-29 05:54:33 | 显示全部楼层
最喜欢源代码,谢谢分享
举报

点赞 评论 使用道具

1594135666
DDD
| 发表于 2026-1-29 06:19:30 | 显示全部楼层
多多留言,会变有钱 这句话让我不得不留言
举报

点赞 评论 使用道具

绿野游狼
D
| 发表于 2026-1-29 12:09:51 | 显示全部楼层
源码也不会编译啊?大家知道能自动编程的地方不?
举报

点赞 评论 使用道具

dayu1362007
D
| 发表于 2026-1-29 14:23:17 | 显示全部楼层
最喜欢源代码,谢谢分享大家知道能自动编程
举报

点赞 评论 使用道具

dengzehua
DD
| 发表于 2026-1-30 09:06:49 | 显示全部楼层
多多点赞
举报

点赞 评论 使用道具

漫步者
DD
| 发表于 2026-1-30 10:31:12 | 显示全部楼层
好看,不错
举报

点赞 评论 使用道具

hehaigm
D
| 发表于 2026-1-31 09:40:34 | 显示全部楼层
最喜欢源代码,谢谢分享。。。。。
举报

点赞 评论 使用道具

xhvvvv
D
| 发表于 2026-2-2 17:54:34 | 显示全部楼层
这玩意有用吗
举报

点赞 评论 使用道具

dhy385
D
| 发表于 2026-2-3 18:24:38 | 显示全部楼层
这个我需要
举报

点赞 评论 使用道具

q570644129
D
| 发表于 2026-2-4 03:47:36 | 显示全部楼层
多多留言,会变有钱 这句话让我不得不留言,主卧一飞冲天吧
举报

点赞 评论 使用道具

1370367744
DDD
| 发表于 2026-2-7 21:04:17 | 显示全部楼层
点赞,谢谢分享
举报

点赞 评论 使用道具

islove
D
| 发表于 2026-2-8 00:09:23 | 显示全部楼层
真的很棒哦,点赞,谢谢分享
举报

点赞 评论 使用道具

1612471379
D
| 发表于 2026-2-21 10:17:12 来自手机 | 显示全部楼层
留言学习在火火
举报

点赞 评论 使用道具

tcjyy
D
| 发表于 2026-2-25 10:49:38 | 显示全部楼层
源代码分享,感谢,努力学习中
举报

点赞 评论 使用道具

peterzhu2004
DDD
| 发表于 2026-3-7 07:00:00 | 显示全部楼层
复制代码重新做了一个指标,赞
举报

点赞 评论 使用道具

1594135666
DDD
| 发表于 2026-3-8 21:04:50 | 显示全部楼层
谢谢源码
举报

点赞 评论 使用道具

chaoyi996
D
| 发表于 6 天前 | 显示全部楼层
十分感谢,已下载
举报

点赞 评论 使用道具

snowbuyi
D
| 发表于 4 天前 | 显示全部楼层
怎么加载   谁能教一下
举报

点赞 评论 使用道具

轩轩
D
| 发表于 4 天前 | 显示全部楼层
这个可以
举报

点赞 评论 使用道具

12下一页
发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册

广告位