Advertisements
$ £ ¥
¥ £ $

PSAR Trailing Stop MT4/MT5 Expert Advisor

The Parabolic SAR, in short PSAR, is a very useful indicator during trending periods. Below you can download a free expert advisor for MetaTrader 4/5 that uses the PSAR indicator to apply trailing stop to your orders.


What is Trailing Stop?

In case you are new to the concept of trailing stop: trailing stop is the practice of moving the stop-loss level closer to the current price when the price moves in your favor.

Trailing the stop-loss allows traders to limit their losses and safeguard their profits. It is a very popular practice.

As you may have read in books and forums, one of the first rules in Forex is Cut your losses short and let your profits run.


What is Parabolic SAR?

We won't get too much into details here, but PSAR is an indicator that follows the trend of the price. It has two parameters to adjust the speed of reaction: step and max step.

The blue dots on the image below are from PSAR set up with step at 0.02 and max step at 0.2.

Example of PSAR Indicator with Step = 0.02, Max Step = 0.2
Example of PSAR Indicator with Step = 0.02, Max Step = 0.2

In MetaTrader 4 MQL4 language, the function to retrieve the value of the Parabolic SAR is iSAR(). You can find more details about the function in the PSAR official MT4 documentation.

In MetaTrader 5 MQL5 language, you would need to create an indicator handle for the Parabolic SAR via a call to iSAR(). You can learn more about it in the PSAR official MT5 documentation.


MT4 PSAR Trailing Stop

About MT4 PSAR Trailing Stop EA
About MT4 PSAR Trailing Stop EA

The expert advisor PSAR Trailing Stop moves the stop-loss of the selected orders by assigning them the value of the PSAR at the previous candle. It is a very simple rule but it can limit losses.

Stop-Loss Following the Parabolic SAR

Why Is MT4 PSAR Trailing Stop EA Useful?

Risk management is one of the most important aspect in trading. Having a stop-loss will protect you from margin calls and big losses.

In many cases, it is useful to have a trailing stop, which is a "moving stop". A trailing stop is a stop-loss where the value is updated when the price moves in the favor of the trade.

There are many types of trailing stop — it can be a fixed step change or it can follow some indicator.

In the case of MT4 PSAR Trailing Stop expert advisor, the stop-loss follows the Parabolic SAR values.

There are several advantages of using MT4 PSAR Trailing Stop EA:

  1. Filtering options to select which trades are managed.
  2. A stop-loss is set automatically if there is none.
  3. The stop-loss follows the price when moving in the favor of the trade.
  4. It doesn't require human interaction.
  5. Limit losses.
  6. Secure profits.
  7. Avoid margin calls.
  8. Notifications when the stop-loss is updated.

Parameters

Trailing Stop PSAR Parameters
Trailing Stop PSAR Parameters

This expert advisor has the following parameters that can be use to configure it:

  • PSAR Step — the value of the step; 0.02 by default.
  • PSAR Max — the value of the maximum step; 0.02 by default.
  • Shift In The PSAR Value — the number of candle to get the PSAR from for the stop-loss. 0 means the current candle.
  • Apply To Current Symbol Only — if true, the EA will apply its trailing stop only to the current chart's symbol. Otherwise, it will calculate a separate PSAR stop-loss for trades on all symbols.
  • Apply To — select which types of orders to apply a trailing stop to.
  • Filter By Magic Number — true or false depending on whether you want to modify only the orders with a specific magic number.
  • Magic Number — specify the magic number in case the above is true.
  • Filter By Comment — true or false depending on whether you want to modify only the orders with a specific comment.
  • Comment — specify the comment if the above is true.
  • Enable Trailing Stop — if true, the EA is active and is trailing stop-losses.
  • Enable Notifications feature — if true, the EA will send notifications upon triggering.
  • Send Alert Notification — if true, the EA will issue native on-screen alerts.
  • Send Notification to Mobile — if true, the EA will send push-notifications to your mobile device.
  • Send Notification via Email — if true, the EA will send emails when it updates a stop-loss.
  • Show Graphical Panel — if true, a graphical panel will appear on the chart to control the expert advisor.

