technical icon indicating copy to clipboard operation
technical copied to clipboard

Error upon running Ichimoku Cloud

Open r3nd4n opened this issue 3 years ago • 3 comments

# --- Do not remove these libs ---
from freqtrade.strategy.interface import IStrategy
from typing import Dict, List
from functools import reduce
from pandas import DataFrame
from technical.indicators import ichimoku
# --------------------------------

import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
import numpy # noqa
#---------------------------------
#import ccxt
import plotly.graph_objects as go


class ichis(IStrategy):
    minimal_roi = {
        "0": 1
    }
    timeframe = "15m",
    """
    This means that the strategy will take profit at 100% profit,
    initially it will set a stop loss of -10%
    and will trail the stop when it reaches 20% profits
    by moving the stop-loss to -15% from the 20% point,
    and then it will trail it with the highest reached price.
    """
    stoploss = -0.1
    trailing_stop = True,
    trailing_stop_positive = -0.15,
    trailing_stop_positive_offset = 0.20,
    trailing_only_offset_is_reached = True

def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:

    ichi=ichimoku(dataframe)
    dataframe['tenkan']=ichi['tenkan_sen']
    dataframe['kijun']=ichi['kijun_sen']
    dataframe['senkou_a']=ichi['senkou_span_a']
    dataframe['senkou_b']=ichi['senkou_span_b']
    dataframe['cloud_green']=ichi['cloud_green']
    dataframe['cloud_red']=ichi['cloud_red']

    return dataframe

def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
    dataframe.loc[
            (
                (dataframe['tenkan'].shift(1) < dataframe['kijun'].shift(1)) &
                (dataframe['tenkan'] > dataframe['kijun']) &
                (dataframe['cloud_red'] == True)
            ),
            'buy'] = 1
    return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (
            ),
            'sell'] = 1
        return dataframe

=========================================================================== Error:

021-06-03 17:01:44,487 - freqtrade.commands.trade_commands - ERROR - Can't instantiate abstract class ichis with abstract methods populate_buy_trend, populate_indicators, populate_sell_trend
2021-06-03 17:01:44,487 - freqtrade.commands.trade_commands - ERROR - Fatal exception!
Traceback (most recent call last):
  File "/home/whatthefuck/freqtrade/freqtrade/commands/trade_commands.py", line 18, in start_trading
    worker = Worker(args)
  File "/home/whatthefuck/freqtrade/freqtrade/worker.py", line 35, in __init__
    self._init(False)
  File "/home/whatthefuck/freqtrade/freqtrade/worker.py", line 52, in _init
    self.freqtrade = FreqtradeBot(self._config)
  File "/home/whatthefuck/freqtrade/freqtrade/freqtradebot.py", line 66, in __init__
    self.strategy: IStrategy = StrategyResolver.load_strategy(self.config)
  File "/home/whatthefuck/freqtrade/freqtrade/resolvers/strategy_resolver.py", line 45, in load_strategy
    strategy: IStrategy = StrategyResolver._load_strategy(
  File "/home/whatthefuck/freqtrade/freqtrade/resolvers/strategy_resolver.py", line 190, in _load_strategy
    strategy = StrategyResolver._load_object(paths=abs_paths,
  File "/home/whatthefuck/freqtrade/freqtrade/resolvers/iresolver.py", line 121, in _load_object
    return module(**kwargs)
TypeError: Can't instantiate abstract class ichis with abstract methods populate_buy_trend, populate_indicators, populate_sell_trend

r3nd4n avatar Jun 03 '21 09:06 r3nd4n

Looks like your indentation is off. your methods are at the same level as "class" - which means they're not part of the class - which makes initialization fail. it's got nothing to do with the indicators themselfs...

xmatthias avatar Jun 03 '21 17:06 xmatthias

I did modify the indentation, still the same error. Is it because of the indicator used?

r3nd4n avatar Jun 04 '21 02:06 r3nd4n

The error you get - TypeError: Can't instantiate abstract class ichis with abstract methods populate_buy_trend, populate_indicators, populate_sell_trend indicates that the required methods are not available in the strategy.

Best make sure you only have ONE file with this strategy name available in your strategy directory - and that the indentation is correct (which it isn't in the above example).

As long as you get this particular error - it's got nothing to do with the indicator (it won't even get this far).

xmatthias avatar Jun 04 '21 03:06 xmatthias

Closing this as i think your question has been answered.

Feel free to comment below if it's still unclear.

xmatthias avatar Aug 22 '23 05:08 xmatthias