最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

indie - Symbol self.length not found - Stack Overflow

programmeradmin6浏览0评论

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?

Share Improve this question asked Mar 19 at 17:52 PavlitoPavlito 414 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Note 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
发布评论

评论列表(0)

  1. 暂无评论