Skip to main content

How to Trail Stop Losses After Profit

Learn how trailing stop management works: Select Trades, Check Profit/Loss, Modify SL/TP, fixed-pip trailing after 10/20 pips, breakeven, lock-in profit, variables, Count Trades, and common setup mistakes.

Use this article to understand how trailing stop-loss management works in the Builder.

This includes:

  • trailing a stop loss after a trade reaches profit

  • moving a stop loss to breakeven

  • locking in profit

  • trailing by fixed pips

  • trailing with a moving average

  • using variables to control multi-step stop-loss logic

Also known as: trailing stop, trail stop loss, move stop loss after 10 pips, breakeven stop loss, lock in profit, fixed-pip trailing, Modify SL/TP, Check Profit/Loss, stop-loss management, trade management template.


Summary

A trailing stop-loss component does not open trades.

It manages trades that already exist.

The basic structure is:

  1. Run the management logic

  2. Select the trades you want to manage

  3. Check whether the trade is in enough profit

  4. Modify the stop loss

  5. Optionally use variables to control the next step

The most important point:

Before modifying a stop loss, the EA must know which trade is in scope. That is why management templates usually use Select Trades before Modify SL/TP.


Template links

Main template for this article:

Other related management templates from the video:


What trailing stop management does

Trailing stop management updates the stop loss of an existing trade after a condition is met.

Examples:

  • If a trade is 10 pips in profit, move the stop loss to a fixed-pip distance.

  • If a trade is 20 pips in profit, tighten the stop loss further.

  • If a trade is 1% in profit, move the stop loss to a moving average.

  • If a trade is 1% in profit, move the stop loss to breakeven.

  • If a trade is 2% in profit, move the stop loss above entry to lock in profit.

The exact rule depends on the blocks you use.

The Builder does not force one trailing-stop style. You decide what triggers the stop-loss update and where the new stop loss should be placed.


Run per Candle

Runs the management logic once when a new candle forms.

This is useful when you only want to update the stop loss once per candle, for example at every candle close or new candle open.

Most trailing stop examples use Run per Candle because it keeps the management logic controlled and easier to debug.


Run per Tick

Runs the logic on every market price update.

This can be useful for reset logic, for example when you want to detect quickly that no trade is open anymore and reset a variable.

Be careful with Run per Tick. It can trigger very frequently.


Trade Rule

Compares two values.

In trailing-stop templates, Trade Rule is often used to check whether a variable is active or inactive.

Example:

OnOff = 0

This means the first trailing step is still allowed.

Example:

OnOff = 1

This means the first trailing step already happened and the next trailing step can now be checked.


Select Trades

Selects which trades the following management blocks should affect.

This is mandatory in most trade management logic.

You can filter by:

  • buy trades

  • sell trades

  • symbol

  • group number

  • trade source

Example:

If your component should only manage sell trades, use Select Sell Trades.

If your component should only manage trades from one specific strategy, use a group number.

Do not skip this block. Without a clean selection step, you may manage the wrong trades or make the logic harder to control.


Check Profit/Loss

Checks whether the selected trade is in enough profit or loss.

Examples:

  • trade is at least 10 pips in profit

  • trade is at least 20 pips in profit

  • trade is at least 1% in profit

  • trade reached a specific money amount

This block decides when the stop-loss management should activate.


Modify SL/TP

Changes the stop loss and/or take profit of the selected trade.

In this article, we focus on stop loss only.

The stop loss can be adjusted in different ways, for example:

  • fixed pips

  • breakeven

  • moving average value

  • candle high or low

  • another price level

You can leave take profit unchanged if the template only manages the stop loss.


Modify Variables

Updates a variable while the EA is running.

In the staged trailing example, a variable is used as an on/off switch.

Example:

  • OnOff = 0 means the first trailing step has not happened yet.

  • OnOff = 1 means the first trailing step has happened and the second step is now allowed.

This is useful when users want the EA to manage the stop loss multiple times in a controlled sequence.


Example 1: Simple trailing stop with a moving average

This is the classic trailing stop style.

The logic:

  1. Run once per candle

  2. Select the trades to manage

  3. Check whether the trade is in enough profit

  4. Move the stop loss to a moving average value

Example:

If a trade is at least 1% in profit, the EA moves the stop loss to the EMA 20 value.

Then, on every new candle, the EA checks again. If the condition is still true, the stop loss is updated again based on the latest moving average value.

This is useful when you want the stop loss to follow market structure or trend movement instead of using a fixed pip distance.


Example 2.1: Start trailing after 10 pips of profit

