简体   繁体   English

Python MetaTrader5 指标

[英]Python MetaTrader5 indicators

I'm using Metatrader5 module for python and this is my code我正在为 python 使用 Metatrader5 模块,这是我的代码

''' #python ''' #Python

from datetime import datetime
import MetaTrader5 as mt5

# display data on the MetaTrader 5 package
print("MetaTrader5 package author: ", mt5.__author__)
print("MetaTrader5 package version: ", mt5.__version__)

# import the 'pandas' module for displaying data obtained in the tabular form
import pandas as pd

pd.set_option('display.max_columns', 500)  # number of columns to be displayed
pd.set_option('display.width', 1500)  # max table width to display
# import pytz module for working with time zone
import pytz

# establish connection to MetaTrader 5 terminal
if not mt5.initialize():
print("initialize() failed")
mt5.shutdown()

# set time zone to UTC
timezone = pytz.timezone("Etc/UTC")
# create 'datetime' object in UTC time zone to avoid the implementation of a local time zone offset
utc_from = datetime(2020, 1, 10, tzinfo=timezone)
# get 10 EURUSD H4 bars starting from 01.10.2020 in UTC time zone
rates = mt5.copy_rates_from("EURUSD", mt5.TIMEFRAME_H4, utc_from, 10)

# shut down connection to the MetaTrader 5 terminal
mt5.shutdown()
# display each element of obtained data in a new line
print("Display obtained data 'as is'")
for rate in rates:
print(rate)
# create DataFrame out of the obtained data
rates_frame = pd.DataFrame(rates)
# convert time in seconds into the datetime format
rates_frame['time'] = pd.to_datetime(rates_frame['time'], unit='s')

# display data
print("\nDisplay dataframe with data")
print(rates_frame)  

''' '''

My question is s there any easy way to calculate stock indicators like RSI and MFI and other indicators using this module?我的问题是有没有什么简单的方法可以使用此模块计算 RSI 和 MFI 等股票指标以及其他指标?

No. Its possible if using other modules though.不。如果使用其他模块,它可能会。

Here is a method using another that could achieve it: https://www.mql5.com/en/articles/5691这是一种使用另一种方法可以实现的方法: https : //www.mql5.com/en/articles/5691

Alternatively, you can pull the data from MT5 and throw it in TA-lib for analysis.或者,您可以从 MT5 中提取数据并将其放入 TA-lib 进行分析。 TA-lib consumes the data and provides values for the indicators outside MT5. TA-lib 使用数据并为 MT5 之外的指标提供值。

Check out TA-lib: https://mrjbq7.github.io/ta-lib/查看 TA-lib: https : //mrjbq7.github.io/ta-lib/

Since your data will be in a pandas df, I would check out pandas-ta, https://pypi.org/project/pandas-ta , all technical indicators.由于您的数据将在 pandas df 中,因此我会查看 pandas-ta、 https://pypi.org/project/pandas-ta ,所有技术指标。 Also, thats a lot of code to pull your data, this is what I use;另外,那是很多代码来提取您的数据,这就是我使用的;

import MetaTrader5 as mt
import pandas as pd
from datetime import datetime

mt.initialize()

df = pd.DataFrame( mt.copy_rates_range( '@MNQ', #micro nasd100
                                        mt.TIMEFRAME_D1, 
                                        datetime( 2022, 1, 1 ), 
                                        datetime.now() ) )

# manipulate as you please

mt.shutdown()

and i didnt like the GMT+2 timezone used by metatrader at first but Ive found its easier to get used to it as the date change is timed to the daily futures market open at 5pm central, which in GMT+2 is day+1 00:00.我一开始不喜欢 metatrader 使用的 GMT+2 时区,但我发现它更容易习惯,因为日期更改是在中央时间下午 5 点开放的每日期货市场上进行的,在 GMT+2 中是 day+1 00 :00。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM