EduardoMattje

ATR Bands

EduardoMattje Cập nhật   
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.
Phát hành các Ghi chú:
I put the new features of the input functions to use, making them more organized. I also removed the option to select a different type of average, because as this script is based on ATR, it should only use the RMA average in which it was designed for. You can still configure the length tho.
Phát hành các Ghi chú:
Now that there are tables on pine, I made use of them on the statistics part.
Phát hành các Ghi chú:
Oops, I forgot to adjust the colors of the lower bands.
Mã nguồn mở

Với tinh thần TradingView, tác giả của tập lệnh này đã xuất bản nó dưới dạng mã nguồn mở, vì vậy các nhà giao dịch có thể hiểu và xác minh nó. Chúc mừng tác giả! Bạn có thể sử dụng mã này miễn phí, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?