-
Notifications
You must be signed in to change notification settings - Fork 1
/
FGV_mod_MACD.mq4
94 lines (91 loc) · 3.71 KB
/
FGV_mod_MACD.mq4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//+------------------------------------------------------------------+
//| Custom FGV_mod_MACD.mq4 |
//| Copyright 2005-2014, MetaQuotes Software Corp. |
//| http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "2005-2014, MetaQuotes Software Corp."
#property link "http://www.mql4.com"
#property description "Exponential Moving Averages Convergence/Divergence"
#property strict
//+------------------------------------------------------------------+
//| |
//| Modified by FGV http://sapienssapiens.com |
//| |
//+------------------------------------------------------------------+
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Red
#property indicator_width1 2
//--- indicator parameters
input int InpFastEMA=12; // Fast EMA Period
input int InpSlowEMA=26; // Slow EMA Period
input int InpSignalEMA=9; // Signal EMA Period
//--- indicator buffers
double ExtMacdBuffer[];
double ExtSignalBuffer[];
//--- right input parameters flag
bool ExtParameters=false;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
IndicatorDigits(Digits+1);
//--- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(1,InpSignalEMA);
//--- indicator buffers mapping
SetIndexBuffer(0,ExtMacdBuffer);
SetIndexBuffer(1,ExtSignalBuffer);
//--- name for DataWindow and indicator subwindow label
IndicatorShortName("FGV_mod_MACD("+IntegerToString(InpFastEMA)+","+IntegerToString(InpSlowEMA)+","+IntegerToString(InpSignalEMA)+")");
SetIndexLabel(0,"FGV_mod_MACD");
SetIndexLabel(1,"Signal");
//--- check for input parameters
if(InpFastEMA<=1 || InpSlowEMA<=1 || InpSignalEMA<=1 || InpFastEMA>=InpSlowEMA)
{
Print("Wrong input parameters");
ExtParameters=false;
return(INIT_FAILED);
}
else
ExtParameters=true;
//--- initialization done
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence |
//+------------------------------------------------------------------+
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;
//---
if(rates_total<=InpSignalEMA || !ExtParameters)
return(0);
//--- last counted bar will be recounted
limit=rates_total-prev_calculated;
if(prev_calculated>0)
limit++;
//--- macd counted in the 1-st buffer
for(i=0; i<limit; i++)
ExtMacdBuffer[i]=iMA(NULL,0,InpFastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
iMA(NULL,0,InpSlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//--- signal line counted in the 2-nd buffer
ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpSignalEMA,ExtMacdBuffer,ExtSignalBuffer);
//--- done
return(rates_total);
}
//+------------------------------------------------------------------+