首页 > 解决方案 > Pine 脚本:2 种不同的背景颜色

问题描述

我使用这段代码,我想在 80% 行之后有一个彩色背景,在 20% 行之前有另一个背景颜色

study(title="Stochastic RSI 50", shorttitle="Stoch RSI 50", format=format.price, precision=2, resolution="")
smoothK = input(3, "K", minval=1)
smoothD = input(3, "D", minval=1)
lengthRSI = input(14, "RSI Length", minval=1)
lengthStoch = input(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
plot(k, "K", color=#2962FF)
plot(d, "D", color=#FF6D00)
h0 = hline(80, "Upper Band", color=#787B86)
h1 = hline(20, "Lower Band", color=#787B86)
hm = hline(50, "50 band", color=#787B86)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")

如何在 pine 脚本中制作thant。

谢谢你的帮助

标签: pine-script

解决方案


你的意思是 80 到 100 填充颜色和 20 到 0 填充颜色?如果是这样,那么使用下面的代码,

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SafetyHammer

//@version=4
study(title="Stochastic RSI 50", shorttitle="Stoch RSI 50", format=format.price, precision=2, resolution="")
smoothK = input(3, "K", minval=1)
smoothD = input(3, "D", minval=1)
lengthRSI = input(14, "RSI Length", minval=1)
lengthStoch = input(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = rsi(src, lengthRSI)
k = sma(stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = sma(k, smoothD)
plot(k, "K", color=#2962FF)
plot(d, "D", color=#FF6D00)


h0 = hline(0, "Upper Band 0 &", color=#787B86)
h1 = hline(20, "Lower Band 20 %", color=#787B86)

h2 = hline(80, "Upper Band 80 %", color=#787B86)
h3 = hline(100, "Upper Band 100 %", color=#787B86)


hm = hline(50, "50 band", color=#787B86)

fill(h1, h2, color=color.rgb(33, 150, 243, 90), title="Middle Background")

fill(h2, h3, color=color.new(color.red,85), title="Upper Background")

fill(h0, h1, color=color.new(color.green,85), title="Lower Background")


推荐阅读