Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
dMACD
//+------------------------------------------------------------------+
//| Dynamyc MACD.mq4 |
//| Copyright © 2010, Yury Zinoviev |
//| zinoviev.yury@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Yury Zinoviev"
#property link "http://forex-memory.blogspot.com/"
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 DimGray
#property indicator_color2 Silver
#property indicator_color3 Red
#property indicator_width1 2
extern int Depth=12;
extern int smooth=5;
extern double factor=4;
extern int FastEMA=12;
extern int SlowEMA=26;
extern int SignalSMA=9;
extern int MaxBars=600;
double MacdBuffer[];
double MacdBuffer2[];
double SignalBuffer[];
static int pres=52;
int init()
{
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexStyle(1,DRAW_LINE);
SetIndexStyle(2,DRAW_LINE);
SetIndexDrawBegin(1,SignalSMA);
IndicatorDigits(Digits+1);
SetIndexBuffer(0,MacdBuffer2);
SetIndexBuffer(1,MacdBuffer);
SetIndexBuffer(2,SignalBuffer);
IndicatorShortName("dMACD("+FastEMA+","+SlowEMA+","+SignalSMA+")");
SetIndexLabel(0,"Hysto");
SetIndexLabel(1,"MACD");
SetIndexLabel(2,"Signal");
// ArrayInitialize(MacdBuffer2,0);
// ArrayInitialize(MacdBuffer,0);
// ArrayInitialize(SignalBuffer,0);
return(0);
}
int start()
{
int limit;
int counted_bars=IndicatorCounted();
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
int j=0;
for(int i=0; i<limit; i++)
{
// MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
int l=getLoopWide(i);
int _FastEMA=l/2; int _SlowEMA=l;
if(l<2) {_FastEMA=FastEMA; _SlowEMA=SlowEMA;}
MacdBuffer2[i]=getMACD(i,_FastEMA,_SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN);
j++;
if(j>MaxBars) break;
}
j=0;
for(i=0; i<limit; i++)
{
// MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
MacdBuffer[i]=iMAOnArray(MacdBuffer2,Bars,smooth,0,MODE_SMA,i);
j++;
if(j>MaxBars) break;
}
j=0;
for(i=0; i<limit; i++)
{
SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
/*
l=getLoopWide(i);
_FastEMA=l/2; _SlowEMA=l;
if(l<2) {_FastEMA=FastEMA; _SlowEMA=SlowEMA;}
SignalBuffer[i]=getMACD(i,_FastEMA,_SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL);
*/
j++;
if(j>MaxBars) break;
}
IndicatorShortName("dMACD("+_FastEMA+","+_SlowEMA+","+SignalSMA+")");
Comment("\n" + "dMACD\n" + "Fast: " + _FastEMA + "\nSlow: " + _SlowEMA + "\nSignal: " + SignalSMA);
return(0);
}
//+------------------------------------------------------------------+
double getMACD(int i,int fast,int slow,int signal,int price,int mode)
{
double mm=iMACD(Symbol(),0,fast,slow,signal,price,mode,i);
return(mm);
}
int getLoopWide(int j)
{
int max=101;
for(int i=j;i<=j+max;i++)
{
double zz=iCustom(Symbol(),0,"ZigZag_fx",Depth,0,i);
if(zz!=0) break;
}
int p1=i;
for(i=p1+1;i<=p1+max;i++)
{
zz=iCustom(Symbol(),0,"ZigZag_fx",Depth,0,i);
if(zz!=0) break;
}
int p2=i;
for(i=p2+1;i<=p2+max;i++)
{
zz=iCustom(Symbol(),0,"ZigZag_fx",Depth,0,i);
if(zz!=0) break;
}
int p3=i;
for(i=p3+1;i<=p3+max;i++)
{
zz=iCustom(Symbol(),0,"ZigZag_fx",Depth,0,i);
if(zz!=0) break;
}
int p4=i;
for(i=p4+1;i<=p4+max;i++)
{
zz=iCustom(Symbol(),0,"ZigZag_fx",Depth,0,i);
if(zz!=0) break;
}
int p5=i;
for(i=p5+1;i<=p5+max;i++)
{
zz=iCustom(Symbol(),0,"ZigZag_fx",Depth,0,i);
if(zz!=0) break;
}
int p6=i;
int res=((p5-p1)+(p6-p2))/factor;
//Print("res=" + res);
int res2=(res+pres)/2;
pres=res;
return(res2);
}
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
---