Reputation: 238
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.
I am trying this above code but it's not returning the value of color... How can I achieve it?
Upvotes: 1
Views: 5424
Reputation: 8799
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.
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).
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.
Upvotes: 1