在Pine中使用新色彩

May 13, 2021

现在,我们从RGB调色板中添加了新的系列颜色和渐变,您的脚本将闪耀明亮的颜色。

新函数 ‘color.rgb (red, green, blue, transp)’ 已添加到Pine。它允许您通过传递红色,绿色,蓝色和透明度(transp)的成分值作为参数来设置颜色。现在,您可以摆脱脚本中使用的整个调色板的定义,而根据传递的参数来计算颜色。看一下这个小例子,它显示了使用复杂的颜色过渡现在变得多么容易:

//@version=4
study("Relative Bars Color Saturation", "RBCS", overlay=true)

i_barcolor = input(color.rgb(33, 150, 243), "Bar Color", input.color)

f_grad_transp(_c_col, _transp) =>
    _c_red = color.r(_c_col)
    _c_green = color.g(_c_col)
    _c_blue = color.b(_c_col)
    color.rgb(_c_red, _c_green, _c_blue, _transp)

f_indexedPercent(_currentValue, _relativeValue, _maxValue) =>
    _currentValue * _maxValue / _relativeValue

transp = f_indexedPercent(abs(close - open), high - low, 100)
c_color = f_grad_transp(i_barcolor, transp)
barcolor(c_color)

颜色的成分值设置在0(最低强度)到255(最高强度)之间。对于透明度成分,此范围是从0(完全不透明)到100(完全透明)。

如果需要获取特定颜色或透明度成分的数值,请尝试使用特殊函数 ‘color.r()’, ‘color.g()’, ‘color.b()’  ‘color.t()’ ,方法是将颜色作为参数传递给它们。

借助 ‘color.from_gradient()’ 功能,您可以在每根K线上创建令人印象深刻的颜色过渡,脚本的颜色现在仅受限于您的想象力。这是一个示例,显示了根据相对强弱指数的值来描述颜色变得多么容易:

//@version=4
study("RGB RSI")
i_src = input(close, "Source", input.source)
i_length = input(14, "Length", input.integer)

f_grad_transp(_c_col, _transp) =>
    _c_red = color.r(_c_col)
    _c_green = color.g(_c_col)
    _c_blue = color.b(_c_col)
    color.rgb(_c_red, _c_green, _c_blue, _transp)

rsi = rsi(i_src, i_length)
c_grad = color.from_gradient(rsi, 30, 70, color.lime, color.red)

plot(rsi, color=c_grad, linewidth=3)
band1 = hline(70, "Overbought", color=color.rgb(255, 82, 82))
band0 = hline(30, "Oversold", color=color.rgb(76, 175, 80))
fill(band1, band0, color=f_grad_transp(c_grad, 90), title="Background")

在用户手册的发行说明章节中阅读有关所有Pine更新的信息。

一些内置指标(动量、TRIX、价格震荡指标、区间震荡指标(DPO)、蔡金震荡指标、成交量震荡指标、简易波动指标(EOM)、波动率)已经更新。现在使用这些新功能,您可以将它们添加到图表中以查看有效的RGB功能。

这里有一些由社区开发人员提供的,令人印象深刻的带有RGB颜色的指标示例:

Directional Value by RicardoSantos

Color Gradient Framework by LucF, for PineCoders

Delta Volume Columns Pro by LucF

我们希望大家发现新功能有用。请务必继续给我们提供反馈和建议 — 我们正在为您打造TradingView,并且我们始终热衷于了解您对我们平台更新的看法。


 

还没有关注我们的中文微信公众号?快来扫二维码吧!

Look first Then leap

TradingView专门为您而打造,请确保您充分利用我们出色的功能
开启图表