you must use the order Id to modify it. In your code there is no way for the second order_send to locate the original order.
https://www.mql5.com/en/docs/constants/structures/mqltraderequest
| position | Ticket of a position. Should be filled in when a position is modified or closed to identify the position. As a rule it is equal to the ticket of the order, based on which the position was opened. |
in your case, position = li_4.order
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Request Structure
- www.mql5.com
Interaction between the client terminal and a trade server for executing the order placing operation is performed by using trade requests. The...
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
price = mt5.symbol_info_tick(symbol).ask request = { "action": mt5.TRADE_ACTION_DEAL, "symbol": symbol, "volume": ld_8, "type": mt5.ORDER_TYPE_BUY, "price": price, "deviation": slippage, "magic": MagicNumber, "comment": EA_Name + ls_32, "type_filling": find_filling_mode(symbol), "type_time": mt5.ORDER_TIME_GTC} li_4 = mt5.order_send(request) if li_4.retcode != mt5.TRADE_RETCODE_DONE: print("order_send failed, retcode={}".format(li_4.retcode)) return else: time.sleep(10) if li_4.order >= 0: orders = mt5.positions_get(symbol=symbol) empty = () if orders == empty: print("No orders EURUSD, error code={}".format(mt5.last_error())) else: orders_df = pd.DataFrame(list(orders),columns=orders[0]._asdict().keys()) orders_df['time'] = pd.to_datetime(orders_df['time'], unit='s') orders_df['time_msc'] = pd.to_datetime(orders_df['time_msc'], unit='ms') orders_df['time_update'] = pd.to_datetime(orders_df['time_update'], unit='s') orders_df['time_update_msc'] = pd.to_datetime(orders_df['time_update_msc'], unit='ms') point = mt5.symbol_info(symbol).point price = mt5.symbol_info_tick(symbol).ask tp = float(price + 100 * point) sl = float(price - 100 * point) position = int(orders_df.loc[len(orders_df) - 1, 'ticket']) volume = float(orders_df.loc[len(orders_df) - 1, 'volume']) print('position: ', position) print('sl: ', sl) print('tp: ', tp) print('volume: ', volume) request = { "action": mt5.TRADE_ACTION_SLTP, "symbol": symbol, "ticket": position, "volume": volume, "sl": sl, "tp": tp, "magic": MagicNumber, "comment": EA_Name + 'Modify', "type_time": mt5.ORDER_TIME_GTC, "type_filling": find_filling_mode(symbol)} li_4 = mt5.order_send(request) if li_4 is None: print('order send failed!!!') elif li_4.retcode != mt5.TRADE_RETCODE_DONE: print("order_send failed, retcode={}".format(li_4.retcode)) else: print('Modify OK!!!')Print:
order_send failed, retcode=10036