Indicators Used
Miscellaneous
0
Views
0
Downloads
0
Favorites
MACD_4H[1]
//+------------------------------------------------------------------+
//| MACD_4H.mq4 |
//| Copyright © 2006, lukas1 |
//| MACD from given timeframe |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, lukas1"
#property link "http://www.alpari-idc.ru/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
// #property indicator_width1 2
//---- indicator parameters
extern int FastEMA = 12;
extern int SlowEMA = 26;
extern int SignalSMA = 9;
extern int AppliedPrice = 0;
extern int VarPeriod = 240; // çàäàííûé òàéìôðåéì
//---- indicator buffers
double MacdBuffer[], SignalBuffer[];
double MA1[], MA2[];
int p; // òåêóùèé ïåðèîä
int k; // êðàòíîñòü ïåðèîäà
int i, j;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
p = Period();
SetIndexStyle(0, DRAW_HISTOGRAM);
SetIndexStyle(1, DRAW_LINE);
SetIndexDrawBegin(0, SlowEMA);
SetIndexDrawBegin(1, SlowEMA);
IndicatorDigits(Digits + 1);
//---- indicator buffers mapping
SetIndexBuffer(0, MacdBuffer);
SetIndexBuffer(1, SignalBuffer);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("MACD_4H (" + FastEMA + "," + SlowEMA + "," + SignalSMA +
"," + VarPeriod + ")");
SetIndexLabel(0, "MACD_4H(" + VarPeriod + ")");
SetIndexLabel(1, "Signal_4H(" + VarPeriod + ")");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence (MACD) for given timeframe|
//+------------------------------------------------------------------+
int start()
{
int limit;
int counted_bars = IndicatorCounted();
//---- check for possible errors
if(counted_bars < 0)
return(-1);
if(counted_bars <= SlowEMA)
limit = Bars - SlowEMA - 1;
else
limit = Bars - counted_bars;
p = Period();
//----
if(counted_bars == 0)
if(p <= VarPeriod)
k = VarPeriod / p; // êðàòíîñòü ïåðèîäà ââåðõ
else
k = p / VarPeriod; // êðàòíîñòü ïåðèîäà âíèç
//----
if(p <= VarPeriod)
{
for(i = 0; i < limit; i++)
{
j = i / k;
MacdBuffer[i] = iMACD(NULL, VarPeriod, FastEMA, SlowEMA, SignalSMA,
AppliedPrice, 0, j);
SignalBuffer[i] = iMACD(NULL, VarPeriod, FastEMA, SlowEMA, SignalSMA,
AppliedPrice, 1, j);
}
}
else
{
for(i = 0; i < limit; i++)
{
MacdBuffer[i] = iMACD(NULL, VarPeriod, FastEMA, SlowEMA, SignalSMA,
AppliedPrice, 0, i*k);
SignalBuffer[i] = iMACD(NULL, VarPeriod, FastEMA, SlowEMA, SignalSMA,
AppliedPrice, 1, i*k);
}
}
//---- 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
---