Set Fixed SL and TP Script for MT4
One of the first rules in money management and risk management in Forex is to always have a stop-loss set for all your trades. Remember that a broker can execute a margin call on your account if a trade moves against you and you don't have sufficient funds to cover the loss. Long story short, missing a stop-loss may result in your account wiped or badly damaged. The MT4 script SetFixedSLandTP (short for Set Fixed Stop-Loss and Take-Profit) allows you to set a stop-loss and an optional take-profit price for all open orders in a selected currency pair.
There may be cases where you need to open an order quickly or you simply forget to set a stop-loss and take-profit for your order. Sometimes, you may also have many orders open based on the same strategy and you may want to set the stop-loss and take-profit for all of them at once. You can use the SetFixedSLandTP script to do it faster than you would be setting SL and TP manually.
You can download the script for educational purposes and test it on a demo account before apply it to any live trades.
You can also use this script's code as an example of an MQL4 program that works with orders and their parameters in MT4.
When you run the script on a chart, you can set some parameters to limit which orders will be affected. You will also have to specify the pips of distance from the open price for the stop-loss and take-profit price.
The parameters are:
- Take-Profit in pips — distance in pips between the open price and the take-profit.
- Stop-Loss in pips — distance in pips between the open price and the stop-loss.
- Modify only orders matching the magic number — can be false or true; it specifies whether you want to limit the changes only to orders with a specific magic number.
- Matching magic number — in case the previous parameter is set to true, you need to specify which magic number to use for the match.
- Modify only orders with the following comment — can be false or true, depending on whether you want to modify only orders with a specific comment.
- Matching comment — input the comment to match in case the previous parameter is set to true.
- Slippage — to specify the maximum allowed slippage in pips.
- Delay to wait between modifying orders (in milliseconds) — this is in case you want to delay the execution of the changes; could be necessary with some brokers or systems.
The script is free to download and use.
Downloads➥ Download Set Fixed SL and TP
To install the script, 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.
You can also read a more detailed instruction on how to perform the installation.