/
Cyf_Elder's_Impulse_MTF_Release_V_1.0.cs
executable file
·330 lines (276 loc) · 13.1 KB
/
Cyf_Elder's_Impulse_MTF_Release_V_1.0.cs
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
329
330
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
/// download the CSV File by adding a day to the current date "http://www.dailyfx.com/files/Calendar-22-10-2016.csv"
namespace cAlgo
{
[Indicator(IsOverlay = false, ScalePrecision = 0, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class Cyf_Impulse : Indicator
{
private string[] theBullet =
{
"◾",
"◼",
"•",
"●",
"♦",
"★",
"▣",
"☗",
"♠",
"♟",
"♞",
"♝",
"☤",
"♫",
"٭",
"◓",
"▌"
};
private string getTimeFrame(MarketSeries theTime)
{
switch (theTime.TimeFrame.ToString())
{
case "Minute":
return "m1";
case "Minute2":
return "m2";
case "Minute3":
return "m3";
case "Minute4":
return "m4";
case "Minute5":
return "m5";
case "Minute6":
return "m6";
case "Minute7":
return "m7";
case "Minute8":
return "m8";
case "Minute9":
return "m9";
case "Minute10":
return "m10";
case "Minute15":
return "m15";
case "Minute20":
return "m20";
case "Minute30":
return "m30";
case "Minute45":
return "m45";
case "Hour":
return "H1";
case "Hour2":
return "H2";
case "Hour3":
return "H3";
case "Hour4":
return "H4";
case "Hour6":
return "H6";
case "Hour8":
return "H8";
case "Hour12":
return "H12";
case "Daily":
return "D1";
case "Day2":
return "D2";
case "Day3":
return "D3";
case "Weekly":
return "W1";
case "Monthly":
return "M1";
default:
return " ";
}
}
private string Bullet = "◼";
private VerticalAlignment vAlign = VerticalAlignment.Center;
private HorizontalAlignment hAlign = HorizontalAlignment.Center;
private Colors UpColor = Colors.DeepSkyBlue;
private Colors DnColor = Colors.SeaGreen;
/////////////////////////////////////////
private MacdHistogram Mac;
private MacdHistogram Mac_veryLongTF;
private MacdHistogram Mac_LongTF;
private MacdHistogram Mac_MedTF;
private MacdHistogram Mac_SmallTF;
private ExponentialMovingAverage EMA;
private ExponentialMovingAverage EMA_veryLongTF;
private ExponentialMovingAverage EMA_LongTF;
private ExponentialMovingAverage EMA_MedTF;
private ExponentialMovingAverage EMA_SmallTF;
private MarketSeries veryLongTF_Series;
private MarketSeries LongTF_Series;
private MarketSeries MedTF_Series;
private MarketSeries SmallTF_Series;
/////////////////////////////////////////
[Parameter("Shape", DefaultValue = 16, MinValue = 0, MaxValue = 16)]
public int Draw_String { get; set; }
[Parameter("UpColor", DefaultValue = "DeepSkyBlue")]
public string upColor { get; set; }
[Parameter("DnColor", DefaultValue = "SeaGreen")]
public string dnColor { get; set; }
///////****************************************
[Parameter("Num TF", DefaultValue = 3, MaxValue = 5, MinValue = 1)]
public int Num_TF { get; set; }
[Parameter("vLong_TF", DefaultValue = "Daily")]
public TimeFrame vRef_TF { get; set; }
[Parameter("Long_TF", DefaultValue = "Hour4")]
public TimeFrame Ref_TF { get; set; }
[Parameter("Med_TF", DefaultValue = "Hour")]
public TimeFrame Med_TF { get; set; }
[Parameter("Small_TF", DefaultValue = "Minute15")]
public TimeFrame Lil_TF { get; set; }
///////*****************************************
[Parameter(DefaultValue = 13)]
public int Period { get; set; }
[Parameter("LongCycle", DefaultValue = 26)]
public int LongCycle { get; set; }
[Parameter("ShrtCycle", DefaultValue = 12)]
public int ShrtCycle { get; set; }
[Parameter("Signal", DefaultValue = 9)]
public int Signal { get; set; }
protected override void Initialize()
{
Bullet = theBullet[Draw_String];
Enum.TryParse(upColor, out UpColor);
Enum.TryParse(dnColor, out DnColor);
///////*******************************************************
Mac = Indicators.MacdHistogram(MarketSeries.Close, LongCycle, ShrtCycle, Signal);
EMA = Indicators.ExponentialMovingAverage(MarketSeries.Close, Period);
if (Num_TF > 4)
{
veryLongTF_Series = MarketData.GetSeries(vRef_TF);
Mac_veryLongTF = Indicators.MacdHistogram(veryLongTF_Series.Close, LongCycle, ShrtCycle, Signal);
EMA_veryLongTF = Indicators.ExponentialMovingAverage(veryLongTF_Series.Close, Period);
}
if (Num_TF > 3)
{
LongTF_Series = MarketData.GetSeries(Ref_TF);
Mac_LongTF = Indicators.MacdHistogram(LongTF_Series.Close, LongCycle, ShrtCycle, Signal);
EMA_LongTF = Indicators.ExponentialMovingAverage(LongTF_Series.Close, Period);
}
if (Num_TF > 2)
{
MedTF_Series = MarketData.GetSeries(Med_TF);
Mac_MedTF = Indicators.MacdHistogram(MedTF_Series.Close, LongCycle, ShrtCycle, Signal);
EMA_MedTF = Indicators.ExponentialMovingAverage(MedTF_Series.Close, Period);
}
if (Num_TF > 1)
{
SmallTF_Series = MarketData.GetSeries(Lil_TF);
Mac_SmallTF = Indicators.MacdHistogram(SmallTF_Series.Close, LongCycle, ShrtCycle, Signal);
EMA_SmallTF = Indicators.ExponentialMovingAverage(SmallTF_Series.Close, Period);
}
////////////***********************************************
}
public override void Calculate(int index)
{
var indexVeryLongTF = 0;
var indexLongTF = 0;
var indexMedTF = 0;
var indexSmallTF = 0;
if (Num_TF > 4)
indexVeryLongTF = veryLongTF_Series.OpenTime.GetIndexByTime(MarketSeries.OpenTime.LastValue);
if (Num_TF > 3)
indexLongTF = LongTF_Series.OpenTime.GetIndexByTime(MarketSeries.OpenTime.LastValue);
if (Num_TF > 2)
indexMedTF = MedTF_Series.OpenTime.GetIndexByTime(MarketSeries.OpenTime.LastValue);
if (Num_TF > 1)
indexSmallTF = SmallTF_Series.OpenTime.GetIndexByTime(MarketSeries.OpenTime.LastValue);
////////////////
if (Num_TF > 4)
ChartObjects.DrawText("verylong_TF", getTimeFrame(veryLongTF_Series), index + 5, 0.0, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Gray);
if (Num_TF > 3)
ChartObjects.DrawText("long_TF", getTimeFrame(LongTF_Series), index + 5, 0.2, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Gray);
if (Num_TF > 2)
ChartObjects.DrawText("Med_TF", getTimeFrame(MedTF_Series), index + 5, 0.4, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Gray);
if (Num_TF > 1)
ChartObjects.DrawText("small_TF", getTimeFrame(SmallTF_Series), index + 5, 0.6, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Gray);
ChartObjects.DrawText("Cur_TF", getTimeFrame(MarketSeries), index + 5, 0.8, VerticalAlignment.Center, HorizontalAlignment.Center, Colors.Gray);
//////////////////
if (EMA.Result[index] > EMA.Result[index - 1] && Mac.Histogram[index] > Mac.Histogram[index - 1])
{
ChartObjects.DrawText("EMA_Dots" + index, Bullet, index, 0.8, vAlign, hAlign, UpColor);
}
else if (EMA.Result[index] < EMA.Result[index - 1] && Mac.Histogram[index] < Mac.Histogram[index - 1])
{
ChartObjects.DrawText("EMA_Dots" + index, Bullet, index, 0.8, vAlign, hAlign, DnColor);
}
else
{
ChartObjects.DrawText("EMA_Dots" + index, Bullet, index, 0.8, vAlign, hAlign, Colors.Black);
}
/////////********************************Very Long Series **************
if (Num_TF > 4)
{
if (EMA_veryLongTF.Result[indexVeryLongTF] > EMA_veryLongTF.Result[indexVeryLongTF - 1] && Mac_veryLongTF.Histogram[indexVeryLongTF] > Mac_veryLongTF.Histogram[indexVeryLongTF - 1])
{
ChartObjects.DrawText("veryLng_MAC_EMA" + index, Bullet, index, 0.0, vAlign, hAlign, UpColor);
}
else if (EMA_veryLongTF.Result[indexVeryLongTF] < EMA_veryLongTF.Result[indexVeryLongTF - 1] && Mac_veryLongTF.Histogram[indexVeryLongTF] < Mac_veryLongTF.Histogram[indexVeryLongTF - 1])
{
ChartObjects.DrawText("veryLng_MAC_EMA" + index, Bullet, index, 0.0, vAlign, hAlign, DnColor);
}
else
{
ChartObjects.DrawText("veryLng_MAC_EMA" + index, Bullet, index, 0.0, vAlign, hAlign, Colors.Black);
}
}
/////////********************************Long Series **************
if (Num_TF > 3)
{
if (EMA_LongTF.Result[indexLongTF] > EMA_LongTF.Result[indexLongTF - 1] && Mac_LongTF.Histogram[indexLongTF] > Mac_LongTF.Histogram[indexLongTF - 1])
{
ChartObjects.DrawText("Lng_MAC_EMA" + index, Bullet, index, 0.2, vAlign, hAlign, UpColor);
}
else if (EMA_LongTF.Result[indexLongTF] < EMA_LongTF.Result[indexLongTF - 1] && Mac_LongTF.Histogram[indexLongTF] < Mac_LongTF.Histogram[indexLongTF - 1])
{
ChartObjects.DrawText("Lng_MAC_EMA" + index, Bullet, index, 0.2, vAlign, hAlign, DnColor);
}
else
{
ChartObjects.DrawText("Lng_MAC_EMA" + index, Bullet, index, 0.2, vAlign, hAlign, Colors.Black);
}
}
/////////********************************Med Series **************
if (Num_TF > 2)
{
if (EMA_MedTF.Result[indexMedTF] > EMA_MedTF.Result[indexMedTF - 1] && Mac_MedTF.Histogram[indexMedTF] > Mac_MedTF.Histogram[indexMedTF - 1])
{
ChartObjects.DrawText("Med_MAC_EMA" + index, Bullet, index, 0.4, vAlign, hAlign, UpColor);
}
else if (EMA_MedTF.Result[indexMedTF] < EMA_MedTF.Result[indexMedTF - 1] && Mac_MedTF.Histogram[indexMedTF] < Mac_MedTF.Histogram[indexMedTF - 1])
{
ChartObjects.DrawText("Med_MAC_EMA" + index, Bullet, index, 0.4, vAlign, hAlign, DnColor);
}
else
{
ChartObjects.DrawText("Med_MAC_EMA" + index, Bullet, index, 0.4, vAlign, hAlign, Colors.Black);
}
}
/////////********************************Small Series**************
if (Num_TF > 1)
{
if (EMA_SmallTF.Result[indexSmallTF] > EMA_SmallTF.Result[indexSmallTF - 1] && Mac_SmallTF.Histogram[indexSmallTF] > Mac_SmallTF.Histogram[indexSmallTF - 1])
{
ChartObjects.DrawText("small_MAC_EMA" + index, Bullet, index, 0.6, vAlign, hAlign, UpColor);
}
else if (EMA_SmallTF.Result[indexSmallTF] < EMA_SmallTF.Result[indexSmallTF - 1] && Mac_SmallTF.Histogram[indexSmallTF] < Mac_SmallTF.Histogram[indexSmallTF - 1])
{
ChartObjects.DrawText("small_MAC_EMA" + index, Bullet, index, 0.6, vAlign, hAlign, DnColor);
}
else
{
ChartObjects.DrawText("small_MAC_EMA" + index, Bullet, index, 0.6, vAlign, hAlign, Colors.Black);
}
}
}
}
}