ATR+ (Stop Loss Indicator)




This is a trading tool that I use every single day. I could not live without it for both my live trading and especially my back-testing. It calculates your stop loss size (in pips) based on the current ATR.

If you like this indicator then you might also like my ATR By Time indicator which calculates the current ATR based on the trading session / time of day instead of recent price action:

How It Works

The first number in blue is the current ATR (pips). The second number in green is your stop loss size for Long trades, and the third number in green is your take profit size for Long trades. The fourth number in red is your stop loss size for Short trades, and the final number in red is your take profit size for Short trades.

For short trades, the stop loss value is calculated by adding the distance in pips between the most recent swing high’s price and the currently selected candle’s close price. The take profit is calculated by subtracting one ATR from your entry price.

For example – if the ATR is 10 pips, and the current candle-close of EUR/USD is 1.13, with the most recent swing high being 1.1325, and you want to enter short, then your stop loss would be at 1.1335 (a size of 35 pips). With a 2:1R, your take profit size would be 70 pips (at 1.1265).

Settings

R/R:
Your risk to reward profile.

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

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

Stop Distance (In Pips Or ATR): This controls your ATR multiplier, or sets your S/L in pips.

Use ATR x ^ for stop loss?: If you uncheck this, then the Stop Distance setting will be treated as pips instead of an ATR multiplier.



Source Code

// Created by Matthew J. Slabosz
// www.zenandtheartoftrading.com
// @version=4
study("ATR+ (Stop Loss Indicator)", "ATR+", overlay=false, precision=1)

// Get user input
riskratio = input(title="R/R:", type=input.float, defval=1, minval=0.1)
atrLength = input(title="ATR Length:", type=input.integer, defval=14, minval=1)
lookback = input(title="How Far To Look Back For High/Lows:", type=input.integer, defval=3, minval=1)
stopSizeInput = input(1.0, minval=0.0, title="Stop Distance (in pips or ATR):")
stopSizeUseATR = input(title="Use ATR x ^ for stop loss?", type=input.bool, defval=true)

// Calculate ATR
atrValue = atr(atrLength)
decimals = abs(log(syminfo.mintick) / log(10))
atrWhole = atrValue
if decimals == 5
    atrWhole := atrValue * 10000
if decimals == 4
    atrWhole := atrValue * 1000
if decimals == 3
    atrWhole := atrValue * 100
if decimals == 2
    atrWhole := atrValue * 10

// Calculate stop loss info
stopSizeATR = stopSizeInput
if decimals == 5
    stopSizeATR := stopSizeATR / 10000
if decimals == 4
    stopSizeATR := stopSizeATR / 1000
if decimals == 3
    stopSizeATR := stopSizeATR / 100
if decimals == 2
    stopSizeATR := stopSizeATR / 10
if stopSizeUseATR
    stopSizeATR := atrValue * stopSizeInput

// Get SL pips
longEntrySize = close - lowest(low, lookback) + stopSizeATR
shortEntrySize = highest(high, lookback) - close + stopSizeATR

// Convert stop sizes to whole number
if decimals == 5
    longEntrySize := longEntrySize * 10000
    shortEntrySize := shortEntrySize * 10000
if decimals == 4
    longEntrySize := longEntrySize * 1000
    shortEntrySize := shortEntrySize * 1000
if decimals == 3
    longEntrySize := longEntrySize * 100
    shortEntrySize := shortEntrySize * 100
if decimals == 2
    longEntrySize := longEntrySize * 10
    shortEntrySize := shortEntrySize * 10

// Plot data
plot(atrWhole, color=color.teal, style=plot.style_circles, title="ATR", transp=100)
plot(longEntrySize, color=color.green, style=plot.style_circles, title="Long Entry Size", transp=100)
plot(longEntrySize * riskratio, color=color.green, style=plot.style_circles, title="Long Target Size", transp=100)
plot(shortEntrySize, color=color.red, style=plot.style_circles, title="Short Entry Size", transp=100)
plot(shortEntrySize * riskratio, color=color.red, style=plot.style_circles, title="Short Target Size", transp=100)

Last Updated: 16th September, 2019


TradingView Charting Platform

Leave a Comment, Question or Suggestion