The MyTestStrategy class is a backtesting strategy that applies technical analysis (TA) indicators to a given DataFrame of trading data. It has several methods to populate indicators, determine buy signals, determine sell signals, and execute trades. The populate_indicators method adds various TA indicators to the DataFrame, providing the necessary data for the strategy.
It advises using a minimal number of indicators for optimal performance.
The populate_buy_trend method populates the buy signal for each row in the DataFrame based on the TA indicators.
In this specific implementation, it assigns a value of 1 to the 'buy' column for every other row. The populate_sell_trend method populates the sell signal for each row in the DataFrame based on the TA indicators. However, in the provided code, this method returns the DataFrame as is, without modifying the 'buy' column. The populate_entry method is responsible for determining the entry price for a trade. It receives information such as the current time, the proposed rate, and additional arguments. It sets the entry price to 99% of the proposed rate and returns this value. The confirm_trade_entry method confirms the entry of a trade. It receives information similar to the populate_entry method and checks if the entry price is not None and if the necessary data (data provider and wallets) are available. If so, it confirms the trade entry and returns True; otherwise, it returns False. The populate_sell method determines the sell signal or reason for selling. In the provided code, it always returns the string "my_custom_sell" as the sell reason. The populate_exit method calculates the exit price for a trade. It receives information similar to the populate_entry method and sets the exit price to 101% of the proposed rate. It returns this exit price. The confirm_trade_exit method confirms the exit of a trade. It receives information similar to the populate_exit method and checks if the sell reason is "my_custom_sell" and if the necessary data (data provider and wallets) are available. If so, it confirms the trade exit and returns True; otherwise, it returns False. Overall, this strategy adds TA indicators to a DataFrame, generates buy signals based on those indicators, determines entry and exit prices for trades, and confirms the execution of trades based on specific conditions.
Traceback (most recent call last):
File "/home/ftuser/.local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3791, in get_loc
return self._engine.get_loc(casted_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "index.pyx", line 152, in pandas._libs.index.IndexEngine.get_loc
File "index.pyx", line 181, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'buy'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/freqtrade/freqtrade/main.py", line 42, in main
return_code = args['func'](args)
^^^^^^^^^^^^^^^^^^
File "/freqtrade/freqtrade/commands/optimize_commands.py", line 58, in start_backtesting
backtesting.start()
File "/freqtrade/freqtrade/optimize/backtesting.py", line 1401, in start
min_date, max_date = self.backtest_one_strategy(strat, data, timerange)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/freqtrade/freqtrade/optimize/backtesting.py", line 1335, in backtest_one_strategy
results = self.backtest(
^^^^^^^^^^^^^^
File "/freqtrade/freqtrade/optimize/backtesting.py", line 1213, in backtest
data: Dict = self._get_ohlcv_as_lists(processed)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/freqtrade/freqtrade/optimize/backtesting.py", line 381, in _get_ohlcv_as_lists
df_analyzed = self.strategy.ft_advise_signals(pair_data, {'pair': pair})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/freqtrade/freqtrade/strategy/interface.py", line 1391, in ft_advise_signals
dataframe = self.advise_entry(dataframe, metadata)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/freqtrade/freqtrade/strategy/interface.py", line 1425, in advise_entry
df = self.populate_entry_trend(dataframe, metadata)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/freqtrade/freqtrade/strategy/interface.py", line 225, in populate_entry_trend
return self.populate_buy_trend(dataframe, metadata)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/freqtrade/user_data/strategies/Discord_MyTestStrategy.py", line 177, in populate_buy_trend
dataframe.iloc[index, dataframe.columns.get_loc('buy')] = 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/ftuser/.local/lib/python3.11/site-packages/pandas/core/indexes/base.py", line 3798, in get_loc
raise KeyError(key) from err
KeyError: 'buy'