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.

About MT4 Script Set Fixed SL and TP

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.

Set Fixed SL and TP - Input Parameters

Warning! This script will update also SL and TP for positions that already have SL and TP set, overwriting pre-existing parameters. Please also note that this script will work only with orders for the currency pair it is being applied to.

The script is free to download and use.

➥ Download Set Fixed SL and TP

To install the script, please follow the instructions below:

  1. Download the script archive file.
  2. Open the MetaTrader 4 data folder (via File→Open Data Folder).
  3. Open the MQL4 Folder.
  4. Copy all the folders from the archive directly to the MQL4 folder.
  5. 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.

© 2005–2021

EarnForex.com

Design — Mart Studio

Forex trading bears intrinsic risks of loss. You must understand that Forex trading, while potentially profitable, can make you lose your money. Never trade with the money that you cannot afford to lose! Trading with leverage can wipe your account even faster.

CFDs are leveraged products and as such loses may be more than the initial invested capital. Trading in CFDs carry a high level of risk thus may not be appropriate for all investors.