Pine Script: цвет гистограммы не может быть окрашен

я начинающий кодер pine script

я хочу сделать индикатор для средней длины свечи, все столбцы гистограммы будут черными, за исключением того, что это сказка> 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)

проблема в том, что столбцы гистограммы всегда черные!!


person Ahmed Ashkar    schedule 13.05.2020    source источник


Ответы (1)


Вы забыли использовать назначение переменной оператор для зеленых и красных свечей проверьте здесь:

// 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 на тип с плавающей запятой.

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

введите здесь описание изображения

person Baris Yakut    schedule 13.05.2020