freqtradeを一カ月近く走らせました。Dryrun、すなわちデモ取引なのですが。なにかの参考になれば幸いです。戦略はフィボナッチ。先月デモ口座を走らせて、異常にロスが出たものは、取引しないような設定になっています。プロフィットファクターが3を超えたときもありましたが、BTCのETF承認後から雲行きが怪しくなり、どんどんロスが発生しています。
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement# flake8: noqa: F401
# --- Do not remove these libs ---import numpy as np # noqaimport pandas as pd # noqafrom pandas import DataFrame
from freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter,IStrategy, IntParameter)
# --------------------------------# Add your lib to import hereimport talib.abstract as taimport pandas_ta as ptaimport freqtrade.vendor.qtpylib.indicators as qtpylib
from technical.indicators import fibonacci_retracements
class Fibo_2(IStrategy):# Strategy interface version - allow new iterations of the strategy interface.# Check the documentation or the Sample strategy to get the latest version.INTERFACE_VERSION = 3
# Optimal timeframe for the strategy.timeframe = '15m'
# Minimal ROI designed for the strategy.# This attribute will be overridden if the config file contains "minimal_roi".minimal_roi = {"1440": 0.0,"360": 0.01,"240": 0.02,"120": 0.03,"60": 0.04,"0": 0.05}
# Optimal stoploss designed for the strategy.# This attribute will be overridden if the config file contains "stoploss".stoploss = -0.10
# Trailing stoplosstrailing_stop = Truetrailing_only_offset_is_reached = Truetrailing_stop_positive = 0.10trailing_stop_positive_offset = 0.11 # Disabled / not configured
# Run "populate_indicators()" only for new candle.process_only_new_candles = False
# These values can be overridden in the "ask_strategy" section in the config.use_sell_signal = Truesell_profit_only = Falseignore_roi_if_buy_signal = False
# Number of candles the strategy requires before producing valid signalsstartup_candle_count: int = 30
# Strategy parameters
# Optional order type mapping.order_types = {'buy': 'limit','sell': 'limit','stoploss': 'market',}
# Optional order time in force.order_time_in_force = {'buy': 'gtc','sell': 'gtc'}@propertydef plot_config(self):return {'main_plot': {'fibo': {},'plotly': {'name': 'L-0'},# 'color': 'rgba(0,0,0,0)',# 'fill_to': '1st_level',# 'fill_color': 'rgba(51,51,255,0.2)', # blue},'1st_level': {'plotly': {'name': 'L1-0.236 '},# 'fill_to': '2nd_level',# 'fill_color': 'rgba(204,204,255,0.5)', # purple},'2nd_level': {'plotly': {'name': 'L2-0.382 '},# 'fill_to': '3th_level',# 'fill_color': 'rgba(102,255,255,0.5)', # cyan},'3th_level': {'plotly': {'name': 'L3-0.5 '},# 'fill_to': '4th_level',# 'fill_color': 'rgba(255,204,204,0.5)', # orange},'4th_level': {'plotly': {'name': 'L4-0.618 '},# 'fill_to': 'max_value',# 'fill_color': 'rgba(255,255,102,0.3)', # yellow},'plotly': {'name': 'L-100'},# 'color': 'rgba(0,0,0,0)',},},}
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
# Fibonacci Levels ---------------------------------------------------------------------------------------- /
# Fibonacci Levels (UPTREND) - PKG ------------------------------------------------------------------------ /fibo_df = fibonacci_retracements(dataframe)
# Fibonacci Levels (UPTREND) - MANUAL ------------------------------------------------------------------------ /
return dataframe
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:dataframe.loc[((dataframe['close'] < dataframe['3th_level']) &(dataframe['close'].shift(1) > dataframe['3th_level'].shift(1)) &(dataframe['volume'] > 0) # Make sure Volume is not 0),'buy'] = 1
return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:# dataframe.loc[:, 'sell'] = 0
dataframe.loc[((dataframe['volume'] > 0) # Make sure Volume is not 0),'sell'] = 1
return dataframe
環境としては、Dockerのうえで、VSCodeとTelegramを24時間動かしっぱなしにしました。
結果は以下の通り。
ROI: Closed trades
∙ -1360.87 USDT (-1.20%) (-9.07 Σ%)
∙ -1360.629 USD
ROI: All trades
∙ -1525.854 USDT (-1.29%) (-10.17 Σ%)
∙ -1525.584 USD
Total Trade Count: 118
Bot started: 2024-01-06 22:53:47
First Trade opened: 2 weeks ago (2024-01-07 02:10:11)
Latest Trade opened: 15 hours ago (2024-01-26 17:40:10)
Win / Loss: 88 / 25
Winrate: 77.88%
Expectancy (Ratio): -12.04 (-0.11)
Avg. Duration: 1 day, 7:19:38
Best Performing: ASTR/USDT: 13.98%
Trading volume: 230463.504 USDT
Profit factor: 0.50
Max Drawdown: 14.49% (2273.512 USDT)
from 2024-01-17 01:18:42 (686.703 USDT)
to 2024-01-23 14:11:52 (-1586.808 USDT)
あまり良くない。どんな戦略でもそうでしょうけれど、マクロとミクロがぴったり合わないと利益はでないですね。