我遵循了Metatrader5 python 文档和堆栈溢出中的这个答案我尝试建立卖出头寸:import MetaTrader5 as mt5ea_magic_number = 9986989 # if you want to give every bot a unique identifierdef get_info(symbol): '''https://www.mql5.com/en/docs/integration/python_metatrader5/mt5symbolinfo_py ''' # get symbol properties info=mt5.symbol_info(symbol) return infodef open_trade(action, symbol, lot, sl_points, tp_points, deviation): '''https://www.mql5.com/en/docs/integration/python_metatrader5/mt5ordersend_py ''' # prepare the buy request structure symbol_info = get_info(symbol) if action == 'buy': trade_type = mt5.ORDER_TYPE_BUY price = mt5.symbol_info_tick(symbol).ask elif action =='sell': trade_type = mt5.ORDER_TYPE_SELL price = mt5.symbol_info_tick(symbol).bid point = mt5.symbol_info(symbol).point buy_request = { "action": mt5.TRADE_ACTION_DEAL, "symbol": symbol, "volume": lot, "type": trade_type, "price": price, "sl": price - sl_points * point, "tp": price + tp_points * point, "deviation": deviation, "magic": ea_magic_number, "comment": "sent by python", "type_time": mt5.ORDER_TIME_GTC, # good till cancelled "type_filling": mt5.ORDER_FILLING_RETURN, } # send a trading request result = mt5.order_send(buy_request) return result, buy_request def close_trade(action, buy_request, result, deviation): '''https://www.mql5.com/en/docs/integration/python_metatrader5/mt5ordersend_py ''' # create a close request symbol = buy_request['symbol'] if action == 'buy': trade_type = mt5.ORDER_TYPE_BUY price = mt5.symbol_info_tick(symbol).ask elif action =='sell': trade_type = mt5.ORDER_TYPE_SELL price = mt5.symbol_info_tick(symbol).bid position_id=result.order lot = buy_request['volume']没有任何反应,应用程序终端也没有任何反应。我还检查了 Metatrader5 中的贸易和历史部分以查找一些相关信息,但我一无所获。我如何在Metatrader5中监控日志来调试代码并解决问题?
3 回答
慕尼黑5688855
TA贡献1848条经验 获得超2个赞
我变了:
"type_filling": mt5.ORDER_FILLING_RETURN
到 :
"type_filling": mt5.ORDER_FILLING_IOC
然后它对我有用。
我正在使用 python 版本 3.10
呼唤远方
TA贡献1856条经验 获得超11个赞
仅适用于达到此主题且算法交易按钮打开且发送订单时没有任何反应的人。
在我的例子中,这是因为我将请求的“音量”设置为一个整数,而且它必须是一个浮点数。没有显示错误,没有生命迹象,order_send(...) 返回 None 就是这样。只需将传入值转换为浮点数即可。
这不是问题作者的情况,但我希望它能在未来帮助一些冒险的灵魂。
添加回答
举报
0/150
提交
取消