Jump to content

MACD Color Cross Indicator


benny3

Recommended Posts

Re: (Req) MACD Colour cross indicator

 

Hi benny3,

Try this MACDbar

 

//+------------------------------------------------------------------+
//|                                      MACDBars.mq4 modified from  |
//|                                              mtt-ErgodicMACD.mq4 |
//|                   Copyright © 2004-07, MetaQuotes Software Corp. |
//|                                       [url]http://www.metaquotes.net/[/url] |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2004-07, mietectec"
#property  link      ""
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  DarkGreen
#property  indicator_color2  Red
#property indicator_width1 4
#property indicator_width2 4
#property  indicator_minimum 0
#property  indicator_maximum 1

// MACD
extern int FastEma = 12;
extern int SlowEma = 26;
extern int SignalSMMA = 9;
extern string note1 = "0=Close,1=Open,2=High,3=Low";
extern string note2 = "4=Median Price,5=Typical Price";
extern string note3 = "6=Weighted Price";
extern int PriceField = 0;
extern string note4 = "Numbers of bars to calculate";
extern int MaxBars=392; 

//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
 {
  
//---- drawing settings

  SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,4,indicator_color1);
  SetIndexBuffer(0,ExtMapBuffer1);
  SetIndexLabel(0,"BuyZone");
  
  SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,4,indicator_color2);
  SetIndexBuffer(1,ExtMapBuffer2);
  SetIndexLabel(1,"SellZone");
  
//---- name for DataWindow and indicator subwindow label

  string shortName = "MACD ("+FastEma+","+SlowEma+","+SignalSMMA+")";
  IndicatorShortName(shortName);   
//---- initialization done
  return(0);
 }
//+------------------------------------------------------------------+
//| Calculations                                    |
//+------------------------------------------------------------------+
int start()
 {
  int limit;
  
  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;
  if(limit>MaxBars) limit=MaxBars;

//---- main loop
  
for(int i=0; i<limit; i++)
{
ExtMapBuffer1[i] = 0; ExtMapBuffer2[i] = 0;
/*
double indMacdMain0 = iCustom(NULL, 0,"MACDsmoothed", FastEma, SlowEma, SignalSMMA, 0, i);
double indMacdMain1 = iCustom(NULL, 0, "MACDsmoothed", FastEma, SlowEma, SignalSMMA, 0, i+1);
double indMacdSignal0 = iCustom(NULL, 0, "MACDsmoothed",FastEma, SlowEma, SignalSMMA, 1, i);
double indMacdSignal1 = iCustom(NULL, 0, "MACDsmoothed",FastEma, SlowEma, SignalSMMA, 1, i+1);
*/
double indMacdMain0 = iMACD(NULL,0,FastEma, SlowEma, SignalSMMA,PriceField,0,i);
double indMacdMain1 = iMACD(NULL,0,FastEma, SlowEma, SignalSMMA,PriceField,0,i+1);
double indMacdSignal0 = iMACD(NULL,0,FastEma, SlowEma, SignalSMMA,PriceField,1,i);
double indMacdSignal1 = iMACD(NULL,0,FastEma, SlowEma, SignalSMMA,PriceField,1,i+1);
  
if (indMacdMain0 > indMacdSignal0) ExtMapBuffer1[i]=2;
else if (indMacdMain0 < indMacdSignal0 ) ExtMapBuffer2[i]=2;
}
return(0);
 }
//+------------------------------------------------------------------+

 

http://www.abysse.co.jp/mt4/indicatorimgaes2/MACDBars.gif

Link to comment
Share on other sites

  • 1 year later...

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

//| MACDBars.mq4 modified from |

//| mtt-ErgodicMACD.mq4 |

//| Copyright © 2004-07, MetaQuotes Software Corp. |

//| http://www.metaquotes.net/ |

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

#property copyright "Copyright © 2004-07, mietectec"

#property link ""

//---- indicator settings

#property indicator_separate_window

#property indicator_buffers 2

#property indicator_color1 DarkGreen

#property indicator_color2 Red

#property indicator_width1 4

#property indicator_width2 4

#property indicator_minimum 0

#property indicator_maximum 1

 

// MACD

extern int Timeframe=0;

extern int FastEma = 12;

extern int SlowEma = 26;

extern int SignalSMMA = 9;

extern string note1 = "0=Close,1=Open,2=High,3=Low";

extern string note2 = "4=Median Price,5=Typical Price";

extern string note3 = "6=Weighted Price";

extern int PriceField = 0;

extern string note4 = "Numbers of bars to calculate";

extern int MaxBars=392;

 

//---- indicator buffers

double ExtMapBuffer1[];

double ExtMapBuffer2[];

 

 

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

//| Custom indicator initialization function |

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

int init()

{

 

//---- drawing settings

 

SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,4,indicator_color1);

SetIndexBuffer(0,ExtMapBuffer1);

SetIndexLabel(0,"BuyZone");

 

SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,4,indicator_color2);

SetIndexBuffer(1,ExtMapBuffer2);

SetIndexLabel(1,"SellZone");

 

//---- name for DataWindow and indicator subwindow label

 

string shortName = "MACD ("+FastEma+","+SlowEma+","+SignalSMMA+")";

IndicatorShortName(shortName);

//---- initialization done

return(0);

}

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

//| Calculations |

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

int start()

{

int limit;

 

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;

if(limit>MaxBars) limit=MaxBars;

 

//---- main loop

 

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

{

ExtMapBuffer1 = 0; ExtMapBuffer2 = 0;

/*

double indMacdMain0 = iCustom(NULL, 0,"MACDsmoothed", FastEma, SlowEma, SignalSMMA, 0, i);

double indMacdMain1 = iCustom(NULL, 0, "MACDsmoothed", FastEma, SlowEma, SignalSMMA, 0, i+1);

double indMacdSignal0 = iCustom(NULL, 0, "MACDsmoothed",FastEma, SlowEma, SignalSMMA, 1, i);

double indMacdSignal1 = iCustom(NULL, 0, "MACDsmoothed",FastEma, SlowEma, SignalSMMA, 1, i+1);

*/

double indMacdMain0 = iMACD(NULL,Timeframe,FastEma, SlowEma, SignalSMMA,PriceField,0,i);

double indMacdMain1 = iMACD(NULL,Timeframe,FastEma, SlowEma, SignalSMMA,PriceField,0,i+1);

double indMacdSignal0 = iMACD(NULL,Timeframe,FastEma, SlowEma, SignalSMMA,PriceField,1,i);

double indMacdSignal1 = iMACD(NULL,Timeframe,FastEma, SlowEma, SignalSMMA,PriceField,1,i+1);

 

if (indMacdMain0 > indMacdSignal0) ExtMapBuffer1=2;

else if (indMacdMain0 < indMacdSignal0 ) ExtMapBuffer2=2;

}

return(0);

}

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...