-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gmacd2.mq4
328 lines (272 loc) · 16.2 KB
/
Gmacd2.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
//+------------------------------------------------------------------+
//| GMACD#2.mq4 |
//| Copyright © 2006, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
/*********************************************************************
* Author: Muhammad Hamizi Jaminan (hymns)
* Original Author: CJA
*
* Date: December 14, 2006
* Custom Indicator: GMACD2.mq4
* Version: 1.0.1
* Description: Multi TimeFrame MACD Signal & MACD Graph
*
* Change Logs
* Version 1.0.1
* - Rewriting Code. Using less variable & ObjectCreate. Reduce CPU
* Usage. Solve multiple object label show on load.
*
* Version G#MACD#2
* - Release by CJA
**********************************************************************/
#property indicator_separate_window
#property indicator_buffers 7
#property indicator_color1 Black //DarkSlateGray // HISTO
#property indicator_color2 Black //Red // inside line
#property indicator_color3 Black //Blue // inside line
#property indicator_color4 Black //Red //middle line
#property indicator_color5 Black //Blue //middle line
#property indicator_color6 Black //DarkOrange // outside line
#property indicator_color7 Black //DodgerBlue //outside line
//#property indicator_width1 2
//---- input parameters
extern int FastEMA=8;
extern int FFastEMA=7;
extern int FFFastEMA=6;
extern int SlowEMA=17;
extern int SSlowEMA=16;
extern int SSSlowEMA=15;
extern int SignalSMA=9;
extern int SSignalSMA=8;
extern int SSSignalSMA=7;
extern bool Show_MAJOR_TREND = false;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
double ExtMapBuffer6[];
double ExtMapBuffer7[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("GMACD2");
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexStyle(3,DRAW_LINE);
SetIndexBuffer(3,ExtMapBuffer4);
SetIndexStyle(4,DRAW_LINE);
SetIndexBuffer(4,ExtMapBuffer5);
SetIndexStyle(5,DRAW_LINE);
SetIndexBuffer(5,ExtMapBuffer6);
SetIndexStyle(6,DRAW_LINE);
SetIndexBuffer(6,ExtMapBuffer7);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectsDeleteAll(0,OBJ_LABEL);
ObjectDelete("Label1"); ObjectDelete("Label2"); ObjectDelete("Label3");
ObjectDelete("DataM1"); ObjectDelete("DataM5"); ObjectDelete("DataM15");
ObjectDelete("DataM30"); ObjectDelete("DataH1"); ObjectDelete("DataH4");
ObjectDelete("DataD1"); ObjectDelete("DataW1"); ObjectDelete("DataMN");
ObjectDelete("Trend1"); ObjectDelete("Trend2"); ObjectDelete("Level1");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
for(int i=Bars;i>=0;i--){
ExtMapBuffer2[i]=iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,i);
ExtMapBuffer3[i]=iMACD(NULL,0,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,i);
ExtMapBuffer4[i]=iMACD(NULL,0,FFastEMA,SSlowEMA,SSignalSMA,PRICE_CLOSE,MODE_MAIN,i);
ExtMapBuffer5[i]=iMACD(NULL,0,FFastEMA,SSlowEMA,SSignalSMA,PRICE_CLOSE,MODE_SIGNAL,i);
ExtMapBuffer6[i]=iMACD(NULL,0,FFFastEMA,SSSlowEMA,SSSignalSMA,PRICE_CLOSE,MODE_MAIN,i);
ExtMapBuffer7[i]=iMACD(NULL,0,FFFastEMA,SSSlowEMA,SSSignalSMA,PRICE_CLOSE,MODE_SIGNAL,i);
ExtMapBuffer1[i]=ExtMapBuffer2[i] - ExtMapBuffer3[i];
}
double macd_M1=iMACD(NULL,PERIOD_M1,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,0);
double macd_MM1=iMACD(NULL,PERIOD_M1,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,0);
double macd_M5=iMACD(NULL,PERIOD_M5,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,0);
double macd_MM5=iMACD(NULL,PERIOD_M5,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,0);
double macd_M15=iMACD(NULL,PERIOD_M15,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,0);
double macd_MM15=iMACD(NULL,PERIOD_M15,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,0);
double macd_M30=iMACD(NULL,PERIOD_M30,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,0);
double macd_MM30=iMACD(NULL,PERIOD_M30,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,0);
double macd_H1=iMACD(NULL,PERIOD_H1,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,0);
double macd_HH1=iMACD(NULL,PERIOD_H1,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,0);
double macd_H4=iMACD(NULL,PERIOD_H4,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,0);
double macd_HH4=iMACD(NULL,PERIOD_H4,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,0);
if (Show_MAJOR_TREND == true)
{
double macd_D1=iMACD(NULL,PERIOD_D1,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,0);
double macd_DD1=iMACD(NULL,PERIOD_D1,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,0);
double macd_W1=iMACD(NULL,PERIOD_W1,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,0);
double macd_WW1=iMACD(NULL,PERIOD_W1,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,0);
double macd_MN1=iMACD(NULL,PERIOD_MN1,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_MAIN,0);
double macd_MMN1=iMACD(NULL,PERIOD_MN1,FastEMA,SlowEMA,SignalSMA,PRICE_CLOSE,MODE_SIGNAL,0);
}
string trend_signal = "", trend_main = "", trend_level = "";
color color_m1, color_m5, color_m15, color_m30, color_h1, color_h4, color_d1, color_w1, color_mn,
color_signal, color_main, color_level;
// UP Data
if ((macd_M5 > macd_MM5) && (macd_M1 > macd_MM1)) { trend_signal = "TREND/UP"; color_signal = Lime;}
//Down Data
if ((macd_M5 < macd_MM5) && (macd_M1 < macd_MM1)) { trend_signal = "TREND/DN"; color_signal = Red; }
//Consolidation Data
if ((macd_M5 < macd_MM5) && (macd_M1 > macd_MM1)) { trend_signal = "SIDEWAY"; color_signal = Orange; }
if ((macd_M5 > macd_MM5) && (macd_M1 < macd_MM1)) { trend_signal = "SIDEWAY"; color_signal = Orange; }
if ((macd_M15 < macd_MM15) && (macd_M30 > macd_MM30) && (macd_H1 > macd_HH1)&& (macd_H4 < macd_HH4)) { trend_level = "WEAK"; color_level = Tomato; }
if ((macd_M15 > macd_MM15) && (macd_M30 < macd_MM30) && (macd_H1 < macd_HH1)&& (macd_H4 > macd_HH4)) { trend_level = "WEAK"; color_level = Tomato; }
if ((macd_M15 < macd_MM15) && (macd_M30 > macd_MM30) && (macd_H1 < macd_HH1) && (macd_H4 < macd_HH4)) { trend_level = "MEDIUM"; color_level = Orange; }
if ((macd_M15 > macd_MM15) && (macd_M30 < macd_MM30) && (macd_H1 > macd_HH1) && (macd_H4 > macd_HH4)) { trend_level = "MEDIUM"; color_level = Orange; }
if ((macd_M5 > macd_MM5) && (macd_M15 > macd_MM15) && (macd_M30 > macd_MM30) && (macd_H1 < macd_HH1) && (macd_H4 > macd_HH4)) { trend_level = "MEDIUM"; color_level = Orange; }
if ((macd_M5 < macd_MM5) && (macd_M15 < macd_MM15) && (macd_M30 < macd_MM30) && (macd_H1 >macd_HH1) && (macd_H4 < macd_HH4)) { trend_level = "MEDIUM"; color_level = Orange; }
if ((macd_M15 < macd_MM15) && (macd_M30 > macd_MM30) && (macd_H1 > macd_HH1)) { trend_main = "TREND/UP"; color_main = YellowGreen; }
if ((macd_M15 > macd_MM15) && (macd_M30 < macd_MM30) && (macd_H1 < macd_HH1)) { trend_main = "TREND/DN"; color_main = Tomato; }
if ((macd_M15 < macd_MM15) && (macd_M30 < macd_MM30) && (macd_H1 > macd_HH1)) { trend_main = "TREND/DN"; color_main = Tomato; }
if ((macd_M15 > macd_MM15) && (macd_M30 > macd_MM30) && (macd_H1 < macd_HH1)) { trend_main = "TREND/UP"; color_main = YellowGreen; }
if ((macd_M15 < macd_MM15) && (macd_M30 > macd_MM30) && (macd_H1 < macd_HH1)) { trend_main = "TREND/DN"; color_main = Red; }
if ((macd_M15 > macd_MM15) && (macd_M30 < macd_MM30) && (macd_H1 > macd_HH1)) { trend_main = "TREND/UP"; color_main = Lime; }
if ((macd_M5 < macd_MM5) && (macd_M15 < macd_MM15) && (macd_H1 > macd_HH1) && (macd_H4 > macd_HH4)) { trend_level = "WEAK"; color_level = Tomato; }
if ((macd_M5 > macd_MM5) && (macd_M15 > macd_MM15) && (macd_H1 < macd_HH1) && (macd_H4 < macd_HH4)) { trend_level = "WEAK"; color_level = Tomato; }
if ((macd_M15 > macd_MM15) && (macd_H1 > macd_HH1) && (macd_M30 > macd_MM30) && (macd_H4 < macd_HH4)) { trend_level = "MEDIUM"; color_level = Orange; }
if ((macd_M15 < macd_MM15) && (macd_H1 < macd_HH1) && (macd_M30 < macd_MM30) && (macd_H4 > macd_HH4)) { trend_level = "MEDIUM"; color_level = Orange; }
if ((macd_M15 > macd_MM15) && (macd_H1 > macd_HH1) && (macd_M30 > macd_MM30) && (macd_H4 > macd_HH4)) { trend_level = "STRONG"; color_level = Yellow; }
if ((macd_M15 < macd_MM15) && (macd_H1 < macd_HH1) && (macd_M30 < macd_MM30) && (macd_H4 < macd_HH4)) { trend_level = "STRONG"; color_level = Yellow; }
if ((macd_M15 > macd_MM15) && (macd_H1 > macd_HH1) && (macd_M30 > macd_MM30) && (macd_H4 > macd_HH4)) { trend_main = "TREND/UP"; color_main = Lime; }
if ((macd_M15 < macd_MM15) && (macd_H1 < macd_HH1) && (macd_M30 < macd_MM30) && (macd_H4 < macd_HH4)) { trend_main = "TREND/DN"; color_main = Red; }
if ((macd_M15 > macd_MM15) && (macd_H1 > macd_HH1) && (macd_M30 > macd_MM30) && (macd_H4 < macd_HH4)) { trend_main = "TREND/UP"; color_main = Lime; }
if ((macd_M15 < macd_MM15) && (macd_H1 < macd_HH1) && (macd_M30 < macd_MM30) && (macd_H4 > macd_HH4)) { trend_main = "TREND/DN"; color_main = Red; }
//MACD Direction
if ((macd_M1 > macd_MM1)) { color_m1 = Lime; }
if ((macd_M1 < macd_MM1)) { color_m1 = Red; }
if ((macd_M5 > macd_MM5)) { color_m5 = Lime; }
if ((macd_M5 < macd_MM5)) { color_m5 = Red; }
if ((macd_M15 > macd_MM15)) { color_m15 = Lime; }
if ((macd_M15 < macd_MM15)) { color_m15 = Red; }
if ((macd_M30 > macd_MM30)) { color_m30 = Lime; }
if ((macd_M30 < macd_MM30)) { color_m30 = Red; }
if ((macd_H1 > macd_HH1)) { color_h1 = Lime; }
if ((macd_H1 < macd_HH1)) { color_h1 = Red; }
if ((macd_H4 > macd_HH4)) { color_h4 = Lime; }
if ((macd_H4 < macd_HH4)) { color_h4 = Red; }
if (Show_MAJOR_TREND == true)
{
if ((macd_D1 > macd_DD1)) { color_d1 = Lime; }
if ((macd_D1 < macd_DD1)) { color_d1 = Red; }
if ((macd_W1 > macd_WW1)) { color_w1 = Lime; }
if ((macd_W1 < macd_WW1)) { color_w1 = Red; }
if ((macd_MN1 > macd_MMN1)) { color_mn = Lime; }
if ((macd_MN1 < macd_MMN1)) { color_mn = Red; }
}
//Signal Labels
ObjectCreate("Label1", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);
ObjectSetText("Label1","SIGNAL",8, "Arial Bold", Silver);
ObjectSet("Label1", OBJPROP_CORNER, 0);
ObjectSet("Label1", OBJPROP_XDISTANCE, 5);
ObjectSet("Label1", OBJPROP_YDISTANCE, 15);
//MACD Direction M1-M5
ObjectCreate("DataM1", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);//M1 SIGNAL
ObjectSetText("DataM1","M1",9, "Arial Bold", color_m1);
ObjectSet("DataM1", OBJPROP_CORNER, 0);
ObjectSet("DataM1", OBJPROP_XDISTANCE, 50);
ObjectSet("DataM1", OBJPROP_YDISTANCE, 15);
ObjectCreate("DataM5", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);//M5 SIGNAL
ObjectSetText("DataM5","M5",9, "Arial Bold", color_m5);
ObjectSet("DataM5", OBJPROP_CORNER, 0);
ObjectSet("DataM5", OBJPROP_XDISTANCE, 75);
ObjectSet("DataM5", OBJPROP_YDISTANCE, 15);
//M1 & M5 TREND Data
ObjectCreate("Trend1", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);
ObjectSetText("Trend1",trend_signal,12, "Arial Bold", color_signal);
ObjectSet("Trend1", OBJPROP_CORNER, 0);
ObjectSet("Trend1", OBJPROP_XDISTANCE, 100);
ObjectSet("Trend1", OBJPROP_YDISTANCE, 15);
//Main Trend Label
ObjectCreate("Label2", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);
ObjectSetText("Label2","MAIN TREND", 8, "Arial Bold", Silver);
ObjectSet("Label2", OBJPROP_CORNER, 0);
ObjectSet("Label2", OBJPROP_XDISTANCE, 190);
ObjectSet("Label2", OBJPROP_YDISTANCE, 15);
//MACD Direction M15-H4
ObjectCreate("DataM15", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);//M15 SIGNAL
ObjectSetText("DataM15","M15",9, "Arial Bold", color_m15);
ObjectSet("DataM15", OBJPROP_CORNER, 0);
ObjectSet("DataM15", OBJPROP_XDISTANCE,260);
ObjectSet("DataM15", OBJPROP_YDISTANCE, 15);
ObjectCreate("DataM30", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);//M30 SIGNAL
ObjectSetText("DataM30","M30",9, "Arial Bold", color_m30);
ObjectSet("DataM30", OBJPROP_CORNER, 0);
ObjectSet("DataM30", OBJPROP_XDISTANCE, 290);
ObjectSet("DataM30", OBJPROP_YDISTANCE, 15);
ObjectCreate("DataH1", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);//H1 SIGNAL
ObjectSetText("DataH1","H1",9, "Arial Bold", color_h1);
ObjectSet("DataH1", OBJPROP_CORNER, 0);
ObjectSet("DataH1", OBJPROP_XDISTANCE, 320);
ObjectSet("DataH1", OBJPROP_YDISTANCE, 15);
ObjectCreate("DataH4", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);//H4 SIGNAL
ObjectSetText("DataH4","H4",9, "Arial Bold", color_h4);
ObjectSet("DataH4", OBJPROP_CORNER, 0);
ObjectSet("DataH4", OBJPROP_XDISTANCE, 340);
ObjectSet("DataH4", OBJPROP_YDISTANCE, 15);
//M15 - H4 TREND Data
ObjectCreate("Trend2", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);
ObjectSetText("Trend2",trend_main,12, "Arial Bold", color_main);
ObjectSet("Trend2", OBJPROP_CORNER, 0);
ObjectSet("Trend2", OBJPROP_XDISTANCE, 365);
ObjectSet("Trend2", OBJPROP_YDISTANCE, 15);
//Level Data
ObjectCreate("Level1", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);
ObjectSetText("Level1",trend_level,8, "Arial Bold", color_level);
ObjectSet("Level1", OBJPROP_CORNER, 0);
ObjectSet("Level1", OBJPROP_XDISTANCE,455);
ObjectSet("Level1", OBJPROP_YDISTANCE, 15);
if (Show_MAJOR_TREND == true)
{
ObjectCreate("Label3", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);
ObjectSetText("Label3","MAJOR TREND", 8, "Arial Bold", Silver);
ObjectSet("Label3", OBJPROP_CORNER, 0);
ObjectSet("Label3", OBJPROP_XDISTANCE, 805);
ObjectSet("Label3", OBJPROP_YDISTANCE, 4);
ObjectCreate("DataD1", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);//D1 SIGNAL
ObjectSetText("DataD1","D1",9, "Arial Bold", color_d1);
ObjectSet("DataD1", OBJPROP_CORNER, 0);
ObjectSet("DataD1", OBJPROP_XDISTANCE, 885);
ObjectSet("DataD1", OBJPROP_YDISTANCE, 4);
ObjectCreate("DataW1", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);//W1 SIGNAL
ObjectSetText("DataW1","W1",9, "Arial Bold", color_w1);
ObjectSet("DataW1", OBJPROP_CORNER, 0);
ObjectSet("DataW1", OBJPROP_XDISTANCE, 905);
ObjectSet("DataW1", OBJPROP_YDISTANCE, 4);
ObjectCreate("DataMN", OBJ_LABEL, WindowFind("GMACD2"), 0, 0);//MN SIGNAL
ObjectSetText("DataMN","MN",9, "Arial Bold", color_mn);
ObjectSet("DataMN", OBJPROP_CORNER, 0);
ObjectSet("DataMN", OBJPROP_XDISTANCE, 930);
ObjectSet("DataMN", OBJPROP_YDISTANCE, 4);
}
}
//----
return(0);
//+------------------------------------------------------------------+