OPEN-SOURCE SCRIPT

Dynamic ATR Label

52
//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)

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.