[英]How to set wick color based on candle body color in pine script v4?
palette = ( abs(open-close)/abs(high-low) > 0.5 )? open < close ? color.green : color.red : color.blue
plotcandle(choice =="Candle" ? value_open:na,value_high,value_low,value_close,color=palette,**wickcolor=(value_close > value_open ? color.green:color.red)**)
value_high, value_low, value_open, value_close is custom high, low, open, close variable that is working fine issue is only with wickcolor. value_high、value_low、value_open、value_close 是自定义的高、低、开、关变量,工作正常问题仅适用于 wickcolor。
I am trying this above code but it's not returning the value of color... How can I achieve it?我正在尝试上面的代码,但它没有返回颜色的值......我怎样才能实现它?
As you can see in the refman for plotcandle()
, contrary to the body's color which can be a series color (so vary on each bar), the wickcolor
parameter requires an input color , which entails it must be known before the script executes.正如您在
plotcandle()
的 refman 中看到的那样,与可以是系列颜色的主体颜色相反(因此在每个条上都不同), wickcolor
参数需要一个输入 color ,这意味着它必须在脚本执行之前已知。
To overcome this constraint, we need to use separate plotcandle()
calls for each color, and your script must have room for the 8 additional plots this adds to your script's total plot count (4 plots / plotcandle()
call).为了克服这个限制,我们需要为每种颜色使用单独的
plotcandle()
调用,并且您的脚本必须有空间容纳 8 个额外的绘图,这会增加脚本的总绘图计数(4 个绘图 / plotcandle()
调用)。
It's not pretty but it works:它不漂亮,但它有效:
//@version=4
study("")
choice = input("Candle")
value_open = open
value_high = high
value_low = low
value_close = close
palette = (abs(open - close) / abs(high - low) > 0.5 ) ? open < close ? color.green : color.red : color.blue
// Returns a value `_v` only if user wants to plot candle and `palette` matches the required color `_c`.
f_v(_c, _v) => choice == "Candle" and palette == _c ? _v : na
c_g = color.green
plotcandle(f_v(c_g, value_open), f_v(c_g, value_high), f_v(c_g, value_low), f_v(c_g, value_close), color = c_g, wickcolor = c_g)
c_r = color.red
plotcandle(f_v(c_r, value_open), f_v(c_r, value_high), f_v(c_r, value_low), f_v(c_r, value_close), color = c_r, wickcolor = c_r)
c_b = color.blue
plotcandle(f_v(c_b, value_open), f_v(c_b, value_high), f_v(c_b, value_low), f_v(c_b, value_close), color = c_b, wickcolor = c_b)
I use the same technique in my Delta Volume Candles [LucF] script.我在我的Delta Volume Candles [LucF]脚本中使用了相同的技术。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.