Account Protector is a MetaTrader expert advisor that lets you manage trades and control your profit and loss across multiple currency pairs using a number of parameters and settings. Here are some examples of the things you can accomplish with Account Protector:
- Close all positions once account equity increases by 10%.
- Delete all EUR/USD pending orders once floating profit on EUR/USD trades reaches $500.
- Email you the current account state and disable autotrading once free margin drops below $1,000.
- Trail stop-losses on all trades with non-empty commentary field.
- Close all positions and exit MetaTrader once total floating profit on trades with magic number "1000" reaches 50 pips.
Account Protector's main benefits include:
- You control all the main settings using a graphic panel.
- You can close, minimize, and move the panel freely across the chart.
- Settings can be adjusted inside the panel with just a few mouse clicks.
- You can apply mass breakeven and trailing stop mechanism to secure your profit.
- You can set it to trigger by timer.
- You can choose whether to count swaps and commission when calculating profit/loss.
- The panel displays the current instrument's spread.
- Two snapshots (free margin and equity) are available for advanced trigger conditions.
- You can filter trades by magic numbers, instrument, and order commentaries.
- You can combine as many conditions and filters as you like.
- The panel can inform you about its actions via email and mobile push-notifications.
- The panel automatically saves and loads its settings on timeframe change or platform restart, preserving your configuration efforts.
- It uses only one standard Windows DLL (to disable autotrading) — the EA can work without DLLs if you do not need it to disable autotrading.
- You can use it in MetaTrader 4 and MetaTrader 5 (both hedging and netting modes).
- The panel scales properly on high-DPI screens (4K, for example).
- You are free to browse and modify its open-source code.
The main tab of the panel serves to control the trailing stop and breakeven settings as well as free margin and equity snapshots. Also, you can use it to set the timer and to choose whether to count swaps and commission as profit and loss. Additionally, this tab displays the current spread. All the tabs show the expert advisor's status:
To turn on the timer, you need to set the checkbox and the time (trading server or local PC time) when you want expert advisor's actions to be executed (not the time until those actions triggering).
Trailing stop and breakeven are set similarly — by clicking the checkbox and setting the relevant value in the input field:
- The first trailing input allows you to set the profit level in pips when the trailing stop is first activated. For example, 100 pips; when position will reach at least 100 pips profit, the trailing stop will be applied using the stop distance from the next input field.
- The actual trailing stop distance to be used.
- The first breakeven input field is the target number of profitable pips when the stop-loss is moved to breakeven.
- The final input field lets you enter the number of extra pips to add to the breakeven level if you want to capture some minimum profit with the trade. This value is useless if the main breakeven value is not set.
This tab lets you restrict which trades are monitored and managed by the Account Protector using magic numbers, order symbol, and order commentary.
The magic number field lets you input several numeric values and either force the EA to work with the trades associated with these numbers or exclude such trades from being processed by the EA. Symbol filtering is organized as a group of radio buttons with explicitly described choices. Order commentary filtering is based on a textual input field and a choice of whether to look for exact match, comments containing the text, comments not containing the text, or comments not equal the entered text.
In this tab, you can set the conditions to trigger the EA's actions.
The first six conditions involve floating profit/loss and they trigger if:
- Floating loss reaches a given percentage of balance. E.g., paper loss becomes greater or equal to 20%.
- Floating loss reaches a number of currency units. E.g., paper loss becomes greater or equal to $100.
- Floating loss reaches a number of pips. E.g., paper loss becomes greater or equal to 50 pips.
- Floating profit reaches a given percentage of balance. E.g., paper profit becomes greater or equal to 40%.
- Floating profit reaches a number of currency units. E.g., paper profit becomes greater or equal to $200.
- Floating profit reaches a number of pips. E.g., paper profit becomes greater or equal to 100 pips.
The next two conditions compare account equity to a given amount of money:
- Equity becomes less or equal to a given number of currency units. E.g., equity falls to or below $800.
- Equity becomes greater or equal to a given number of currency units. E.g., equity rises to or above $1200.
Then, there are two conditions that compare account equity to the previously captured snapshot:
- Equity becomes less or equal to a given percentage of snapshot. E.g., equity falls to or below 90% of the previously captured snapshot.
- Equity becomes greater or equal to a given percentage of snapshot. E.g., equity rises to or above 115% of the previously captured snapshot.
Similar conditions exist for free margin. The first two conditions compare it to some amount of money:
- Free margin becomes less or equal to a given number of currency units. E.g., free margin falls to or below $500.
- Free margin becomes greater or equal to a given number of currency units. E.g., free margin rises to or above $750.
The final two conditions compare free margin to a snapshot:
- Free margin becomes less or equal to a given percentage of snapshot. E.g., free margin falls to or below 80% of the previously captured snapshot.
- Free margin becomes greater or equal to a given percentage of snapshot. E.g., free margin rises to or above 130% of the previously captured snapshot.
This tab lets you select the actions that should trigger if your chosen conditions are met.
Five actions are supported by Account Protector:
- Close all positions will close all active trades in all trading instruments that are not filtered out (using the Filters tab) and where trading is enabled.
- Delete all pending orders will remove all stop, limit, and stop-limit orders in all trading instruments that are not filtered out (using the Filters tab) and where trading is enabled.
- Disable autotrading will turn off the platform's AutoTrading button preventing further operation of all expert advisors. Account Protector uses a call to one of user32.dll functions to emulate the button press. The action will not work if DLLs are disabled.
- Send e-mail will notify you using an e-mail if there are correct settings under Tools->Options->Email menu. One e-mail message will be sent with brief description of what condition has been met and what actions have been taken.
- Send push notifications will inform you using mobile push notifications if there are correct settings under Tools->Options->Notifications menu. Two notifications will be sent with brief description of what condition has been met and what actions have been taken.
After some action is taken, its checkbox will be unchecked.
The aim of Account Protector (AP) is to help you preserve your account balance. AP works based on the conditions and actions you set. The actions are applied at the moment when at least one of the conditions is triggered. The graphic panel helps you operate the expert advisor.
You can ensure proper operation of AP by turning on AutoTrading button in MetaTrader terminal. Allowing DLL imports enables AP to automatically disable autotrading when you configure it to do so. The expert advisor will alert you if either AutoTrading button or DLL imports are off but will continue operating in a restricted mode.
The EA will apply trailing stop-loss and breakeven stops if you configure it via the Main tab and enable autotrading.
If you set Enable emergency button input parameter to Yes, a big red emergency button will appear at the bottom of the Main tab. You can press it to close all positions, delete all pending orders, and disable autotrading immediately. The emergency button respects the filters set via the Filters tab.
You can monitor the status of the Account Protector by looking at the panel's top line. It shows the current status as one of the five possible values:
- Autotrading is disabled — the expert advisor will not be able to perform any trading operations until autotrading is enabled.
- No condition is set — you need to set some condition in the Conditions tab for the EA to trigger and to take some actions.
- No action is set — you need to set some action in the Actions tab for AP to do anything when a condition triggers.
- OK — AP is fully operational and will take some actions when at least one of the given conditions is met.
- Triggered at <timestamp> — appears after some condition has triggered.
When AP is attached to the chart, it logs the trading account information and its input parameters if the log file name is set.
During its operation, AP logs the following events:
- When some condition is triggered, AP logs the name of that condition, current account information, and all the panel settings.
- When some action is taken, AP logs the name of that action and the detailed list of all the closed positions and deleted pending orders.
- AP logs error messages (when some entered input value is invalid).
- It is possible to see most of the log messages inside the Experts tab of the MT4/MT5 terminal.
- When you remove AP from the chart, it again logs all the relevant trading account information and its own input values.
Each line of the log file is accompanied by a timestamp based on the trading server time.
- Slippage (default = 2) — slippage value given in broker's pips to be used when closing positions.
- Log file name (default = "log.txt") — if given, Account Protector will log its settings and events into that file.
- Enable emergency button (default = No) — if Yes, the emergency button will be present on the panel for quick removal of all trades and disabling of autotrading.
- PanelOnTopOfChart (default = true) — if true, the panel will be drawn on foreground, and the chart will be drawn as background. Setting it to false will uncover the chart behind the panel.
Downloads (ver. 1.00, 2017-02-06)
Account Protector for MetaTrader 4
Account Protector for MetaTrader 5
To install — unzip and copy the whole Account Protector folder to MQL4/Experts/ or MQL5/Experts/ (if you are on MetaTrader 5) of your terminal's data folder.
Do you have any suggestions or questions regarding this expert advisor? You can always discuss Account Protector with other traders and MQL coders in the forum.