TTD - True Range Above Candles

mcarter-griffith · study · 32 行 · 点赞 11 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
indicator("TTD - True Range Above Candles", overlay=true, max_labels_count=500)
 
// Settings
showTR = input.bool(true, "Show True Range")
decimals = input.int(2, "Decimal Places", minval=0, maxval=6)
offsetATR = input.float(0.20, "Label Distance (ATR)", minval=0.0, step=0.05)
textColor = input.color(color.yellow, "Text Color")
labelSize = input.string("Tiny", "Text Size", options=["Tiny", "Small", "Normal"])
 
// True Range calculation
tr = ta.tr(true)
atr = ta.atr(14)
 
// Format value
formatTR = decimals == 0 ? "#" : decimals == 1 ? "#.0" : decimals == 2 ? "#.00" : decimals == 3 ? "#.000" : decimals == 4 ? "#.0000" : decimals == 5 ? "#.00000" : "#.000000"
 
trText = str.tostring(tr, formatTR)
 
// Label size
txtSize = labelSize == "Small" ? size.small : labelSize == "Normal" ? size.normal : size.tiny
 
// Display True Range below each candle
if showTR and not na(tr)
    label.new(
         x=bar_index,
         y=low - atr * offsetATR,
         text=trText,
         style=label.style_none,
         textcolor=textColor,
         size=txtSize
     )

← 返回列表