EduardoMattje

ATR Bands

EduardoMattje 업데이트됨   
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.
릴리즈 노트:
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.
릴리즈 노트:
Now that there are tables on pine, I made use of them on the statistics part.
릴리즈 노트:
Oops, I forgot to adjust the colors of the lower bands.
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?