-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoreBox.mq4
253 lines (241 loc) · 7.55 KB
/
CoreBox.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
//+------------------------------------------------------------------+
//| CoreBox.mq4 |
//| Copyright 2024, Conisma. |
//| https://www.blog.conisma.com |
//+------------------------------------------------------------------+
#property strict
#property indicator_chart_window
extern int ATRPeriod = 55;
extern string SupportedTimeFrame = "D1 - H4 - H1 - M15";
extern ENUM_TIMEFRAMES CustomTF = PERIOD_D1;
extern int UnitToProcess = 20;
extern int DojiDiff = 2;
extern color UpColor = C'218,250,218';
extern color DownColor = C'250,211,211';
extern color DojiColor = C'255,245,195';
datetime starttime[],endtime[];
double lowprice[],highprice[],closeprice[];
double atr[];
int bars_in_one_rectangle;
color BarsColor[];
int ChartPeriod;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
ChartPeriod=Period();
//D1
if(CustomTF==PERIOD_D1)
{
switch(ChartPeriod)
{
case PERIOD_M1 :
bars_in_one_rectangle=1440-1;
break;
case PERIOD_M5 :
bars_in_one_rectangle=288-1;
break;
case PERIOD_M15:
bars_in_one_rectangle=96-1;
break;
case PERIOD_M30:
bars_in_one_rectangle=48-1;
break;
case PERIOD_H1 :
bars_in_one_rectangle=24-1;
break;
case PERIOD_H4 :
bars_in_one_rectangle=6-1;
break;
default :
ChartPeriod=240;
}
}
//H4
else
if(CustomTF==PERIOD_H4)
{
switch(ChartPeriod)
{
case PERIOD_M1 :
bars_in_one_rectangle=240-1;
break;
case PERIOD_M5 :
bars_in_one_rectangle=48-1;
break;
case PERIOD_M15:
bars_in_one_rectangle=16-1;
break;
case PERIOD_M30:
bars_in_one_rectangle=8-1;
break;
case PERIOD_H1 :
bars_in_one_rectangle=4-1;
break;
default :
ChartPeriod=60;
}
}
//H1
else
if(CustomTF==PERIOD_H1)
{
switch(ChartPeriod)
{
case PERIOD_M1 :
bars_in_one_rectangle=60-1;
break;
case PERIOD_M5 :
bars_in_one_rectangle=12-1;
break;
case PERIOD_M15:
bars_in_one_rectangle=4-1;
break;
case PERIOD_M30:
bars_in_one_rectangle=2-1;
break;
default :
ChartPeriod=30;
}
}
//M30
else
if(CustomTF==PERIOD_M30)
{
switch(ChartPeriod)
{
case PERIOD_M1 :
bars_in_one_rectangle=30-1;
break;
case PERIOD_M5 :
bars_in_one_rectangle=6-1;
break;
case PERIOD_M15:
bars_in_one_rectangle=2-1;
break;
default :
ChartPeriod=15;
}
}
//M15
else
if(CustomTF==PERIOD_M15)
{
switch(ChartPeriod)
{
case PERIOD_M1 :
bars_in_one_rectangle=15-1;
break;
case PERIOD_M5 :
bars_in_one_rectangle=3-1;
break;
default :
ChartPeriod=5;
}
}
//M5
else
if(CustomTF==PERIOD_M5)
{
switch(ChartPeriod)
{
case PERIOD_M1 :
bars_in_one_rectangle=5-1;
break;
default :
ChartPeriod=1;
}
}
ArrayResize(starttime, UnitToProcess);
ArrayResize(endtime, UnitToProcess);
ArrayResize(lowprice, UnitToProcess);
ArrayResize(closeprice, UnitToProcess);
ArrayResize(highprice, UnitToProcess);
ArrayResize(BarsColor, UnitToProcess);
ArrayResize(atr, UnitToProcess);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
for(int w=0; w<UnitToProcess; w++)
{
ObjectDelete("CustomTF"+w);
}
Comment("");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
for(int w=0; w<UnitToProcess; w++)
{
ObjectDelete("CustomTF"+w);
}
for(int w=0; w<UnitToProcess; w++)
{
switch(CustomTF)
{
case PERIOD_MN1 :
atr[w] = iATR(NULL,PERIOD_D1,ATRPeriod,w);
break;
case PERIOD_W1:
atr[w] = iATR(NULL,PERIOD_H4,ATRPeriod,w);
break;
case PERIOD_D1 :
atr[w] = iATR(NULL,PERIOD_H1,ATRPeriod,w);
break;
case PERIOD_H4 :
atr[w] = iATR(NULL,PERIOD_M15,ATRPeriod,w);
break;
case PERIOD_H1:
atr[w] = iATR(NULL,PERIOD_M5,ATRPeriod,w);
break;
case PERIOD_M15:
atr[w] = iATR(NULL,PERIOD_M1,ATRPeriod,w);
break;
default :
atr[w] = iATR(NULL,PERIOD_M1,ATRPeriod,w);
}
}
for(int w=0; w<UnitToProcess-1; w++)
{
starttime[w]=iTime(NULL,CustomTF,w);
endtime[w]=starttime[w]+bars_in_one_rectangle*Period()*60;
lowprice[w]=iLow(NULL,CustomTF,w);
highprice[w]=iHigh(NULL,CustomTF,w);
closeprice[w]=iClose(NULL,CustomTF,w);
if(iOpen(NULL,CustomTF,w+1)<iClose(NULL,CustomTF,w+1)-(DojiDiff*Point))
{
BarsColor[w]=UpColor;
ObjectCreate("CustomTF"+w,OBJ_RECTANGLE,0,starttime[w],closeprice[w+1],endtime[w],closeprice[w+1]-atr[w+1]);
ObjectSet("CustomTF"+w,OBJPROP_COLOR,BarsColor[w]);
}
else
{
if(iOpen(NULL,CustomTF,w+1)>iClose(NULL,CustomTF,w+1)+(DojiDiff*Point))
{
BarsColor[w]=DownColor;
ObjectCreate("CustomTF"+w,OBJ_RECTANGLE,0,starttime[w],closeprice[w+1],endtime[w],closeprice[w+1]+atr[w+1]);
ObjectSet("CustomTF"+w,OBJPROP_COLOR,BarsColor[w]);
}
else
{
BarsColor[w]=DojiColor;
ObjectCreate("CustomTF"+w,OBJ_RECTANGLE,0,starttime[w],closeprice[w+1]+(atr[w+1]/2),endtime[w],closeprice[w+1]+(atr[w+1]/2));
ObjectSet("CustomTF"+w,OBJPROP_COLOR,BarsColor[w]);
}
}
}
return(0);
}
//+------------------------------------------------------------------+