This is the new fixed-pip example.

The goal:

When a sell trade reaches 10 pips in profit, adjust the stop loss using a fixed-pip setting.

In the example template, the first stop-loss adjustment uses 50 pips.

The logic:

  1. Run per Candle

  2. Check whether OnOff = 0

  3. Select Sell Trades

  4. Check whether price moved at least 10 pips in profit

  5. Modify the stop loss using Fixed pips

  6. Set OnOff = 1


Why the OnOff variable is needed

The OnOff variable prevents the first stop-loss adjustment from being repeated forever.

By default:

OnOff = 0

This means the first step is still allowed.

Once the trade reaches 10 pips in profit and the stop loss is adjusted, the template changes the variable:

OnOff = 1

Now the first decision tree is blocked, and the second decision tree can take over.

This is how you turn specific parts of your trade management logic on and off while the EA is running.


Example 2.2: Tighten the stop loss after 20 pips of profit

The second stage starts after the first stage has already happened.

The goal:

When the selected sell trade reaches 20 pips in profit, tighten the stop loss further.

In the example template, the second stop-loss adjustment uses 20 pips.

The logic:

  1. Run per Candle

  2. Check whether OnOff = 1

  3. Select Sell Trades

  4. Check whether price moved at least 20 pips in profit

  5. Modify the stop loss using Fixed pips

This creates a simple two-step trailing model:

  • at 10 pips profit, apply the first stop-loss rule

  • at 20 pips profit, apply the tighter stop-loss rule

You can change the pip values and stop-loss settings to fit your own strategy logic.


Example 2.3: Reset the OnOff variable when the trade is closed

The staged trailing logic uses a variable.

That variable also needs to be reset.

If the trade closes because of stop loss, take profit, or manual closure, the trade count goes back to zero.

The reset tree checks for this and sets the variable back to zero.

The logic:

  1. Run per Tick

  2. Count Trades

  3. If no matching trade is open anymore, set OnOff = 0

This prepares the component for the next trade.

Without this reset, the EA may stay stuck at OnOff = 1, meaning the first trailing step would not activate correctly for the next trade.

Important:

Make sure Count Trades uses the same scope as the trades you manage.

If the trailing component manages only sell trades, the reset logic should also check the relevant sell trades. If your strategy uses group numbers or symbols, keep the filters consistent.


Why the staged trailing template uses three decision trees

The updated fixed-pip template uses three decision trees because each tree has a separate job.

Tree 1: First stop-loss adjustment

This tree waits for 10 pips in profit.

Then it adjusts the stop loss and switches OnOff from 0 to 1.

Tree 2: Second stop-loss adjustment

This tree only becomes active after OnOff = 1.

Then it waits for 20 pips in profit and adjusts the stop loss again.

Tree 3: Reset logic

This tree checks whether the trade is closed.

If no relevant trade is open anymore, it resets OnOff back to 0.

This makes the component reusable for the next trade.


Breakeven trailing

Breakeven trailing is a simpler version of stop-loss management.

The idea:

When a trade reaches a defined profit threshold, move the stop loss to the entry price.

Example:

If a trade reaches 1% profit, move stop loss to breakeven.

The logic:

  1. Run per Candle

  2. Select Trades

  3. Check Profit/Loss

  4. Modify SL/TP to entry price

This can help prevent a winning trade from turning into a full losing trade.

Important:

Breakeven does not guarantee zero loss in every real trading situation. Spread, slippage, execution quality, and broker conditions can still affect the final result.


Lock-in profit management

Lock-in profit management goes one step further than breakeven.

Instead of moving stop loss to the entry price, the EA moves the stop loss beyond the entry price to secure a profit if price reverses.

Example:

If a trade reaches 2% profit, move the stop loss to lock in 1% profit.

The logic:

  1. Run per Candle

  2. Select Trades

  3. Check whether the trade reached the profit threshold

  4. Modify the stop loss above or below the entry price, depending on trade direction

For buy trades, the stop loss is moved above the entry price.

For sell trades, the stop loss is moved below the entry price.


Candle high/low trailing

Candle high/low trailing uses candle structure instead of fixed pips or an indicator.

Example:

For a buy trade, the EA may move the stop loss to a previous candle low.

For a sell trade, the EA may move the stop loss to a previous candle high.

The logic:

  1. Run per Candle

  2. Select Trades

  3. Check whether the trade is in enough profit

  4. Modify stop loss to a candle high or candle low

This can make sense when you want the stop loss to follow recent market structure.


Partial profit taking vs trailing stop

