How to set stop loss based on the ATR indicator?

14 April 2024

We often get the question of how to set the stop loss (SL) to a value using the ATR indicator, instead of using a fixed SL value. In this blog, I'll explain how to achieve this using the EA Builder Pro tool.


If you're used to the standard Stop Loss module, you've probably set SL to a fixed value, which is always set right after opening an order.
You may want to delay setting the SL value (by defining a condition) when SL should be set. The Stop Loss Trailing module will give you that flexibility by setting the precondition (or 'threshold'), which has to be gained, before SL is set.
If you want even more flexibility, the Stop Loss - Conditional module will allow you to set advanced preconditions, by allowing the usage of indicators or functions, or both. An example of a precondition would be that you want to set SL when the price passes the previous candle's close price.

Setting the SL value

Previously mentioned modules give increasing flexibility for deciding when SL is set, hence the name 'precondition', but the value of SL has so far been a fixed value in pips relative to the current price.
If you want flexibility for all aspects of SL, you should use the Stop Loss - Conditional (Pro) module, which allows you to set the value, in addition to the precondition, of SL to the value of indicators and functions.

The ATR example

In this example, we're going to use the ATR indicator to set SL. This is a way to adjust SL depending on market conditions, rather than a fixed value. Since we need a flexible way to set the value of SL, we'll be using the Stop Loss - Conditional (Pro) module.

Precondition of the ATR example

In this example, we want to set the value of SL the moment the order is opened, so we leave the precondition empty.

SL value of the ATR example

In this example, we'll set the SL to:
1,5 times ATR below the previous candle's low.

A more mathematical way to say this is:
previous candle's Low - current candle's ATR * 1.5.

In the language of MetaTrader this is:
Low (Shift 1) - ATR (Shift 0) * 1.5.

Finally, this is how to configure this module in the way we described:

stop loss conditional - pro module setup with ATR