Revision | b256639f78930d43173401fd25cfca4fc5f7c573 (tree) |
---|---|
Time | 2023-04-03 07:07:46 |
Author | kazuhiro_kondow <simauma.circus@gmai...> |
Commiter | kazuhiro_kondow |
macdsignalの判定に一定の制限を設ける
ポジション解消フラグを見直し->全てのポジション解消へ動作修正
@@ -53,16 +53,19 @@ LossCut = 1.0 | ||
53 | 53 | # テクニカル分析 |
54 | 54 | [Technical] |
55 | 55 | # 短期EMAの期間 |
56 | -FastEMAperiod = 15 | |
56 | +FastEMAperiod = 20 | |
57 | 57 | # 長期EMAの期間 |
58 | -SlowEMAperiod = 64 | |
58 | +SlowEMAperiod = 98 | |
59 | 59 | # シグナルの期間 |
60 | -Signalperiod = 33 | |
60 | +Signalperiod = 34 | |
61 | 61 | # 交差角度閾値 |
62 | -CrossingAngleThreshold = 1.375 | |
62 | +CrossingAngleThreshold = 1.025 | |
63 | 63 | |
64 | 64 | ; 2023/04/02 |
65 | -; MACDCross(n1=15,n2=64,ns=33,angle=55,take=20,cut=40) | |
66 | -; crossover_angle = 1.375 | |
65 | +; Trades 180.0 | |
66 | +; Win Rate [%] 66.111111 | |
67 | +; SQN 2.571405 | |
68 | +; MACDCross(n1=20,n2=98,ns=34,angle=41,take=20,cut=40) | |
69 | +; crossover_angle = 1.025 | |
67 | 70 | ; ProfitTaking = 0.5 |
68 | 71 | ; LossCut = 1.0 |
\ No newline at end of file |
@@ -193,8 +193,8 @@ class Setting(object): | ||
193 | 193 | @property |
194 | 194 | def close_position(self) -> bool | None: |
195 | 195 | """close position |
196 | - True: sellポジションを解消 | |
197 | - False: buyポジションを解消 | |
196 | + True: 全てのポジションを解消 | |
197 | + False: Unset | |
198 | 198 | None: Unset |
199 | 199 | """ |
200 | 200 | return self.__close_position |
@@ -5,4 +5,4 @@ TECHNICAL_GOLDEN_CROSS = 1 | ||
5 | 5 | TECHNICAL_DEAD_CROSS = 2 |
6 | 6 | TECHNICAL_UPTREND = 3 |
7 | 7 | TECHNICAL_DOWNTREND = 4 |
8 | - | |
8 | +TECHNICAL_ROSSCUT = 5 |
@@ -258,8 +258,38 @@ class ExchangeRateInfo(): | ||
258 | 258 | msg = f'befor turning point:{s.turning_point}' |
259 | 259 | logger.debug(msg) |
260 | 260 | |
261 | + # signalが降下サインのまま0を超えた | |
262 | + if self.__crossover(macdsignal[-2:], [0.0, 0.0]) and \ | |
263 | + s.turning_point is False: | |
264 | + # turning_pointが降下サインのまま0を上回った場合 | |
265 | + # 降下サインを取り消し、ロスカットを行う | |
266 | + msg = ( | |
267 | + 'CrossOver up zero line. Treat as a rising sign.' | |
268 | + ) | |
269 | + msg = msg + ' Already judged loss cut.' | |
270 | + s.technical_indicator = DEF.TECHNICAL_UPTREND | |
271 | + s.turning_point = None | |
272 | + s.close_position = True | |
273 | + | |
274 | + # signalが上昇サインのまま0を下回った | |
275 | + elif self.__crossover([0.0, 0.0], macdsignal[-2:]) and \ | |
276 | + s.turning_point is True: | |
277 | + # turning_pointが上昇サインのまま0を下回った場合 | |
278 | + # 上昇サインを取り消し、ロスカットを行う | |
279 | + msg = ( | |
280 | + 'CrossOver down zero line. Treat as a descent sign.' | |
281 | + ) | |
282 | + msg = msg + ' Already judged loss cut.' | |
283 | + s.technical_indicator = DEF.TECHNICAL_DOWNTREND | |
284 | + s.turning_point = None | |
285 | + s.close_position = True | |
286 | + | |
287 | + # macdsignalが一定範囲の時は判定しない | |
288 | + elif macdsignal < 0.04 and macdsignal > -0.04: | |
289 | + return | |
290 | + | |
261 | 291 | # macdがsignalを上回った時 |
262 | - if self.__crossover(macd[-2:], macdsignal[-2:]): | |
292 | + elif self.__crossover(macd[-2:], macdsignal[-2:]): | |
263 | 293 | msg = ( |
264 | 294 | 'CrossOver up.' |
265 | 295 | f' vector angle:{v_angle}' |
@@ -288,31 +318,31 @@ class ExchangeRateInfo(): | ||
288 | 318 | msg = msg + ' Already judged deadcross.' |
289 | 319 | s.technical_indicator = DEF.TECHNICAL_DOWNTREND |
290 | 320 | |
291 | - # signalが降下サインのまま0を超えた | |
292 | - elif self.__crossover(macdsignal[-2:], [0.0, 0.0]) and \ | |
293 | - s.turning_point is False: | |
294 | - # turning_pointが降下サインのまま0を上回った場合 | |
295 | - # 降下サインを取り消し、ロスカットを行う | |
296 | - msg = ( | |
297 | - 'CrossOver up zero line. Treat as a rising sign.' | |
298 | - ) | |
299 | - msg = msg + ' Already judged loss cut.' | |
300 | - s.technical_indicator = DEF.TECHNICAL_UPTREND | |
301 | - s.turning_point = None | |
302 | - s.close_position = True | |
303 | - | |
304 | - # signalが上昇サインのまま0を下回った | |
305 | - elif self.__crossover([0.0, 0.0], macdsignal[-2:]) and \ | |
306 | - s.turning_point is True: | |
307 | - # turning_pointが上昇サインのまま0を下回った場合 | |
308 | - # 上昇サインを取り消し、ロスカットを行う | |
309 | - msg = ( | |
310 | - 'CrossOver down zero line. Treat as a descent sign.' | |
311 | - ) | |
312 | - msg = msg + ' Already judged loss cut.' | |
313 | - s.technical_indicator = DEF.TECHNICAL_DOWNTREND | |
314 | - s.turning_point = None | |
315 | - s.close_position = False | |
321 | + # # signalが降下サインのまま0を超えた | |
322 | + # elif self.__crossover(macdsignal[-2:], [0.0, 0.0]) and \ | |
323 | + # s.turning_point is False: | |
324 | + # # turning_pointが降下サインのまま0を上回った場合 | |
325 | + # # 降下サインを取り消し、ロスカットを行う | |
326 | + # msg = ( | |
327 | + # 'CrossOver up zero line. Treat as a rising sign.' | |
328 | + # ) | |
329 | + # msg = msg + ' Already judged loss cut.' | |
330 | + # s.technical_indicator = DEF.TECHNICAL_UPTREND | |
331 | + # s.turning_point = None | |
332 | + # s.close_position = True | |
333 | + | |
334 | + # # signalが上昇サインのまま0を下回った | |
335 | + # elif self.__crossover([0.0, 0.0], macdsignal[-2:]) and \ | |
336 | + # s.turning_point is True: | |
337 | + # # turning_pointが上昇サインのまま0を下回った場合 | |
338 | + # # 上昇サインを取り消し、ロスカットを行う | |
339 | + # msg = ( | |
340 | + # 'CrossOver down zero line. Treat as a descent sign.' | |
341 | + # ) | |
342 | + # msg = msg + ' Already judged loss cut.' | |
343 | + # s.technical_indicator = DEF.TECHNICAL_DOWNTREND | |
344 | + # s.turning_point = None | |
345 | + # s.close_position = True | |
316 | 346 | |
317 | 347 | # 2023-03-17 05:53:50 num[-3]: MACD: 0.0601, MACDSignal: 0.0504 |
318 | 348 | # 2023-03-17 05:53:50 num[-2]: MACD: 0.0557, MACDSignal: 0.051 |
@@ -58,11 +58,9 @@ class PositionMng(): | ||
58 | 58 | indicator = s.technical_indicator |
59 | 59 | # 解消する対象のポジション mt5.ENUM_POSITION_TYPE |
60 | 60 | position_to_be_canceled: int = -1 # -1:Undefine |
61 | - if indicator == DEF.TECHNICAL_GOLDEN_CROSS or \ | |
62 | - s.close_position is True: | |
61 | + if indicator == DEF.TECHNICAL_GOLDEN_CROSS: | |
63 | 62 | position_to_be_canceled = mt5.POSITION_TYPE_SELL |
64 | - elif indicator == DEF.TECHNICAL_DEAD_CROSS or \ | |
65 | - s.close_position is False: | |
63 | + elif indicator == DEF.TECHNICAL_DEAD_CROSS: | |
66 | 64 | position_to_be_canceled = mt5.POSITION_TYPE_BUY |
67 | 65 | else: |
68 | 66 | pass |
@@ -84,8 +82,23 @@ class PositionMng(): | ||
84 | 82 | f'position {position.ticket} is close.' |
85 | 83 | ) |
86 | 84 | |
87 | - # エラーが無ければフラグを初期化 | |
88 | - s.close_position = None | |
85 | + # 無条件にすべてのポジションを解消する | |
86 | + if s.close_position: | |
87 | + logger.warning('========== Close All positions. ==========') | |
88 | + for position in positions: | |
89 | + result = self.__close_position( | |
90 | + position.ticket, | |
91 | + position.volume, | |
92 | + position.type | |
93 | + ) | |
94 | + if result: | |
95 | + logger.info( | |
96 | + f'position {position.ticket} is close.' | |
97 | + ) | |
98 | + s.close_position = False | |
99 | + | |
100 | + # # エラーが無ければフラグを初期化 | |
101 | + # s.close_position = None | |
89 | 102 | |
90 | 103 | except Exception as e: |
91 | 104 | logger.error(e) |