This repository has been archived by the owner on Apr 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
MASi_Wave.mq4
287 lines (277 loc) · 11.6 KB
/
MASi_Wave.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
//+---------------------------------------------------------------------------+
//| MASi_Wave.mq4 |
//| Copyright 2017, Terentyev Aleksey |
//| https://www.mql5.com/ru/users/terentyev23 |
//+---------------------------------------------------------------------------+
#property copyright "Copyright 2017, Terentyev Aleksey"
#property link "https://www.mql5.com/ru/users/terentyev23"
#property description "Raghee's Cicle indicator (aka Wave)."
#property description "Indicator of the market cycle."
#property description "The idea of Raghee Horner."
#property version "1.4"
#property icon "ico/wave.ico";
#property strict
#include "MASh_Include.mqh"
//---------------------Indicators---------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 15
#property indicator_plots 15
//--- plot
#property indicator_label1 "OpenB"
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_color1 clrDeepSkyBlue
#property indicator_style1 STYLE_SOLID
#property indicator_width1 3
#property indicator_label2 "CloseB"
#property indicator_type2 DRAW_HISTOGRAM
#property indicator_color2 clrDeepSkyBlue
#property indicator_style2 STYLE_SOLID
#property indicator_width2 3
#property indicator_label3 "HighB"
#property indicator_type3 DRAW_HISTOGRAM
#property indicator_color3 clrDeepSkyBlue
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
#property indicator_label4 "LowB"
#property indicator_type4 DRAW_HISTOGRAM
#property indicator_color4 clrDeepSkyBlue
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
#property indicator_label5 "OpenG"
#property indicator_type5 DRAW_HISTOGRAM
#property indicator_color5 clrGreen
#property indicator_style5 STYLE_SOLID
#property indicator_width5 3
#property indicator_label6 "CloseG"
#property indicator_type6 DRAW_HISTOGRAM
#property indicator_color6 clrGreen
#property indicator_style6 STYLE_SOLID
#property indicator_width6 3
#property indicator_label7 "HighG"
#property indicator_type7 DRAW_HISTOGRAM
#property indicator_color7 clrGreen
#property indicator_style7 STYLE_SOLID
#property indicator_width7 1
#property indicator_label8 "LowG"
#property indicator_type8 DRAW_HISTOGRAM
#property indicator_color8 clrGreen
#property indicator_style8 STYLE_SOLID
#property indicator_width8 1
#property indicator_label9 "OpenR"
#property indicator_type9 DRAW_HISTOGRAM
#property indicator_color9 clrRed
#property indicator_style9 STYLE_SOLID
#property indicator_width9 3
#property indicator_label10 "CloseR"
#property indicator_type10 DRAW_HISTOGRAM
#property indicator_color10 clrRed
#property indicator_style10 STYLE_SOLID
#property indicator_width10 3
#property indicator_label11 "HighR"
#property indicator_type11 DRAW_HISTOGRAM
#property indicator_color11 clrRed
#property indicator_style11 STYLE_SOLID
#property indicator_width11 1
#property indicator_label12 "LowR"
#property indicator_type12 DRAW_HISTOGRAM
#property indicator_color12 clrRed
#property indicator_style12 STYLE_SOLID
#property indicator_width12 1
#property indicator_label13 "Wave Close"
#property indicator_type13 DRAW_LINE
#property indicator_color13 clrDeepSkyBlue
#property indicator_style13 STYLE_DASH
#property indicator_width13 1
#property indicator_label14 "Wave High"
#property indicator_type14 DRAW_LINE
#property indicator_color14 clrGreen
#property indicator_style14 STYLE_DASH
#property indicator_width14 1
#property indicator_label15 "Wave Low"
#property indicator_type15 DRAW_LINE
#property indicator_color15 clrRed
#property indicator_style15 STYLE_DASH
#property indicator_width15 1
//--- indicator buffers
double OBBuffer[], CBBuffer[], HBBuffer[], LBBuffer[];
double OGBuffer[], CGBuffer[], HGBuffer[], LGBuffer[];
double ORBuffer[], CRBuffer[], HRBuffer[], LRBuffer[];
double EmaCBuffer[], EmaHBuffer[], EmaLBuffer[];
//-----------------Global variables-------------------------------------------+
enum IndicatorAlert {
TurnedOff = 0,
AllCandles = 1,
NeutralCandles = 2,
PositivCandles = 3,
NegativeCandles = 4,
PositivAndNegative = 5
};
//---
input int EMA = 34; // EMA
input BoolEnum ON_EMA = Enable; // Moving avegage line
input BoolEnum ON_PRICES = Disable; // Prices flags
input IndicatorAlert ON_ALERT = TurnedOff; // Type of alert about changes candles
//---
//+---------------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, OBBuffer); SetIndexBuffer(1, CBBuffer);
SetIndexBuffer(2, HBBuffer); SetIndexBuffer(3, LBBuffer);
SetIndexBuffer(4, OGBuffer); SetIndexBuffer(5, CGBuffer);
SetIndexBuffer(6, HGBuffer); SetIndexBuffer(7, LGBuffer);
SetIndexBuffer(8, ORBuffer); SetIndexBuffer(9, CRBuffer);
SetIndexBuffer(10, HRBuffer); SetIndexBuffer(11, LRBuffer);
SetIndexBuffer(12, EmaCBuffer);
SetIndexBuffer(13, EmaHBuffer); SetIndexBuffer(14, EmaLBuffer);
IndicatorShortName("Wave ( " + IntegerToString(EMA) + " )");
if( EMA <= 1 ) {
Print("Wrong input parameters");
return INIT_FAILED;
}
return INIT_SUCCEEDED;
}
//+---------------------------------------------------------------------------+
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 limit = rates_total - prev_calculated;
if( limit >= Bars(Symbol(), Period()) ) {
limit = Bars(Symbol(), Period()) - EMA;
}
if( prev_calculated > 0 ) {
limit++;
}
ResizeBar();
static double tmp;
for( int idx = limit; idx >= 0; idx-- ) {
tmp = iWave(idx, Symbol(), Period(), EMA);
if( tmp > 0 ) {
ClearBuffer(idx);
OGBuffer[idx] = iOpen(NULL, 0, idx); CGBuffer[idx] = iClose(NULL, 0, idx);
HGBuffer[idx] = iHigh(NULL, 0, idx); LGBuffer[idx] = iLow(NULL, 0, idx);
} else if( tmp < 0 ) {
ClearBuffer(idx);
ORBuffer[idx] = iOpen(NULL, 0, idx); CRBuffer[idx] = iClose(NULL, 0, idx);
HRBuffer[idx] = iHigh(NULL, 0, idx); LRBuffer[idx] = iLow(NULL, 0, idx);
} else {
ClearBuffer(idx);
OBBuffer[idx] = iOpen(NULL, 0, idx); CBBuffer[idx] = iClose(NULL, 0, idx);
HBBuffer[idx] = iHigh(NULL, 0, idx); LBBuffer[idx] = iLow(NULL, 0, idx);
}
if( ON_EMA ) {
EmaHBuffer[idx] = iMA(Symbol(), Period(), EMA, 0, MODE_EMA, PRICE_HIGH, idx);
EmaLBuffer[idx] = iMA(Symbol(), Period(), EMA, 0, MODE_EMA, PRICE_LOW, idx);
EmaCBuffer[idx] = iMA(Symbol(), Period(), EMA, 0, MODE_EMA, PRICE_CLOSE, idx);
}
}
if( ON_PRICES ) {
static string name = "wave_price_green";
if( ObjectFind(name) >= 0 ) {
ObjectDelete(name);
}
if( !ObjectCreate(0, name, OBJ_ARROW_RIGHT_PRICE, 0, Time[0], iMA(Symbol(), Period(), EMA, 0, MODE_EMA, PRICE_HIGH, 0)) ) {
Print( __FUNCTION__, ": Error = ", GetLastError() );
return rates_total;
}
ObjectSetInteger(0, name, OBJPROP_COLOR, clrGreen);
ObjectSetInteger(0, name, OBJPROP_WIDTH, 1);
ObjectSetInteger(0, name, OBJPROP_BACK, false);
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, name, OBJPROP_SELECTED, false);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
name = "wave_price_red";
if( ObjectFind(name) >= 0 ) {
ObjectDelete(name);
}
if( !ObjectCreate(0, name, OBJ_ARROW_RIGHT_PRICE, 0, Time[0], iMA(Symbol(), Period(), EMA, 0, MODE_EMA, PRICE_LOW, 0)) ) {
Print( __FUNCTION__, ": Error = ", GetLastError() );
return rates_total;
}
ObjectSetInteger(0, name, OBJPROP_COLOR, clrRed);
ObjectSetInteger(0, name, OBJPROP_WIDTH, 1);
ObjectSetInteger(0, name, OBJPROP_BACK, false);
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, name, OBJPROP_SELECTED, false);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
}
if( ON_ALERT ) {
int candles[4];
candles[0] = OGBuffer[0] != EMPTY_VALUE ? 1 : (ORBuffer[0] != EMPTY_VALUE ? -1 : 0);
candles[1] = OGBuffer[1] != EMPTY_VALUE ? 1 : (ORBuffer[1] != EMPTY_VALUE ? -1 : 0);
candles[2] = OGBuffer[2] != EMPTY_VALUE ? 1 : (ORBuffer[2] != EMPTY_VALUE ? -1 : 0);
candles[3] = OGBuffer[3] != EMPTY_VALUE ? 1 : (ORBuffer[3] != EMPTY_VALUE ? -1 : 0);
if( candles[1] == candles[2] && candles[2] == candles[3] ) {
if( candles[0] != candles[1] ) {
string msg1 = "Warning! Possibly changes market stage.", msg2;
if( candles[0] > candles[1] ) {
msg2 = "Perhaps an upward trend.";
} else if( candles[0] < candles[1] ) {
msg2 = "Perhaps a downward trend.";
} else {
msg2 = "Perhaps consolidation.";
}
switch( ON_ALERT ) {
case TurnedOff: { break; }
case AllCandles: { Alert(msg1, "\r\n", msg2); break; }
case NeutralCandles: { Alert(msg1, "\r\n", msg2); break; }
case PositivCandles: { Alert(msg1, "\r\n", msg2); break; }
case NegativeCandles: { Alert(msg1, "\r\n", msg2); break; }
case PositivAndNegative: { Alert(msg1, "\r\n", msg2); break; }
default: break;
}
}
}
}
return rates_total;
}
//+---------------------------------------------------------------------------+
void OnDeinit(const int reason)
{
if( ON_PRICES ) {
ObjectDelete("wave_price_green");
ObjectDelete("wave_price_red");
}
}
//+---------------------------------------------------------------------------+
void OnChartEvent(const int id, const long& lparam,
const double& dparam, const string& sparam)
{
if( id == CHARTEVENT_CHART_CHANGE ) {
ResizeBar();
ChartRedraw();
}
}
//+---------------------------------------------------------------------------+
void ResizeBar()
{
static int tmpS, tmpT;
int scale, typeBar, size = 1;
scale = (int)ChartGetInteger(0, CHART_SCALE);
typeBar = (int)ChartGetInteger(0, CHART_MODE);
if( scale == tmpS && typeBar == tmpT ) { return; }
if( typeBar == CHART_CANDLES ) {
size = scale > 3 ? 5 : (scale == 0 ? 1 : scale);
}
SetIndexStyle(0, DRAW_HISTOGRAM, EMPTY, size);
SetIndexStyle(1, DRAW_HISTOGRAM, EMPTY, size);
SetIndexStyle(4, DRAW_HISTOGRAM, EMPTY, size);
SetIndexStyle(5, DRAW_HISTOGRAM, EMPTY, size);
SetIndexStyle(8, DRAW_HISTOGRAM, EMPTY, size);
SetIndexStyle(9, DRAW_HISTOGRAM, EMPTY, size);
tmpS = scale; tmpT = typeBar;
}
//+---------------------------------------------------------------------------+
void ClearBuffer(const int bar = 0)
{
OGBuffer[bar] = EMPTY_VALUE; HGBuffer[bar] = EMPTY_VALUE; LGBuffer[bar] = EMPTY_VALUE; CGBuffer[bar] = EMPTY_VALUE;
ORBuffer[bar] = EMPTY_VALUE; HRBuffer[bar] = EMPTY_VALUE; LRBuffer[bar] = EMPTY_VALUE; CRBuffer[bar] = EMPTY_VALUE;
OBBuffer[bar] = EMPTY_VALUE; HBBuffer[bar] = EMPTY_VALUE; LBBuffer[bar] = EMPTY_VALUE; CBBuffer[bar] = EMPTY_VALUE;
}