What is a Pending Order?
A pending order is a type of order that will be executed when the market price reaches a specified level. In simpler terms, it allows you to set up a trade at a certain price point. Once the price hits this predetermined level, your trade will automatically open.
Types of Pending Orders in EA
In MetaTrader 4, there are six different order types:
- Type 0: Buy
- Type 1: Sell
- Type 2: Buy Limit
- Type 3: Sell Limit
- Type 4: Buy Stop
- Type 5: Sell Stop
From these, we’ll focus on the four types of pending orders available. Let’s dive into each type and how to implement them.
1. Buy Limit
A buy limit order is set below the current market price. This means that you are willing to buy once the price drops to your specified level.
OrderSend(Symbol(), 2, start_lot, Ask - Distance * Point, 3, Ask - Distance * Point - SL * Point, Ask - Distance * Point + TP * Point, "", Magic, 0, Blue);
Remember to adjust the distance between the current price and the order price when setting up your buy limit order.
2. Sell Limit
A sell limit order is set above the current market price. You're essentially saying that you want to sell once the price rises to your specified level.
OrderSend(Symbol(), 3, start_lot, Bid + Distance * Point, 3, Bid + Distance * Point + SL * Point, Bid + Distance * Point - TP * Point, "", Magic, 0, Red);
3. Buy Stop
A buy stop order is placed above the current market price. This order is activated when the price rises to your specified level.
OrderSend(Symbol(), 4, start_lot, Ask + Distance * Point, 3, Ask + Distance * Point - SL * Point, Ask + Distance * Point + TP * Point, "", Magic, 0, Blue);
4. Sell Stop
A sell stop order is set below the current market price. You're indicating that you want to sell once the price falls to your specified level.
OrderSend(Symbol(), 5, start_lot, Bid - Distance * Point, 3, Bid - Distance * Point + SL * Point, Bid - Distance * Point - TP * Point, "", Magic, 0, Red);
Building an EA for Your Pending Orders
Now that we've covered the basics, let’s put this knowledge into practice by creating an EA that utilizes all four types of pending orders.
This EA will be straightforward, allowing you to easily manage your pending orders based on the type and the filters you've set.
Here’s a snippet of how to call the total order function for a buy limit:
if(totalorder(OP_BUYLIMIT) == 0) { res = OrderSend(Symbol(), 2, start_lot, Ask - Distance * Point, 3, Ask - Distance * Point - SL * Point, Ask - Distance * Point + TP * Point, "", Magic, 0, Blue); }
The EA is designed to run smoothly, helping you make the most of your trading strategies.

Hopefully, this guide has helped clarify pending orders for you. If you have any questions or comments, feel free to drop them below!
Wishing you profitable trades and a fantastic day!

Comments 0