pine-script - 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。
谢谢你的帮助
解决方案
你的意思是 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")
推荐阅读
- wso2esb - 试图在 wso2 中创建数据服务
- powerbi - 如何计算特定级别的 DAX 表达式
- azure - 通过 C# 将数据插入 Azure 数据资源管理器
- bash - 自动 awk 命令删除 VCF 的 INFO 列中的重复字段,保持第一次出现
- css - 是否可以使用传统 CSS(不使用 SASS 或 LESS 等)进行条件 if/else 逻辑?
- react-native - 没有堆栈',原因:'未处理的 JS 异常:无效的正则表达式:无效的组说明符名称
- html - 如何将标签元素的一侧更改为左侧
- javascript - 如何在不与 svelte 中的编译器对抗的情况下避免循环依赖?
- r - 如何在满足条件的所有行之前只选择前 10 行?
- php - 在 apache php 上实现 http2 推送方法