freqtrade / technical

Various indicators developed or collected for the Freqtrade
GNU General Public License v3.0
769 stars 217 forks source link

HELP #128

Closed wupeng1211 closed 4 years ago

wupeng1211 commented 4 years ago

` def Ichimoku_Score(self, dataframe, conversion_line_period = 9, base_line_periods = 26, laggin_span = 52, displacement = 26): df = dataframe.copy()

    # # Heikin Ashi Strategy
    heikinashi = qtpylib.heikinashi(df)
    df['ha_open'] = heikinashi['open']
    df['ha_close'] = heikinashi['close']
    df['ha_high'] = heikinashi['high']
    df['ha_low'] = heikinashi['low']

    df['tenkan'] = (df['ha_high'].rolling(window=conversion_line_period).max()+ df['ha_low'].rolling(window=conversion_line_period).min()) / 2
    df['kijun']  = (df['ha_high'].rolling(window=base_line_periods).max()+ df['ha_low'].rolling(window=base_line_periods).min()) / 2
    df['leading_senkou_a'] = (df['tenkan'] + df['kijun']) / 2
    df['leading_senkou_b'] = (df['ha_high'].rolling(window=laggin_span).max()+ df['ha_low'].rolling(window=laggin_span).min()) / 2
    df['senkou_span_a'] = df['leading_senkou_a'].shift(displacement)
    df['senkou_span_b'] = df['leading_senkou_b'].shift(displacement)
    df['chikou_span'] = df['ha_close'].shift(-displacement)

    # cloud_green = (senkou_span_a > senkou_span_b)
    # cloud_red = (senkou_span_b > senkou_span_a)

    def calcTkCross():

        if ((df['tenkan'] > df['kijun']) and (df['tenkan'] < df['kijun'])):
            Intersect=((df['tenkan'].shift(1) * (df['kijun'] - df['kijun'].shift(1)) - df['kijun'].shift(1) * (df['tenkan'] - df['tenkan'].shift(1))) / ((df['kijun'] - df['kijun'].shift(1)) - (df['tenkan'] - df['tenkan'].shift(1))))

            if (Intersect > df['senkou_span_a']) and (Intersect > df['senkou_span_b']):
                return 2
            elif (Intersect < df['senkou_span_a']) and (Intersect < df['senkou_span_b']):
                return 0.5
            else :
                return 1

        elif ((df['tenkan'] < df['kijun']) and (df['tenkan'] > df['kijun'])):
            Intersect=((df['tenkan'].shift(1) * (df['kijun'] - df['kijun'].shift(1)) - df['kijun'].shift(1) * (df['tenkan'] - df['tenkan'].shift(1))) / ((df['kijun'] - df['kijun'].shift(1)) - (df['tenkan'] - df['tenkan'].shift(1))))

            if (Intersect < df['senkou_span_a']) and (Intersect < df['senkou_span_b']):
                return -2
            elif (Intersect > df['senkou_span_a']) and (Intersect > df['senkou_span_b']):
                return -0.5
            else :
                return -1

        else :
            return 0

    return calcTkCross()`

File "/home/wupeng1211/freqtrade-strategies/user_data/strategies/Ichimoku.py", line 274, in calcTkCross if ((df['tenkan'] > df['kijun']) and (df['tenkan'] < df['kijun'])): File "/home/wupeng1211/freqtrade/.env/lib/python3.7/site-packages/pandas/core/generic.py", line 1330, in nonzero f"The truth value of a {type(self).name} is ambiguous. " ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

wupeng1211 commented 4 years ago

if ((df['tenkan'] > df['kijun']) and (df['tenkan'] < df['kijun'])):

xmatthias commented 4 years ago

Please name issues according to the problem you have, and not just "help".

Each of these are dataframe columns - you cannot use "if" on them - and this is why your'e getting an error.

Best get familiar with how pandas dataframes work (e.g. with 10 minutes to pandas) - otherwise you will struggle greatly while writing strategies.


Please note that since we're a open source project with people donating their free time to support and develop things further, giving support on basic things like "How pandas work" are not within our possibilities - so we'll have to point you to either the pandas documentation, or encourage self-paced learning through other online resources (no, we do not give recommendations for such resources - as everyone learns differently).

Thanks for your understanding.

wupeng1211 commented 4 years ago

thks