Pine Script:直方图的颜色不能着色
Pine Script : The color of histogram can't be colored
我是一名 pine 脚本初学者
我想制作平均蜡烛长度的指标
所有直方图条都是黑色的,除了它的故事 > 蜡烛的(高-低)10%
Default color is black
green_upper_tale is the upper tale of the green candle
red_upper_tale is the upper tale of the red candle
green_lower_tale is the lower tale of the green candle
red_lower_tale is the lower tale of the red candle
actually_bar_length is the over all length of the candle
//@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)
问题是直方图条总是黑色!!
您忘记对绿色和红色蜡烛使用 variable assignment 运算符,请在此处查看:
// 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
只需将那些 =
更改为 :=
就可以了。
除此之外,您还应该将 xxx_tale
变量更改为 float 类型。
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
我是一名 pine 脚本初学者
我想制作平均蜡烛长度的指标 所有直方图条都是黑色的,除了它的故事 > 蜡烛的(高-低)10%
Default color is black
green_upper_tale is the upper tale of the green candle
red_upper_tale is the upper tale of the red candle
green_lower_tale is the lower tale of the green candle
red_lower_tale is the lower tale of the red candle
actually_bar_length is the over all length of the candle
//@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)
问题是直方图条总是黑色!!
您忘记对绿色和红色蜡烛使用 variable assignment 运算符,请在此处查看:
// 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
只需将那些 =
更改为 :=
就可以了。
除此之外,您还应该将 xxx_tale
变量更改为 float 类型。
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