Expert Advisor – Trailing Stop with Fixed Step 1.0

In this article you can download a simple Expert Advisor to perform a Trailing Stop on your orders with MetaTrader 4. The trailing stop fixed step is an EA that follows a simple rule with only one step, we will see it in more details and with some examples.

If you want to learn more about Trailing Stop and its automation through Expert Advisors you can read this article.

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

MQL4 Trailing Stop Fixed Step 1.0

download-ea-trailingstopfixedstep_v1-0-1
Presentation

The Trailing Stop Fixed Step is an Expert Advisor for MetaTrader 4.

You can download the code for the Trailing Stop Fixed Step Expert Advisor 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-EA-Expert-Advisors-MT4

Parameters

download-ea-trailingstopfixedstep_v1-0-2
Parameters

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

  • StopLossStep, this is the distance required between the current stop loss and the price, before the stop loss can be moved, this is expressed in pips
  • StopLossMove, this is the number of pips to move the stop loss
  • MoveTakeProfitToo, true or false depending if you want to move also the take profit level
  • 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

Rules

The EA has the following rules:

  • The price moves in the direction of the order, UP for BUY order and DOWN for SELL orders
  • The distance between the stop loss level and the price is equal or greater than a number of pips STEP
  • The stop loss level moves in the direction of the order of a number of pips MOVE
  • MOVE must be smaller than STEP

With this expert advisor you can choose to select which order to manage depending on the Magic Number and or Comment included.

You can also choose if move the Take Profit as well as the Stop Loss.

Examples

These two examples are to explain the machanics of the EA.

I suggest to download the code as we will be using the name of some variables.

Example 1 – BUY order EURUSD open price 1.2670, Stop Loss 1.2620, Take Profit 1.2710, StopLossStep 20, StopLossMove 10 and MoveTakeProfitToo True.

  • When price reaches 1.2620+20=1.2640 the stop loss will be moved of 10 pips to 1.2620+10=1.2630, Take profit same will be moved to 1.2710+10=1.2720
  • When price reaches 1.2630+20=1.2650 the stop loss will be moved of 10 pips to 1.2630+10=1.2640, Take profit same will be moved to 1.2720+10=1.2730

This will continue until the stop loss is hit, in case MoveTakeProfitToo is false the Take Profit will not be changed.

Example 2 – SELL order EURUSD open price 1.2670, Stop Loss 1.2720, Take Profit 1.2620, StopLossStep 20, StopLossMove 10 and MoveTakeProfitToo True.

  • When price reaches 1.2720-20=1.2700 the stop loss will be moved of 10 pips to 1.2720-10=1.2710, Take profit same will be moved to 1.2620-10=1.2610
  • When price reaches 1.2710-20=1.2690 the stop loss will be moved of 10 pips to 1.2710-10=1.2700, Take profit same will be moved to 1.2610-10=1.2600

This will continue until the stop loss is hit, in case MoveTakeProfitToo is false the Take Profit will not be changed.

In the image below you can see a simulation of the Expert Advisor, do not pay attention to the orders that are opened randomly.

You can see that all the yellow lines are events where the Take Profit and Stop Level prices are modified.

download-ea-trailingstopfixedstep_v1-0-3
Simulation of the EA

Conclusion

Using a Trailing Stop is a good practice with many trading strategies, it can help limiting losses.

This version of Trailing Stop follows some simple rules and no indicators.

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.

Furthermore and if you follow me on Social Media I will post tips and other information.

MQL4 Programming for Traders: Build Robust Trading Robots!

Black Algo Trading: Build Your Trading Robot

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