Discussing the article: "Developing a Multi-Currency Expert Advisor (Part 28): Adding a Position Closing Manager"

 

Check out the new article: Developing a Multi-Currency Expert Advisor (Part 28): Adding a Position Closing Manager.

When running multiple strategies in parallel, you may want to periodically close all open positions and start the strategies over again. The existing code only allows this behavior to be implemented through manual intervention. Let's try to automate this part.

In Part 12, we added a risk manager module to the multi-currency EA to limit daily and overall drawdown. It does not increase profits, but is critical to protecting funds in adverse conditions. It is based on prop trading rules with flexible settings: drawdown in currency, as a percentage of the balance, or from the start of the day.

The module is implemented as the CVirtualRiskManager class with methods for tracking balance, profit, and checking limitations. A profit-locking function is also provided: once the target is reached, all positions are closed and trading stops.

For regular accounts, it would be preferable for trading to restart automatically once the profit target has been reached. Currently, this requires manual intervention. It is time to automate this as well.

I have considered two options of restarting trading strategies when reaching the target profit:

  1. expand the current risk manager,

  2. create a separate module.

I have chosen the second path because the current risk manager operates independently of strategies: it closes only real positions without affecting virtual ones. Changing this logic would complicate the architecture and violate modular independence.

The risk manager also creates additional testing overhead, so it is better to move the new functionality into a separate module — it can be used even without the risk manager running.

The new goal is a module that can restart all strategies when specified conditions (profit, loss, time, etc.) are met, without relying on trading history and without manual intervention. I will call the new module the closing manager, as it is a separate optional module, but its addition can improve the results, and it manages the process of completely closing all positions, both real and virtual.


Author: Yuriy Bykov