# How to Cancel an Order 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, metatrader 5 python trading bot, metatrader 5 python expert advisor **URL:** https://paragraph.com/@appnologyjames/how-to-cancel-an-order-on-metatrader-5-with-python ## Content The combination of Python and MetaTrader 5 can be incredibly powerful for your trading bot.Bringing together the world’s most popular programming language and one of the world’s largest retail trading platforms is a game changer. In fact, TradeOxy is built on leveraging these factors to help traders!If you’re looking to integrate MetaTrader5 (MT5) and Python together into a trading bot, you’ll need a few functions:How to connect to MetaTrader5How to initialize a symbol on MetaTrader5 (needed if you want to retrieve data or make orders)How to retrieve 50,000 candlesIn this article, I’ll show you how to cancel an open order (i.e. before it executes and becomes a position)Join our amazing Discord community here. How to Cancel an OrderI’ll assume you’ve connected to MT5.To cancel an order on MT5, all you need is an order number. Check out my article “How to Get a List of Open Orders on MetaTrader 5 with Python” if you want to find out how to retrieve a list of order numbers.With your order number in hand, here’s the code:# Function to cancel an order def cancel_order(order_number): # Create the request request = { "action": MetaTrader5.TRADE_ACTION_REMOVE, "order": order_number, "comment": "Order Removed" } # Send order to MT5 order_result = MetaTrader5.order_send(request) return order_result ## 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-cancel-an-order-on-metatrader-5-with-python): Support the author by collecting this post - [View Collectors](https://paragraph.com/@appnologyjames/how-to-cancel-an-order-on-metatrader-5-with-python/collectors): See who has collected this post