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 period (how many candles to include in the calculation).
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.
Here is the chart companion script for this indicator:
Go to https://zenandtheartoftrading.com/indicators/atr-trailing-stop-indicator/ for the source code – it’s free!
Go to http://www.zenandtheartoftrading.com for articles on forex trading, trading psychology, trading resources, Pine Script lessons and more!
I personally try to shoot for 2 ATR worth of profit before I consider exiting my profitable trades. If you risk 1% per trade and you're making +2% on your average winner, then you only need to win about 35% of your trades to be profitable over the long-term (key word being "average winner" - not all your winners will be that big, but over a large sample size, the average ought to be well over 1% on your average winner unless your strategy has a 60%+ win rate).
This video might help you understand the math behind risk:reward and risk management: https://www.youtube.com/watch?v=PGkOH-oFOSI&%3Blist=PLSP_1DBafH-Eh33zVCtmy3FuqULNn5nt1&%3Bindex=4