IchiV1 Strategy ported to V3
Timeframe
5m
Direction
Long Only
Stoploss
-5.0%
Trailing Stop
Yes
ROI
0m: 2.0%, 5m: 1.5%, 15m: 1.0%, 30m: 0.5%
Interface Version
3
Startup Candles
96
Indicators
3
freqtrade/freqtrade-strategies
# --- Do not remove these libs ---
from freqtrade.strategy import IStrategy
from pandas import DataFrame
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
import pandas as pd # noqa
pd.options.mode.chained_assignment = None # default='warn'
import technical.indicators as ftt
from functools import reduce
from datetime import datetime, timedelta
from freqtrade.strategy import merge_informative_pair
import numpy as np
from freqtrade.strategy import stoploss_from_open
class IchiV1(IStrategy):
"""
IchiV1 Strategy ported to V3
"""
INTERFACE_VERSION = 3
# NOTE: Optimized for faster trading pace (~24 trades/day)
# Buy hyperspace params:
buy_params = {
"buy_trend_above_senkou_level": 1,
"buy_trend_bullish_level": 4, # Lowered from 6 to allow more entries
"buy_fan_magnitude_shift_value": 1, # Reduced from 3 to allow faster entries
"buy_min_fan_magnitude_gain": 1.0005 # Lowered from 1.002 for more frequent signals
}
# Sell hyperspace params:
sell_params = {
"sell_trend_indicator": "trend_close_15m", # Changed from 2h to 15m for faster exits
}
# ROI table: Tighter targets for faster closes
minimal_roi = {
"0": 0.02, # Take 2% profit immediately if available
"5": 0.015, # 1.5% after 5 minutes
"15": 0.01, # 1% after 15 minutes
"30": 0.005, # 0.5% after 30 minutes
"60": 0 # Close at breakeven after 1 hour
}
# Stoploss: Tighter for less margin risk
stoploss = -0.05 # Changed from -27.5% to -5%
# Optimal timeframe for the strategy
timeframe = '5m'
startup_candle_count = 96
process_only_new_candles = False
trailing_stop = True
trailing_stop_positive = 0.005 # Trail at 0.5% profit
trailing_stop_positive_offset = 0.01 # Start trailing after 1% profit
trailing_only_offset_is_reached = True
use_exit_signal = True
exit_profit_only = False
ignore_roi_if_entry_signal = False
# Plot config
plot_config = {
'main_plot': {
'senkou_a': {
'color': 'green',
'fill_to': 'senkou_b',
'fill_label': 'Ichimoku Cloud',
'fill_color': 'rgba(255,76,46,0.2)',
},
'senkou_b': {},
'trend_close_5m': {'color': '#FF5733'},
'trend_close_2h': {'color': '#E3FF33'},
},
'subplots': {
'fan_magnitude': {
'fan_magnitude': {}
},
}
}
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
heikinashi = qtpylib.heikinashi(dataframe)
dataframe['open'] = heikinashi['open']
dataframe['high'] = heikinashi['high']
dataframe['low'] = heikinashi['low']
# Do not overwrite close with HA close for typical price action strategies unless strictly intended
# The original strategy commented out HA close, so we will use regular close for indicators?
# Revisiting logic: The original populated `trend_close_5m` = `close`.
# If we use HA open/high/low, but regular close, it's a mix.
# However, looking at the code: `dataframe['open'] = heikinashi['open']`.
# It modifies the main dataframe "open" column. This is risky for backtesting if not careful.
# But this is what the user provided. We will trust the logic "as provided" but ensure V3 compatibility.
dataframe['trend_close_5m'] = dataframe['close']
dataframe['trend_close_15m'] = ta.EMA(dataframe['close'], timeperiod=3)
dataframe['trend_close_30m'] = ta.EMA(dataframe['close'], timeperiod=6)
dataframe['trend_close_1h'] = ta.EMA(dataframe['close'], timeperiod=12)
dataframe['trend_close_2h'] = ta.EMA(dataframe['close'], timeperiod=24)
dataframe['trend_close_4h'] = ta.EMA(dataframe['close'], timeperiod=48)
dataframe['trend_close_6h'] = ta.EMA(dataframe['close'], timeperiod=72)
dataframe['trend_close_8h'] = ta.EMA(dataframe['close'], timeperiod=96)
dataframe['trend_open_5m'] = dataframe['open']
dataframe['trend_open_15m'] = ta.EMA(dataframe['open'], timeperiod=3)
dataframe['trend_open_30m'] = ta.EMA(dataframe['open'], timeperiod=6)
dataframe['trend_open_1h'] = ta.EMA(dataframe['open'], timeperiod=12)
dataframe['trend_open_2h'] = ta.EMA(dataframe['open'], timeperiod=24)
dataframe['trend_open_4h'] = ta.EMA(dataframe['open'], timeperiod=48)
dataframe['trend_open_6h'] = ta.EMA(dataframe['open'], timeperiod=72)
dataframe['trend_open_8h'] = ta.EMA(dataframe['open'], timeperiod=96)
dataframe['fan_magnitude'] = (dataframe['trend_close_1h'] / dataframe['trend_close_8h'])
dataframe['fan_magnitude_gain'] = dataframe['fan_magnitude'] / dataframe['fan_magnitude'].shift(1)
ichimoku = ftt.ichimoku(dataframe, conversion_line_period=20, base_line_periods=60, laggin_span=120, displacement=30)
dataframe['senkou_a'] = ichimoku['senkou_span_a']
dataframe['senkou_b'] = ichimoku['senkou_span_b']
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = []
# Trending market
if self.buy_params['buy_trend_above_senkou_level'] >= 1:
conditions.append(dataframe['trend_close_5m'] > dataframe['senkou_a'])
conditions.append(dataframe['trend_close_5m'] > dataframe['senkou_b'])
# Trends bullish (relaxed for more signals)
if self.buy_params['buy_trend_bullish_level'] >= 4:
conditions.append(dataframe['trend_close_1h'] > dataframe['trend_open_1h'])
# Trends magnitude
conditions.append(dataframe['fan_magnitude_gain'] >= self.buy_params['buy_min_fan_magnitude_gain'])
conditions.append(dataframe['fan_magnitude'] > 1)
for x in range(self.buy_params['buy_fan_magnitude_shift_value']):
conditions.append(dataframe['fan_magnitude'].shift(x+1) < dataframe['fan_magnitude'])
if conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
'enter_long'] = 1
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = []
conditions.append(qtpylib.crossed_below(dataframe['trend_close_5m'], dataframe[self.sell_params['sell_trend_indicator']]))
if conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
'exit_long'] = 1
return dataframe