Partial profit taking and trailing stops are different management styles.

Partial profit taking closes part of the trade.

Trailing stop management keeps the trade open but changes the stop loss.

Example:

Partial profit taking:

  • Close 50% of the trade at 1% profit

  • Close another part at 2% profit

  • Let the rest continue

Trailing stop:

  • Keep the trade open

  • Move the stop loss as price moves in your favor

You can combine both, but test carefully. Too many management rules can conflict or make the results harder to understand.


Common mistakes

1. Forgetting Select Trades

Modify SL/TP needs to know which trade to manage.

Use Select Trades before management actions.

If you only want to manage sell trades, select sell trades.

If you only want to manage one strategy, use group numbers.


2. Using the wrong trade direction

Buy and sell trades need different stop-loss logic.

For buys, stop losses usually move upward as price moves in profit.

For sells, stop losses usually move downward as price moves in profit.

Make sure your template matches the trade direction your strategy actually uses.


3. Mixing percentage profit and pip profit

Check Profit/Loss can be used in different ways.

A rule like “1% profit” is not the same as “10 pips in profit.”

Be clear about what you want:

  • percentage of balance

  • money amount

  • pips

  • another profit/loss condition


4. Not resetting variables

If you use an on/off variable, reset it when the trade is closed.

Otherwise, the next trade may start with the wrong variable state.

In the staged trailing example, OnOff should go back to 0 once no matching trade is open anymore.


5. Using one OnOff variable for multiple trades

A single global OnOff variable is simple, but it is best suited for systems that manage one trade at a time.

If your EA can manage multiple trades at the same time, one shared variable may not be enough.

In that case, use stricter trade filters, group numbers, or a simpler management structure.


6. Making the stop loss too tight too early

If the stop loss is moved too close to price too quickly, the trade may close before the setup has enough room to develop.

This is not a Builder issue. It is a strategy design issue.

Test different thresholds and stop-loss distances in MT5 before deciding which version to use.


7. Running every management rule at the same time

If you combine breakeven, fixed-pip trailing, moving average trailing, partial profit taking, and lock-in profit, your logic can become messy fast.

Start with one management component.

Test it.

Then add the next layer only if you understand exactly what it changes.


How to test trailing stop logic in MT5 Visual Mode

Use MT5 Visual Mode to check the management behavior candle by candle.

Look for:

  1. Did the EA select the correct trade?

  2. Did the stop loss only move after the profit threshold was reached?

  3. Did the stop loss move to the expected level?

  4. Did the variable switch from 0 to 1 after the first adjustment?

  5. Did the second trailing step only activate after the variable changed?

  6. Did the variable reset after the trade closed?

  7. Did the EA manage only the intended buy/sell trades?

  8. Did the stop loss move too early, too late, or too often?

If something looks wrong, do not change everything at once.

Change one block setting, export again, and retest.


How to choose the right trailing style

Use fixed pips when you want simple, measurable stop-loss movement.

Use breakeven when you want to reduce downside after a trade reaches a profit threshold.

Use lock-in profit when you want to secure part of the open profit after price has moved far enough.

Use moving average trailing when you want the stop loss to follow trend movement.

Use candle high/low trailing when you want the stop loss to follow recent price structure.

There is no universal best version.

The right version depends on your entry logic, timeframe, symbol, volatility, and risk model.


Make it your own

You can adjust:

  • the profit trigger, for example 10 pips, 20 pips, 1%, or 2%

  • the trade direction, for example buy trades, sell trades, or both

  • the selected symbol or group number

  • the stop-loss mode

  • the fixed-pip distance

  • the moving average period

  • the candle high/low reference

  • whether the take profit stays active or is removed

  • whether the logic runs per candle or per tick

  • whether variables are used for staged management

Best practice:

Start simple.

Build one management component first. Confirm it works in Visual Mode. Then add more advanced layers.


Conclusion

Trailing stop management is built from a simple block pattern:

Run logic → Select Trades → Check Profit/Loss → Modify SL/TP

For simple trailing, this is enough.

For multi-step trailing, use variables.

In the staged fixed-pip example, the OnOff variable controls which part of the management logic is active:

  • OnOff = 0 allows the first trailing step

  • after 10 pips in profit, the stop loss is adjusted and OnOff becomes 1

  • OnOff = 1 allows the second trailing step

  • after the trade closes, the reset tree sets OnOff back to 0

This gives you a clean way to build stop-loss management that changes as the trade develops.

Templates are for educational purposes only. Always backtest and validate your logic before using it in live trading.

Did this answer your question?