Breakeven MetaTrader Script
Table of contents
Breakeven MetaTrader script is a simple tool to move stop-loss to breakeven for one or more positions filtered according to given parameters. It is available both for MT4 and MT5.
Breakeven is a price point where trade's profit equals zero. Setting a position to breakeven means setting its stop-loss to where the position's open price is. It makes sense to move stop-loss of some of your trades to breakeven when you want to 'let the profits run', but prefer to be calm the trade not returning to the red zone.
It isn't difficult to modify a single trade's stop-loss to move it to the trade's open price. However, when there are many positions to work with, this might be cumbersome and time-consuming. This is where the Breakeven script for MT4/MT5 can help you.
Running Breakeven script
Running the Breakeven script is easy. After you double-click on it or move to the chart, you will be able to optionally set any of the input parameters for filtering or click the OK button immediately.
The script will start its execution running through all open trades and looking for those that are in profit and that conform to the selected conditions. Each position is then modified to move its stop-loss to a breakeven position.
You can make the process even faster by editing the input parameters in the script's source code directly and removing the line that requires it to show the input parameters screen on execution. The line is #property show_inputs
in MT4 and #property script_show_inputs
in MT5. This way, after re-compiling the source code, you will be able to run the Breakeven script nearly instantly.
Input parameters
The Breakeven script for MetaTrader supports a range of input parameters to let you choose which positions you want it to work on and how you want the breakeven level to be modified.
- OnlyCurrentSymbol (default = false) — if true, the script will set breakeven only to trades on the same symbol as the current chart.
- OrderTypeFilter (default = ALL ORDERS) — filter orders by order direction (all, buy, or sell).
- MinimumProfit (default = 0) — the minimum profit (given in points) to consider moving the trade's SL to breakeven.
- AdditionalProfit (default = 0) — the additional profit (given in points) to add to breakeven. Use this if you want to secure at least some profit instead of doing a regular breakeven.
- OnlyMagicNumber (default = false) — if true, the script will set breakeven only to trades with the Magic number given in the next input parameter.
- MagicNumber (default = 0) — the required Magic number if you set OnlyMagicNumber to true.
- OnlyWithComment (default = false) — if true, the script will set breakeven only to trades with the same Commentary field value as given in the next input parameter.
- MatchingComment (default = "") — the required Commentary field value if you set OnlyWithComment to true.
Example
Here is an example of the results reported by the Breakeven scripts after running it just once:
Downloads
Script Installation
To install the script in MetaTrader 4, please follow the instructions below:
- Download the script archive file.
- Open the MetaTrader 4 data folder (via File→Open Data Folder).
- Open the MQL4 folder.
- Copy all the folders from the archive directly to the MQL4 folder.
- Restart MetaTrader 4 or refresh the list of scripts by right-clicking the Navigator subwindow of the platform and choosing Refresh.
To install the script in MetaTrader 5, please follow the instructions below:
- Download the script archive file.
- Open the MetaTrader 5 data folder (via File→Open Data Folder).
- Open the MQL5 folder.
- Copy all the folders from the archive directly to the MQL5 folder.
- Restart MetaTrader 5 or refresh the list of scripts by right-clicking the Navigator subwindow of the platform and choosing Refresh.
You can also read a more detailed instruction on how to perform the installation.
Discussion
Do you have any suggestions or questions regarding this script? You can always discuss Breakeven script with the other traders and MQL4/MQL5 coders on our forum.
You might be also interested in our Breakeven Line Indicator. You can use it to display a total breakeven price for multiple trades on the same symbol.