Using the MetaTrader 5 Python library, How can i set take profit orders for open positions that execute like limit orders instead of market orders
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
As the title says i want to take profit on open positions that execute like limit orders to avoid crossing the spread or incurring slippage. TRADE_ACTION_SLTP allows you to set a take profit price that the order is execute at but the actual execution acts like a market order.
Here is my current code:
# Get open positions positions=mt.positions_get(symbol=symbol) for position in positions: if position.type == 0: request = { "action": mt.TRADE_ACTION_SLTP, "position": position.ticket, "type": mt.ORDER_TYPE_SELL_LIMIT, "tp": current_average_position_price+2, "symbol": position.symbol, "type_time": mt.ORDER_TIME_GTC, "type_filling": mt.ORDER_FILLING_IOC,} mt.order_send(request)