ATR Trailing Stop Indicator

I rely on this script for both my live trading and my backtesting process. I couldn’t live without it. It’s extremely simple – all it does is calculate your trailing stop price.

How It Works

The first number in blue is the current ATR (pips). The second number in green is your trailing stop loss price for Long trades, and the third number in red is your trailing stop loss price for Short trades.

For short trades, the stop loss price is calculated by adding the current ATR value to the highest-high of the given lookback period.

For long trades, the stop loss price is calculated by subtracting the current ATR value from the lowest-low of the given lookback period.


ATR Trailing Stop Loss Indicator

ATR Length:
ATR period (how many candles to include in the calculation).

Use Structure?
If set to true, the script will use swing lows and highs in its calculation. If set to false, the script will ignore swing lows and highs and give you the distance of the ATR from the current candle close instead.

How Far To Look Back For High/Lows:
Candle lookback period for swing high/lows.

ATR X ?:
This controls your ATR multiplier. For example, if you want to use a 2x ATR stop, set this to 2.

Pine Script Basics Course

Source Code

The source code for this particular script is private.

If you’d like to purchase access to all of my source code including detailed video lessons explaining how and why it was written, then you can find more information over at

And if not that’s fine! No hard feelings. Not everyone is willing to invest in their education and I respect that decision. But feel free to help yourself to my wealth of other open-source scripts.

Last Updated: 10th September, 2019

Free Premium Charts!

5 1 vote
Article Rating
Notify of
Newest Most Voted
Inline Feedbacks
View all comments
Edwin Goh
Edwin Goh
1 year ago

the ATR trailing stop indicator loads on my chart, but do you know how to set ATR trailing stop on my trade order

Tayfun Ata Delice
Tayfun Ata Delice
5 months ago

Hello Mathew, thanks for the scripts. I just pasted and saved it in pine script. But it flattens the chart like sma/chandliers…

How can I fix it?

Thank you.


1 month ago

fucking circular bullshit – click for source takes to a page with click to download – which takes to click for source – which takes to click to download….is this just a poorly written clickbait attempt?

2 days ago

Hi Mathew,

Many thanks for the script. Really appreciate it.

I have one question tho, how do you trail the stop loss? From the chart it can be seen that the price has never touched the stop loss (gree/red line).

Once again thanks man

Reply to  niko
2 days ago

Hey Niko! The way I use it is once I’ve entered my position and it goes in my favour, I set my stoploss to the highest line. If I’m long and the line goes down for example, I don’t lower my stop loss. I only raise it.