# How to Modify an Open Position on MetaTrader 5 with Python > MetaTrader 5 Python Trading Bot **Published by:** [The Crypto - AI - Cyber Disruption Continuum](https://paragraph.com/@appnologyjames/) **Published on:** 2024-08-06 **Categories:** python, trading bot, metatrader 5, metatrader 5 python trading bot, metatrader 5 python expert advisor **URL:** https://paragraph.com/@appnologyjames/how-to-modify-an-open-position-on-metatrader-5-with-python ## Content When MetaTrader 5 introduced the MetaTrader5 Python Library, it was a game-changer. Finally, the world’s most popular and widely used programming language could be easily integrated into one of the world’s largest retail trading platforms.The extensive range of Python libraries and widespread availability of powerful computing platforms meant that everyday traders could integrate powerful machine learning libraries and concepts into their day-trading activities. In fact, my company Creative Appnologies, uses it extensively in our analysis programs.These integrations mean that sometimes you need to modify an open position.Modify An Open PositionTo modify an open position, you need the following:A connection to MetaTrader 5 with PythonThe order number of the positionSymbolNew Stop Loss valueNew Take Profit valueHere’s the code to modify an open position:# Function to modify an open position def modify_position(order_number, symbol, new_stop_loss, new_take_profit): # Create the request request = { "action": MetaTrader5.TRADE_ACTION_SLTP, "symbol": symbol, "sl": new_stop_loss, "tp": new_take_profit, "position": order_number } # Send order to MT5 order_result = MetaTrader5.order_send(request) if order_result[0] == 10009: return True else: return FalseWant to See it All Working Together?https://paragraph.xyzHow to Build a MetaTrader 5 Python Trading Bot: Getting StartedGet started building your MetaTrader 5 Expert Advisor. Using Python, I'll show you everything you need to build it for yourself. ## Publication Information - [The Crypto - AI - Cyber Disruption Continuum](https://paragraph.com/@appnologyjames/): Publication homepage - [All Posts](https://paragraph.com/@appnologyjames/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@appnologyjames): Subscribe to updates ## Optional - [Collect as NFT](https://paragraph.com/@appnologyjames/how-to-modify-an-open-position-on-metatrader-5-with-python): Support the author by collecting this post - [View Collectors](https://paragraph.com/@appnologyjames/how-to-modify-an-open-position-on-metatrader-5-with-python/collectors): See who has collected this post