OPEN-SOURCE SCRIPT
Dynamic ATR Label

//version=5
indicator("Dynamic ATR Label", overlay=true)
// User definable ATR parameters
atrLength = input.int(14, "ATR Length", minval=1)
priceSource = input.source(close, "Price Source")
// Calculate ATR
atrValue = ta.atr(atrLength)
// Calculate ATR in percentage
atrPercent = (atrValue / priceSource) * 100
// Format the ATR percentage for display
atrText = "ATR: " + str.tostring(atrPercent, "#.##") + "%"
// Create or update the label
var label atrLabel = na
if na(atrLabel)
// Create the label on the first bar
atrLabel := label.new(x=bar_index, y=high, text=atrText,
xloc=xloc.bar_index, yloc=yloc.price, // Define how x and y are interpreted
style=label.style_label_down, color=color.blue,
textcolor=color.white, size=size.normal)
else
// Update the label's position and text on subsequent bars
label.set_xy(atrLabel, x=bar_index, y=high) // Only update x and y coordinates
label.set_text(atrLabel, atrText)
indicator("Dynamic ATR Label", overlay=true)
// User definable ATR parameters
atrLength = input.int(14, "ATR Length", minval=1)
priceSource = input.source(close, "Price Source")
// Calculate ATR
atrValue = ta.atr(atrLength)
// Calculate ATR in percentage
atrPercent = (atrValue / priceSource) * 100
// Format the ATR percentage for display
atrText = "ATR: " + str.tostring(atrPercent, "#.##") + "%"
// Create or update the label
var label atrLabel = na
if na(atrLabel)
// Create the label on the first bar
atrLabel := label.new(x=bar_index, y=high, text=atrText,
xloc=xloc.bar_index, yloc=yloc.price, // Define how x and y are interpreted
style=label.style_label_down, color=color.blue,
textcolor=color.white, size=size.normal)
else
// Update the label's position and text on subsequent bars
label.set_xy(atrLabel, x=bar_index, y=high) // Only update x and y coordinates
label.set_text(atrLabel, atrText)
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
開源腳本
本著TradingView的真正精神,此腳本的創建者將其開源,以便交易者可以查看和驗證其功能。向作者致敬!雖然您可以免費使用它,但請記住,重新發佈程式碼必須遵守我們的網站規則。
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。