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

【MACD】变色MACD  

| 发表于 2021-8-5 08:12:18 | 显示全部楼层 |复制链接
//+------------------------------------------------------------------+
//|                                                       macdbs.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property  indicator_separate_window
#property  indicator_buffers 3
#property  indicator_color1  Black
#property  indicator_color2  Green
#property  indicator_color3  Red
//--- buffers
double     ExtMacdBuffer[];
double     ExtUpBuffer[];
double     ExtDnBuffer[];
//---
#define PERIOD_FAST  12
#define PERIOD_SLOW 26
//--- bars minimum for calculation
#define DATA_LIMIT  34
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit(void)
  {
//--- drawing settings
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   IndicatorDigits(Digits+1);
   SetIndexDrawBegin(0,DATA_LIMIT);
   SetIndexDrawBegin(1,DATA_LIMIT);
   SetIndexDrawBegin(2,DATA_LIMIT);
//--- 3 indicator buffers mapping
   SetIndexBuffer(0,ExtMacdBuffer);
   SetIndexBuffer(1,ExtUpBuffer);
   SetIndexBuffer(2,ExtDnBuffer);
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD");
   IndicatorShortName("MACD("+IntegerToString(PERIOD_FAST)+","+IntegerToString(PERIOD_SLOW)+")");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
  }
//+------------------------------------------------------------------+
//| Awesome 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=rates_total-prev_calculated;
   double prev=0.0,current;
//--- check for rates total
   if(rates_total<=DATA_LIMIT)
      return(0);
//--- last counted bar will be recounted
   if(prev_calculated>0)
     {
      limit++;
      prev=ExtMacdBuffer[limit];
     }
//--- macd
   for(i=0; i<limit; i++)
      ExtMacdBuffer[i]=iMA(NULL,0,PERIOD_FAST,0,MODE_EMA,PRICE_CLOSE,i)-
                     iMA(NULL,0,PERIOD_SLOW,0,MODE_EMA,PRICE_CLOSE,i);
//--- dispatch values between 2 buffers
   bool up=true;
   for(i=limit-1; i>=0; i--)
     {
      current=ExtMacdBuffer[i];
      if(current>prev)
         up=true;
      if(current<prev)
         up=false;
      if(!up)
        {
         ExtDnBuffer[i]=current;
         ExtUpBuffer[i]=0.0;
        }
      else
        {
         ExtUpBuffer[i]=current;
         ExtDnBuffer[i]=0.0;
        }
      prev=current;
     }
//--- done
   return(rates_total);
  }
//+------------------------------------------------------------------+

macd.png
macdbs.png

macdbs.mq4

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

变色MACD指标源码

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

评论 使用道具

精彩评论11

jongjongyoshen
D
| 发表于 2021-8-5 08:16:14 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

bba5675
DDD
| 发表于 2021-8-5 09:05:36 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

木头8500
C
| 发表于 2021-8-5 11:38:55 来自手机 | 显示全部楼层
积分
举报

点赞 评论 使用道具

时光微醺
DD
| 发表于 2021-8-5 13:30:09 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

chun
DDD
| 发表于 2021-8-6 21:38:38 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

tianping
DDD
| 发表于 2021-8-7 09:22:56 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

zhaozhen0224
DD
| 发表于 2021-8-7 09:30:47 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

bba5675
DDD
| 发表于 2021-9-7 14:36:12 | 显示全部楼层
感谢分享
举报

点赞 评论 使用道具

6669
DDD
| 发表于 2022-5-28 09:43:40 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

tui2002
D
| 发表于 2022-6-5 05:35:25 | 显示全部楼层
谢谢分享
举报

点赞 评论 使用道具

空军一号
D
| 发表于 2023-5-22 23:17:19 | 显示全部楼层
怎么没有双线呢

举报

点赞 评论 使用道具

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

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