Bid, Ask & Spread
Before we discuss the order types in MQL we need to review the price types and slippage. As a Forex trader, you’re probably already familiar with the Bid and Ask prices. But you might not be aware of their role in order placement. It is very important to use the correct price when opening or closing orders.The Bid price is what you see on the MetaTrader charts. It is usually what we think of when we think of the “current price.” The Ask price is generally just a few pips above the Bid price. The difference between the Bid and the Ask is the the spread, which is the broker’s commission for placing the order.The Ask price is where we open buy orders, and close sell orders. The Bid price is where we open sell orders, and close buy orders. You’ll need to indicate the correct price when opening a market order,or when closing an order at market, so remember the difference between the two.
There are three types of orders that can be placed in MetaTrader: market, stop and limit orders.
Market orders are the most common. A market order opens a position immediately at the prevailing Bid or Ask price.When placing a market order in MQL, we must specify an opening price (generally the latest Bid or Ask quote). If the specified opening price is outdated, due to a fast moving market or a delay in program execution, the terminal will attempt to place the order at the current market price, provided it is within the maximum slippage.If you place a market order using the New Order dialog in MetaTrader, you’ll see a setting at the bottom labeled “Enable maximum deviation from quoted price.” When this is checked, you can then specify the maximum deviation in pips. This is the maximum slippage.If the current price falls outside of our specified opening price, plus or minus the slippage, a requote error will occur and the order will not be placed. You may have noticed this when attempting to place a market order during a fast moving market. Note that ECN/STP brokers do not use a slippage setting, and will always open market orders at the current price.
stop order is a type of pending order. Pending orders are a request to open a market order at a certain price. A buy stop order is placed above the current price, while a sell stop order is placed below the current price. The expectation is that the price will eventually rise or fall to that level and continue in that direction, resulting in a profit.
limit order is the opposite of a stop order. A buy limit order is placed below the current price, while a sell limit order is placed above the current price. The expectation is that the price will rise or fall to that level, triggering the order, and then reversing. Limit orders are not used very often in automated trading. An expiration time can be set for pending orders. If the order is not filled by the expiration time, the order is automatically deleted. Not all brokers support trade expiration.