Minimalist Price Movement Label

nathaliechou · study · 40 行 · 点赞 11 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Meowella7777
 
//@version=6
 
indicator("Price Movement Label", overlay = true)
 
showPercent = input.bool(true, "Show percentage")
showPrice = input.bool(false, "Show current price")
showCountdown = input.bool(false, "Show candle countdown")
 
var float startPrice = na
var label priceLabel = label.new(
     na, na, "", style = label.style_label_left,
     textcolor = color.white, size = size.normal)
 
if time == chart.left_visible_bar_time
    startPrice := open
 
if time == chart.right_visible_bar_time and not na(startPrice) and startPrice != 0
    movement = (close / startPrice - 1) * 100
    labelText = ""
 
    if showPercent
        labelText := str.tostring(movement, "#.###") + " %"
 
    if showPrice
        labelText += (labelText == "" ? "" : "\n") + str.tostring(close, format.mintick)
 
    if showCountdown and barstate.isrealtime and not na(time_close)
        remaining = math.max(0, int(math.ceil((time_close - timenow) / 1000)))
        minutes = int(remaining / 60)
        seconds = remaining % 60
        labelText += (labelText == "" ? "" : "\n") +
             str.tostring(minutes, "00") + ":" + str.tostring(seconds, "00")
 
    label.set_xy(priceLabel, labelText == "" ? na : bar_index + 1, close)
    label.set_text(priceLabel, labelText)
    label.set_color(priceLabel, movement < 0 ?
         color.rgb(142, 83, 161) : color.rgb(28, 137, 205))

← 返回列表