【问题标题】:How to get the final Stop Loss price on a closed trade using MetaTrader for Python?如何使用 Python 版 MetaTrader 获取平仓交易的最终止损价?
【发布时间】:2023-01-22 00:39:55
【问题描述】:

MetaTrader for Python documentation 表明用户只能使用history_orders_gethistory_deals_get 函数来访问历史交易数据,而不是简单的 history_positions_get 函数。

在 MT5 上,交易分为 5 个元素;

  1. 位置
  2. “按顺序”
  3. “交易中”
  4. “退出”订单
  5. “退出”交易

    这可以从 MT Manager View 更好地可视化

    这对于执行交易等来说很好,但对于想要在 python 中创建自定义账户报告的用户来说,了解平仓时的最终止损值是很有价值的。

    在 Python 库的 MetaTrader 上,我们似乎只能访问订单和交易,所以这里是我可以检索的位置 275 的所有历史数据:

    TradeOrder(ticket=275, time_setup=1657825200, time_setup_msc=1657825200024, time_done=1657825200, time_done_msc=1657825200053, time_expiration=0, type=0, type_time=0, type_filling=0, state=4, magic=0, position_id=275, position_by_id=0, reason=3, volume_initial=12.5, volume_current=0.0, price_open=0.0, sl=138.876, tp=140.266, price_current=139.154, price_stoplimit=0.0, symbol='EURJPY', comment='Long Breakout PERIOD_H1', external_id='')
    
    TradeDeal(ticket=285, order=275, time=1657825200, time_msc=1657825200053, type=0, entry=0, magic=0, position_id=275, reason=3, volume=12.5, price=139.154, commission=0.0, swap=0.0, profit=0.0, fee=0.0, symbol='EURJPY', comment='Long Breakout PERIOD_H1', external_id='')
    
    TradeOrder(ticket=276, time_setup=1657868538, time_setup_msc=1657868538652, time_done=1657868538, time_done_msc=1657868538652, time_expiration=0, type=1, type_time=0, type_filling=1, state=4, magic=0, position_id=275, position_by_id=0, reason=4, volume_initial=12.5, volume_current=0.0, price_open=139.243, sl=0.0, tp=0.0, price_current=139.243, price_stoplimit=0.0, symbol='EURJPY', comment='[sl 139.243]', external_id='')
    
    TradeDeal(ticket=286, order=276, time=1657868538, time_msc=1657868538652, type=1, entry=1, magic=0, position_id=275, reason=4, volume=12.5, price=139.243, commission=0.0, swap=-45.15, profit=800.41, fee=0.0, symbol='EURJPY', comment='[sl 139.243]', external_id='')
    

    如您所见,只有订单数据提供有关 SL 头寸的信息,并且仅针对订单。对于此交易,给出的唯一 SL 价格是 138.876,但是当从 MT5 报表查看 POSITION 时,我们可以看到该头寸以 139.243 的止损平仓:

    MT5 Report

    从技术上讲,最终止损应该在“出局”交易中可用,但出于某种原因,您不能从交易中提取止损或止盈值,只能从订单中提取。

    如果可能的话,我将不胜感激关于如何获得最终止损价格的一些想法!

    提前致谢。

【问题讨论】:

    标签: python trading algorithmic-trading forex metatrader5


    【解决方案1】:

    我也有同样的问题。你找到什么了吗?我正在考虑套接字编程并使用我的 MT5 上的专家来获取位置信息。

    【讨论】:

      猜你喜欢
      • 2023-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-25
      • 2021-12-12
      • 2020-12-23
      • 1970-01-01
      • 2016-03-18
      相关资源
      最近更新 更多