BTC Onchain Levels

faint_idea · study · 50 行 · 点赞 1 · 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/
// © faint_idea
 
//@version=6
indicator("BTC Onchain Levels", "BTC Levels", overlay = true)
// developed by ciasis
 
isBtcBase   = syminfo.basecurrency == "BTC" or syminfo.basecurrency == "XBT"
isBtcTicker = str.contains(str.upper(syminfo.ticker), "BTC") or str.contains(str.upper(syminfo.ticker), "XBT")
isUsd       = syminfo.currency == "USD" or syminfo.currency == "USDT" or syminfo.currency == "USDC"
isBtc       = (isBtcBase or isBtcTicker) and isUsd
 
grpStyle   = "Display"
showLabels = input.bool(true, "Show labels", group = grpStyle)
showPrices = input.bool(true, "Show price in label", group = grpStyle)
lineWidth  = input.int(1, "Line width", minval = 1, maxval = 4, group = grpStyle)
labelShift = input.int(8, "Label offset (bars)", minval = 0, maxval = 50, group = grpStyle)
 
grpLevels = "Levels"
levelValues = input.string("", "Values (STH;LTH;TMM;Realized;CVDD)", group = grpLevels)
parts = str.split(str.replace_all(levelValues, " ", ""), ";")
f_value(int i) => array.size(parts) > i ? str.tonumber(array.get(parts, i)) : na
sthCBShow = input.bool(true, "STH Cost Basis", group = grpLevels)
sthCB = f_value(0)
lthCBShow = input.bool(true, "LTH Cost Basis", group = grpLevels)
lthCB = f_value(1)
tmmShow = input.bool(true, "True Market Mean", group = grpLevels)
tmm = f_value(2)
realizedShow = input.bool(true, "Realized Price", group = grpLevels)
realized = f_value(3)
cvddShow = input.bool(true, "CVDD", group = grpLevels)
cvdd = f_value(4)
 
f_level(bool show, float price, color col, string txt) =>
    var line  ln = na
    var label lb = na
    if barstate.islast
        line.delete(ln)
        label.delete(lb)
        if show and not na(price)
            ln := line.new(bar_index - 1, price, bar_index, price, extend = extend.left, color = col, width = lineWidth)
            if showLabels
                lblTxt = showPrices ? txt + " · " + str.tostring(price, format.mintick) : txt
                lb := label.new(bar_index + labelShift, price, lblTxt, style = label.style_label_left, color = color.new(col, 82), textcolor = col, size = size.small)
 
f_level(isBtc and sthCBShow, sthCB, color.rgb(247, 147, 26), "STH Cost Basis")
f_level(isBtc and lthCBShow, lthCB, color.rgb(59, 130, 246), "LTH Cost Basis")
f_level(isBtc and tmmShow, tmm, color.rgb(16, 185, 129), "True Market Mean")
f_level(isBtc and realizedShow, realized, color.rgb(239, 68, 68), "Realized Price")
f_level(isBtc and cvddShow, cvdd, color.rgb(139, 92, 246), "CVDD")

← 返回列表