GregoryMorse / trendln

Support and Resistance Trend lines Calculator for Financial Analysis
MIT License
663 stars 162 forks source link

NameError: name 'METHOD_NCUBED' is not defined #14

Open saulable opened 4 years ago

saulable commented 4 years ago

Hello,

I'm not that great with Python, more of a JS dev, so I don't know if this is correct?

When trying to pass in the parameters method, extmethod without quotes results in error. I suggest a fix.

trendln.plot_support_resistance(
            hist[-1000:].Close, method="METHOD_PROBHOUGH")

Then on lines 950 - 960 of init.py


    if method == "METHOD_NCUBED":
        trendmethod = get_trend
    elif method == "METHOD_NSQUREDLOGN":
        trendmethod = get_trend_opt
    elif method == "METHOD_HOUGHPOINTS":
        trendmethod = houghpt
    # pip install scikit-image
    elif method == "METHOD_HOUGHLINES":
        trendmethod = hough
    elif method == "METHOD_PROBHOUGH":
        trendmethod = prob_hough
saulable commented 4 years ago

Otherwise I get error of NameError: name 'METHOD_PROBHOUGH' is not defined when doing like so

trendln.plot_support_resistance( hist[-1000:].Close, method=METHOD_PROBHOUGH)

just-a-normal-human commented 4 years ago

I have the same problem but also when passing with quotes i get error:

ValueError: method must be one of METHOD_NCUBED, METHOD_NSQUREDLOGN, METHOD_HOUGHPOINTS, METHOD_HOUGHLINES, METHOD_PROBHOUGH

And without quotes:

NameError: name 'METHOD_NSQUREDLOGN' is not defined

@GregoryMorse @saulable

pete011 commented 4 years ago

has this been resolved? thanks

tsferro2 commented 4 years ago

I am having the same issue

coditori commented 4 years ago

@saulable It's an enum not a string, try this one:

trendln.plot_support_resistance(
            hist[-1000:].Close, method=trendln.METHOD_NCUBED)
GregoryMorse commented 4 years ago

The correct solution is to either import everything e.g. import trendln and to as suggested use trendln.CONSTANT_NAME syntax or use from trendln import CONSTANT_NAME. It is not necessary for these to be strings. However I will update the examples or look for scenarios where this confusion can come up so it will be corrected in the next version. These are just numeric constants with names provided for convenience. Strings might be okay as performance is not particularly an issue on these parameters but nonetheless, constants seem cleaner.