Expert Advisor – Trailing Stop following Fractals Indicator 1.0

As you already saw in another article Fractals can be a very useful indicator. In this article you can download the Trailing Stop Fractals Expert Advisor for MetaTrader 4 that uses Fractals to trail the Stop Loss level of an order.

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 indicator Fractals?

We examined in more details the Fractals indicator in this article.

In short, fractals are represented with arrows and highlight points where the price stops and reverses.

Fractals example
Fractals example

In MetaTrader 4 MQL4 language the function to retrieve the value of Fractals is iFractals().

You can see how to use it in this article.

Trailing Stop following Fractals 1.0

Trailing Stop following Fractals presentation
Trailing Stop following Fractals presentation

The Expert Advisor TrailingStopFractals_v1-0.mq4 moves the stop loss of the selected orders assigning the value of the most recent Fractal.

It can be very useful in trending periods to follow the trend and cut 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.



Trailing Stop Fractals parameters
Trailing Stop Fractals parameters

This Expert Advisor has the following parameters that can be set:

  • 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 it is used the most recent lower fractal
  • For Sell orders it is used the most recent upper fractal

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.


We can see an ideal example of this Expert Advisor.

The Trailing Stop moves the Stop Loss level when it detects a new Fractal and meets the conditions.

Example of Fractal following 1
Example of Fractal following 1
Example of Fractal following 2
Example of Fractal following 2
Example of Fractal following 3
Example of Fractal following 3


One of the uses of Fractals is the detection of support and resistance levels.

With this Exprert Advisor we can Trail the Stop Loss level to this prices.

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 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.

Also, if you follow me on Social Media I will post tips and topics to assist in the process.

MQL4 Programming for Traders: Build Robust Trading Robots!

Black Algo Trading: Build Your Trading Robot

If you found this article useful or if you have any question please feel free to leave a comment below or Contact Us.

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!

Leave a Comment

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