I'm working on an Indie v5
indicator, and I encountered an issue when trying to extract the red, green, and blue components from a Color parameter.
I receive the error:
Error: 96:12 symbol `trend_col.red` not found
when trying to access color components like this:
fill_color = color.rgba(
trend_col.red(),
trend_col.green(),
trend_col.blue(),
0.2
)
The variable trend_col
is a Color
parameter that is passed to the function:
trend_col = upper_col if trend_up else lower_col
Both upper_col
and lower_col
are user-defined parameters of type Color
:
@param.color("upper_col", default=color.GREEN, title="Up Color")
@param.color("lower_col", default=color.RED, title="Down Color")
What I Tried:
- Using
color.red(trend_col)
– Also gives an error (symbol indie.color.red not found
). - Using
trend_col.red()
– Producessymbol trend_col.red not found
. - Using
color.r(trend_col)
– Also fails.
Question:
How can I properly extract the RGB values from a Color
object in Indie?
Example of full code with error:
# indie:lang_version = 5
from indie import indicator, MainContext, param, plot, color, MutSeriesF, algorithm, SeriesF, Optional, Color
from indie.algorithms import Atr
import math
@algorithm
def KalmanFilter(self, src: SeriesF, length: int, R: float = 0.01, Q: float = 0.1) -> SeriesF:
estimate = MutSeriesF.new(init=float('nan'))
error_est = MutSeriesF.new(init=1.0)
error_meas = MutSeriesF.new(init=R * length)
kalman_gain = MutSeriesF.new(init=0.0)
if math.isnan(estimate[0]):
estimate[0] = src[1]
prediction = estimate[0]
kalman_gain[0] = error_est[0] / (error_est[0] + error_meas[0])
estimate[0] = prediction + kalman_gain[0] * (src[0] - prediction)
error_est[0] = (1 - kalman_gain[0]) * error_est[0] + Q / length
return estimate
@indicator("Kalman Trend Levels [BigBeluga]", overlay_main_pane=True)
@param.int("short_len", default=50, title="Short Length")
@param.int("long_len", default=150, title="Long Length")
@param.bool("retest_sig", default=False, title="Retest Signals")
@param.bool("candle_color", default=True, title="Candle Color")
@param.color("upper_col", default=color.GREEN, title="Up Color")
@param.color("lower_col", default=color.RED, title="Down Color")
@plot.line("p1", title="Short Kalman")
@plot.line("p2", title="Long Kalman", line_width=2)
@plot.fill("p1", "p2")
class Main(MainContext):
def __init__(self):
self.prev_short_kalman = 0.0
self.prev_trend_up = False
self.lower_box_start = 0
self.lower_box_top = 0.0
self.lower_box_bottom = 0.0
self.upper_box_start = 0
self.upper_box_top = 0.0
self.upper_box_bottom = 0.0
def calc(self, short_len, long_len, retest_sig, candle_color, upper_col, lower_col):
atr = Atr.new(200, "RMA")[0] * 0.5
short_kalman_series = KalmanFilter.new(self.close, short_len)
long_kalman_series = KalmanFilter.new(self.close, long_len)
short_kalman = short_kalman_series[0]
long_kalman = long_kalman_series[0]
short_kalman_2 = self.prev_short_kalman
self.prev_short_kalman = short_kalman
trend_up = short_kalman > long_kalman
prev_trend_up = self.prev_trend_up
trend_changed = trend_up != prev_trend_up
trend_col = upper_col if trend_up else lower_col
trend_col1 = upper_col if short_kalman > short_kalman_2 else lower_col
candle_col: Optional[Color] = None
if candle_color:
if trend_up and short_kalman > short_kalman_2:
candle_col = upper_col
elif not trend_up and short_kalman < short_kalman_2:
candle_col = lower_col
else:
candle_col = color.GRAY
if trend_up and not prev_trend_up:
self.lower_box_start = self.bar_index
self.lower_box_top = self.low[0] + atr
self.lower_box_bottom = self.low[0]
close_rounded = round(self.close[0], 1)
if prev_trend_up and not trend_up:
self.upper_box_start = self.bar_index
self.upper_box_top = self.high[0]
self.upper_box_bottom = self.high[0] - atr
close_rounded = round(self.close[0], 1)
if retest_sig:
if self.high[0] < self.upper_box_bottom and self.high[1] >= self.upper_box_bottom:
pass
if self.low[0] > self.lower_box_top and self.low[1] <= self.lower_box_top:
pass
self.prev_trend_up = trend_up
fill_color = color.rgba(
trend_col.r,
trend_col.g,
trend_col.b,
0.2
)
return (
plot.Line(short_kalman, color=trend_col1),
plot.Line(long_kalman, color=trend_col),
plot.Fill(color=fill_color)
)
I'm working on an Indie v5
indicator, and I encountered an issue when trying to extract the red, green, and blue components from a Color parameter.
I receive the error:
Error: 96:12 symbol `trend_col.red` not found
when trying to access color components like this:
fill_color = color.rgba(
trend_col.red(),
trend_col.green(),
trend_col.blue(),
0.2
)
The variable trend_col
is a Color
parameter that is passed to the function:
trend_col = upper_col if trend_up else lower_col
Both upper_col
and lower_col
are user-defined parameters of type Color
:
@param.color("upper_col", default=color.GREEN, title="Up Color")
@param.color("lower_col", default=color.RED, title="Down Color")
What I Tried:
- Using
color.red(trend_col)
– Also gives an error (symbol indie.color.red not found
). - Using
trend_col.red()
– Producessymbol trend_col.red not found
. - Using
color.r(trend_col)
– Also fails.
Question:
How can I properly extract the RGB values from a Color
object in Indie?
Example of full code with error:
# indie:lang_version = 5
from indie import indicator, MainContext, param, plot, color, MutSeriesF, algorithm, SeriesF, Optional, Color
from indie.algorithms import Atr
import math
@algorithm
def KalmanFilter(self, src: SeriesF, length: int, R: float = 0.01, Q: float = 0.1) -> SeriesF:
estimate = MutSeriesF.new(init=float('nan'))
error_est = MutSeriesF.new(init=1.0)
error_meas = MutSeriesF.new(init=R * length)
kalman_gain = MutSeriesF.new(init=0.0)
if math.isnan(estimate[0]):
estimate[0] = src[1]
prediction = estimate[0]
kalman_gain[0] = error_est[0] / (error_est[0] + error_meas[0])
estimate[0] = prediction + kalman_gain[0] * (src[0] - prediction)
error_est[0] = (1 - kalman_gain[0]) * error_est[0] + Q / length
return estimate
@indicator("Kalman Trend Levels [BigBeluga]", overlay_main_pane=True)
@param.int("short_len", default=50, title="Short Length")
@param.int("long_len", default=150, title="Long Length")
@param.bool("retest_sig", default=False, title="Retest Signals")
@param.bool("candle_color", default=True, title="Candle Color")
@param.color("upper_col", default=color.GREEN, title="Up Color")
@param.color("lower_col", default=color.RED, title="Down Color")
@plot.line("p1", title="Short Kalman")
@plot.line("p2", title="Long Kalman", line_width=2)
@plot.fill("p1", "p2")
class Main(MainContext):
def __init__(self):
self.prev_short_kalman = 0.0
self.prev_trend_up = False
self.lower_box_start = 0
self.lower_box_top = 0.0
self.lower_box_bottom = 0.0
self.upper_box_start = 0
self.upper_box_top = 0.0
self.upper_box_bottom = 0.0
def calc(self, short_len, long_len, retest_sig, candle_color, upper_col, lower_col):
atr = Atr.new(200, "RMA")[0] * 0.5
short_kalman_series = KalmanFilter.new(self.close, short_len)
long_kalman_series = KalmanFilter.new(self.close, long_len)
short_kalman = short_kalman_series[0]
long_kalman = long_kalman_series[0]
short_kalman_2 = self.prev_short_kalman
self.prev_short_kalman = short_kalman
trend_up = short_kalman > long_kalman
prev_trend_up = self.prev_trend_up
trend_changed = trend_up != prev_trend_up
trend_col = upper_col if trend_up else lower_col
trend_col1 = upper_col if short_kalman > short_kalman_2 else lower_col
candle_col: Optional[Color] = None
if candle_color:
if trend_up and short_kalman > short_kalman_2:
candle_col = upper_col
elif not trend_up and short_kalman < short_kalman_2:
candle_col = lower_col
else:
candle_col = color.GRAY
if trend_up and not prev_trend_up:
self.lower_box_start = self.bar_index
self.lower_box_top = self.low[0] + atr
self.lower_box_bottom = self.low[0]
close_rounded = round(self.close[0], 1)
if prev_trend_up and not trend_up:
self.upper_box_start = self.bar_index
self.upper_box_top = self.high[0]
self.upper_box_bottom = self.high[0] - atr
close_rounded = round(self.close[0], 1)
if retest_sig:
if self.high[0] < self.upper_box_bottom and self.high[1] >= self.upper_box_bottom:
pass
if self.low[0] > self.lower_box_top and self.low[1] <= self.lower_box_top:
pass
self.prev_trend_up = trend_up
fill_color = color.rgba(
trend_col.r,
trend_col.g,
trend_col.b,
0.2
)
return (
plot.Line(short_kalman, color=trend_col1),
plot.Line(long_kalman, color=trend_col),
plot.Fill(color=fill_color)
)
Share
Improve this question
asked Mar 18 at 0:04
crysisencrysisen
214 bronze badges
1 Answer
Reset to default 0You can add transparency to trend_color
this way:
fill_color = trend_col(0.2)
The class Color does not give access to the fields (https://takeprofit/docs/indie/Library-reference/package-indie#color), usually it is not necessary.