Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
WMACD
//+------------------------------------------------------------------+
//| WMACD.mq4 |
//| Copyright © 2011 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_color1 Black
#property indicator_color2 Green
#property indicator_color3 Maroon
#property indicator_color4 LightSkyBlue
#property indicator_color5 DarkKhaki
#property indicator_color6 DarkKhaki
#property indicator_width1 2
#property indicator_width2 2
#property indicator_width3 2
#property indicator_width4 1
#property indicator_width5 1
#property indicator_width6 1
extern int S_MA=26;
extern int F_MA=12;
extern int SMA=9;
extern double Dvn=1.0;
extern int Price=0;
extern int Mode=1;
//---- indicator buffers
double MacdBuffer0[];
double MacdBuffer1[];
double MacdBuffer2[];
double SignalBuffer[];
double EnvUpBuffer[];
double EnvDnBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_NONE);
SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2);
SetIndexStyle(3,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(4,DRAW_LINE,STYLE_DOT,1);
SetIndexStyle(5,DRAW_LINE,STYLE_DOT,1);
SetIndexDrawBegin(0,S_MA);
SetIndexDrawBegin(1,S_MA);
SetIndexDrawBegin(2,S_MA);
SetIndexDrawBegin(3,S_MA);
SetIndexDrawBegin(4,S_MA);
SetIndexDrawBegin(5,S_MA);
SetIndexBuffer(0,MacdBuffer0);
SetIndexBuffer(1,MacdBuffer1);
SetIndexBuffer(2,MacdBuffer2);
SetIndexBuffer(3,SignalBuffer);
SetIndexBuffer(4,EnvUpBuffer);
SetIndexBuffer(5,EnvDnBuffer);
IndicatorDigits(Digits+1);
if(Dvn<0.1) Dvn=0.1;
if(Dvn>100.0) Dvn=100.0;
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("WMACD("+S_MA+","+F_MA+","+SMA+")");
SetIndexLabel(1,"MACD");
SetIndexLabel(2,"MACD");
SetIndexLabel(3,"Signal");
SetIndexLabel(4,"EnvUp("+Dvn+")");
SetIndexLabel(5,"EnvDn("+Dvn+")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
int start()
{
double prev,current;
int counted_bars = IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars > 0) counted_bars--;
int limit = Bars - counted_bars;
if(counted_bars==0) limit-=1+1;
//---- macd
for(int i=0; i<limit; i++)
MacdBuffer0[i]=iMA(NULL,0,F_MA,0,Mode,Price,i)-iMA(NULL,0,S_MA,0,Mode,Price,i);
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit; i++)
SignalBuffer[i]=iMAOnArray(MacdBuffer0,WHOLE_ARRAY,SMA,0,MODE_SMA,i);
//---- envelopes line counted
for(i=0; i<limit; i++)
EnvUpBuffer[i] =((0+ iMA(NULL,0,S_MA,0,Mode,Price,i))/100)*Dvn;
for(i=0; i<limit; i++)
EnvDnBuffer[i] =((0- iMA(NULL,0,S_MA,0,Mode,Price,i))/100)*Dvn;
//---- done
//---- dispatch values between 2 buffers
bool up=true;
for(i=limit-1; i>=0; i--)
{
current=MacdBuffer0[i];
prev=MacdBuffer0[i+1];
if(current>prev) up=true;
if(current<prev) up=false;
if(!up)
{
MacdBuffer2[i]=current;
MacdBuffer1[i]=0.0;
}
else
{
MacdBuffer1[i]=current;
MacdBuffer2[i]=0.0;
}
}
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---