首页 > 解决方案 > 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)

问题是直方图条总是黑色的!

标签: pine-scriptforex

解决方案


您忘记在此处检查绿色和红色蜡烛的变量赋值运算符:

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

在此处输入图像描述


推荐阅读