質問編集履歴
1
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,14 +12,8 @@
|
|
12
12
|
|
13
13
|
```
|
14
14
|
|
15
|
-
'Calculated_Point' - undeclared identifier//関数の部分
|
16
|
-
|
17
|
-
|
18
|
-
|
19
15
|
'return' - 'void' function returns a value//最後の部分
|
20
16
|
|
21
|
-
|
22
|
-
|
23
17
|
```
|
24
18
|
|
25
19
|
|
@@ -30,58 +24,312 @@
|
|
30
24
|
|
31
25
|
```MQL4
|
32
26
|
|
27
|
+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
|
28
|
+
|
29
|
+
#property link "https://www.mql5.com"
|
30
|
+
|
31
|
+
#property version "1.00"
|
32
|
+
|
33
|
+
#property strict
|
34
|
+
|
35
|
+
#property copyright"詳解MT4"
|
36
|
+
|
37
|
+
#property link"http://mt4-traders.com"
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
//変数の宣言
|
42
|
+
|
43
|
+
extern int Magic = 1515;
|
44
|
+
|
45
|
+
extern int Break_Period = 24;
|
46
|
+
|
47
|
+
extern double Lots = 0.1;
|
48
|
+
|
49
|
+
extern int Slippage = 10;
|
50
|
+
|
51
|
+
extern string Comments = "Break Out";
|
52
|
+
|
53
|
+
extern int Trailing_Stop = 50;
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
int Buy_Ticket = 0;
|
58
|
+
|
59
|
+
int Sell_Ticket = 0;
|
60
|
+
|
61
|
+
double Pips = 0;
|
62
|
+
|
63
|
+
int Adjusted_Slippage = 0;
|
64
|
+
|
65
|
+
|
66
|
+
|
33
67
|
//関数の定義
|
34
68
|
|
69
|
+
//関数1
|
70
|
+
|
35
71
|
double AdjustPoint(string Currency)
|
36
72
|
|
37
|
-
|
73
|
+
{
|
74
|
+
|
38
|
-
|
75
|
+
double Calculated_Point;
|
76
|
+
|
39
|
-
|
77
|
+
int Symbol_Digits = MarketInfo(Currency,MODE_DIGITS);
|
40
|
-
|
78
|
+
|
41
|
-
|
79
|
+
if(Symbol_Digits == 2 || Symbol_Digits == 3)
|
42
|
-
|
80
|
+
|
43
|
-
|
81
|
+
{
|
44
|
-
|
82
|
+
|
45
|
-
|
83
|
+
Calculated_Point = 0.01;
|
46
|
-
|
84
|
+
|
47
|
-
|
85
|
+
}
|
48
|
-
|
86
|
+
|
49
|
-
|
87
|
+
else if(Symbol_Digits == 4 || Symbol_Digits == 5)
|
50
|
-
|
88
|
+
|
51
|
-
|
89
|
+
{
|
52
|
-
|
90
|
+
|
53
|
-
|
91
|
+
Calculated_Point = 0.0001;
|
54
|
-
|
92
|
+
|
55
|
-
|
93
|
+
}
|
56
|
-
|
94
|
+
|
57
|
-
|
95
|
+
return(Calculated_Point);
|
58
|
-
|
96
|
+
|
59
|
-
|
97
|
+
}
|
60
|
-
|
61
|
-
|
62
|
-
|
98
|
+
|
99
|
+
|
100
|
+
|
63
|
-
//
|
101
|
+
//関数2
|
64
|
-
|
102
|
+
|
65
|
-
|
103
|
+
int AdjustSlippage(string Currency,int Slippage_Pips)
|
66
|
-
|
104
|
+
|
67
|
-
|
105
|
+
{
|
106
|
+
|
68
|
-
|
107
|
+
int Calculated_Slippage;
|
108
|
+
|
69
|
-
|
109
|
+
int Symbol_Digits = MarketInfo(Currency,MODE_DIGITS);
|
110
|
+
|
70
|
-
|
111
|
+
if(Symbol_Digits == 2 || Symbol_Digits == 4)
|
112
|
+
|
113
|
+
{
|
114
|
+
|
115
|
+
Calculated_Slippage = Slippage_Pips;
|
116
|
+
|
71
|
-
|
117
|
+
}
|
118
|
+
|
119
|
+
else if(Symbol_Digits== 3 || Symbol_Digits == 5)
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
Calculated_Slippage = Slippage_Pips*10;
|
72
124
|
|
73
125
|
}
|
74
126
|
|
127
|
+
return(Calculated_Slippage);
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
int OnInit()
|
134
|
+
|
135
|
+
{
|
136
|
+
|
137
|
+
Pips = AdjustPoint(Symbol());
|
138
|
+
|
139
|
+
Adjusted_Slippage = AdjustSlippage(Symbol(),Slippage);
|
140
|
+
|
141
|
+
return(0);
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
void OnDeinit(const int reason)
|
148
|
+
|
149
|
+
{
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
void OnTick()
|
156
|
+
|
157
|
+
{
|
158
|
+
|
159
|
+
//チケット番号の初期化
|
160
|
+
|
161
|
+
if(OrdersTotal()==0)
|
162
|
+
|
163
|
+
{
|
164
|
+
|
165
|
+
Buy_Ticket=0;
|
166
|
+
|
167
|
+
Sell_Ticket=0;
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
//クローズ処理
|
172
|
+
|
173
|
+
//ポジション保有の確認
|
174
|
+
|
175
|
+
if(OrderSelect(0,SELECT_BY_POS,MODE_TRADES)==true)
|
176
|
+
|
177
|
+
{
|
178
|
+
|
179
|
+
//ロングポジションクローズ
|
180
|
+
|
181
|
+
if(OrderType()==OP_BUY)
|
182
|
+
|
183
|
+
{
|
184
|
+
|
185
|
+
if(Close[0]<Low[iLowest(Symbol(),0,MODE_LOW,Break_Period,1)] && OrderCloseTime()==0)
|
186
|
+
|
187
|
+
{
|
188
|
+
|
189
|
+
bool Closed = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Adjusted_Slippage,Magenta);
|
190
|
+
|
191
|
+
if(Closed==true)
|
192
|
+
|
193
|
+
{
|
194
|
+
|
195
|
+
Buy_Ticket=0;
|
196
|
+
|
197
|
+
}
|
198
|
+
|
75
199
|
}
|
76
200
|
|
201
|
+
}
|
202
|
+
|
203
|
+
//ショートポジションクローズ
|
204
|
+
|
205
|
+
else if(OrderType()==OP_SELL)
|
206
|
+
|
207
|
+
{
|
208
|
+
|
209
|
+
if(Close[0]>High[iHighest(Symbol(),0,MODE_HIGH,Break_Period,1)] && OrderCloseTime()==0)
|
210
|
+
|
211
|
+
{
|
212
|
+
|
213
|
+
bool Closed = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Adjusted_Slippage,Aqua);
|
214
|
+
|
215
|
+
if(Closed==true)
|
216
|
+
|
217
|
+
{
|
218
|
+
|
219
|
+
Sell_Ticket=0;
|
220
|
+
|
221
|
+
}
|
222
|
+
|
77
223
|
}
|
78
224
|
|
225
|
+
}
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
//エントリー処理
|
232
|
+
|
233
|
+
//ロングエントリー
|
234
|
+
|
235
|
+
if(Close[0]>High[iHighest(NULL,0,MODE_HIGH,Break_Period,1)] && OrdersTotal()==0)
|
236
|
+
|
237
|
+
{
|
238
|
+
|
239
|
+
Buy_Ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Adjusted_Slippage,0,0,Comments,Magic,0,Magenta);
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
//ショートエントリー
|
246
|
+
|
247
|
+
if(Close[0]<Low[iLowest(NULL,0,MODE_LOW,Break_Period,1)] && OrdersTotal()==0)
|
248
|
+
|
249
|
+
{
|
250
|
+
|
251
|
+
Sell_Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Adjusted_Slippage,0,0,Comments,Magic,0,Aqua);
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
//トレイリングストップ
|
258
|
+
|
259
|
+
if(Buy_Ticket>0 || Sell_Ticket>0)
|
260
|
+
|
261
|
+
{
|
262
|
+
|
263
|
+
for(int i=OrdersTotal()-1; i>=0; i--)
|
264
|
+
|
265
|
+
{
|
266
|
+
|
267
|
+
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
|
268
|
+
|
269
|
+
{
|
270
|
+
|
271
|
+
//買いポジションの場合
|
272
|
+
|
273
|
+
if(OrderType()==OP_BUY)
|
274
|
+
|
275
|
+
{
|
276
|
+
|
277
|
+
double Max_Stop_Loss = Bid-Trailing_Stop*Pips;
|
278
|
+
|
279
|
+
Max_Stop_Loss = NormalizeDouble(Max_Stop_Loss,MarketInfo(Symbol(),MODE_DIGITS));
|
280
|
+
|
281
|
+
double Current_Stop=NormalizeDouble(OrderStopLoss(),MarketInfo(Symbol(),MODE_DIGITS));
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
//損切価格の変更
|
286
|
+
|
287
|
+
if(OrderMagicNumber()==Magic && OrderSymbol()==Symbol() && Current_Stop<Max_Stop_Loss)
|
288
|
+
|
289
|
+
{
|
290
|
+
|
291
|
+
bool Modified=OrderModify(OrderTicket(),OrderOpenPrice(),Max_Stop_Loss,0,0);
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
//売りポジションの場合
|
298
|
+
|
299
|
+
else if(OrderType()==OP_SELL)
|
300
|
+
|
301
|
+
{
|
302
|
+
|
303
|
+
double Max_Stop_Loss=Ask+Trailing_Stop*Pips;
|
304
|
+
|
305
|
+
Max_Stop_Loss=NormalizeDouble(Max_Stop_Loss,MarketInfo(Symbol(),MODE_DIGITS));
|
306
|
+
|
307
|
+
double Current_Stop=NormalizeDouble(OrderStopLoss(),MarketInfo(Symbol(),MODE_DIGITS));
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
//損切価格の変更
|
312
|
+
|
313
|
+
if(OrderMagicNumber()==Magic && OrderSymbol()==Symbol() && (Current_Stop>Max_Stop_Loss || Current_Stop==0))
|
314
|
+
|
315
|
+
{
|
316
|
+
|
317
|
+
double Modified=OrderModify(OrderTicket(),OrderOpenPrice(),Max_Stop_Loss,0,0);
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
}
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
return(0);
|
330
|
+
|
79
331
|
}
|
80
332
|
|
81
|
-
return(0); ←ここが問題点
|
82
|
-
|
83
|
-
}
|
84
|
-
|
85
333
|
```
|
86
334
|
|
87
335
|
|
@@ -98,4 +346,4 @@
|
|
98
346
|
|
99
347
|
|
100
348
|
|
101
|
-
|
349
|
+
https://mt4-traders.com/wp-content/uploads/2018/12/Break-Out-EA.pdf ←参考にしたもの
|