Specific hyperopt params for specific pairs

This is a very simple example of having different RSI trigger for trade entry for BTC, ETH, BNB, and the rest of the pairs.

import numpy as np
import talib.abstract as ta
from freqtrade.strategy import IStrategy
from freqtrade.strategy import IntParameter
from pandas import DataFrame, Series
from typing import Dict, List, Optional, Tuple, Union
from functools import reduce
from freqtrade.persistence import Trade
import logging
from logging import FATAL

logger = logging.getLogger(__name__)

class RSI_specific (IStrategy):

	def version(self) -> str:
		return "rsi-specific-v1"

	INTERFACE_VERSION = 3

	minimal_roi = {
		"0": 0.01
	}

	buy_rsi_btc = IntParameter(1, 10, default=5, optimize=True)
	buy_rsi_eth = IntParameter(1, 10, default=5, optimize=True)
	buy_rsi_bnb = IntParameter(1, 10, default=5, optimize=True)
	buy_rsi_others = IntParameter(1, 10, default=5, optimize=True)

	# Stoploss:
	stoploss = -0.05

	# Trailing stop:
	trailing_stop = False
	trailing_stop_positive = 0.01
	trailing_stop_positive_offset = 0.03
	trailing_only_offset_is_reached = False

	# Sell signal
	use_exit_signal = True
	exit_profit_only = False
	exit_profit_offset = 0.01
	ignore_roi_if_entry_signal = False

	timeframe = '5m'

	process_only_new_candles = True
	startup_candle_count = 999

	def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
		
		dataframe['rsi'] = ta.RSI(dataframe['close'], timeperiod=14)

		return dataframe
	
	def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
		
		conditions = []

		buy_rsi_entry = 5 * self.buy_rsi_others.value

		if (metadata['pair'].startswith('BTC/')):
			buy_rsi_entry = 5 * self.buy_rsi_btc.value
		else if (metadata['pair'].startswith('ETH/')):
			buy_rsi_entry = 5 * self.buy_rsi_eth.value
		else if (metadata['pair'].startswith('BNB/')):
			buy_rsi_entry = 5 * self.buy_rsi_bnb.value
		
		dataframe['enter_tag'] = ''
		dataframe['enter_long'] = 0

		buy_1 = (
			(dataframe['rsi'] < buy_rsi_entry)
		)
		dataframe.loc[buy_1, 'enter_tag'] += 'rsi '
		conditions.append(buy_1)

		if conditions:

			dataframe.loc[
				reduce(lambda x, y: x | y, conditions)
				&
				add_check,
				'enter_long',
			]= 1

		return dataframe

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

		dataframe['exit_tag'] = ''
		conditions = []

		sell_1 = (
			(dataframe['rsi'] > 70)
		)
		conditions_short.append(sell_1)
		dataframe.loc[sell_1, 'exit_tag'] += 'rsi_up '

		if conditions:
			dataframe.loc[
				reduce(lambda x, y: x | y, conditions)
				&
				add_check,
				'exit_long',
			]= 1

		return dataframe

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *