-1

I am having some trouble calling one function from inside another

Here is the code I have:

supported_timeframes = ['1m', '5m', '1h', '1d']
supported_indicators = ['SMA', ... ]
supported_sources = ['open', 'close']

indicator_values = {}


class Indicator:

    def __init__(self):
        self.indictor = ''      # indicator 
        self.timeframe = ''     # timeframe
        self.period = 0         # look-back period
        self.source = ''        # open / close

    def error(self, indicator, timeframe, period, source):
        if timeframe not in supported_timeframes:
            return 'timeframe not supported --', 'supported 
            timeframes:', supported_indicators
        if indicator not in supported_indicators:
            return 'indicator not found --', 'supported indicators:', 
            supported_indicators
        if source not in supported_sources:
            return 'source is not -- open -- or -- close'
    else:
        pass

    def SMA(self, indicator, timeframe, period, source):
        error()

        # TODO get candle data from timeframe
        # TODO calc requested indicator from candle data and append to 
        # indicator_values dict

        # return indicator
        for indicator in indicator_values:
            return indicator

I have the function error first to check if wrong values have been entered into the parameters.

Then I want to call that function in def SMA(...) function because I am going to have many more functions that each calculate an indicator similar to the SMA one, so to keep things concise I am trying to call error() in each of them instead of copy and pasting the code within every time.

However when doing this, I get an error message within def SMA(...) that says error() is undefined.

Thank you so much in advance if you can help me out!

0

1 Answer 1

2

Unless I'm missing something, you just need to add self where you are calling error()

def SMA(self, indicator, timeframe, period, source):
        self.error()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.