Revision | fe7ef08ec9971cc997d69d12b86093c81c888b5b (tree) |
---|---|
Time | 2023-02-03 10:51:33 |
Author | kazuhiro_kondow <simauma.circus@gmai...> |
Commiter | kazuhiro_kondow |
MACDインジケータの判定バグを修正
@@ -21,6 +21,9 @@ count = 68 * 2 | ||
21 | 21 | |
22 | 22 | rates = mt5.copy_rates_from_pos(cp, mt5.TIMEFRAME_M1, 0, count) |
23 | 23 | |
24 | +type(rates) | |
25 | +# <class 'numpy.ndarray'> | |
26 | + | |
24 | 27 | print(rates) |
25 | 28 | # array([(1675201440, 130.104, 130.109, 130.098, 130.101, 47, 3, 0), |
26 | 29 | # (1675201500, 130.1 , 130.1 , 130.08 , 130.083, 23, 4, 0), |
@@ -36,7 +36,7 @@ Allowablespread = 0.01 | ||
36 | 36 | # 1銭は0.01円 |
37 | 37 | OpenMergin = 0.007 |
38 | 38 | # 利益確定(円) |
39 | -ProfitTaking = 0.5 | |
39 | +ProfitTaking = 1.0 | |
40 | 40 | # 損切(円) |
41 | 41 | LossCut = 0.5 |
42 | 42 |
@@ -63,7 +63,6 @@ class ExchangeRateInfo(): | ||
63 | 63 | 0, |
64 | 64 | count |
65 | 65 | ) |
66 | - | |
67 | 66 | return rates['close'] |
68 | 67 | |
69 | 68 | def __crossover(self, series1: np.ndarray, series2: np.ndarray) -> bool: |
@@ -157,7 +156,7 @@ class ExchangeRateInfo(): | ||
157 | 156 | |
158 | 157 | # MACDテクニカル分析に必要なデータ件数 |
159 | 158 | # mt5アプリの表示と数値の乖離があるので件数を増やしてみる |
160 | - count = (self.__n2 + self.__ns) * 3 | |
159 | + count = (self.__n2 + self.__ns) * 20 | |
161 | 160 | |
162 | 161 | # 終値履歴を取得 |
163 | 162 | closes = self.__get_history_closes( |
@@ -173,17 +172,16 @@ class ExchangeRateInfo(): | ||
173 | 172 | signalperiod=self.__ns |
174 | 173 | ) |
175 | 174 | |
176 | - # MACDの結果を端数処理(少数点以下4) | |
177 | - macd = np.around(macd, 4) | |
178 | - macdsignal = np.around(macdsignal, 4) | |
179 | - | |
180 | - # 前回の暫定判断の答え合わせ | |
181 | - conf_macd = macd[-1] | |
182 | - conf_macdsig = macdsignal[-1] | |
183 | - msg = ( | |
184 | - f'Confirm MACD: {conf_macd}, Signal: {conf_macdsig} .' | |
185 | - ) | |
186 | - logger.debug(msg) | |
175 | + # MACDの結果を端数処理(少数点以下5) | |
176 | + macd = np.around(macd, 5) | |
177 | + macdsignal = np.around(macdsignal, 5) | |
178 | + | |
179 | + # for debug | |
180 | + for i in range(-4, 0, 1): | |
181 | + msg = ( | |
182 | + f'num[{i}]: MACD: {macd[i]}, MACDSignal: {macdsignal[i]}' | |
183 | + ) | |
184 | + logger.debug(msg) | |
187 | 185 | |
188 | 186 | # 最新bidを暫定終わり値としてclosesに追加 |
189 | 187 | # closes = np.append(closes, self.__get_latest_bid()) |
@@ -208,22 +206,30 @@ class ExchangeRateInfo(): | ||
208 | 206 | # logger.debug(msg) |
209 | 207 | |
210 | 208 | # 指標判定 |
211 | - if self.__crossover(macd, macdsignal): | |
209 | + if self.__crossover(macd, macdsignal) and macd[-1] < 0.0: | |
212 | 210 | # GoldenCross 上昇転換サイン |
213 | 211 | s.technical_indicator = DEF.TECHNICAL_GOLDEN_CROSS |
214 | 212 | msg = 'Technical Indicator: GoldenCross.' |
215 | - elif self.__crossover(macdsignal, macd): | |
213 | + elif self.__crossover(macdsignal, macd) and macd[-1] > 0.0: | |
216 | 214 | # DeadCross 降下転換サイン |
217 | 215 | s.technical_indicator = DEF.TECHNICAL_DEAD_CROSS |
218 | 216 | msg = 'Technical Indicator: DeadCross.' |
219 | - elif macd[-1] > macdsignal[-1]: | |
220 | - # 上昇トレンド | |
217 | + elif macd[-1] > macdsignal[-1] and macd[-1] < 0.0: | |
218 | + # 弱い上昇トレンド | |
219 | + s.technical_indicator = DEF.TECHNICAL_UPTREND | |
220 | + msg = 'Technical Indicator: Weak Uptrend.' | |
221 | + elif macd[-1] > macdsignal[-1] and macd[-1] > 0.0: | |
222 | + # 強い上昇トレンド | |
221 | 223 | s.technical_indicator = DEF.TECHNICAL_UPTREND |
222 | - msg = 'Technical Indicator: Up Trand.' | |
223 | - elif macdsignal[-1] > macd[-1]: | |
224 | - # 降下トレンド | |
224 | + msg = 'Technical Indicator: Strong Uptrend.' | |
225 | + elif macd[-1] < macdsignal[-1] and macd[-1] > 0.0: | |
226 | + # 弱い降下トレンド | |
227 | + s.technical_indicator = DEF.TECHNICAL_DOWNTREND | |
228 | + msg = 'Technical Indicator: Weak Downtrand.' | |
229 | + elif macd[-1] < macdsignal[-1] and macd[-1] < 0.0: | |
230 | + # 強い降下トレンド | |
225 | 231 | s.technical_indicator = DEF.TECHNICAL_DOWNTREND |
226 | - msg = 'Technical Indicator: Down Trand.' | |
232 | + msg = 'Technical Indicator: Strong Downtrand.' | |
227 | 233 | else: |
228 | 234 | # いずれにも該当しない |
229 | 235 | s.technical_indicator = DEF.TECHNICAL_UNCHANGED |
@@ -65,9 +65,9 @@ def main(): | ||
65 | 65 | # PositionMngは長期ポジションに対応する |
66 | 66 | logger.debug("set schedule.") |
67 | 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) | |
68 | + schedule.every().minute.at(":02").do(rt.execute) | |
69 | + schedule.every().minute.at(":04").do(pm.execute) | |
70 | + schedule.every().minute.at(":06").do(ac.execute) | |
71 | 71 | schedule.every().minute.at(":08").do(tm.execute) |
72 | 72 | |
73 | 73 | logger.debug("start loop.") |