Skip to content

Commit bb8d29e

Browse files
committed
init and finished project
1 parent 130e049 commit bb8d29e

File tree

2 files changed

+253
-0
lines changed

2 files changed

+253
-0
lines changed

CoreBox.mq4

Lines changed: 253 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
//+------------------------------------------------------------------+
2+
//| CoreBox.mq4 |
3+
//| Copyright 2024, Conisma. |
4+
//| https://www.blog.conisma.com |
5+
//+------------------------------------------------------------------+
6+
#property strict
7+
#property indicator_chart_window
8+
extern int ATRPeriod = 55;
9+
extern string SupportedTimeFrame = "D1 - H4 - H1 - M15";
10+
extern ENUM_TIMEFRAMES CustomTF = PERIOD_D1;
11+
extern int UnitToProcess = 20;
12+
extern int DojiDiff = 2;
13+
extern color UpColor = C'218,250,218';
14+
extern color DownColor = C'250,211,211';
15+
extern color DojiColor = C'255,245,195';
16+
17+
18+
datetime starttime[],endtime[];
19+
double lowprice[],highprice[],closeprice[];
20+
double atr[];
21+
int bars_in_one_rectangle;
22+
color BarsColor[];
23+
int ChartPeriod;
24+
//+------------------------------------------------------------------+
25+
//| Custom indicator initialization function |
26+
//+------------------------------------------------------------------+
27+
int init()
28+
{
29+
//----
30+
ChartPeriod=Period();
31+
32+
//D1
33+
if(CustomTF==PERIOD_D1)
34+
{
35+
switch(ChartPeriod)
36+
{
37+
case PERIOD_M1 :
38+
bars_in_one_rectangle=1440-1;
39+
break;
40+
case PERIOD_M5 :
41+
bars_in_one_rectangle=288-1;
42+
break;
43+
case PERIOD_M15:
44+
bars_in_one_rectangle=96-1;
45+
break;
46+
case PERIOD_M30:
47+
bars_in_one_rectangle=48-1;
48+
break;
49+
case PERIOD_H1 :
50+
bars_in_one_rectangle=24-1;
51+
break;
52+
case PERIOD_H4 :
53+
bars_in_one_rectangle=6-1;
54+
break;
55+
default :
56+
ChartPeriod=240;
57+
}
58+
}
59+
//H4
60+
else
61+
if(CustomTF==PERIOD_H4)
62+
{
63+
switch(ChartPeriod)
64+
{
65+
case PERIOD_M1 :
66+
bars_in_one_rectangle=240-1;
67+
break;
68+
case PERIOD_M5 :
69+
bars_in_one_rectangle=48-1;
70+
break;
71+
case PERIOD_M15:
72+
bars_in_one_rectangle=16-1;
73+
break;
74+
case PERIOD_M30:
75+
bars_in_one_rectangle=8-1;
76+
break;
77+
case PERIOD_H1 :
78+
bars_in_one_rectangle=4-1;
79+
break;
80+
default :
81+
ChartPeriod=60;
82+
}
83+
}
84+
//H1
85+
else
86+
if(CustomTF==PERIOD_H1)
87+
{
88+
switch(ChartPeriod)
89+
{
90+
case PERIOD_M1 :
91+
bars_in_one_rectangle=60-1;
92+
break;
93+
case PERIOD_M5 :
94+
bars_in_one_rectangle=12-1;
95+
break;
96+
case PERIOD_M15:
97+
bars_in_one_rectangle=4-1;
98+
break;
99+
case PERIOD_M30:
100+
bars_in_one_rectangle=2-1;
101+
break;
102+
default :
103+
ChartPeriod=30;
104+
}
105+
}
106+
//M30
107+
else
108+
if(CustomTF==PERIOD_M30)
109+
{
110+
switch(ChartPeriod)
111+
{
112+
case PERIOD_M1 :
113+
bars_in_one_rectangle=30-1;
114+
break;
115+
case PERIOD_M5 :
116+
bars_in_one_rectangle=6-1;
117+
break;
118+
case PERIOD_M15:
119+
bars_in_one_rectangle=2-1;
120+
break;
121+
default :
122+
ChartPeriod=15;
123+
}
124+
}
125+
//M15
126+
else
127+
if(CustomTF==PERIOD_M15)
128+
{
129+
switch(ChartPeriod)
130+
{
131+
case PERIOD_M1 :
132+
bars_in_one_rectangle=15-1;
133+
break;
134+
case PERIOD_M5 :
135+
bars_in_one_rectangle=3-1;
136+
break;
137+
default :
138+
ChartPeriod=5;
139+
}
140+
}
141+
//M5
142+
else
143+
if(CustomTF==PERIOD_M5)
144+
{
145+
switch(ChartPeriod)
146+
{
147+
case PERIOD_M1 :
148+
bars_in_one_rectangle=5-1;
149+
break;
150+
default :
151+
ChartPeriod=1;
152+
}
153+
}
154+
155+
156+
157+
ArrayResize(starttime, UnitToProcess);
158+
ArrayResize(endtime, UnitToProcess);
159+
ArrayResize(lowprice, UnitToProcess);
160+
ArrayResize(closeprice, UnitToProcess);
161+
ArrayResize(highprice, UnitToProcess);
162+
ArrayResize(BarsColor, UnitToProcess);
163+
ArrayResize(atr, UnitToProcess);
164+
165+
166+
167+
//----
168+
return(0);
169+
}
170+
//+------------------------------------------------------------------+
171+
//| Custom indicator deinitialization function |
172+
//+------------------------------------------------------------------+
173+
int deinit()
174+
{
175+
//----
176+
for(int w=0; w<UnitToProcess; w++)
177+
{
178+
ObjectDelete("CustomTF"+w);
179+
}
180+
Comment("");
181+
//----
182+
return(0);
183+
}
184+
//+------------------------------------------------------------------+
185+
//| Custom indicator iteration function |
186+
//+------------------------------------------------------------------+
187+
int start()
188+
{
189+
190+
for(int w=0; w<UnitToProcess; w++)
191+
{
192+
ObjectDelete("CustomTF"+w);
193+
}
194+
for(int w=0; w<UnitToProcess; w++)
195+
{
196+
switch(CustomTF)
197+
{
198+
case PERIOD_MN1 :
199+
atr[w] = iATR(NULL,PERIOD_D1,ATRPeriod,w);
200+
break;
201+
case PERIOD_W1:
202+
atr[w] = iATR(NULL,PERIOD_H4,ATRPeriod,w);
203+
break;
204+
case PERIOD_D1 :
205+
atr[w] = iATR(NULL,PERIOD_H1,ATRPeriod,w);
206+
break;
207+
case PERIOD_H4 :
208+
atr[w] = iATR(NULL,PERIOD_M15,ATRPeriod,w);
209+
break;
210+
case PERIOD_H1:
211+
atr[w] = iATR(NULL,PERIOD_M5,ATRPeriod,w);
212+
break;
213+
case PERIOD_M15:
214+
atr[w] = iATR(NULL,PERIOD_M1,ATRPeriod,w);
215+
break;
216+
default :
217+
atr[w] = iATR(NULL,PERIOD_M1,ATRPeriod,w);
218+
}
219+
}
220+
for(int w=0; w<UnitToProcess-1; w++)
221+
{
222+
starttime[w]=iTime(NULL,CustomTF,w);
223+
endtime[w]=starttime[w]+bars_in_one_rectangle*Period()*60;
224+
lowprice[w]=iLow(NULL,CustomTF,w);
225+
highprice[w]=iHigh(NULL,CustomTF,w);
226+
closeprice[w]=iClose(NULL,CustomTF,w);
227+
228+
229+
if(iOpen(NULL,CustomTF,w+1)<iClose(NULL,CustomTF,w+1)-(DojiDiff*Point))
230+
{
231+
BarsColor[w]=UpColor;
232+
ObjectCreate("CustomTF"+w,OBJ_RECTANGLE,0,starttime[w],closeprice[w+1],endtime[w],closeprice[w+1]-atr[w+1]);
233+
ObjectSet("CustomTF"+w,OBJPROP_COLOR,BarsColor[w]);
234+
}
235+
else
236+
{
237+
if(iOpen(NULL,CustomTF,w+1)>iClose(NULL,CustomTF,w+1)+(DojiDiff*Point))
238+
{
239+
BarsColor[w]=DownColor;
240+
ObjectCreate("CustomTF"+w,OBJ_RECTANGLE,0,starttime[w],closeprice[w+1],endtime[w],closeprice[w+1]+atr[w+1]);
241+
ObjectSet("CustomTF"+w,OBJPROP_COLOR,BarsColor[w]);
242+
}
243+
else
244+
{
245+
BarsColor[w]=DojiColor;
246+
ObjectCreate("CustomTF"+w,OBJ_RECTANGLE,0,starttime[w],closeprice[w+1]+(atr[w+1]/2),endtime[w],closeprice[w+1]+(atr[w+1]/2));
247+
ObjectSet("CustomTF"+w,OBJPROP_COLOR,BarsColor[w]);
248+
}
249+
}
250+
}
251+
return(0);
252+
}
253+
//+------------------------------------------------------------------+

CoreBox.mqproj

1.33 KB
Binary file not shown.

0 commit comments

Comments
 (0)