简体   繁体   中英

PIne script : 2 different background color

I use this code and i want to have a color background after the line of 80% And another background color before the line of 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")

How it's possible to make thant in pine script.

Thanks for your help

do you mean 80 to 100 fill color and 20 to 0 fill color? if so then use code below,

// 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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM