Basics
mode: spot
timeframe: 1d
interface version: 3
Settings
stoploss: -1.0
has minimal roi
process only new candles
startup candle count: 30
hyperopt
hyperopt params: 2
Indicators
ATR
pandas_ta
talib
technical
Methods
buy_sell
plot_config
tp_sl
2 related strategies (⧉ identical code, ≈ similar name)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | # ============================================================================================== # KDA strategy for Spot # # Made by: # ______ _ _ _____ _ ______ _ # | _ \ | | | | / __ \ | | | _ \ | | # | | | | _ _ | |_ ___ | |__ | / \/ _ __ _ _ _ __ | |_ ___ | | | | __ _ __| | # | | | || | | || __|/ __|| '_ \ | | | '__|| | | || '_ \ | __|/ _ \ | | | |/ _` | / _` | # | |/ / | |_| || |_| (__ | | | || \__/\| | | |_| || |_) || |_| (_) || |/ /| (_| || (_| | # |___/ \__,_| \__|\___||_| |_| \____/|_| \__, || .__/ \__|\___/ |___/ \__,_| \__,_| # __/ || | # |___/ |_| # Version : 1.0 # Date : 2023-05 # Remarks : # As published, explained and tested in my Youtube video and blog site. # Visit my site for more information: https://www.dutchalgotrading.com/ # Become my Patron: https://www.patreon.com/dutchalgotrading # ============================================================================================== # --- Used commands for later reference --- # source .env/bin/activate # freqtrade --version # freqtrade new-config # freqtrade new-strategy --strategy <strategyname> # freqtrade test-pairlist -c user_data/spot_config.json # freqtrade download-data -c user_data/spot_config.json --timerange 20170606- -t 1d 4h 1h 30m 15m 5m 1m # freqtrade backtesting -c user_data/spot_config.json -s kda_s --timerange=20190101-20210530 --timeframe=1d # freqtrade backtesting -c user_data/spot_config.json -s kda_s --timerange=-20230101 --timeframe=1d # freqtrade backtesting-analysis # freqtrade hyperopt -c user_data/spot_config.json -s kda_s --epochs 50 --spaces sell --random-state 8105 --min-trades 10 --hyperopt-loss SharpeHyperOptLoss # freqtrade plot-dataframe -p BTC/USDT --strategy kda_s -c user_data/spot_config.json # # freqtrade backtesting -c user_data/spot_config.json -s kda_s --timerange=-20230101 --timeframe=1d -p CRV/USDT --export=signals # freqtrade backtesting-analysis -c user_data/spot_config.json --analysis-groups 0 1 2 3 4 5 --enter-reason-list signal_long --indicator-list buyprice takeprofit stoploss close atr # freqtrade plot-dataframe -p CRV/USDT --strategy kda_s -c user_data/spot_config.json # ============================================================================================== # pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement # flake8: noqa: F401 # isort: skip_file # --- Do not remove these libs --- import numpy as np import pandas as pd from pandas import DataFrame from datetime import datetime from typing import Optional, Union from freqtrade.strategy import ( BooleanParameter, CategoricalParameter, DecimalParameter, IntParameter, IStrategy, merge_informative_pair, ) # -------------------------------- # Add your lib to import here import talib.abstract as ta import pandas_ta as pta from technical import qtpylib class kda_s(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 # Proposed timeframe for the strategy. Can be altered to your own preferred timeframe. timeframe = "1d" # Can this strategy go short? can_short: bool = False # Minimal ROI designed for the strategy. minimal_roi = {"0": 100.0} # Optimal stoploss designed for the strategy. # Either the stoploss according to the strategy get's hit or 25% loss should be taken. stoploss = -1 # Trailing stoploss trailing_stop = False # Run "populate_indicators()" only for new candle. process_only_new_candles = True # These values can be overridden in the config. use_exit_signal = True exit_profit_only = False ignore_roi_if_entry_signal = False # Number of candles the strategy requires before producing valid signals # Set to the default of 30. startup_candle_count: int = 30 # Optional order type mapping. order_types = { "entry": "limit", "exit": "limit", "stoploss": "market", "stoploss_on_exchange": False, } # Optional order time in force. order_time_in_force = {"entry": "GTC", "exit": "GTC"} @property def plot_config(self): return { 'main_plot': { 'takeprofit': {"color": "green"}, 'stoploss': {'color': 'red'}, 'buyprice': {'color': 'grey'} }, 'subplots': { # Subplots - each dict defines one additional plot "KTS": { 'kst': {'color': 'blue'}, 'ksts': {'color': 'orange'}, }, "DPO": { 'dpo': {'color': 'purple'}, }, "ATR": { 'atr': {'color': 'grey'}, } } } # Optimization spaces - Using categorical parameters to limit the amount of possible outcomes and optimization time # Uncomment this if you want to hyperopt atr_sl_mult_space = CategoricalParameter([1, 1.5, 2, 2.5, 3, 3.5, 4], default=2, space="sell") r_r_space = CategoricalParameter([1, 1.5, 2, 2.5, 3, 3.5, 4], default=2, space="sell") def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: # Creating the Know Sure Thing', 'Deterrent Price Oscillator' and 'Average True Range'. dataframe['kst'] = pta.kst(close=dataframe['close'])['KST_10_15_20_30_10_10_10_15'] dataframe['ksts'] = pta.kst(close=dataframe['close'])['KSTs_9'] dataframe['dpo'] = pta.dpo(close=dataframe['close'], lookahead=False) dataframe['atr'] = pta.atr(close=dataframe['close'], high=dataframe['high'], low=dataframe['low']) # These are the variables where I can determine how low the stop loss should be or # how far the risk reward ratio should be. These should be tweaked for optimal performance # Uncomment this if you want to manually determine the atr and r:r settings # atr_sl_mult = 2.5 # r_r = 2 # Determine the optimal stoploss and risk:reward settings # Uncomment this if you want to hyperopt for val in self.atr_sl_mult_space.range: atr_sl_mult = val for val in self.r_r_space.range: r_r = val # Functions for additional columns and calculations def buy_sell(data): ''' This function looks at the conditions for each cell in a row and detects long or short if all the specific conditions are met. If not, then the Neutral signal is given. ''' signal = [] for i in range(len(dataframe)): if ((dataframe['kst'][i] > dataframe['ksts'][i]) & (dataframe['dpo'][i] > 0)): signal.append('long') elif ((dataframe['kst'][i] < dataframe['ksts'][i]) & (dataframe['dpo'][i] < 0)): signal.append('short') else: signal.append('Neutral') return signal # Add the long or short signals to the dataframe column signal dataframe['signal'] = buy_sell(dataframe) dataframe['advice_changed'] = dataframe['signal'].shift(+1) != dataframe['signal'] def tp_sl(data): # Make some empty lists to store information later stoploss = [] takeprofit = [] buyprice = [] # Preconfigured values that are used as 'memory' of the last candle value in this function previous_signal = None previous_stoploss = np.nan previous_takeprofit = np.nan previous_buyprice = np.nan for i, row in data.iterrows(): current_signal = row['signal'] # Here is where the values are calculated, based on the status of the signals if current_signal != previous_signal: if current_signal == 'long': stoploss.append(row['close'] - (row['atr'] * atr_sl_mult)) takeprofit.append(row['close'] + ((row['atr'] * atr_sl_mult) * r_r)) buyprice.append(row['close']) elif current_signal == 'short': stoploss.append(row['close'] + (row['atr'] * atr_sl_mult)) takeprofit.append(row['close'] - ((row['atr'] * atr_sl_mult) * r_r)) buyprice.append(row['close']) else: stoploss.append(np.nan) takeprofit.append(np.nan) buyprice.append(np.nan) previous_stoploss = stoploss[-1] previous_takeprofit = takeprofit[-1] previous_buyprice = buyprice[-1] else: stoploss.append(previous_stoploss) takeprofit.append(previous_takeprofit) buyprice.append(previous_buyprice) previous_signal = current_signal # Finally add the outcome of the statements above to the dataframe data['stoploss'] = stoploss data['takeprofit'] = takeprofit data['buyprice'] = buyprice return data # Run the function that creates tp, sl and buy tp_sl(dataframe) # first check if dataprovider is available if self.dp: if self.dp.runmode.value in ("live", "dry_run"): ob = self.dp.orderbook(metadata["pair"], 1) dataframe["best_bid"] = ob["bids"][0][0] dataframe["best_ask"] = ob["asks"][0][0] # Uncomment this for analyzing dataframe generation and output # print(self) # print(metadata) # print(dataframe.tail(55)) return dataframe def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe.loc[ ( # If buy long signal is True, then enter a long trade (dataframe["signal"] == 'long') & (dataframe["advice_changed"] == True) & (dataframe["volume"] > 0) # Guard ), ["enter_long", "enter_tag"], ] = (1, "signal_long") return dataframe def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe.loc[ ( # There can be two conditions under which the long trade can be exited # close is either above takeprofit or below stoploss. (dataframe["close"] > dataframe["takeprofit"]) # & (dataframe["signal"] == 'long') & (dataframe["volume"] > 0) # Guard ), ["exit_long", "exit_tag"], ] = (1, "takeprofit_long_exit") dataframe.loc[ ( # There can be two conditions under which the long trade can be exited # close is either above takeprofit or below stoploss. (dataframe["close"] < dataframe["stoploss"]) # & (dataframe["signal"] == 'long') & (dataframe["volume"] > 0) # Guard ), ["exit_long", "exit_tag"], ] = (1, "stoploss_long_exit") # # Just an additional idea that I left behind # dataframe.loc[ # ( # # There is one final exit signal that indicates that the momentum is over # # and the chance of getting profits is negligable. That is when the KST get's below its KST signal line # (dataframe["kst"] < dataframe["ksts"]) # # & (dataframe["signal"] == 'long') # & (dataframe["volume"] > 0) # Guard # ), # ["exit_long", "exit_tag"], # ] = (1, "momentum_long_passed_exit") return dataframe |
Strategy League — fixed backtest that feeds the ranking
Export report Freqtrade logsRun finished · took 20.2s
pairs 33 pairs
timerange 20210101-20260101
mode spot
timeframe 1d
stake 100 USDT
wallet 1000 USDT
max open trades 10
fee exchange lowest tier
total profit+105.16%
final wallet2052 USDT
win rate33.9%
max drawdown-36.68%
market change+403.38%
vs market-298.22%
timeframe1d
profit factor1.21
expectancy ratio0.136
sharpe0.383
sortino1.322
CAGR+15.4%
calmar3.0
avg MFE+21.65%
avg MAE-14.79%
avg profit/trade1.71%
avg duration365h 06m
best trade+323.37%
worst trade-57.25%
positive months27/60
consistent (3-mo)48.3%
worst 3-mo-47.79%
trades616
revision1
likely annual return+15%
range (5th–95th)+3% … +32%
chance of profit98.5%
worst-5% outcome+0%
significance (p)0.066
risk of ruin0.0%
- did not beat simply holding the market
- 98% of resampled runs stayed profitable
Resampling the trade sequence 2,000× shows the spread of results this edge could plausibly produce — separating a dependable strategy from one that got lucky once.
Loading charts…
Monthly breakdown
| Month | Regime | Trades | Profit % | Avg % | Win | Loss | Win % | DD % | Avg dur |
|---|---|---|---|---|---|---|---|---|---|
| Jan 2026 | bullish trending low vol | 4 | -0.55 | -1.36 | 1 | 3 | 25.0 | -24.78 | 372h 00m |
| Dec 2025 | bearish trending low vol | 7 | -6.43 | -9.18 | 0 | 7 | 0.0 | -24.54 | 274h 17m |
| Nov 2025 | bearish trending high vol | 9 | +5.04 | 5.60 | 3 | 6 | 33.3 | -22.6 | 210h 40m |
| Oct 2025 | bearish trending low vol | 13 | -18.44 | -14.19 | 1 | 12 | 7.7 | -24.03 | 238h 09m |
| Sep 2025 | bullish choppy low vol | 19 | -1.20 | -0.63 | 5 | 14 | 26.3 | -17.93 | 337h 16m |
| Aug 2025 | bullish choppy low vol | 11 | -3.52 | -3.20 | 2 | 9 | 18.2 | -16.83 | 364h 22m |
| Jul 2025 | bullish choppy low vol | 8 | +12.94 | 16.17 | 7 | 1 | 87.5 | -19.42 | 462h 00m |
| Jun 2025 | bearish choppy low vol | 6 | +3.61 | 6.01 | 4 | 2 | 66.7 | -21.0 | 712h 00m |
| May 2025 | bullish trending low vol | 11 | +8.06 | 7.33 | 7 | 4 | 63.6 | -24.67 | 591h 16m |
| Apr 2025 | bullish choppy low vol | 10 | -13.35 | -13.35 | 0 | 10 | 0.0 | -24.56 | 297h 36m |
| Mar 2025 | bearish trending high vol | 15 | -26.30 | -17.54 | 0 | 15 | 0.0 | -19.67 | 200h 00m |
| Feb 2025 | bearish trending low vol | 8 | -7.38 | -9.23 | 0 | 8 | 0.0 | -10.02 | 267h 00m |
| Jan 2025 | bearish choppy low vol | 13 | -14.11 | -10.85 | 1 | 12 | 7.7 | -7.31 | 289h 51m |
| Dec 2024 | bullish trending low vol | 6 | +0.69 | 1.16 | 3 | 3 | 50.0 | -3.26 | 368h 00m |
| Nov 2024 | bullish trending low vol | 22 | +31.79 | 14.44 | 13 | 9 | 59.1 | -15.52 | 340h 22m |
| Oct 2024 | bullish choppy low vol | 11 | +2.53 | 2.30 | 6 | 5 | 54.5 | -14.98 | 519h 16m |
| Sep 2024 | bearish choppy low vol | 16 | -6.14 | -3.84 | 3 | 13 | 18.8 | -18.16 | 268h 30m |
| Aug 2024 | bearish choppy high vol | 8 | -0.92 | -1.15 | 1 | 7 | 12.5 | -13.45 | 357h 00m |
| Jul 2024 | bearish trending low vol | 7 | -0.82 | -1.18 | 2 | 5 | 28.6 | -12.38 | 408h 00m |
| Jun 2024 | bearish choppy low vol | 14 | -7.94 | -5.67 | 4 | 10 | 28.6 | -12.08 | 435h 26m |
| May 2024 | bullish choppy high vol | 5 | -2.13 | -4.25 | 1 | 4 | 20.0 | -9.17 | 408h 00m |
| Apr 2024 | bearish choppy high vol | 10 | -16.99 | -17.00 | 0 | 10 | 0.0 | -8.39 | 235h 12m |
| Mar 2024 | bullish trending high vol | 12 | +23.12 | 19.27 | 8 | 4 | 66.7 | -10.1 | 486h 00m |
| Feb 2024 | bullish trending low vol | 7 | +15.31 | 21.86 | 6 | 1 | 85.7 | -15.68 | 500h 34m |
| Jan 2024 | bearish choppy high vol | 17 | -2.02 | -1.19 | 2 | 15 | 11.8 | -16.25 | 319h 04m |
| Dec 2023 | bullish trending low vol | 11 | +8.35 | 7.59 | 4 | 7 | 36.4 | -19.14 | 279h 16m |
| Nov 2023 | bullish trending low vol | 10 | +22.07 | 22.06 | 10 | 0 | 100.0 | -26.28 | 340h 48m |
| Oct 2023 | bullish trending low vol | 16 | +15.98 | 9.98 | 10 | 6 | 62.5 | -32.3 | 429h 00m |
| Sep 2023 | bearish choppy low vol | 4 | +0.08 | 0.19 | 2 | 2 | 50.0 | -32.67 | 330h 00m |
| Aug 2023 | bearish choppy low vol | 4 | -0.81 | -2.03 | 1 | 3 | 25.0 | -32.84 | 402h 00m |
| Jul 2023 | bullish trending low vol | 19 | +8.73 | 4.59 | 9 | 10 | 47.4 | -34.79 | 377h 41m |
| Jun 2023 | bullish trending low vol | 15 | -7.22 | -4.81 | 3 | 12 | 20.0 | -36.68 | 281h 36m |
| Apr 2023 | bullish trending low vol | 13 | +2.41 | 1.85 | 5 | 8 | 38.5 | -33.22 | 518h 46m |
| Mar 2023 | bullish trending high vol | 12 | -16.90 | -14.08 | 1 | 11 | 8.3 | -33.7 | 350h 00m |
| Feb 2023 | bullish trending low vol | 6 | -5.60 | -9.33 | 2 | 4 | 33.3 | -27.5 | 420h 00m |
| Jan 2023 | bullish trending low vol | 10 | +20.39 | 20.38 | 10 | 0 | 100.0 | -32.08 | 208h 48m |
| Dec 2022 | bearish trending low vol | 12 | -13.12 | -10.93 | 1 | 11 | 8.3 | -32.92 | 346h 00m |
| Nov 2022 | bearish trending high vol | 15 | -15.58 | -10.38 | 4 | 11 | 26.7 | -28.11 | 353h 36m |
| Oct 2022 | bullish choppy low vol | 12 | -1.68 | -1.40 | 2 | 10 | 16.7 | -23.87 | 324h 00m |
| Sep 2022 | bearish choppy high vol | 9 | -7.84 | -8.71 | 2 | 7 | 22.2 | -23.21 | 296h 00m |
| Aug 2022 | bullish choppy high vol | 11 | +0.47 | 0.43 | 4 | 7 | 36.4 | -20.4 | 805h 05m |
| Jul 2022 | bearish trending high vol | 6 | +13.20 | 21.99 | 4 | 2 | 66.7 | -25.28 | 452h 00m |
| Jun 2022 | bearish trending high vol | 9 | -21.79 | -24.21 | 0 | 9 | 0.0 | -23.92 | 237h 20m |
| May 2022 | bearish trending high vol | 3 | -2.49 | -8.35 | 1 | 2 | 33.3 | -16.81 | 136h 00m |
| Apr 2022 | bearish choppy high vol | 8 | +0.61 | 0.79 | 3 | 5 | 37.5 | -15.11 | 537h 00m |
| Mar 2022 | bullish choppy high vol | 6 | +8.32 | 13.86 | 3 | 3 | 50.0 | -19.48 | 300h 00m |
| Feb 2022 | bearish trending high vol | 10 | -14.89 | -14.89 | 0 | 10 | 0.0 | -18.28 | 350h 24m |
| Jan 2022 | bearish trending high vol | 13 | -16.97 | -13.05 | 1 | 12 | 7.7 | -12.82 | 324h 55m |
| Dec 2021 | bearish trending high vol | 5 | -2.19 | -4.29 | 1 | 4 | 20.0 | -8.86 | 172h 48m |
| Nov 2021 | bullish trending high vol | 16 | -0.54 | -0.34 | 5 | 11 | 31.2 | -6.48 | 475h 30m |
| Oct 2021 | bullish trending high vol | 6 | +2.99 | 5.02 | 2 | 4 | 33.3 | -5.6 | 536h 00m |
| Sep 2021 | bearish trending high vol | 9 | -9.84 | -10.97 | 2 | 7 | 22.2 | -6.69 | 290h 40m |
| Aug 2021 | bullish trending high vol | 11 | +38.29 | 34.83 | 10 | 1 | 90.9 | -16.07 | 388h 22m |
| Jul 2021 | bearish trending high vol | 10 | -20.38 | -20.40 | 1 | 9 | 10.0 | -17.33 | 321h 36m |
| Jun 2021 | bearish trending high vol | 3 | -8.61 | -28.69 | 0 | 3 | 0.0 | -9.65 | 288h 00m |
| May 2021 | bearish trending high vol | 13 | +4.54 | 3.48 | 3 | 10 | 23.1 | -6.5 | 367h 23m |
| Apr 2021 | bearish choppy high vol | 14 | +31.86 | 22.76 | 9 | 5 | 64.3 | -0.81 | 418h 17m |
| Mar 2021 | bullish choppy high vol | 8 | +32.65 | 40.80 | 3 | 5 | 37.5 | -2.81 | 396h 00m |
| Feb 2021 | bullish trending high vol | 14 | +77.90 | 55.60 | 9 | 5 | 64.3 | -3.69 | 358h 17m |
| Jan 2021 | bullish trending high vol | 4 | +7.94 | 19.86 | 2 | 2 | 50.0 | -2.06 | 108h 00m |
Yearly breakdown
| Year | Trades | Profit % | Avg % | Win | Loss | Win % | DD % | Avg dur |
|---|---|---|---|---|---|---|---|---|
| 2026 | 4 | -0.55 | -1.36 | 1 | 3 | 25.0 | -24.78 | 372h 00m |
| 2025 | 130 | -61.08 | -4.70 | 30 | 100 | 23.1 | -24.67 | 336h 00m |
| 2024 | 135 | +36.48 | 2.70 | 49 | 86 | 36.3 | -18.16 | 375h 17m |
| 2023 | 120 | +47.48 | 3.95 | 57 | 63 | 47.5 | -36.68 | 360h 12m |
| 2022 | 114 | -71.76 | -6.29 | 25 | 89 | 21.9 | -32.92 | 385h 28m |
| 2021 | 113 | +154.61 | 13.68 | 47 | 66 | 41.6 | -17.33 | 370h 50m |
Trade charts — best 2 and worst 2 performing pairs (full OHLC candles are expensive to render for every pair)
Backtests — over a market period
Backtest this strategy over a chosen crypto-cycle period. These don't affect the League ranking, and need that period's candle data downloaded.
Log in or sign up to run backtests.
| Period | Range | Total % | Win % | Max DD | Trades | |
|---|---|---|---|---|---|---|
| 2020 · DeFi Summer & Pre-Halving Rally | 20200101-20210101 | not run | ||||
| 2021 · Institutional Bull Market | 20210101-20220101 | not run | ||||
| 2022 · Post-Bull Crash & Macro Tightening | 20220101-20230101 | not run | ||||
| 2023–2024 · Recovery & ETF Anticipation | 20230101-20250101 | not run | ||||
| 2025–2026 · Current Cycle | 20250101-20260101 | not run | ||||
Walk forward
Out-of-sample backtest on recent data · 33 pairs · 20260101-20260701.
Backtest trust check
no lookahead patterns · 3 thing(s) worth reviewing before trusting the numbers
| Line | Pattern | Detail | |
|---|---|---|---|
| 167 | review | slow_loop | a `for i in range(len(...))` pass over the dataframe runs in Python for every candle of every pair. Vectorise it, or the run is likely to hit the sandbox timeout before producing a result |
| 193 | review | slow_loop | .iterrows() walks the dataframe one row at a time in Python. Over a full backtest that's millions of iterations -- the usual cause of a sandbox timeout. Express it with vectorised column operations |
| 245 | review | enter_tag_overwrite | enter_tag/exit_tag is written by 3 separate assignments -- they share one column and run in source order, so a row matching more than one condition keeps only the LAST tag. Per-tag statistics won't mean what they appear to |
ran by Ron · took s
Lookahead analysis
freqtrade lookahead-analysis: detects strategies peeking at future candles.