Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hyperopt for time parameters #7964

Closed
Nayefuk opened this issue Jan 2, 2023 · 0 comments
Closed

Hyperopt for time parameters #7964

Nayefuk opened this issue Jan 2, 2023 · 0 comments
Labels
Question Questions - will be closed after some period of inactivity.

Comments

@Nayefuk
Copy link

Nayefuk commented Jan 2, 2023

Describe your environment

  • Operating system: Ubuntu 22.04 / Linux5.15
  • Python Version: 3.10.6
  • CCXT version: CCXT 1.92.20
  • Freqtrade Version: 2022.8.dev-686b72a82

Your question

How do I run hyperopt on time parameters? this is the code ive come up with thus far, but it doesnt seem to be working.

``

# Strategy parameters
buy_open_hour = IntParameter(0, 23, default=23, space="buy")
buy_open_minute = IntParameter(0, 59, default=58, space="buy")

sell_open_hour = IntParameter(0, 23, default=23, space="sell")
sell_open_minute = IntParameter(0, 59, default=58, space="sell")

# Run "populate_indicators()" only for new candle.
process_only_new_candles = False

# Number of candles the strategy requires before producing valid signals
startup_candle_count: int = 0

# Optional order type mapping.
order_types = {
    'entry': 'market',
    'exit': 'limit',
    'stoploss': 'limit',
    'stoploss_on_exchange': False
}

# Optional order time in force.
order_time_in_force = {
    'entry': 'gtc',
    'exit': 'gtc'
}

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:
    """
    Customize leverage for each new trade. This method is only called in futures mode.

    :param pair: Pair that's currently analyzed
    :param current_time: datetime object, containing the current datetime
    :param current_rate: Rate, calculated based on pricing settings in exit_pricing.
    :param proposed_leverage: A leverage proposed by the bot.
    :param max_leverage: Max leverage allowed on this pair
    :param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.
    :param side: 'long' or 'short' - indicating the direction of the proposed trade
    :return: A leverage amount, which is between 1.0 and max_leverage.
    """
    return 20.0

def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
    """
    Adds several different TA indicators to the given DataFrame

    Performance Note: For the best performance be frugal on the number of indicators
    you are using. Let uncomment only the indicator you are using in your strategies
    or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
    :param dataframe: Dataframe with data from the exchange
    :param metadata: Additional information, like the currently traded pair
    :return: a Dataframe with all mandatory indicators for the strategies
    """

    """Generate all indicators used by the strategy"""

    current_hour = dataframe['date'].dt.hour
    current_minute = dataframe['date'].dt.minute

    # Calculate all hour values
    for val in self.buy_open_hour.range:
        dataframe[f'hour_{val}'] = dataframe['date'].dt.hour

    # Calculate all minute values
    for val in self.buy_open_minute.range:
        dataframe[f'minute_{val}'] = dataframe['date'].dt.minute

    return dataframe

def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
    conditions = []
    conditions.append(dataframe[f'hour_{self.buy_open_hour.value}'])
    conditions.append(dataframe[f'minute_{self.buy_open_minute.value}'])
    conditions.append(dataframe['volume'] > 0)

    if conditions:
        dataframe.loc[
            reduce(lambda x, y: x & y, conditions),
            'enter_long'] = 1
    return dataframe
@Nayefuk Nayefuk added the Question Questions - will be closed after some period of inactivity. label Jan 2, 2023
@Nayefuk Nayefuk closed this as completed Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Questions - will be closed after some period of inactivity.
Projects
None yet
Development

No branches or pull requests

1 participant