Rules

The expert advisor is configured with the following rules:

  • For Buy orders, the PSAR value of the previous candle must be above the original stop-loss level and below the current price level.
  • For Sell orders, the PSAR value of the previous candle must be below the original stop-loss level and above the current price level.

Remember that we want to move the stop-loss level only in the trade's direction and to never move it back. This ensures decreasing potential loss and increasing potential profit.

Example

In this example, you can see how the stop-loss was moved according to the PSAR (yellow dots).

Example MT4 PSAR Trailing Stop EA Working
Trailing Stop with PSAR Simulation
Results of MT4 PSAR Trailing Stop EA Application to a Trade
Order Updates Log

Trailing stop is a very popular practice in trading. With the MT4 PSAR Trailing Stop, you can have your orders' stop-loss follow the Parabolic SAR indicator.

MT4 PSAR Trailing Stop Panel Looks

Download PSAR Trailing Stop EA for MT4

You can download the MT4 version of this expert advisor using the link below and install it by following the presented instructions.

➥ Download MQLTA MT4 PSAR Trailing Stop

The installation is very easy to perform; the same is the use. Once you run the expert advisor, you can set all the necessary input parameters.

Make sure you enable Live Trading in the Common tab when attaching the EA and also in the platform's menu Tools→Options→Expert Advisors. Otherwise, it won't be able to modify orders.

How to Enable Live Trading for Expert Advisors in MT4?

MT4 PSAR Trailing Stop EA Installation

To install the EA in MetaTrader 4, please follow the instructions below:

  1. Download the expert advisor 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 expert advisors list by right-clicking the Navigator subwindow of the platform and choosing Refresh.

Or you can read a more detailed instruction on how to perform the installation.


MT5 PSAR Trailing Stop

The MT5 version of this PSAR Trailing Stop EA is very similar that for MT4. It will trail stop-loss of all positions based on the filtering parameters. It will calculate PSAR values separately for each currency pair if you select it to work on all symbols.

Download PSAR Trailing Stop EA for MT5

You can download the MT5 version of this expert advisor using the link below and install it by following the presented instructions.

➥ Download MQLTA MT5 PSAR Trailing Stop

The installation is very easy to perform; the same is the use. Once you run the expert advisor, you can set all the necessary input parameters.

Make sure you enable Live Trading in the Common tab when attaching the EA and also in the platform's menu Tools→Options→Expert Advisors. Otherwise, it won't be able to modify orders.

How to Enable Live Trading for Expert Advisors in MT4?

MT5 PSAR Trailing Stop EA Installation

To install the EA in MetaTrader 5, please follow the instructions below:

  1. Download the expert advisor archive file.
  2. Open the MetaTrader 5 data folder (via File→Open Data Folder).
  3. Open the MQL5 Folder.
  4. Copy all the folders from the archive directly to the MQL5 folder.
  5. Restart MetaTrader 5 or refresh the expert advisors list by right-clicking the Navigator subwindow of the platform and choosing Refresh.

Or you can read a more detailed instruction on how to perform the installation.


Conclusion

Using a trailing stop that follows PSAR can be ideal in a situation where there is a clear trend. This type of trailing stop will allow you to follow the trend to protect your trades from unexpected spikes and reversals.

 

You can open a trading account with any of the MT4 Forex brokers to freely use the presented here expert advisor for MetaTrader 4. If you want to use an MT5 version of the expert advisor presented here, you would need to open an account with a broker that offers MetaTrader 5.

Discussion

Do you have any suggestions or questions regarding this expert advisor? You can always discuss PSAR Trailing Stop with other FX traders and MQL programmers on the expert advisors forums.


Changelog

1.05 — 2023-05-25

  • Fixed various bugs that could inhibit normal operation of the EA.

1.04 — 2023-05-05

  • Added an MT5 version of the expert advisor.
  • Added an option to trail stop-losses for all symbols.
  • Added panel scaling on hi-DPI screens.
  • Fixed stop-loss calculation.
  • Fixed the calculation process to take into account the symbol's tick size (useful for CFDs).