Script – SetFixedSLandTP 1.0

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 the 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 script SetFixedSLandTP (short for Set Fixed Stop Loss and Take Profit) allows you to set a stop loss and an optional take profit price to all the open orders in a determined currency.

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 following 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 make it faster for you.

You can download the script for educational purposes and test it on a Demo Account.

Download Here


When you run the script on a chart you can set some parameters in order 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 martching the magic number, can be false or true and it specifies if you want to limit the changes only to orders of a specific magic number
  • Matching magic number, in case the previous is true you need to specify which magic number to use for the match
  • Modify only oders with the following comment, can be false or true depending if you want to modify only orders with a specific comment
  • Matching comment, write the comment to match in case the previous is true
  • Slippage, to specify the slippage in pips
  • Delay to wait between modifying orders (in milliseconds), this is in case you want to delay the execution of the changes, may be necessary with some brokers or systems


The script is free to download and use.

Download Here

Please leave a comment if you have any feedback or doubt and remember to like us on Social Media!

I would really appreciate also suggestions for improvements and reports of any bug found. Thank you!

If you want to save hours of research and coding and you want to see some professional code check this out! You can use it to build your own EA!

7 thoughts on “Script – SetFixedSLandTP 1.0”

  1. Hello,

    I was not able to attach the script to the chart. MT4 gave me an error message that said “‘SetFixedSLandTP_v1-0’ is not expert and cannot be executed”. Thanks.

    • Hi Andy,
      Looks like you are trying to attach it as an Expert rather than a Script. The code is a script, you need to copy it in the script folder and compile it then you will find it in the script section of MetaTrader.


  2. i think this doesn’t work on my Oanda MT4 build 1170.. Can’t attach it a simple Open Limit or Stop order.

    Got and suggestions or updates? Thx

    • Hi Randy,
      This doesn’t work with Limit orders, it only works with open market orders
      You need to edit the code if you want it to work with Limit orders too


Leave a Comment

We use cookies to ensure that we give you the best experience on our website.