4 Additional Forex EA Order Functions You Need to Know

Last month, we’ve covered the topic of opening trade orders on your forex EA and looked at a few examples. This time I’ll be discussing additional functions you might need in managing your trade orders.

1. OrderDelete

This function deletes a previously placed pending order. This is very useful when your forex system sets limit or stop orders, and you’d like to ensure that several pending orders aren’t floating around or getting randomly triggered even when trading conditions have changed.

Its proper syntax is:

bool OrderDelete (int ticket);

As you’ve probably noticed, this function returns a boolean value. That’s because the forex robot needs to let the user know if the specified order was deleted successfully or not.

2. OrderModify

This allows you to modify the open price, stop loss, profit target, and expiration details of a particular order. Take note that the order still has to be pending or untriggered in order to make these adjustments.

Its proper syntax is:

bool OrderModify (int ticket, double price, double stop loss, double take profit, datetime expiration);

The OrderModify function also returns a boolean value because it needs to confirm whether or not the adjustments were made successfully.

3. OrderClose

This function allows you to exit an open trade while specifying the number of lots and the closing price. You can use this function if you want to code a trailing stop or if your system has risk management rules that allow for booking profits partially.

Its proper syntax is:

bool OrderClose (int ticket, double lots, double price, int slippage);

4. OrderCloseBy

This function closes an existing open order when the forex EA gives the signal to take the opposite position. This can come in handy when you have a moving average system that needs to automatically exit a short (long) position when a valid upward (downward) crossover signal is seen.

Take note that this is different from the OrderDelete function, which deletes a pending order when a new one is made or when an opposite signal is given. The OrderCloseBy function exits an open position when an opposite signal is seen. Its proper syntax is:

bool OrderCloseBy (int ticket, int opposite);

Phew! That’s a lot to cover in a day. Even forex robots get tired, you know? I’ll save the examples for these functions for the next weeks so make sure you stay tuned!