freqtrade / freqtrade

Free, open source crypto trading bot

Home Page:https://www.freqtrade.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Strategy backtesting without error alerts, auto-stop

l3104468710 opened this issue · comments

Describe your environment

  • Operating system: ____ Windows10
  • Python Version: _____ 3.11.7
  • CCXT version: _____ 4.2.82
  • Freqtrade Version: ____ 2024.3**

Your question

Strategy backtesting without error alerts, auto-stop

This is backtesting command:
docker compose run --rm freqtrade backtesting -s VWAP --timerange 20220101- --dry-run-wallet 10000 --stake-amount 1000 --eps --breakdown month

This is part of the running log:
2024-05-08 12:03:55,698 - freqtrade.data.history.datahandlers.idatahandler - WARNING - XRP/USDT:USDT, funding_rate, 8h, data starts at 2022-01-01 00:00:00
2024-05-08 12:03:55,720 - freqtrade.data.history.datahandlers.idatahandler - WARNING - YFI/USDT:USDT, funding_rate, 8h, data starts at 2022-01-01 00:00:00
2024-05-08 12:03:55,742 - freqtrade.data.history.datahandlers.idatahandler - WARNING - ZEN/USDT:USDT, funding_rate, 8h, data starts at 2022-01-01 00:00:00
2024-05-08 12:03:55,887 - freqtrade.data.history.datahandlers.idatahandler - WARNING - APE/USDT:USDT, mark, 8h, data starts at 2022-03-17 08:00:00
2024-05-08 12:03:55,909 - freqtrade.data.history.datahandlers.idatahandler - WARNING - API3/USDT:USDT, mark, 8h, data starts at 2022-02-21 08:00:00
2024-05-08 12:03:56,273 - freqtrade.data.history.datahandlers.idatahandler - WARNING - DUSK/USDT:USDT, mark, 8h, data starts at 2022-01-06 08:00:00
2024-05-08 12:03:56,487 - freqtrade.data.history.datahandlers.idatahandler - WARNING - FLOW/USDT:USDT, mark, 8h, data starts at 2022-02-09 08:00:00
2024-05-08 12:03:56,606 - freqtrade.data.history.datahandlers.idatahandler - WARNING - JASMY/USDT:USDT, mark, 8h, data starts at 2022-04-19 00:00:00
2024-05-08 12:03:56,848 - freqtrade.data.history.datahandlers.idatahandler - WARNING - OP/USDT:USDT, mark, 8h, data starts at 2022-06-01 00:00:00
2024-05-08 12:03:57,293 - freqtrade.optimize.backtesting - INFO - Dataload complete. Calculating indicators
2024-05-08 12:03:57,296 - freqtrade.optimize.backtesting - WARNING - Backtest result caching disabled due to use of open-ended timerange.
2024-05-08 12:03:57,296 - freqtrade.optimize.backtesting - INFO - Running backtesting for Strategy VWAP
2024-05-08 12:03:57,297 - freqtrade.strategy.hyper - INFO - No params for buy found, using default values.
2024-05-08 12:03:57,297 - freqtrade.strategy.hyper - INFO - No params for sell found, using default values.
2024-05-08 12:03:57,297 - freqtrade.strategy.hyper - INFO - No params for protection found, using default values.
2024-05-08 12:07:29,825 - freqtrade.optimize.backtesting - INFO - Backtesting with data from 2022-01-01 00:00:00 up to 2024-05-07 13:25:00 (857 days).

E:\ft_userdata\user_data>

This is my strategy code:

from freqtrade.strategy.interface import IStrategy
from pandas import DataFrame
import freqtrade.vendor.qtpylib.indicators as qtpylib
import pandas_ta as pta
import talib.abstract as ta
from datetime import datetime, timedelta, timezone
from typing import Optional

# VWAP bands
def VWAPB(dataframe, window_size=20, num_of_std=1):
    df = dataframe.copy()
    df['vwap'] = qtpylib.rolling_vwap(df,window=window_size)
    rolling_std = df['vwap'].rolling(window=window_size).std()
    df['vwap_low'] = df['vwap'] - (rolling_std * num_of_std)
    df['vwap_high'] = df['vwap'] + (rolling_std * num_of_std)
    return df['vwap_low'], df['vwap'], df['vwap_high']

def top_percent_change(dataframe: DataFrame, length: int) -> float:
        """
        Percentage change of the current close from the range maximum Open price

        :param dataframe: DataFrame The original OHLC dataframe
        :param length: int The length to look back
        """
        if length == 0:
            return (dataframe['open'] - dataframe['close']) / dataframe['close']
        else:
            return (dataframe['open'].rolling(length).max() - dataframe['close']) / dataframe['close']

class VWAP(IStrategy):
    """

    author: @jilv220

    """

    # Minimal ROI designed for the strategy.
    # adjust based on market conditions. We would recommend to keep it low for quick turn arounds
    # This attribute will be overridden if the config file contains "minimal_roi"
    minimal_roi = {
        "0": 0.02
    }

    # Optimal stoploss designed for the strategy
    stoploss = -0.99  #实际应为-0.15,是因为加了6倍杠杆

    # Optimal timeframe for the strategy
    timeframe = '5m'

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

        vwap_low, vwap, vwap_high = VWAPB(dataframe, 20, 1)
        dataframe['vwap_low'] = vwap_low
        dataframe['tcp_percent_4'] = top_percent_change(dataframe , 4)
        dataframe['cti'] = pta.cti(dataframe["close"], length=20)
        # RSI
        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
        dataframe['rsi_84'] = ta.RSI(dataframe, timeperiod=84)
        dataframe['rsi_112'] = ta.RSI(dataframe, timeperiod=112)

        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (
                (dataframe['close'] < dataframe['vwap_low']) &
                (dataframe['tcp_percent_4'] > 0.04) &
                (dataframe['cti'] < -0.8) &
                (dataframe['rsi'] < 35) &
                (dataframe['rsi_84'] < 60) &
                (dataframe['rsi_112'] < 60) &
                (dataframe['volume'] > 0)
            ),
            'buy'] = 1
        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (
            ),
            'sell'] = 1
        return dataframe

    def leverage(self, pair: str, current_time: datetime, current_rate: float,
                 proposed_leverage: float, max_leverage: float, entry_tag: Optional[str],
                 side: str, **kwargs) -> float:

        return 6.0

Ask the question you have not been able to find an answer in the Documentation

Seems like the usual "run out of memory" issue

seems like it, yes - but "the usual error" won't help a user who never encountered this 😆


Best try to reduce the timerange for your backtest to counter this.

Depending on the timeframe (and number of pairs) - memory consumption can become significant - and at some point, the operating systems ofte decide to "victimze" the process with the most memory consumption.
The process (freqtrade, in this case) will not be informed by this - so there's no way for us to show a message highlighting this.

The combination of "docker on windows" makes this slightly worse - as by default, docker will not be able to use all available memory - but is limited to 2GB of the host's memory source. Apparently, this can be increased in the UI - though i've never tried this combination myself.

using --eps will make this problem worse - and will result in a backtest that is impossible to reproduce (this setting serves a very specific purpose - and is not suited / meant for regular use).

Closing this - as it's a "simple" out of memory error - to which solutions have been described above.