设为首页 收藏本站 切换语言

【双线macd指标】MT4里macd是单线,此源码为双线

| 发表于 2023-10-24 13:51:39 | 显示全部楼层 |复制链接
© 本贴为 chenxiangcic 原创/首发,严禁抄袭!
image.png
image.png
#property copyright   "chenxiangcic"
#property description "Moving Averages of Oscillator"
#property strict

#include <MovingAverages.mqh>

//--- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  clrGreen
#property  indicator_color2  clrRed
#property  indicator_color3  clrYellow
#property  indicator_width1  1
//--- indicator parameters
input int InpFastEMA=12;   // Fast EMA Period
input int InpSlowEMA=26;   // Slow EMA Period
input int InpSignalSMA=9;  // Signal SMA Period
//--- indicator buffers
double ExtmacdBuffer[];
double ExtdifBuffer[];
double ExtdeaBuffer[];
//--- right input parameters flag
bool   ExtParameters=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- 2 additional buffers are used for counting.
   IndicatorBuffers(3);
//--- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexDrawBegin(0,InpSignalSMA);
   IndicatorDigits(Digits+1);
//--- 3 indicator buffers mapping
   SetIndexBuffer(0,ExtmacdBuffer);
   SetIndexBuffer(1,ExtdifBuffer);
   SetIndexBuffer(2,ExtdeaBuffer);
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD("+IntegerToString(InpFastEMA)+","+IntegerToString(InpSlowEMA)+","+IntegerToString(InpSignalSMA)+")");
   SetIndexLabel(0,"macd");
   SetIndexLabel(1,"dif");
   SetIndexLabel(2,"dea");
//--- check for input parameters
   if(InpFastEMA<=1 || InpSlowEMA<=1 || InpSignalSMA<=1 || InpFastEMA>=InpSlowEMA)
     {
      Print("Wrong input parameters");
      ExtParameters=false;
      return(INIT_FAILED);
     }
   else
      ExtParameters=true;
//--- initialization done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Moving Average of Oscillator                                     |
//+------------------------------------------------------------------+
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;
//---
   if(rates_total<=InpSignalSMA || !ExtParameters)
      return(0);
//--- last counted bar will be recounted
   limit=rates_total-prev_calculated;
   if(prev_calculated>0)
      limit++;
//--- macd counted in the 1-st buffer
   for(i=0; i<limit; i++)
      ExtdifBuffer=iMA(NULL,0,InpFastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
                    iMA(NULL,0,InpSlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//--- signal line counted in the 2-nd buffer
   SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtdifBuffer,ExtdeaBuffer);
//--- main loop
   for(i=0; i<limit; i++)
      ExtmacdBuffer=ExtdifBuffer-ExtdeaBuffer;
//--- done
   return(0);
  }
举报

评论 使用道具

精彩评论3

1594135666
DDD
| 发表于 2023-10-24 23:15:43 | 显示全部楼层
直接源码了 非常感谢
举报

点赞 评论 使用道具

wwd199077
D
| 发表于 2023-10-24 23:27:34 | 显示全部楼层
谢谢啊。我试试看
举报

点赞 评论 使用道具

jj644719356
DD
| 发表于 2023-10-25 09:21:32 | 显示全部楼层
还是双线好用,感谢分享
举报

点赞 评论 使用道具

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

简体中文
繁體中文
English(英语)
日本語(日语)
Deutsch(德语)
Русский язык(俄语)
بالعربية(阿拉伯语)
Türkçe(土耳其语)
Português(葡萄牙语)
ภาษาไทย(泰国语)
한어(朝鲜语/韩语)
Français(法语)