DS_lambo_5m
♡
Basics
mode: spot
timeframe: 5m
interface version: 3
Settings
stoploss: -0.15
has minimal roi
trailing
dca
custom stoploss
protections
process only new candles
startup candle count: 400
hyperopt
hyperopt params: 16
Indicators
Bollinger_Bands
DEMA
EMA
HMA
Heikin_Ashi
RSI
talib
Concepts
dca
risk_management
trailing
15 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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 | from datetime import datetime from functools import reduce from typing import Optional import logging import math import numpy as np from pandas import DataFrame, Series import freqtrade.vendor.qtpylib.indicators as qtpylib import talib.abstract as ta from freqtrade.persistence import Trade from freqtrade.strategy import ( BooleanParameter, DecimalParameter, IntParameter, RealParameter, stoploss_from_open, merge_informative_pair, ) from freqtrade.strategy.interface import IStrategy logger = logging.getLogger(__name__) ############################################################################ # Custom indicators and helper functions ############################################################################ def bollinger_bands(stock_price: Series, window_size: int, num_of_std: float): rolling_mean = stock_price.rolling(window=window_size).mean() rolling_std = stock_price.rolling(window=window_size).std() lower_band = rolling_mean - (rolling_std * num_of_std) return np.nan_to_num(rolling_mean), np.nan_to_num(lower_band) def ha_typical_price(bars: DataFrame) -> Series: res = (bars["ha_high"] + bars["ha_low"] + bars["ha_close"]) / 3.0 return Series(index=bars.index, data=res) class DS_lambo_5m(IStrategy): INTERFACE_VERSION = 3 ######################################################################## # Main ######################################################################## timeframe = "5m" inf_1h = "1h" use_exit_signal = True use_custom_stoploss = False # set True if you actually want to use custom_stoploss() exit_profit_only = True exit_profit_offset = 0.01 ignore_roi_if_entry_signal = False trailing_stop = False trailing_stop_positive = 0.001 trailing_stop_positive_offset = 0.016 trailing_only_offset_is_reached = False process_only_new_candles = True # Was too low for your indicator stack startup_candle_count = 400 initial_safety_order_trigger = -0.018 max_safety_orders = 8 safety_order_step_scale = 1.2 safety_order_volume_scale = 1.4 order_types = { "entry": "market", "exit": "market", "emergency_exit": "market", "force_entry": "market", "force_exit": "market", "stoploss": "market", "stoploss_on_exchange": False, "stoploss_on_exchange_interval": 60, "stoploss_on_exchange_limit_ratio": 0.99, } order_time_in_force = { "entry": "gtc", "exit": "ioc", } slippage_protection = { "retries": 3, "max_slippage": -0.02, } plot_config = { "main_plot": { "ma_buy": {"color": "green"}, "ma_sell": {"color": "orange"}, }, } ######################################################################## # Hyperopt ######################################################################## buy_params = { "lambo_2_enabled": True, "base_nb_candles_buy": 8, "antipump_threshold": 0.133, "lambo2_ema_14_factor": 0.981, "lambo2_rsi_14_limit": 39, "lambo2_rsi_4_limit": 44, } sell_params = { "base_nb_candles_sell": 22, "high_offset_2": 1.01, "high_offset": 1.014, "sell_fisher": 0.39075, "sell_bbmiddle_close": 0.99754, "pHSL": -0.35, "pPF_1": 0.011, "pPF_2": 0.064, "pSL_1": 0.011, "pSL_2": 0.062, } minimal_roi = { "0": 0.99, } stoploss = -0.15 ######################################################################## # Parameters ######################################################################## is_optimize_base_nb_candles = False base_nb_candles_buy = IntParameter( 8, 20, default=buy_params["base_nb_candles_buy"], space="buy", optimize=is_optimize_base_nb_candles, ) base_nb_candles_sell = IntParameter( 8, 20, default=sell_params["base_nb_candles_sell"], space="sell", optimize=is_optimize_base_nb_candles, ) is_optimize_antipump = True antipump_threshold = DecimalParameter( 0, 0.4, default=buy_params["antipump_threshold"], space="buy", optimize=is_optimize_antipump, ) is_optimize_lambo2 = True lambo2_ema_14_factor = DecimalParameter( 0.8, 1.2, decimals=3, default=buy_params["lambo2_ema_14_factor"], space="buy", optimize=is_optimize_lambo2, ) lambo2_rsi_4_limit = IntParameter( 5, 60, default=buy_params["lambo2_rsi_4_limit"], space="buy", optimize=is_optimize_lambo2, ) lambo2_rsi_14_limit = IntParameter( 5, 60, default=buy_params["lambo2_rsi_14_limit"], space="buy", optimize=is_optimize_lambo2, ) is_optimize_stoploss = True pHSL = DecimalParameter( -0.200, -0.040, default=-0.15, decimals=3, space="sell", optimize=is_optimize_stoploss, load=True, ) pPF_1 = DecimalParameter( 0.008, 0.020, default=0.016, decimals=3, space="sell", optimize=is_optimize_stoploss, load=True, ) pSL_1 = DecimalParameter( 0.008, 0.020, default=0.014, decimals=3, space="sell", optimize=is_optimize_stoploss, load=True, ) pPF_2 = DecimalParameter( 0.040, 0.100, default=0.024, decimals=3, space="sell", optimize=is_optimize_stoploss, load=True, ) pSL_2 = DecimalParameter( 0.020, 0.070, default=0.022, decimals=3, space="sell", optimize=is_optimize_stoploss, load=True, ) is_optimize_sell = True sell_fisher = RealParameter( 0.1, 0.5, default=0.38414, space="sell", optimize=is_optimize_sell, ) sell_bbmiddle_close = RealParameter( 0.97, 1.1, default=1.07634, space="sell", optimize=is_optimize_sell, ) high_offset_2 = DecimalParameter( 1.010, 1.020, default=sell_params["high_offset_2"], space="sell", optimize=True, ) high_offset = DecimalParameter( 1.005, 1.015, default=sell_params["high_offset"], space="sell", optimize=True, ) lambo_2_enabled = BooleanParameter( default=buy_params["lambo_2_enabled"], space="buy", optimize=is_optimize_lambo2, ) ######################################################################## # Informative pairs ######################################################################## def informative_pairs(self): pairs = self.dp.current_whitelist() return [(pair, self.inf_1h) for pair in pairs] def informative_1h_indicators(self, metadata: dict) -> DataFrame: assert self.dp, "DataProvider is required for multiple timeframes." informative_1h = self.dp.get_pair_dataframe( pair=metadata["pair"], timeframe=self.inf_1h, ) if informative_1h is None or informative_1h.empty: logger.warning( f"No informative {self.inf_1h} data for {metadata['pair']}" ) return DataFrame() inf_heikinashi = qtpylib.heikinashi(informative_1h.copy()) informative_1h["ha_close"] = inf_heikinashi["close"] informative_1h["rocr"] = ta.ROCR(informative_1h["ha_close"], timeperiod=168) return informative_1h ######################################################################## # Indicators ######################################################################## def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: if dataframe.empty: return dataframe for val in self.base_nb_candles_buy.range: dataframe[f"ma_buy_{val}"] = ta.EMA(dataframe, timeperiod=val) for val in self.base_nb_candles_sell.range: dataframe[f"ma_sell_{val}"] = ta.EMA(dataframe, timeperiod=val) heikinashi = qtpylib.heikinashi(dataframe.copy()) dataframe["ha_open"] = heikinashi["open"] dataframe["ha_close"] = heikinashi["close"] dataframe["ha_high"] = heikinashi["high"] dataframe["ha_low"] = heikinashi["low"] # Pump / anti-pump dataframe["dema_30"] = ta.DEMA(dataframe, timeperiod=30) dataframe["dema_200"] = ta.DEMA(dataframe, timeperiod=200) dataframe["pump_strength"] = np.where( dataframe["dema_30"] != 0, (dataframe["dema_30"] - dataframe["dema_200"]) / dataframe["dema_30"], 0, ) # Buy side dataframe["ema_14"] = ta.EMA(dataframe, timeperiod=14) dataframe["rsi_4"] = ta.RSI(dataframe, timeperiod=4) dataframe["rsi_14"] = ta.RSI(dataframe, timeperiod=14) # Sell side dataframe["hma_50"] = qtpylib.hull_moving_average(dataframe["close"], window=50) dataframe["ema_100"] = ta.EMA(dataframe, timeperiod=100) dataframe["rsi"] = ta.RSI(dataframe, timeperiod=14) dataframe["rsi_fast"] = ta.RSI(dataframe, timeperiod=4) dataframe["rsi_slow"] = ta.RSI(dataframe, timeperiod=20) rsi = ta.RSI(dataframe, timeperiod=14) dataframe["rsi"] = rsi fisher_base = 0.1 * (rsi - 50) dataframe["fisher"] = (np.exp(2 * fisher_base) - 1) / (np.exp(2 * fisher_base) + 1) mid, lower = bollinger_bands( ha_typical_price(dataframe), window_size=40, num_of_std=2, ) dataframe["lower"] = lower dataframe["mid"] = mid dataframe["bbdelta"] = (dataframe["mid"] - dataframe["lower"]).abs() dataframe["closedelta"] = (dataframe["ha_close"] - dataframe["ha_close"].shift()).abs() dataframe["tail"] = (dataframe["ha_close"] - dataframe["ha_low"]).abs() dataframe["bb_lowerband"] = dataframe["lower"] dataframe["bb_middleband"] = dataframe["mid"] dataframe["ema_fast"] = ta.EMA(dataframe["ha_close"], timeperiod=3) dataframe["ema_slow"] = ta.EMA(dataframe["ha_close"], timeperiod=50) dataframe["volume_mean_slow"] = dataframe["volume"].rolling(window=30).mean() dataframe["rocr"] = ta.ROCR(dataframe["ha_close"], timeperiod=28) informative_1h = self.informative_1h_indicators(metadata) if not informative_1h.empty: dataframe = merge_informative_pair( dataframe, informative_1h, self.timeframe, self.inf_1h, ffill=True, ) dataframe = self.pump_dump_protection(dataframe, metadata) return dataframe ######################################################################## # Pump / dump protection ######################################################################## def pump_dump_protection(self, dataframe: DataFrame, metadata: dict) -> DataFrame: if dataframe.empty: return dataframe df36h = dataframe.copy().shift(432) df24h = dataframe.copy().shift(288) dataframe["volume_mean_short"] = dataframe["volume"].rolling(4).mean() dataframe["volume_mean_long"] = df24h["volume"].rolling(48).mean() dataframe["volume_mean_base"] = df36h["volume"].rolling(288).mean() base_safe = dataframe["volume_mean_base"].replace(0, np.nan) long_safe = dataframe["volume_mean_long"].replace(0, np.nan) dataframe["volume_change_percentage"] = dataframe["volume_mean_long"] / base_safe dataframe["rsi_mean"] = dataframe["rsi"].rolling(48).mean() dataframe["pnd_volume_warn"] = np.where( (dataframe["volume_mean_short"] / long_safe) > 5.0, -1, 0, ) dataframe["pnd_volume_warn"] = dataframe["pnd_volume_warn"].fillna(0) return dataframe ######################################################################## # Buy trend ######################################################################## def check_lambo_2(self, dataframe: DataFrame): return ( bool(self.lambo_2_enabled.value) & (dataframe["close"] < (dataframe["ema_14"] * self.lambo2_ema_14_factor.value)) & (dataframe["rsi_4"] < int(self.lambo2_rsi_4_limit.value)) & (dataframe["rsi_14"] < int(self.lambo2_rsi_14_limit.value)) ) def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: if dataframe.empty: return dataframe dataframe["enter_long"] = 0 dataframe["enter_tag"] = "" dont_buy_conditions = dataframe["pnd_volume_warn"] < 0.0 is_pump_safe = dataframe["pump_strength"] < self.antipump_threshold.value conditions_and_tags = [ (self.check_lambo_2(dataframe), "lambo_2"), ] for condition, tag in conditions_and_tags: dataframe.loc[condition, "enter_tag"] = tag dataframe.loc[ condition & is_pump_safe & ~dont_buy_conditions, "enter_long", ] = 1 dataframe.loc[dont_buy_conditions, "enter_long"] = 0 return dataframe ######################################################################## # Sell trend ######################################################################## def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: if dataframe.empty: return dataframe dataframe["exit_long"] = 0 conditions = [] conditions.append( ( (dataframe["close"] > dataframe["hma_50"]) & ( dataframe["close"] > ( dataframe[f"ma_sell_{self.base_nb_candles_sell.value}"] * self.high_offset_2.value ) ) & (dataframe["rsi"] > 50) & (dataframe["volume"] > 0) & (dataframe["rsi_fast"] > dataframe["rsi_slow"]) ) | ( (dataframe["close"] < dataframe["hma_50"]) & ( dataframe["close"] > ( dataframe[f"ma_sell_{self.base_nb_candles_sell.value}"] * self.high_offset.value ) ) & (dataframe["volume"] > 0) & (dataframe["rsi_fast"] > dataframe["rsi_slow"]) ) ) if conditions: combined_condition = reduce(lambda x, y: x | y, conditions) dataframe.loc[combined_condition, "exit_long"] = 1 return dataframe ######################################################################## # Confirm trade exit ######################################################################## def confirm_trade_exit( self, pair: str, trade: Trade, order_type: str, amount: float, rate: float, time_in_force: str, exit_reason: str, current_time: datetime, **kwargs, ) -> bool: dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe) if dataframe is None or dataframe.empty: return True last_candle = dataframe.iloc[-1].squeeze() if exit_reason in ["exit_signal", "sell_signal"]: if ( (last_candle["hma_50"] * 1.149 > last_candle["ema_100"]) and (last_candle["close"] < last_candle["ema_100"] * 0.951) ): return False try: state = self.slippage_protection["__pair_retries"] except KeyError: state = self.slippage_protection["__pair_retries"] = {} slippage = (rate / last_candle["close"]) - 1 if slippage < self.slippage_protection["max_slippage"]: pair_retries = state.get(pair, 0) if pair_retries < self.slippage_protection["retries"]: state[pair] = pair_retries + 1 return False state[pair] = 0 return True ######################################################################## # Trade protections ######################################################################## @property def protections(self): return [ { "method": "CooldownPeriod", "stop_duration_candles": 5, }, { "method": "MaxDrawdown", "lookback_period_candles": 48, "trade_limit": 20, "stop_duration_candles": 4, "max_allowed_drawdown": 0.2, }, { "method": "StoplossGuard", "lookback_period_candles": 24, "trade_limit": 4, "stop_duration_candles": 2, "only_per_pair": False, }, { "method": "LowProfitPairs", "lookback_period_candles": 6, "trade_limit": 2, "stop_duration_candles": 60, "required_profit": 0.02, }, { "method": "LowProfitPairs", "lookback_period_candles": 24, "trade_limit": 4, "stop_duration_candles": 2, "required_profit": 0.01, }, ] ######################################################################## # Adjust trade position ######################################################################## def adjust_trade_position( self, trade: Trade, current_time: datetime, current_rate: float, current_profit: float, min_stake: float, max_stake: float, **kwargs, ): if current_profit > self.initial_safety_order_trigger: return None dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe) if dataframe is None or len(dataframe) < 2: return None last_candle = dataframe.iloc[-1].squeeze() previous_candle = dataframe.iloc[-2].squeeze() if last_candle["close"] < previous_candle["close"]: return None count_of_buys = 0 for order in trade.orders: if order.ft_is_open or order.ft_order_side != "buy": continue if order.status == "closed": count_of_buys += 1 if 1 <= count_of_buys <= self.max_safety_orders: if self.safety_order_step_scale == 1: safety_order_trigger = abs(self.initial_safety_order_trigger) * count_of_buys else: safety_order_trigger = abs(self.initial_safety_order_trigger) + ( abs(self.initial_safety_order_trigger) * self.safety_order_step_scale * ( math.pow(self.safety_order_step_scale, (count_of_buys - 1)) - 1 ) / (self.safety_order_step_scale - 1) ) if current_profit <= (-1 * abs(safety_order_trigger)): try: stake_amount = self.wallets.get_trade_stake_amount(trade.pair, None) stake_amount = stake_amount * math.pow( self.safety_order_volume_scale, (count_of_buys - 1) ) logger.info( f"Initiating safety order buy #{count_of_buys} for {trade.pair} " f"with stake amount {stake_amount}" ) return stake_amount except Exception as exception: logger.info( f"Error while trying to get stake amount for {trade.pair}: {exception}" ) return None return None ######################################################################## # Custom stoploss ######################################################################## def custom_stoploss( self, pair: str, trade: Trade, current_time: datetime, current_rate: float, current_profit: float, **kwargs, ) -> float: HSL = self.pHSL.value PF_1 = self.pPF_1.value SL_1 = self.pSL_1.value PF_2 = self.pPF_2.value SL_2 = self.pSL_2.value if current_profit > PF_2: sl_profit = SL_2 + (current_profit - PF_2) elif current_profit > PF_1: sl_profit = SL_1 + ((current_profit - PF_1) * (SL_2 - SL_1) / (PF_2 - PF_1)) else: sl_profit = HSL return stoploss_from_open(sl_profit, current_profit) ######################################################################## # Custom exit (old custom_sell renamed for interface v3) ######################################################################## def get_max_loss_threshold(self) -> float: return -0.04 def get_max_holding_days(self) -> int: return 7 def custom_exit( self, pair: str, trade: Trade, current_time: datetime, current_rate: float, current_profit: float, **kwargs, ) -> Optional[str]: max_loss_threshold = self.get_max_loss_threshold() max_holding_days = self.get_max_holding_days() days_held = (current_time - trade.open_date_utc).days if current_profit < max_loss_threshold and days_held >= max_holding_days: logger.info( f"Custom exit for {pair}: Held for {days_held} days with profit {current_profit}." ) return "unclog" return None |
Strategy League — fixed backtest that feeds the ranking
Failed — timed out after 1800s (strategy too complex/slow for the sandbox)
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 | |
|---|---|---|---|
| 65 | review | startup_candles_too_small | startup_candle_count is 400, but DEMA(timeperiod=200) needing 3x warmup needs at least 600 candles -- so the first 200+ candles of every backtest use an indicator that hasn't warmed up. Recursive indicators (EMA/RSI/ADX/ATR) want several times their period, not exactly it |
| 623 | review | dead_callback | custom_stoploss() is defined but use_custom_stoploss isn't True, and freqtrade only calls it when that flag is set -- the method never runs and every trade uses the static stoploss |
| 558 | review | dead_callback | adjust_trade_position() is defined but position_adjustment_enable isn't True -- freqtrade never calls it, so the DCA/pyramiding logic here does nothing and every trade stays at its initial stake |
ran by Ron · took s
Lookahead analysis
freqtrade lookahead-analysis: detects strategies peeking at future candles.