簡體   English   中英

Pine Script:直方圖的顏色不能着色

[英]Pine Script : The color of histogram can't be colored

我是一個 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

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM