pine-script - Pine Script : 直方图的颜色不能着色
问题描述
我是一个 pine 脚本初学者编码器
我想为平均蜡烛长度制作一个指标,所有直方图条都是黑色的,除了它的故事 > 蜡烛的(高低)的 10%
默认颜色为黑色
green_upper_tale 是绿色蜡烛的上层故事
red_upper_tale 是红色蜡烛的上层故事
green_lower_tale 是绿色蜡烛的下层故事
red_lower_tale 是红色蜡烛的下层故事
实际上_bar_length 是蜡烛的总长度
//@version=3
study("Candle Length")
len = input(20, minval=1, title="# of Bars to calculate average")
sum = 0.0
bar_color = black // Default color
for i = 0.0 to len-1
sum := sum + (high[i] - low[i])
green_upper_tale = 0 // the upper tale of the green candle
red_upper_tale = 0 // the upper tale of the red candle
green_lower_tale = 0 // the lower tale of the green candle
red_lower_tale = 0 // the lower tale of the red candle
multiplier = 1.0
multiplier := iff(close <= 10.0, 10000.0, multiplier)
multiplier := iff(close >= 10.0, 100.0, multiplier)
active_bar_length = (close-open)*multiplier
actually_bar_length = (high-low) // the over all length of the candle
// for GREEN candles
if (close > open)
green_upper_tale = high-close // the upper tale of the green candle
green_lower_tale = open-low // the lower tale of the green candle
if (green_upper_tale > (actually_bar_length*0.1)) // if the green_upper_tale > (actually_bar_length/10) the candle bar will be blue
bar_color := blue
// for RED candles
if (close < open)
red_upper_tale = high-open // the upper tale of the red candle
red_lower_tale = close-low // the lower tale of the red candle
if (red_lower_tale > (actually_bar_length*0.1)) // if the red_lower_tale > (actually_bar_length/10) the candle bar will be yellow
bar_color := yellow
if (active_bar_length > 0)
active_bar_length := active_bar_length * 1
if (active_bar_length < 0)
active_bar_length := active_bar_length * -1
plot((sum/len)*multiplier)
plot(active_bar_length, color=bar_color, title="test1", style=histogram, linewidth=3)
问题是直方图条总是黑色的!
解决方案
您忘记在此处检查绿色和红色蜡烛的变量赋值运算符:
// for GREEN candles
if (close > open)
green_upper_tale = high-close // the upper tale of the green candle
green_lower_tale = open-low // the lower tale of the green candle
// for RED candles
if (close < open)
red_upper_tale = high-open // the upper tale of the red candle
red_lower_tale = close-low // the lower tale of the red candle
只需将那些=
s更改为:=
就可以了。
除此之外,您还应该将xxx_tale
变量更改为浮点类型。
green_upper_tale = 0.0 // the upper tale of the green candle
red_upper_tale = 0.0 // the upper tale of the red candle
green_lower_tale = 0.0 // the lower tale of the green candle
red_lower_tale = 0.0 // the lower tale of the red candle
推荐阅读
- python - 如何在 django 中自定义 403 错误页面?
- android - 创建一个卡片小部件,向上滑动时将展开到新屏幕
- shell - Curl HTTPS 返回空字符串,如何在 Linux shell / bash 脚本中设置 CURLOPT_SSL_VERIFYHOST
- mysql - MySQL 5.7:针对太多连接错误进行微调
- build - 多个conanfile.py管理
- java - 使用 PDFMergerUtility 合并两个 pdf 文档会抛出:IOException("Page tree root must be a dictionary")
- typo3 - 升级到 TYPO3 9 后 pibase 扩展无法正常工作
- python - 使用python中已经打开的套接字发送数据
- ios - 条件绑定的初始化程序必须具有可选类型,而不是“URL”
- java - JOLT - 根据 if 条件在 JSONArray 中添加字段