工作已完成
指定
Hi
The objective of this job is to create or fix the next code (Mql5 APY Python) and be able to place orders base on the next conditions:
if:
pre == 0 do nothing
pre == 1 open long
pre == 2 close long
pre == 3 open short
pre == 4 close short
The way to validate the job is to implement the code in a JupyterLab notebook runing in a vps with windows and see the results when changing the pre values
In the next link you can find and copy the entire code: https://controlc.com/63fc1b87
On the next lines the code that I been working on but has an error and do not close the the orders, it open the order but it do not close them....
####### Order info symbol = "EURUSD" lot = 0.4 deviation = 20 ###### Clasification Model Predictions pre = 4 pre ##### Order info def send_order(symbol, lot, pre, position_id = None): if pre== 0: pass if pre==1 and position_id == None: request = { "action": mt5.TRADE_ACTION_DEAL, "symbol": symbol, "volume": lot, "type": mt5.ORDER_TYPE_BUY, "deviation": deviation, "magic": 100001, "comment": "EURUSD_5min", "type_time": mt5.ORDER_TIME_GTC, "type_filling": mt5.ORDER_FILLING_IOC} result = mt5.order_send(request) return result if pre==3 and position_id == None: request = { "action": mt5.TRADE_ACTION_DEAL, "symbol": symbol, "volume": lot, "type": mt5.ORDER_TYPE_SELL, "deviation": deviation, "magic": 100001, "comment": "EURUSD_5min", "type_time": mt5.ORDER_TIME_GTC, "type_filling": mt5.ORDER_FILLING_IOC} result = mt5.order_send(request) return result ############ Close Trades if pre==2 and position_id != None: request = { "position": position_id, "action": mt5.TRADE_ACTION_DEAL, "symbol": symbol, "volume": lot, "type": mt5.ORDER_TYPE_SELL, "deviation": deviation, "magic": 100001, "comment": "EURUSD_5min", "type_time": mt5.ORDER_TIME_GTC, "type_filling": mt5.ORDER_FILLING_IOC} result = mt5.order_send(request) return result if pre==4 and position_id != None: request = { "position": position_id, "action": mt5.TRADE_ACTION_DEAL, "symbol": symbol, "volume": lot, "type": mt5.ORDER_TYPE_BUY, "deviation": deviation, "magic": 100001, "comment": "EURUSD_5min", "type_time": mt5.ORDER_TIME_GTC, "type_filling": mt5.ORDER_FILLING_IOC} result = mt5.order_send(request) return result #### Placion Orders place_order = send_order(symbol, lot , pre) print(place_order) ##### Order Identification if len(mt5.positions_get()) != 0 : df_2 = mt5.positions_get() df_2 = pd.DataFrame(df_2) identifier = df_2.iat[0,7].astype(np.int64) elif len(mt5.positions_get()) == 0: identifier = None print(identifier) ##### Closing Orders close_order = send_order(symbol, lot, pre, position_id = identifier) print(close_order)