MetaTrader 5 Python用户组 - 如何在Metatrader中使用Python - 页 61

 
Vladimir Perervenko :

安装失败

Win10,Py3.6.10和WinPy3.7.7。

再试一次吧。我不得不对其进行重构,以便在Python < 3.8下工作。

 
nicholi shen:

再试一次吧。我不得不对其进行重构,以便在Python < 3.8下工作。

好的

Successfully built pymt5adapter
Installing collected packages: pymt5adapter
Successfully installed pymt5adapter-0.2.1
----- Установка "pymt5adapter" выполнена. -

该版本有什么新内容?

祝好运

 
Vladimir Perervenko:

好的

该版本有什么新内容?

祝好运

calendar_eventshttps://github.com/nicholishen/pymt5adapter/blob/master/pymt5adapter/calendar.py

from datetime import datetime
from datetime import timedelta

import pymt5adapter as mt5
from pymt5adapter.calendar import calendar_events
from pymt5adapter.calendar import Currency
from pymt5adapter.calendar import Importance


def forex_symbol(s):
    modes = [mt5.SYMBOL_CALC_MODE_FOREX, mt5.SYMBOL_CALC_MODE_FOREX_NO_LEVERAGE]
    return s.trade_calc_mode in modes


def main():
    symbol = mt5.symbols_get(function=forex_symbol)[0]
    one_week = timedelta(weeks=1)
    now = datetime.now()
    default_one_week_ahead_all_events = calendar_events()
    filtered_by_callback = calendar_events(function=lambda e: 'fed' in e['event_name'].lower())
    filtered_by_flags = calendar_events(importance=Importance.MEDIUM | Importance.HIGH,
                                        currencies=Currency.USD | Currency.JPY)
    filtered_by_strings = calendar_events(importance='medium high',
                                          currencies='usdjpy')
    filtered_by_iterables = calendar_events(importance=('medium', ' high'),
                                            currencies=('usd', 'jpy'))
    filtered_by_specific_times = calendar_events(time_from=now, time_to=now + one_week)
    filtered_by_timedeltas = calendar_events(time_from=(-one_week), time_to=one_week)
    filtered_by_timedelta_lookback = calendar_events(-one_week)
    calendar_events_in_russian = calendar_events(language='ru')

    employment_events_next_month = calendar_events(
        currencies=Currency.USD,
        importance=Importance.HIGH
        function=lambda e: 'employment' in (name:=e['event_name'].lower()) or 'payroll' in name
    )

    next_event = employment_events_next_month[0]

    for k, v in next_event.items():
        print(k, v)


if __name__ == '__main__':
    with mt5.connected():
        main()
nicholishen/pymt5adapter
nicholishen/pymt5adapter
  • nicholishen
  • github.com
A drop-in pythonic adapter for the MetaTrader5 package to enhance usability. - nicholishen/pymt5adapter
 

下午好!我如何使用TRADE_ACTION_CLOSE_BY ????或谁以及如何关闭所有未结头寸

 
9805244:

下午好!如何使用TRADE_ACTION_CLOSE_BY?或谁和如何关闭所有未结头寸

使用Python?

 

这一行是VS2019(WinPy3.7.7)所规定的(下划线)。

"意外的标记'函数'"

意外的标记":"

意外的令牌'='。

无效的语法

employment_events_next_month = calendar_events(
        currencies=Currency.USD,
        importance=Importance.HIGH
        
function=lambda e: 'employment' in (name
:=e['event_name'].lower()) 
or 'payroll' in name
    )
 
Vladimir Perervenko:

这一行是VS2019(WinPy3.7.7)所规定的(下划线)。

"意外的标记'函数'"

意外的标记":"

意外的令牌'='。

无效的语法

这就是python >=3.8的新赋值表达式,它们非常棒。我不得不从库中删除所有这些东西,以使它与你的版本一起工作,但我认为你可以重构那个示例脚本,使它发挥作用。你应该考虑将你的Python解释器升级到最新版本。 :)

https://www.python.org/dev/peps/pep-0572/

PEP 572 -- Assignment Expressions
PEP 572 -- Assignment Expressions
  • www.python.org
PEP: Title: Author: Status: Type: Created: Python-Version: Post-History: Resolution:
 
nicholi shen:

这就是python >=3.8的新赋值表达式,它们非常棒。我不得不从库中删除所有这些东西,以使它与你的版本一起工作,但我认为你可以重构那个示例脚本,使它发挥作用。你应该考虑将你的Python解释器升级到最新版本。 :)

https://www.python.org/dev/peps/pep-0572/

不能。太多的软件包被捆绑在3.7.7和3.6.10中。

如果可能的话,就建议用什么或怎样的方式来替换它。如果没有,也没问题。

我不是Python的专家。我的语言是R/。

好运。

 
Vladimir Perervenko:

我不能。 太多的软件包被捆绑在3.7.7和3.6.10上。

如果可能的话,请告诉我什么或如何替换。 如果没有,也没问题。

我不是Python专家。 我的语言是R /

好运。

def employment_event(e):
    event_name = e['event_name'].lower()
    return 'payroll' in event_name or 'employment' in event_name


employment_events_next_month = calendar_events(
    currencies=Currency.USD,
    importance=Importance.HIGH,
    function=employment_event
)
 
Vladimir Perervenko:

使用Python?