OPEN-SOURCE SCRIPT
업데이트됨 Filt ADR

🟠 Script Name: Filtered Average Daily Range (Filt ADR)
This script calculates a filtered version of the Average Daily Range (ADR) based on the last 14 daily candles. It's designed to reduce the influence of unusually high or low daily ranges (outliers) by applying a filter before calculating the average.
🔧 How It Works — Step by Step
1. Calculate Daily Ranges (High - Low)
It retrieves the daily price ranges (difference between daily high and low) for the last 14 days using request.security() with the "D" (daily) timeframe.
pinescript
Копировать
Редактировать
high[0] - low[0] // today's daily range
high[1] - low[1] // yesterday's daily range
...
These values are stored into individual variables dr0 to dr13.
2. Build an Array of Daily Ranges
An array named ranges is used to store the 14 daily ranges, but only if they are not na (missing data). This avoids errors during processing.
3. Calculate the Initial (Unfiltered) Average Range
The script sums all values in the ranges array and calculates their average:
pinescript
Копировать
Редактировать
avg_all = total sum of ranges / number of valid entries
4. Filter Out Outliers
Now it filters the values in ranges:
Only keeps the ranges that are between 0.5×avg_all and 2×avg_all.
This is to remove abnormally small or large daily ranges that could distort the average.
The filtered values are added to a second array called filtered.
5. Calculate the Filtered ADR
Finally, it calculates the average of the filtered daily ranges:
pinescript
Копировать
Редактировать
avg_filt = sum of filtered ranges / number of filtered values
This is the Filtered ADR.
6. Plot the Result
The result (avg_filt) is plotted as an orange line on the chart. It updates on each bar (depending on the current timeframe you're viewing) but the underlying data is based on the last 14 daily candles.
pinescript
Копировать
Редактировать
plot(avg_filt, title="Filtered ADR", color=color.orange, linewidth=2)
✅ Use Case
This script is useful for traders who use the Average Daily Range (ADR) to:
Estimate expected price movement during a day
Set volatility-based stop-loss or take-profit levels
Identify days with unusually high or low volatility
By filtering out extreme values, it provides a more stable and reliable estimate of daily volatility.
This script calculates a filtered version of the Average Daily Range (ADR) based on the last 14 daily candles. It's designed to reduce the influence of unusually high or low daily ranges (outliers) by applying a filter before calculating the average.
🔧 How It Works — Step by Step
1. Calculate Daily Ranges (High - Low)
It retrieves the daily price ranges (difference between daily high and low) for the last 14 days using request.security() with the "D" (daily) timeframe.
pinescript
Копировать
Редактировать
high[0] - low[0] // today's daily range
high[1] - low[1] // yesterday's daily range
...
These values are stored into individual variables dr0 to dr13.
2. Build an Array of Daily Ranges
An array named ranges is used to store the 14 daily ranges, but only if they are not na (missing data). This avoids errors during processing.
3. Calculate the Initial (Unfiltered) Average Range
The script sums all values in the ranges array and calculates their average:
pinescript
Копировать
Редактировать
avg_all = total sum of ranges / number of valid entries
4. Filter Out Outliers
Now it filters the values in ranges:
Only keeps the ranges that are between 0.5×avg_all and 2×avg_all.
This is to remove abnormally small or large daily ranges that could distort the average.
The filtered values are added to a second array called filtered.
5. Calculate the Filtered ADR
Finally, it calculates the average of the filtered daily ranges:
pinescript
Копировать
Редактировать
avg_filt = sum of filtered ranges / number of filtered values
This is the Filtered ADR.
6. Plot the Result
The result (avg_filt) is plotted as an orange line on the chart. It updates on each bar (depending on the current timeframe you're viewing) but the underlying data is based on the last 14 daily candles.
pinescript
Копировать
Редактировать
plot(avg_filt, title="Filtered ADR", color=color.orange, linewidth=2)
✅ Use Case
This script is useful for traders who use the Average Daily Range (ADR) to:
Estimate expected price movement during a day
Set volatility-based stop-loss or take-profit levels
Identify days with unusually high or low volatility
By filtering out extreme values, it provides a more stable and reliable estimate of daily volatility.
릴리즈 노트
🔧 General Idea:The script displays the average daily range, but it excludes outlier days — those that are too small or too large compared to others. This makes the indicator more resistant to anomalies, such as gaps or high-volatility news days.
📌 Detailed Logic:
1. Collecting Daily Ranges for the Last 14 Days
pinescript
Копировать
Редактировать
drs = array.from(request.security(syminfo.tickerid, "D", high[0] - low[0]), ...)
Retrieves the daily range (high - low) for today and the previous 13 days.
request.security(..., "D", ...) is used to get daily data even when the indicator runs on a lower timeframe (e.g., 15-minute chart).
All values are stored in the drs array.
2. Calculating the Unfiltered Average
pinescript
Копировать
Редактировать
sum_all = 0.0
count_all = 0
for i = 0 to array.size(drs) - 1
val = array.get(drs, i)
if not na(val)
sum_all += val
count_all += 1
avg_all = count_all > 0 ? sum_all / count_all : na
Sums up all non-na values and counts how many were used.
Computes the simple average (avg_all) of all daily ranges.
3. Filtering Outliers
pinescript
Копировать
Редактировать
for i = 0 to array.size(drs) - 1
val = array.get(drs, i)
if not na(val) and val >= 0.5 * avg_all and val <= 2.0 * avg_all
sum_filt += val
count_filt += 1
avg_filt = count_filt > 0 ? sum_filt / count_filt : na
Keeps only those values between 0.5 and 2.0 times the unfiltered average.
This excludes unusually low (quiet days) or unusually high (volatile days) ranges.
Calculates the filtered average (avg_filt) based on the remaining data.
4. Displaying on the Chart
pinescript
Копировать
Редактировать
plot(avg_filt, title="Filtered ADR", color=color.new(color.orange, 0), linewidth=2)
Plots the avg_filt result as a line on the chart.
The line is orange, fully opaque (opacity = 0), with a width of 2.
✅ Result:
You get a smoothed average daily range over the last 14 days, excluding anomalies. This can be useful for:
Evaluating normal market volatility;
Building ATR-based reaction zones;
Setting stop-losses/take-profits based on average price movement.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.