• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisionb256639f78930d43173401fd25cfca4fc5f7c573 (tree)
Time2023-04-03 07:07:46
Authorkazuhiro_kondow <simauma.circus@gmai...>
Commiterkazuhiro_kondow

Log Message

macdsignalの判定に一定の制限を設ける
ポジション解消フラグを見直し->全てのポジション解消へ動作修正

Change Summary

Incremental Difference

--- a/src/config/setting.ini
+++ b/src/config/setting.ini
@@ -53,16 +53,19 @@ LossCut = 1.0
5353 # テクニカル分析
5454 [Technical]
5555 # 短期EMAの期間
56-FastEMAperiod = 15
56+FastEMAperiod = 20
5757 # 長期EMAの期間
58-SlowEMAperiod = 64
58+SlowEMAperiod = 98
5959 # シグナルの期間
60-Signalperiod = 33
60+Signalperiod = 34
6161 # 交差角度閾値
62-CrossingAngleThreshold = 1.375
62+CrossingAngleThreshold = 1.025
6363
6464 ; 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
6770 ; ProfitTaking = 0.5
6871 ; LossCut = 1.0
\ No newline at end of file
--- a/src/configuration.py
+++ b/src/configuration.py
@@ -193,8 +193,8 @@ class Setting(object):
193193 @property
194194 def close_position(self) -> bool | None:
195195 """close position
196- True: sellポジションを解消
197- False: buyポジションを解消
196+ True: 全てのポジションを解消
197+ False: Unset
198198 None: Unset
199199 """
200200 return self.__close_position
--- a/src/definition.py
+++ b/src/definition.py
@@ -5,4 +5,4 @@ TECHNICAL_GOLDEN_CROSS = 1
55 TECHNICAL_DEAD_CROSS = 2
66 TECHNICAL_UPTREND = 3
77 TECHNICAL_DOWNTREND = 4
8-
8+TECHNICAL_ROSSCUT = 5
--- a/src/exchange_rate_info.py
+++ b/src/exchange_rate_info.py
@@ -258,8 +258,38 @@ class ExchangeRateInfo():
258258 msg = f'befor turning point:{s.turning_point}'
259259 logger.debug(msg)
260260
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+
261291 # macdがsignalを上回った時
262- if self.__crossover(macd[-2:], macdsignal[-2:]):
292+ elif self.__crossover(macd[-2:], macdsignal[-2:]):
263293 msg = (
264294 'CrossOver up.'
265295 f' vector angle:{v_angle}'
@@ -288,31 +318,31 @@ class ExchangeRateInfo():
288318 msg = msg + ' Already judged deadcross.'
289319 s.technical_indicator = DEF.TECHNICAL_DOWNTREND
290320
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
316346
317347 # 2023-03-17 05:53:50 num[-3]: MACD: 0.0601, MACDSignal: 0.0504
318348 # 2023-03-17 05:53:50 num[-2]: MACD: 0.0557, MACDSignal: 0.051
--- a/src/position_mng.py
+++ b/src/position_mng.py
@@ -58,11 +58,9 @@ class PositionMng():
5858 indicator = s.technical_indicator
5959 # 解消する対象のポジション mt5.ENUM_POSITION_TYPE
6060 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:
6362 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:
6664 position_to_be_canceled = mt5.POSITION_TYPE_BUY
6765 else:
6866 pass
@@ -84,8 +82,23 @@ class PositionMng():
8482 f'position {position.ticket} is close.'
8583 )
8684
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
89102
90103 except Exception as e:
91104 logger.error(e)