P/L Manager automatically manages manual positions, or orders which have been orphaned by an EA refusing to run. You define either (or both of) a stop-loss and profit-target for all the positions, and they are automatically closed out when the target is hit.
This document describes the P/L Manager expert advisor (EA) for MetaTrader 4.
The EA is a simple tool for managing the profitability of orders in MT4. It does not place any orders itself. Instead, when the combined profit/loss on open positions hits a defined target, P/L Manager closes all the open positions and deletes all pending orders. You can specify both high and low triggers: i.e. a take-profit level and a stop-loss level.
P/L Manager can either be applied to a single symbol (e.g. EURUSD), or to all open positions on all symbols. It can also be restricted so that it only examines orders with a specific magic number (i.e. created by a particular expert advisor).
When P/L Manager's trigger is hit and positions are closed down, the EA can issue an alert on screen and/or by email. You can also configure the EA to shut down MetaTrader 4 in order to prevent further trading by automated systems. In addition to high and low triggers at which orders are closed, you can also define triggers at which alerts are sent (but no action is taken).
You can also choose to terminate all positions manually, by setting the ImmediateOrderClose property. In other words, P/L Manager can be used as a simple close-all script.
One further point: you can run a normal EA (i.e. which places automated orders) on one chart, and run P/L Manager on another chart for the same symbol. P/L Manager can then act as a fail-safe for the EA, closing out its positions if the EA misbehaves in some way and exceeds a profit target or stop-loss. Alternatively, P/L Manager can be used to provide alerting on another EA, sending out messages if its profitability goes outside certain bounds.
Unless otherwise specified in writing by FX Blue, this software is licensed for personal use only. You are not allowed to distribute it to other people, regardless of whether or not money is changing hands. You only have a licence to use the software if you, personally, downloaded it from our website.
The software is provided entirely at the user's risk, and you should check it thoroughly before deploying it on computers trading real money. FX Blue accepts no responsibility whatsoever for any loss of any kind caused by installation or use of the software.
P/L Manager is installed in the usual MetaTrader 4 fashion: the EX4 file needs to be copied into the experts directory of the MetaTrader installation.
There are some other steps which users may want to take at the time of installation:
You start P/L Manager by attaching the EA to a chart in MetaTrader. The EA's "Allow live trading" setting must be turned on before starting. The "Allow DLL imports" setting must also be turned on if you want to shut down MT4 when the target is hit.
You can use P/L Manager in either of two ways:
You can also choose to restrict the EA so that it only looks at orders which have a specific "magic number". This is designed to allow it to manage the orders created by a particular expert advisor.
Finally, before starting you will usually want to do one of the following:
You can stop P/L Manager simply by removing it from its chart.
While it is running, P/L Manager displays a series of status indicators in the top left corner of its chart (though the position can be altered, using EA settings, to minimise overlay on other graph elements).
P/L Manager displays the following information:
P/L Manager also displays another, smaller indicator in the top left of the chart, directly underneath MetaTrader's display of the symbol and its latest price. This is for monitoring/debugging purposes, and shows the current or most recent status of the EA. There are three main states which this indicator can show:
When the P/L Manager's target has been hit, you can optionally configure it to do either of the following:
Remove the EA from its chart.
If you don't do either of these things, the P/L Manager will continue running, and will close future trades if the profitability levels are breached again.
P/L Manager can be configured to display an alert on screen and/or by email when its trigger is hit. (The EA will also send alerts if it encounters a serious error, such as failure to read the details of an order from MetaTrader.)
You can also use the AlertAboveUpperPnL and AlertBelowLowerPnL settings to define thresholds at which P/L Manager alerts you, but does not take any action. For example, if "AlertAboveUpperPnL" is set to 100, and "CloseAboveUpperPnL" is set to 200, then the EA will issue an alert when the profit on open positions hits $100, and will close the positions (and issue another alert) when the profit hits $200.
These P/L alerts are not sent repeatedly, e.g. if the profitability bounces above and below the threshold defined by "AlertAboveUpperPnL". The alert is only sent once, and will not be sent again until the EA is reloaded - whether by re-adding it to the chart, changing the time period on its chart etc.
Email alerts only occur if valid email settings have been configured in MetaTrader (using Tools/Options). Please note that the from and to addresses for MetaTrader emails are fixed; they cannot be specified by an individual EA. In other words, each EA cannot have a bespoke list of email recipients (at least, not without using its own email sending system rather than the one which MetaTrader provides).
To send emails to multiple addresses, use a method such as creating a Google Group list, and send MetaTrader's emails to the address of the group.
You can configure P/L Manager to shut down MT4 when the upper or lower target is hit. If you are using P/L Manager to control the behaviour of other EAs, then a complete shutdown of the MT4 software is the only reliable way of preventing those EAs from placing further orders.
You enable the shutdown of MT4 using the CloseMT4 parameter. If you are sending email alerts, then you need to use the CloseDelaySeconds parameter to delay the shutdown and give MT4 time to send the email. However, please note that EAs can place further orders during the CloseDelaySeconds period.
Setting | Description |
CloseAboveUpperPnL | Open orders are closed once their combined profitability hits or rises above this upper boundary. |
CloseBelowLowerPnL | Open orders are closed once their combined profitability hits or rises above this lower boundary. (N.B. If the orders are currently in profit, you can implement a "break-even stop" by setting this value to zero. |
RestrictToMagicNumber | If non-zero, P/L Manager only processes orders which have this specific "magic number" (i.e. are created by a particular EA). If this setting is zero, P/L Manager ignores the magic number of orders. |
ApplyToAllSymbols | If this is set to false, P/L Manager only looks at orders for the symbol on the chart which it is attached to. If this setting is set to true, P/L Manager processes all open positions, across all symbols. |
Setting | Description |
ImmediateOrderClose | Simply terminates all applicable orders (i.e. depending on ApplyToAllSymbols) as soon as the first market tick is received from the broker. |
Setting | Description |
DoVisualAlerts | If true, P/L Manager displays alerts on screen when its trigger is hit (and, optionally, when the profitability-alerts below are hit). |
DoEmailAlerts | If true, P/L Manager issues alerts by email when its trigger is hit (and, optionally, when the profitability-alerts below are hit). This setting is effectively ignored unless you configure email details in MetaTrader. |
AlertAboveUpperPnL | Defines an upper threshold for profitability above which P/L Manager sends an alert, but does not take any action. Can be used to send an interim notification before open positions are closed out. |
AlertBelowLowerPnL | Defines a lower threshold for profitability below which P/L Manager sends an alert, but does not take any action. Can be used to send an interim notification before open positions are closed out. |
The following settings control the optional shutdown of MetaTrader 4 when the upper or lower target is hit:
Setting | Description |
CloseMT4 | If turned on, MT4 is shut down when the target is hit. The "Allow DLL imports" setting in MT4 must be turned on. |
CloseDelaySeconds | Number of seconds to wait before closing MT4. If you have turned on email notifications (DoEmailAlerts = true), then you need to allow enough time for MT4 to send the email before shutting down. |
RemoveEA | If turned on, the EA removes itself from its chart when the target is hit |
The following settings control the positioning etc of P/L Manager's status box on the chart.
Setting | Description |
StatusBoxTop | Offset, in pixels, of the top of the status box from the top of the chart window |
StatusBoxLeft | Offset, in pixels, of the left-hand edge of the status box from the left of the chart window |
StatusBoxLineSpace | Number of pixels between each line in the status display. May need to be altered depending on chosen font and size. |
StatusBoxFont | Font used for the status box (e.g. Arial, Verdana) |
StatusBoxFontSize | Font size use for the status box |
StatusBoxColour | Colour of the text in the status box |
Setting | Description |
IncludeSwapInProfit | Determines whether or not P/L Manager includes swap in its calculation of the profitability of open orders. |
SlippageAllowed | Number of pips of slippage allowed when placing market orders to close existing positions. (N.B. MetaTrader's documentation says that this parameter is in points, not pips, but this seems unlikely to be correct.) |