ATR Bands

It has happened to everybody. You enter the market, the position gets a stop loss, then later the market goes in the direction you originally planned. Worse yet - you enter a position, the market goes in your favor, gets near the target, and then it reverses and you get stopped.

We brazilians call this a "violinado", or getting violinated. It happens either because:
1. You put the stop loss too close, or the target too far
2. You entered in the right direction, but at a wrong time

While the second point cannot be programmly adressed, the first can. One popular way of setting a stop loss is by using the average of the true range, it even has a built-in indicator in TV. The problem with it is that you can still get violinated, since as the trend develops, the stop loss only goes up, never down. So if you enter at the wrong time, one slip can still take you out of the market.

Since I got sick of losing money using a conventional stop loss, I made these ATR bands. When you add this indicator to your graph, 6 lines are going to show up, 3 above the price, 3 below it. These lines are calculated from the ATR of the last 20 periods (can be configurated). The upper lines are the high of the last candle + the ATR * the multiplicator factor, the lower lines are the low - ATR * multiplicator factor. There are three multiplicator factors: 1.0, 1.618 and 2.0, and you change them to be whatever you want.

The logic behind it is that theses bands represents the region in which the market is more likely to stay. So if you enter the market at 50.00, you can't expect it to reach 500.00 in the next hour if the ATR is 5.00. And if you set the stop loss at 49.99, it is very likely that the market is going to stop you. By using the ATR bands, you can get a more reasonable price range, so you would set the stop loss at 45.00 and the take profit level at 60.00.

There are two types os ATR you can use: the regular, calculated with RMA, and another using a custom WMA , which puts greater emphasis on large amplitudes. By default, the average uses the past 20 true ranges. You can also choose to use either the closing price or the extremes of the candle as a basis.

Another thing I've added is the violation statistics, which shows the percentages of the times that a band was violated in the next 5 candles (can be configurated). With this, you can get a broader view on the probability of the bands actually being reached.

You may have notice that the bands are lagged by 1 period. I did this so that there is no way you can use future data. You can disable it or increase it, but I recommend just letting it be 1. These bands are the range in which the price is most likely to stay in, if you change the lag you are essentially breaking it's whole purpose.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Want to use this script on a chart?


Great work! Thank you
Home Stock Screener Forex Screener Crypto Screener Economic Calendar About Chart Features Pricing Refer a friend House Rules Help Center Website & Broker Solutions Widgets Charting Solutions Lightweight Charting Library Blog & News Twitter
Profile Profile Settings Account and Billing Referred friends Coins My Support Tickets Help Center Private Messages Chat Sign Out