The Parabolic SAR, in short PSAR, is a very useful indicator during trending periods. In this article you can see and download an Expert Advisor for MetaTrader 4 that uses the PSAR to perform a Trailing Stop on your orders.
What is a Trailing Stop?
I assume you already know what is a trailing stop however if not.
Trailing Stop is that practice of moving the Stop Loss level when the price moves in your favor.
Trailing the Stop Loss price allows to limit the losses and the risk and 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 the Parabolic SAR?
We will not go too much into details here.
The PSAR is an indicator that follows the trend of the price and it has two parameters to adjust the speed of reaction, STEP and Max STEP.
The blue dots in the image is a PSAR of STEP 0.02 and 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 here.
Trailing Stop PSAR 1.0
The Expert Advisor TrailingStopPSAR_v1-0.mq4 moves the stop loss of the selected orders assigning the value of the PSAR in the previous candle, it is a very simple rule but it can limit losses.
You can download the Expert Advisor for MetaTrader 4 with the following link, it is free to use.
If you need a more professional Trailing Stop I would suggest to have a look at this link.
This Expert Advisor has the following parameters that can be set:
- PSARStep, the value of the step, by default 0.02
- PSARMaxStep, the value of the maximum step, by default, 0.2
- OnlyMagicNumber, true or false depending if you want to modify only the orders with a specific magic number
- MagicNumber, specify the magic number in case the above is true
- OnlyWithComment. true or false depending if you want to modify only the orders with a specific comment
- MatchingComment, specify the comment if the above is true
- Slippage, slippage in pips
- Delay, delay to wait before change the next order in the queue
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 always in the direction of the order and never make it larger than the original. This is because of fundamental risk management rules.
In this example we can see how the Stop Loss is moved following the PSAR (yellow dots).
Using a trailing stop that follows the PSAR can be ideal in a situation where there is a clear trend. This type of trailing stop will allow to follow the trend the protect the order from unexpected spikes or reverse.
You can download the source code to use or study it for free with the following link.
I remember when I first started to learn MQL coding, although I had some knowledge of coding many concept
I remember when I first started to learn MQL coding it was quite tough.
Although I had some knowledge of coding many concept were still unclear.
To speed up your learning process I would recommend to follow a quick MQL course.
It will give you the fundamentals you need to create functional Trading Robot.
You can check out the following two course, Udemy often has sales on to make the courses even more affordable.
Furthermore and if you follow me on Social Media I will post tips and other information.
If you found this article useful or if you have any question please feel free to leave a comment below or Contact Us.