• 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

Revisionf79dfd2a46356805eb8e83a25c78e8e0e2c4cbec (tree)
Time2023-02-01 21:56:26
Authorkazuhiro_kondow <simauma.circus@gmai...>
Commiterkazuhiro_kondow

Log Message

コミット漏れ修正

Change Summary

Incremental Difference

--- a/investigation_study/beautifulsoup4_api_test.py
+++ b/investigation_study/beautifulsoup4_api_test.py
@@ -1,8 +1,8 @@
1-# 参考
2-# https://qiita.com/hujuu/items/b0339404b8b0460087f9
3-# https://ai-inter1.com/python-pandas_scraping/
1+# 経済指標取得をinvestpy.news.economic_calendarから取得したかったがメンテナンス中だった
2+# https://investpy.readthedocs.io/_api/news.html
3+# そのため、自力で取得に向いたWebPageを探すがよさそうなところは無い
4+# OANDA RESTAPIの使用を検討する
45
5-from bs4 import BeautifulSoup
66 import pandas as pd
77
88 # スクレイピング対象の URL
@@ -23,3 +23,173 @@ data = pd.read_html(url, header=0)
2323 # 4 16:00 NaN (ドイツ)12月卸売物価指数(WPI)(前月比) ★ -0.9% - -
2424 # 5 22:30 NaN (カナダ)11月製造業出荷(前月比) ★ 2.8% 0.5% -
2525 # 6 24:00 NaN (英国)ベイリー英中銀(BOE)総裁、発言 ★★ - - -, 2023/01/17(火) 2023/01/17(火).1
26+
27+# 外貨ex byGMO
28+url = 'https://www.gaikaex.com/gaikaex/mark/calendar/'
29+data = pd.read_html(url, header=0)
30+# >>> data
31+# [ 発表日 時刻 国 指標名 重要度 予想 結果 前回 (修正)
32+# 0 1/29 (日) NaN NaN NaN NaN NaN NaN NaN
33+# 1 1/30 (月) 06:45 ニュージーランド 12月貿易収支 ★★ NaN NaN -18.63億NZドル
34+# 2 1/30 (月) 17:00 スイス 1月KOF景気先行指数 ★ 93.4 NaN 92.2
35+# 3 1/30 (月) 18:00 ドイツ 10-12月期国内総生産(GDP、速報値)(前期比) ★★★0.0%0.4% NaN NaN NaN
36+# 4 1/30 (月) 18:00 ドイツ 10-12月期国内総生産(GDP、速報値、季調前)(前年同期比) ★★★0.8%1.2% NaN NaN NaN
37+# .. ... ... ... ... ... ... ... ...
38+# 106 2/3 (金) 23:45 米国 1月総合購買担当者景気指数(PMI、改定値) ★★ NaN NaN 46.6
39+# 107 2/3 (金) 23:45 米国 1月サービス部門購買担当者景気指数(PMI、改定値) ★★ NaN NaN 46.6
40+# 108 2/3 (金) 24:00 米国 1月ISM非製造業景況指数(総合) ★★★50.549.6 NaN NaN NaN
41+# 109 2/4 (土) NaN NaN NaN NaN NaN NaN NaN
42+# 110 2/5 (日) NaN NaN NaN NaN NaN NaN NaN
43+
44+# [111 rows x 8 columns]]
45+
46+# FX・外貨両替のマネーパートナーズ
47+url = 'https://www.moneypartners.co.jp/market/schedule/'
48+data = pd.read_html(url, header=0)
49+# >>> data
50+# [ 日付 時刻 重要度 指標 前回 (訂正) 予想 結果
51+# 0 1/9 (月) 未定 NaN (日) 休場 NaN NaN NaN
52+# 1 1/9 (月) 09:30 NaN (豪) 11月 住宅建設許可件数 [前月比] -6.0% (-5.6%) 0.0% -9.0%
53+# 2 1/9 (月) 15:45 NaN (スイス) 12月 失業率 2.0% 2.0% 2.1%
54+# 3 1/9 (月) 16:00 NaN (独) 11月 鉱工業生産 [前月比] -0.1% (-0.4%) 0.3% 0.2%
55+# 4 1/9 (月) 16:00 NaN (独) 11月 鉱工業生産 [前年同月比] 0.0% (-0.2%) 0.2% -0.4%
56+# .. ... ... ... ... ... ... ...
57+# 63 1/13 (金) 19:00 NaN (欧) 11月 貿易収支(季調済) -283億ユーロ (-281億ユーロ) -210億ユーロ -152億ユーロ
58+# 64 1/13 (金) 19:00 NaN (欧) 11月 貿易収支(季調前) -265億ユーロ -211億ユーロ -117億ユーロ
59+# 65 1/13 (金) 22:30 NaN (米) 12月 輸入物価指数 [前月比] -0.6% -0.9% 0.4%
60+# 66 1/13 (金) 22:30 NaN (米) 12月 輸出物価指数 [前月比] -0.3% -0.7% -2.6%
61+# 67 1/13 (金) 24:00 NaN (米) 1月 ミシガン大学消費者態度指数・速報値 59.7 60.5 64.6
62+
63+# [68 rows x 7 columns]
64+
65+# 岡三オンライン証券
66+url = 'https://www.okasan-online.co.jp/tradeinfo/indicator_event/economic_indicators/'
67+data = pd.read_html(url, header=0)
68+# >>> data
69+# [ 日本 アメリカ ユーロ圏 イギリス オーストラリア
70+# 0 (日) (米) (EU) (英) (豪)
71+# 1 ニュージーランド スイス カナダ 南アフリカ 中国
72+# 2 (NZ) (スイ) (加) (南ア) (中国)
73+# 3 香港 シンガポール ドイツ フランス トルコ
74+# 4 (香港) (シン) (独) (仏) (トル)
75+# 5 ポーランド メキシコ スウェーデン ノルウェー NaN
76+# 6 (ポー) (メキ) (スウ) (ノル) NaN]
77+# >>>
78+
79+# みんなのFX
80+url = 'https://min-fx.jp/market/indicators/'
81+data = pd.read_html(url, header=0)
82+# Traceback (most recent call last):
83+# File "<stdin>", line 1, in <module>
84+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper
85+# return func(*args, **kwargs)
86+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 1205, in read_html
87+# return _parse(
88+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 1006, in _parse
89+# raise retained
90+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 986, in _parse
91+# tables = p.parse_tables()
92+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 262, in parse_tables
93+# tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
94+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 618, in _parse_tables
95+# raise ValueError("No tables found")
96+# ValueError: No tables found
97+# >>>
98+
99+# みんかぶ FX/為替
100+url = 'https://fx.minkabu.jp/indicators'
101+data = pd.read_html(url, header=0)
102+# [ 未定 ドイツ・輸入物価指数 12月 [前月比] Unnamed: 2 -20.1pips -4.5% -2.5% ---
103+# 0 未定 ドイツ・輸入物価指数 12月 [前年比] NaN -20.1pips 14.5% 11.6% ---
104+# 1 未定 ドイツ・小売売上高 12月 [前月比] NaN -12.4pips 1.1% (1.7%) 0.3% ---
105+# 2 未定 ドイツ・小売売上高 12月 [前年比] NaN -12.4pips -5.7% (-5.1%) --- ---
106+# 3 06:45 NZ・貿易収支 12月 NaN -0.6pips -18.63億NZドル --- ---
107+# 4 16:00 スウェーデン・実質GDP 第4四半期 [前期比] NaN --- 0.7% 0.2% ---
108+# 5 19:00 ユーロ・消費者信頼感指数(確報値) 01月 [ユーロ圏消費者信頼感] NaN -12.5pips -20.9 --- ---
109+# 6 19:00 ユーロ・景況感 01月 NaN -12.5pips 95.8 96.9 ---, 08:00 韓国・鉱工業生産指数 12月 [前月比] Unnamed: 2 -7.8pips
110+# 0.4% -0.3% ---
111+
112+# Investing.com
113+url = 'https://jp.investing.com/economic-calendar/'
114+data = pd.read_html(url, header=0)
115+# >>> data = pd.read_html(url)
116+# Traceback (most recent call last):
117+# File "<stdin>", line 1, in <module>
118+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper
119+# return func(*args, **kwargs)
120+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 1205, in read_html
121+# return _parse(
122+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 986, in _parse
123+# tables = p.parse_tables()
124+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 262, in parse_tables
125+# tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
126+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 821, in _build_doc
127+# raise e
128+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 802, in _build_doc
129+# with urlopen(self.io) as f:
130+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\common.py", line 265, in urlopen
131+# return urllib.request.urlopen(*args, **kwargs)
132+# File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 216, in urlopen
133+# return opener.open(url, data, timeout)
134+# File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 525, in open
135+# response = meth(req, response)
136+# File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 634, in http_response
137+# response = self.parent.error(
138+# File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 563, in error
139+# return self._call_chain(*args)
140+# File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain
141+# result = func(*args)
142+# File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 643, in http_error_default
143+# raise HTTPError(req.full_url, code, msg, hdrs, fp)
144+# urllib.error.HTTPError: HTTP Error 403: Forbidden
145+# >>>
146+
147+# FX・外国為替取引のFOREX.com
148+url = 'https://www.forex.com/jp/market-info/market-data/economic-calendar/'
149+data = pd.read_html(url, header=0)
150+# >>> data = pd.read_html(url, header=0)
151+# Traceback (most recent call last):
152+# File "<stdin>", line 1, in <module>
153+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper
154+# return func(*args, **kwargs)
155+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 1205, in read_html
156+# return _parse(
157+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 986, in _parse
158+# tables = p.parse_tables()
159+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 262, in parse_tables
160+# tables = self._parse_tables(self._build_doc(), self.match, self.attrs)
161+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 821, in _build_doc
162+# raise e
163+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\html.py", line 802, in _build_doc
164+# with urlopen(self.io) as f:
165+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\pandas\io\common.py", line 265, in urlopen
166+# return urllib.request.urlopen(*args, **kwargs)
167+# File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 216, in urlopen
168+# return opener.open(url, data, timeout)
169+# File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 525, in open
170+# response = meth(req, response)
171+# File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 634, in http_response
172+# response = self.parent.error(
173+# File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 563, in error
174+# return self._call_chain(*args)
175+# File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 496, in _call_chain
176+# result = func(*args)
177+# File "C:\Users\user1\AppData\Local\Programs\Python\Python310\lib\urllib\request.py", line 643, in http_error_default
178+# raise HTTPError(req.full_url, code, msg, hdrs, fp)
179+# urllib.error.HTTPError: HTTP Error 403: Forbidden
180+# >>>
181+
182+# AIゴールド証券
183+url = 'https://www.aigold.co.jp/fx/market/shihyo/'
184+data = pd.read_html(url, header=0)
185+# >>> data
186+# [ 時間 国 指標 予想 結果 前回
187+# 0 1月27日(金) 1月27日(金) 1月27日(金) 1月27日(金) 1月27日(金) 1月27日(金)
188+# 1 09時30分 NaN 第4四半期 生産者物価指数 (前期比) - - 1.9%
189+# 2 09時30分 NaN 第4四半期 生産者物価指数 (前年比) - - 6.4%
190+# 3 09時30分 NaN 第4四半期 輸出物価 - - -3.6%
191+# 4 09時30分 NaN 第4四半期 輸入物価 - - 3.0%
192+# 5 21時00分 NaN 12月貿易収支 (USD) 11.57億USD - -0.96億USD
193+
194+url = 'https://mxp1.monex.co.jp/pc/servlet/ITS/report/EconomyIndexCalendar?attrSrcKey=2f4db36c1d2187b776'
195+data = pd.read_html(url, header=0)
--- /dev/null
+++ b/investigation_study/mt5_api_deal_order_test.py
@@ -0,0 +1,143 @@
1+import MetaTrader5 as mt5
2+mt5.initialize()
3+
4+symbol = 'USDJPY'
5+volume = 0.1
6+loss_cut = 0.5
7+profit_taking = 1.0
8+
9+tick = mt5.symbol_info_tick(symbol)
10+spread = round((tick.ask - tick.bid), 3)
11+
12+buy_price = tick.ask
13+buy_sl = round((buy_price - (loss_cut + spread)), 3)
14+buy_tp = round((buy_price + spread + profit_taking), 3)
15+
16+request = {
17+ "action": mt5.TRADE_ACTION_DEAL,
18+ "symbol": symbol,
19+ "volume": volume,
20+ "type": mt5.ORDER_TYPE_BUY,
21+ "price": buy_price,
22+ "sl": buy_sl,
23+ "tp": buy_tp,
24+ "deviation": 10,
25+ "magic": 1,
26+ "comment": "python script open.",
27+ "type_time": mt5.ORDER_TIME_GTC,
28+ "type_filling": mt5.ORDER_FILLING_IOC,
29+}
30+# 取引リクエストを送信する
31+result = mt5.order_send(request)
32+
33+# 公式ドキュメントと実際の動作が異なる
34+# おそらく公式ドキュメントがメンテナンス不足
35+# https://www.mql5.com/ja/docs/constants/structures/mqltraderequest
36+
37+# Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32
38+# Type "help", "copyright", "credits" or "license" for more information.
39+# >>> import MetaTrader5 as mt5
40+# >>> mt5.initialize()
41+# True
42+# >>>
43+# >>> symbol = 'USDJPY'
44+# >>> volume = 0.1
45+# >>> loss_cut = 0.5
46+# >>> profit_taking = 1.0
47+# >>> tick = mt5.symbol_info_tick(symbol)
48+# >>> spread = round((tick.ask - tick.bid), 3)
49+# >>>
50+# >>> buy_price = tick.ask
51+# >>> buy_sl = round((buy_price - (loss_cut + spread)), 3)
52+# >>> buy_tp = round((buy_price + spread + profit_taking), 3)
53+# >>>
54+# >>> request = {
55+# ... "action": mt5.TRADE_ACTION_DEAL,
56+# ... "symbol": symbol,
57+# ... "volume": volume,
58+# ... "type": mt5.ORDER_TYPE_BUY,
59+# ... "price": buy_price,
60+# ... "deviation": 10,
61+# ... "magic": 1,
62+# ... "comment": "python script open."
63+# ... }
64+# >>> # 取引リクエストを送信する
65+# >>> result = mt5.order_send(request)
66+# >>> result
67+# OrderSendResult(retcode=10030, deal=0, order=0, volume=0.0, price=0.0, bid=0.0, ask=0.0, comment='Unsupported filling mode', request_id=0, retcode_external=0, request=TradeRequest(action=1, magic=1, order=0, symbol='USDJPY', volume=0.1, price=130.49, stoplimit=0.0, sl=0.0, tp=0.0, deviation=10, type=0, type_filling=0, type_time=0, expiration=0, comment='python script open.', position=0, position_by=0))
68+# >>> tick = mt5.symbol_info_tick(symbol)
69+# >>> spread = round((tick.ask - tick.bid), 3)
70+# >>>
71+# >>> buy_price = tick.ask
72+# >>> buy_sl = round((buy_price - (loss_cut + spread)), 3)
73+# >>> buy_tp = round((buy_price + spread + profit_taking), 3)
74+# >>>
75+# >>> request = {
76+# ... "action": mt5.TRADE_ACTION_DEAL,
77+# ... "symbol": symbol,
78+# ... "volume": volume,
79+# ... "type": mt5.ORDER_TYPE_BUY,
80+# ... "price": buy_price,
81+# ... "sl": buy_sl,
82+# ... "tp": buy_tp,
83+# ... "deviation": 10,
84+# ... "magic": 1,
85+# ... "comment": "python script open.",
86+# ... "type_time": mt5.ORDER_TIME_GTC,
87+# ... "type_filling": mt5.ORDER_FILLING_RETURN,
88+# ... }
89+# >>> # 取引リクエストを送信する
90+# >>> result = mt5.order_send(request)
91+# >>> result
92+# OrderSendResult(retcode=10030, deal=0, order=0, volume=0.0, price=0.0, bid=0.0, ask=0.0, comment='Unsupported filling mode', request_id=0, retcode_external=0, request=TradeRequest(action=1, magic=1, order=0, symbol='USDJPY', volume=0.1, price=130.475, stoplimit=0.0, sl=129.951, tp=131.499, deviation=10, type=0, type_filling=2, type_time=0, expiration=0, comment='python script open.', position=0, position_by=0))
93+# >>> tick = mt5.symbol_info_tick(symbol)
94+# >>> spread = round((tick.ask - tick.bid), 3)
95+# >>>
96+# >>> buy_price = tick.ask
97+# >>> buy_sl = round((buy_price - (loss_cut + spread)), 3)
98+# >>> buy_tp = round((buy_price + spread + profit_taking), 3)
99+# >>>
100+# >>> request = {
101+# ... "action": mt5.TRADE_ACTION_DEAL,
102+# ... "symbol": symbol,
103+# ... "volume": volume,
104+# ... "type": mt5.ORDER_TYPE_BUY,
105+# ... "price": buy_price,
106+# ... "sl": buy_sl,
107+# ... "tp": buy_tp,
108+# ... "deviation": 10,
109+# ... "magic": 1,
110+# ... "comment": "python script open.",
111+# ... "type_time": mt5.ORDER_TIME_GTC,
112+# ... "type_filling": mt5.ORDER_FILLING_FOK,
113+# ... }
114+# >>> # 取引リクエストを送信する
115+# >>> result = mt5.order_send(request)
116+# >>> result
117+# OrderSendResult(retcode=10030, deal=0, order=0, volume=0.0, price=0.0, bid=0.0, ask=0.0, comment='Unsupported filling mode', request_id=0, retcode_external=0, request=TradeRequest(action=1, magic=1, order=0, symbol='USDJPY', volume=0.1, price=130.477, stoplimit=0.0, sl=129.952, tp=131.502, deviation=10, type=0, type_filling=0, type_time=0, expiration=0, comment='python script open.', position=0, position_by=0))
118+# >>> tick = mt5.symbol_info_tick(symbol)
119+# >>> spread = round((tick.ask - tick.bid), 3)
120+# >>>
121+# >>> buy_price = tick.ask
122+# >>> buy_sl = round((buy_price - (loss_cut + spread)), 3)
123+# >>> buy_tp = round((buy_price + spread + profit_taking), 3)
124+# >>>
125+# >>> request = {
126+# ... "action": mt5.TRADE_ACTION_DEAL,
127+# ... "symbol": symbol,
128+# ... "volume": volume,
129+# ... "type": mt5.ORDER_TYPE_BUY,
130+# ... "price": buy_price,
131+# ... "sl": buy_sl,
132+# ... "tp": buy_tp,
133+# ... "deviation": 10,
134+# ... "magic": 1,
135+# ... "comment": "python script open.",
136+# ... "type_time": mt5.ORDER_TIME_GTC,
137+# ... "type_filling": mt5.ORDER_FILLING_IOC,
138+# ... }
139+# >>> # 取引リクエストを送信する
140+# >>> result = mt5.order_send(request)
141+# >>> result
142+# OrderSendResult(retcode=10009, deal=0, order=12720437, volume=0.1, price=0.0, bid=0.0, ask=0.0, comment='Request executed', request_id=1, retcode_external=0, request=TradeRequest(action=1, magic=1, order=0, symbol='USDJPY', volume=0.1, price=130.478, stoplimit=0.0, sl=129.952, tp=131.504, deviation=10, type=0, type_filling=1, type_time=0, expiration=0, comment='python script open.', position=0, position_by=0))
143+# >>>
--- a/investigation_study/mt5_api_rate_test.py
+++ b/investigation_study/mt5_api_rate_test.py
@@ -1,5 +1,6 @@
11 import MetaTrader5 as mt5
22 import talib as ta
3+import numpy as np
34
45 mt5.initialize()
56
@@ -16,32 +17,132 @@ n2 = 53
1617 ns = 15
1718 # MACDテクニカル分析に必要なデータ件数
1819 # count = ns + n2
19-count = 68
20+count = 68 * 2
2021
2122 rates = mt5.copy_rates_from_pos(cp, mt5.TIMEFRAME_M1, 0, count)
2223
2324 print(rates)
24-# array([(1674611580, 130.221, 130.223, 130.206, 130.223, 44, 4, 0),
25-# (1674611640, 130.223, 130.235, 130.215, 130.219, 53, 5, 0),
26-# (1674611700, 130.218, 130.244, 130.207, 130.213, 74, 3, 0),
27-# (1674611760, 130.214, 130.228, 130.203, 130.204, 43, 4, 0),
28-# (1674611820, 130.205, 130.241, 130.204, 130.241, 32, 5, 0),
25+# array([(1675201440, 130.104, 130.109, 130.098, 130.101, 47, 3, 0),
26+# (1675201500, 130.1 , 130.1 , 130.08 , 130.083, 23, 4, 0),
27+# (1675201560, 130.083, 130.09 , 130.076, 130.09 , 40, 3, 0),
28+# (1675201620, 130.09 , 130.102, 130.082, 130.095, 51, 3, 0),
29+# (1675201680, 130.095, 130.108, 130.094, 130.107, 38, 3, 0),
2930 # ...
30-# (1674615360, 130.335, 130.345, 130.317, 130.341, 239, 3, 0),
31-# (1674615420, 130.34 , 130.362, 130.33 , 130.356, 163, 4, 0),
32-# (1674615480, 130.356, 130.39 , 130.354, 130.384, 93, 3, 0),
33-# (1674615540, 130.384, 130.384, 130.316, 130.329, 114, 3, 0),
34-# (1674615600, 130.33 , 130.345, 130.318, 130.341, 92, 4, 0)],
35-# dtype=[('time', '<i8'), ('open', '<f8'), ('high', '<f8'), ('low', '<f8'), ('close', '<f8'), ('tick_volume', '<u8'), ('spread', '<i4'), ('real_volume', '<u8')])
36-
37-print(rates['close'])
38-# array([130.223, 130.219, 130.213, 130.204, 130.241, 130.231, 130.211,
39-# 130.255, 130.266, 130.264, 130.253, 130.248, 130.279, 130.29 ,
40-# 130.347, 130.357, 130.355, 130.363, 130.372, 130.383, 130.385,
41-# 130.403, 130.381, 130.37 , 130.405, 130.418, 130.414, 130.405,
42-# 130.396, 130.369, 130.366, 130.377, 130.377, 130.349, 130.353,
43-# 130.355, 130.363, 130.381, 130.402, 130.441, 130.377, 130.411,
44-# 130.405, 130.383, 130.383, 130.369, 130.388, 130.385, 130.392,
45-# 130.38 , 130.394, 130.4 , 130.382, 130.364, 130.406, 130.401,
46-# 130.419, 130.425, 130.392, 130.356, 130.366, 130.326, 130.334,
47-# 130.341, 130.356, 130.384, 130.329, 130.341])
\ No newline at end of file
31+ # (1675209300, 130.078, 130.097, 130.078, 130.093, 50, 22, 0),
32+ # (1675209360, 130.088, 130.1 , 130.088, 130.094, 27, 24, 0),
33+ # (1675209420, 130.094, 130.094, 130.084, 130.087, 22, 26, 0),
34+ # (1675209480, 130.087, 130.097, 130.081, 130.088, 87, 26, 0),
35+ # (1675209540, 130.09 , 130.101, 130.089, 130.095, 7, 21, 0)],
36+ # dtype=[('time', '<i8'), ('open', '<f8'), ('high', '<f8'), ('low', '<f8'), ('close', '<f8'), ('tick_volume', '<u8'), ('spread', '<i4'), ('real_volume', '<u8')])
37+
38+closes = rates['close']
39+print(closes)
40+# array([130.101, 130.083, 130.09 , 130.095, 130.107, 130.117, 130.116,
41+# 130.124, 130.124, 130.127, 130.136, 130.155, 130.174, 130.191,
42+# 130.198, 130.166, 130.156, 130.161, 130.183, 130.172, 130.169,
43+# 130.143, 130.142, 130.143, 130.137, 130.134, 130.141, 130.135,
44+# 130.152, 130.144, 130.151, 130.146, 130.161, 130.169, 130.169,
45+# 130.18 , 130.168, 130.184, 130.187, 130.203, 130.206, 130.202,
46+# 130.191, 130.185, 130.191, 130.194, 130.192, 130.199, 130.206,
47+# 130.219, 130.22 , 130.209, 130.204, 130.204, 130.2 , 130.213,
48+# 130.209, 130.208, 130.217, 130.201, 130.205, 130.187, 130.182,
49+# 130.187, 130.192, 130.187, 130.19 , 130.174, 130.184, 130.176,
50+# 130.167, 130.168, 130.134, 130.138, 130.165, 130.123, 130.163,
51+# 130.17 , 130.157, 130.135, 130.173, 130.152, 130.134, 130.132,
52+# 130.158, 130.145, 130.149, 130.151, 130.141, 130.132, 130.147,
53+# 130.129, 130.121, 130.137, 130.134, 130.134, 130.131, 130.136,
54+# 130.133, 130.137, 130.138, 130.135, 130.12 , 130.123, 130.127,
55+# 130.121, 130.121, 130.097, 130.085, 130.086, 130.09 , 130.086,
56+# 130.088, 130.09 , 130.092, 130.091, 130.095, 130.094, 130.09 ,
57+# 130.092, 130.086, 130.093, 130.089, 130.089, 130.094, 130.091,
58+# 130.082, 130.083, 130.081, 130.079, 130.078, 130.093, 130.094,
59+# 130.087, 130.088, 130.095])
60+
61+macd, macdsignal, _ = ta.MACD(
62+ closes,
63+ fastperiod=n1,
64+ slowperiod=n2,
65+ signalperiod=ns
66+)
67+
68+print(macd)
69+# array([ nan, nan, nan, nan, nan,
70+# nan, nan, nan, nan, nan,
71+# nan, nan, nan, nan, nan,
72+# nan, nan, nan, nan, nan,
73+# nan, nan, nan, nan, nan,
74+# nan, nan, nan, nan, nan,
75+# nan, nan, nan, nan, nan,
76+# nan, nan, nan, nan, nan,
77+# nan, nan, nan, nan, nan,
78+# nan, nan, nan, nan, nan,
79+# nan, nan, nan, nan, nan,
80+# nan, nan, nan, nan, nan,
81+# nan, nan, nan, nan, nan,
82+# nan, 0.01422795, 0.01317656, 0.01251956, 0.01164311,
83+# 0.01054024, 0.00955647, 0.00756448, 0.00588696, 0.00523 ,
84+# 0.00328665, 0.00281308, 0.00260482, 0.00199638, 0.00074335,
85+# 0.00083133, 0.00023758, -0.00087006, -0.00192475, -0.00203528,
86+# -0.00254425, -0.00286635, -0.00308395, -0.00359045, -0.00432274,
87+# -0.00448931, -0.00520189, -0.00608289, -0.00634637, -0.00666216,
88+# -0.00692827, -0.00724494, -0.0073507 , -0.00752253, -0.00752966,
89+# -0.00748489, -0.00752141, -0.00801387, -0.00833914, -0.00848174,
90+# -0.0087795 , -0.00902402, -0.00998649, -0.01120702, -0.01224074,
91+# -0.01300854, -0.0137914 , -0.01439419, -0.014834 , -0.01512656,
92+# -0.01538215, -0.0154443 , -0.0154925 , -0.01562385, -0.01563785,
93+# -0.01580203, -0.01568536, -0.01566841, -0.01561319, -0.01536416,
94+# -0.01519744, -0.0152965 , -0.01531431, -0.01535502, -0.01541615,
95+# -0.01546351, -0.01498755, -0.01449061, -0.01423157, -0.01393105,
96+# -0.01340253])
97+
98+print(macdsignal)
99+
100+macd[-1]
101+# -0.013402525407315125
102+
103+# 端数処理をnp.aroundで行った場合
104+np.around(macd[-1])
105+# -0.0
106+
107+np.around(macd[-1], 4)
108+# -0.0134
109+
110+# 端数処理をnp.format_float_positionalで行った場合
111+np.float64(np.format_float_positional(macd[-1], precision=4))
112+# -0.0134
113+
114+np.around(macd, 4)
115+# array([ nan, nan, nan, nan, nan, nan, nan,
116+# nan, nan, nan, nan, nan, nan, nan,
117+# nan, nan, nan, nan, nan, nan, nan,
118+# nan, nan, nan, nan, nan, nan, nan,
119+# nan, nan, nan, nan, nan, nan, nan,
120+# nan, nan, nan, nan, nan, nan, nan,
121+# nan, nan, nan, nan, nan, nan, nan,
122+# nan, nan, nan, nan, nan, nan, nan,
123+# nan, nan, nan, nan, nan, nan, nan,
124+# nan, nan, nan, 0.0142, 0.0132, 0.0125, 0.0116,
125+# 0.0105, 0.0096, 0.0076, 0.0059, 0.0052, 0.0033, 0.0028,
126+# 0.0026, 0.002 , 0.0007, 0.0008, 0.0002, -0.0009, -0.0019,
127+# -0.002 , -0.0025, -0.0029, -0.0031, -0.0036, -0.0043, -0.0045,
128+# -0.0052, -0.0061, -0.0063, -0.0067, -0.0069, -0.0072, -0.0074,
129+# -0.0075, -0.0075, -0.0075, -0.0075, -0.008 , -0.0083, -0.0085,
130+# -0.0088, -0.009 , -0.01 , -0.0112, -0.0122, -0.013 , -0.0138,
131+# -0.0144, -0.0148, -0.0151, -0.0154, -0.0154, -0.0155, -0.0156,
132+# -0.0156, -0.0158, -0.0157, -0.0157, -0.0156, -0.0154, -0.0152,
133+# -0.0153, -0.0153, -0.0154, -0.0154, -0.0155, -0.015 , -0.0145,
134+# -0.0142, -0.0139, -0.0134])
135+
136+# 配列処理には向かない
137+np.float64(np.format_float_positional(macd, precision=4))
138+# Traceback (most recent call last):
139+# File "<stdin>", line 1, in <module>
140+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\numpy\core\arrayprint.py", line 1216, in format_float_positional
141+# return dragon4_positional(x, precision=precision, unique=unique,
142+# TypeError: only size-1 arrays can be converted to Python scalars
143+np.format_float_positional(macd, precision=4)
144+# Traceback (most recent call last):
145+# File "<stdin>", line 1, in <module>
146+# File "C:\Users\user1\Documents\workspace_fx\mt5-operator\venv\lib\site-packages\numpy\core\arrayprint.py", line 1216, in format_float_positional
147+# return dragon4_positional(x, precision=precision, unique=unique,
148+# TypeError: only size-1 arrays can be converted to Python scalars
--- a/src/config/setting.ini
+++ b/src/config/setting.ini
@@ -36,7 +36,7 @@ Allowablespread = 0.01
3636 # 1銭は0.01円
3737 OpenMergin = 0.007
3838 # 利益確定(円)
39-ProfitTaking = 1.0
39+ProfitTaking = 0.5
4040 # 損切(円)
4141 LossCut = 0.5
4242
--- a/src/exchange_rate_info.py
+++ b/src/exchange_rate_info.py
@@ -156,7 +156,8 @@ class ExchangeRateInfo():
156156 s = Setting()
157157
158158 # MACDテクニカル分析に必要なデータ件数
159- count = self.__n2 + self.__ns
159+ # mt5アプリの表示と数値の乖離があるので件数を増やしてみる
160+ count = (self.__n2 + self.__ns) * 3
160161
161162 # 終値履歴を取得
162163 closes = self.__get_history_closes(
@@ -171,6 +172,11 @@ class ExchangeRateInfo():
171172 slowperiod=self.__n2,
172173 signalperiod=self.__ns
173174 )
175+
176+ # MACDの結果を端数処理(少数点以下4)
177+ macd = np.around(macd, 4)
178+ macdsignal = np.around(macdsignal, 4)
179+
174180 # 前回の暫定判断の答え合わせ
175181 conf_macd = macd[-1]
176182 conf_macdsig = macdsignal[-1]
@@ -180,21 +186,26 @@ class ExchangeRateInfo():
180186 logger.debug(msg)
181187
182188 # 最新bidを暫定終わり値としてclosesに追加
183- closes = np.append(closes, self.__get_latest_bid())
189+ # closes = np.append(closes, self.__get_latest_bid())
184190
185191 # MACDを算出
186- macd, macdsignal, _ = ta.MACD(
187- closes,
188- fastperiod=self.__n1,
189- slowperiod=self.__n2,
190- signalperiod=self.__ns
191- )
192- asum_macd = macd[-1]
193- asum_macdsig = macdsignal[-1]
194- msg = (
195- f'Assumption MACD: {asum_macd}, Signal: {asum_macdsig} .'
196- )
197- logger.info(msg)
192+ # macd, macdsignal, _ = ta.MACD(
193+ # closes,
194+ # fastperiod=self.__n1,
195+ # slowperiod=self.__n2,
196+ # signalperiod=self.__ns
197+ # )
198+
199+ # MACDの結果を端数処理(少数点以下4)
200+ # macd = np.around(macd, 4)
201+ # macdsignal = np.around(macdsignal, 4)
202+
203+ # asum_macd = macd[-1]
204+ # asum_macdsig = macdsignal[-1]
205+ # msg = (
206+ # f'Assumption MACD: {asum_macd}, Signal: {asum_macdsig} .'
207+ # )
208+ # logger.debug(msg)
198209
199210 # 指標判定
200211 if self.__crossover(macd, macdsignal):
@@ -217,7 +228,7 @@ class ExchangeRateInfo():
217228 # いずれにも該当しない
218229 s.technical_indicator = DEF.TECHNICAL_UNCHANGED
219230 msg = 'Technical Indicator: Unchanged.'
220- logger.debug(msg)
231+ logger.info(msg)
221232
222233 except Exception as e:
223234 logger.error(e)
--- a/src/main.py
+++ b/src/main.py
@@ -64,11 +64,11 @@ def main():
6464 # EventMngは経済指標の対応を実装する
6565 # PositionMngは長期ポジションに対応する
6666 logger.debug("set schedule.")
67- schedule.every().minute.at(":00").do(tm.execute)
68- schedule.every().minute.at(":40").do(em.execute)
69- schedule.every().minute.at(":45").do(rt.execute)
70- schedule.every().minute.at(":50").do(pm.execute)
71- schedule.every().minute.at(":55").do(ac.execute)
67+ schedule.every().minute.at(":00").do(em.execute)
68+ schedule.every().minute.at(":02").do(pm.execute)
69+ schedule.every().minute.at(":04").do(ac.execute)
70+ schedule.every().minute.at(":06").do(rt.execute)
71+ schedule.every().minute.at(":08").do(tm.execute)
7272
7373 logger.debug("start loop.")
7474 while True:
--- a/src/position_mng.py
+++ b/src/position_mng.py
@@ -60,17 +60,20 @@ class PositionMng():
6060 # テクニカル指標から逆トレンドの
6161 # 保有ポジションはすべて解消する
6262 # ポジション解消注文を出す
63- for position in positions:
64- if position.type == position_to_be_canceled:
65- result = self.__close_position(
66- position.ticket,
67- position.volume,
68- position.type
69- )
70- if result:
71- logger.info(
72- f'position {position.ticket} is close.'
63+ if position_to_be_canceled != -1:
64+ for position in positions:
65+ if position.type == position_to_be_canceled:
66+ logger.debug('Trend is turning point.')
67+ result = self.__close_position(
68+ position.ticket,
69+ position.volume,
70+ position.type
7371 )
72+ if result:
73+ logger.info(
74+ f'position {position.ticket} is close.'
75+ )
76+
7477 except Exception as e:
7578 logger.error(e)
7679 raise
--- a/src/trade_mng.py
+++ b/src/trade_mng.py
@@ -146,8 +146,8 @@ class TradeMng:
146146 "deviation": 10,
147147 "magic": magic,
148148 "comment": "python script open.",
149- "type_time": mt5.ORDER_TIME_DAY,
150- "type_filling": mt5.ORDER_FILLING_RETURN,
149+ "type_time": mt5.ORDER_TIME_GTC,
150+ "type_filling": mt5.ORDER_FILLING_IOC,
151151 }
152152 # 取引リクエストを送信する
153153 result = mt5.order_send(request)
@@ -354,7 +354,7 @@ class TradeMng:
354354 )
355355 logger.debug(sell_result)
356356 else:
357- pass
357+ logger.info('Not the right time to order.')
358358
359359 except Exception as e:
360360 logger.error(e)