I'm trying to create an indicator in Indie
Language that calculates support, resistance, and median levels using Highest.new()
and Lowest.new()
. I added a length
parameter, but when I try to reference it using self.length
, I get this error:
Error: 19:46 symbol self.length not found
Code with error:
# indie:lang_version = 5
from indie import indicator, param, plot, color, MainContext
from indie.algorithms import Highest, Lowest
@indicator("Support, Resistance and Median with Trend", overlay_main_pane=True)
@param.int("length", default=22, min=1, title="Historical Length")
@plot.line("resistance", color=color.RED, line_width=2, title="Resistance")
@plot.line("support", color=color.GREEN, line_width=2, title="Support")
@plot.line("median", color=color.WHITE, line_width=1, title="Median")
class Main(MainContext):
def calc(self, length):
highest_high = Highest.new(self.high, self.length)[0]
lowest_low = Lowest.new(self.low, self.length)[0]
resistance_level = highest_high
support_level = lowest_low
median_level = (resistance_level + support_level) / 2
return resistance_level, support_level, median_level
I thought that since length
is defined as a parameter, I should be able to access it using self.length
, but it seems like it's not recognized.
Is length
supposed to be a property of self
, or am I missing something? Do I need to initialize it somewhere?
I'm trying to create an indicator in Indie
Language that calculates support, resistance, and median levels using Highest.new()
and Lowest.new()
. I added a length
parameter, but when I try to reference it using self.length
, I get this error:
Error: 19:46 symbol self.length not found
Code with error:
# indie:lang_version = 5
from indie import indicator, param, plot, color, MainContext
from indie.algorithms import Highest, Lowest
@indicator("Support, Resistance and Median with Trend", overlay_main_pane=True)
@param.int("length", default=22, min=1, title="Historical Length")
@plot.line("resistance", color=color.RED, line_width=2, title="Resistance")
@plot.line("support", color=color.GREEN, line_width=2, title="Support")
@plot.line("median", color=color.WHITE, line_width=1, title="Median")
class Main(MainContext):
def calc(self, length):
highest_high = Highest.new(self.high, self.length)[0]
lowest_low = Lowest.new(self.low, self.length)[0]
resistance_level = highest_high
support_level = lowest_low
median_level = (resistance_level + support_level) / 2
return resistance_level, support_level, median_level
I thought that since length
is defined as a parameter, I should be able to access it using self.length
, but it seems like it's not recognized.
Is length
supposed to be a property of self
, or am I missing something? Do I need to initialize it somewhere?
1 Answer
Reset to default 1Note that length
comes to the function as a regular parameter def calc(self, length)
. You can work with this parameter simply by name, as is usually in python Highest.new(self.high, length)[0]
:
# indie:lang_version = 5
from indie import indicator, param, plot, color, MainContext
from indie.algorithms import Highest, Lowest
@indicator("Support, Resistance and Median with Trend", overlay_main_pane=True)
@param.int("length", default=22, min=1, title="Historical Length")
@plot.line("resistance", color=color.RED, line_width=2, title="Resistance")
@plot.line("support", color=color.GREEN, line_width=2, title="Support")
@plot.line("median", color=color.WHITE, line_width=1, title="Median")
class Main(MainContext):
def calc(self, length):
highest_high = Highest.new(self.high, length)[0]
lowest_low = Lowest.new(self.low, length)[0]
resistance_level = highest_high
support_level = lowest_low
median_level = (resistance_level + support_level) / 2
return resistance_level, support_level, median_level