我遵循了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
提交
取消