import copy
import logging
import pathlib
import rapidjson
import numpy as np
import talib.abstract as ta
import pandas as pd
from freqtrade.strategy.interface import IStrategy
from freqtrade.strategy import merge_informative_pair
from pandas import DataFrame, Series
from functools import reduce
from freqtrade.persistence import Trade, Order
from datetime import datetime, timedelta
import time
from typing import Optional
import warnings

log = logging.getLogger(__name__)
# log.setLevel(logging.DEBUG)
warnings.simplefilter(action="ignore", category=pd.errors.PerformanceWarning)


#############################################################################################################
##                 NostalgiaForInfinityX8 by iterativ                                                      ##
##            https://github.com/iterativv/NostalgiaForInfinity                                            ##
##                                                                                                         ##
##    Strategy for Freqtrade https://github.com/freqtrade/freqtrade                                        ##
##                                                                                                         ##
#############################################################################################################
##               GENERAL RECOMMENDATIONS                                                                   ##
##                                                                                                         ##
##   For optimal performance, suggested to use between 6 and 12 open trades, with unlimited stake.         ##
##   A pairlist with 40 to 80 pairs. Volume pairlist works well.                                           ##
##   Prefer stable coin (USDT, USDC etc) pairs, instead of BTC or ETH pairs.                              ##
##   Highly recommended to blacklist leveraged tokens (*BULL, *BEAR, *UP, *DOWN etc).                      ##
##   Ensure that you don't override any variables in you config.json. Especially                           ##
##   the timeframe (must be 5m).                                                                           ##
##     use_exit_signal must set to true (or not set at all).                                               ##
##     exit_profit_only must set to false (or not set at all).                                             ##
##     ignore_roi_if_entry_signal must set to true (or not set at all).                                    ##
##                                                                                                         ##
#############################################################################################################
##               DONATIONS                                                                                 ##
##                                                                                                         ##
##   BTC: bc1qvflsvddkmxh7eqhc4jyu5z5k6xcw3ay8jl49sk                                                       ##
##   ETH (ERC20): 0x83D3cFb8001BDC5d2211cBeBB8cB3461E5f7Ec91                                               ##
##   BEP20/BSC (USDT, ETH, BNB, ...): 0x86A0B21a20b39d16424B7c8003E4A7e12d78ABEe                           ##
##   TRC20/TRON (USDT, TRON, ...): TTAa9MX6zMLXNgWMhg7tkNormVHWCoq8Xk                                      ##
##                                                                                                         ##
##  Patreon: https://www.patreon.com/iterativ                                                              ##
##                                                                                                         ##
##               REFERRAL LINKS                                                                            ##
##                                                                                                         ##
##  Kucoin: https://www.kucoin.com/r/af/QBSSS5J2 (20% lifetime discount on trading fees)                   ##
##  Gate: https://www.gate.com/share/NFINFITY (20% lifetime discount on trading fees)                      ##
##  ByBit: https://partner.bybit.com/b/nfi                                                                 ##
##  ByBit.EU: https://partner.bybit.eu/b/NFINFINITY                                                        ##
##  Bitget: https://bonus.bitget.com/nfinfinity (lifetime 20% +10% extra spot rebate)                      ##
##  Kraken: https://proinvite.kraken.com/rrru/hn3g8qxg (lifetime 20% cashback)                             ##
##  MEXC: https://promote.mexc.com/b/nfinfinity (10% discount on trading fees)                             ##
##  OKX: https://www.okx.com/join/11749725931 (20% discount on trading fees)                               ##
##  HTX: https://www.htx.com/invite/en-us/1f?invite_code=ubpt2223 (signup bonuses)                         ##
##  Bitvavo: https://bitvavo.com/invite?a=D22103A4BC (no fees for the first € 10000)                       ##
##  Binance: https://www.binance.com/join?ref=C68K26A9 (20% discount on trading fees)                      ##
##  BitMart: https://www.bitmart.com/invite/nfinfinity (20% lifetime discount on trading fees)             ##
#############################################################################################################


class NostalgiaForInfinityX8(IStrategy):
  INTERFACE_VERSION = 3

  def version(self) -> str:
    return "v18.0.184"

  stoploss = -0.99

  # Trailing stoploss (not used)
  trailing_stop = False
  trailing_only_offset_is_reached = True
  trailing_stop_positive = 0.01
  trailing_stop_positive_offset = 0.03

  use_custom_stoploss = False
  stoploss_on_exchange = False

  # Optimal timeframe for the strategy.
  timeframe = "5m"
  info_timeframes = ["15m", "1h", "4h", "1d"]

  # BTC informatives
  # btc_info_timeframes = ["5m", "15m", "1h", "4h", "1d"]
  # btc_info_timeframes = ["1h", "4h", "1d"]
  btc_info_timeframes = ["4h"]

  stable_stake_currencies = frozenset(
    ("USDT", "BUSD", "USDC", "DAI", "TUSD", "FDUSD", "PAX", "USD", "EUR", "GBP", "TRY")
  )
  informative_ohlcv_columns = frozenset(("open", "high", "low", "close", "volume"))

  # Backtest Age Filter emulation
  has_bt_agefilter = False
  bt_min_age_days = 3

  # Exchange Downtime protection
  has_downtime_protection = False

  # Do you want to use the hold feature? (with hold-trades.json)
  hold_support_enabled = True

  # Run "populate_indicators()" only for new candle.
  process_only_new_candles = True

  # These values can be overridden in the "ask_strategy" section in the config.
  use_exit_signal = True
  exit_profit_only = False
  ignore_roi_if_entry_signal = True

  # Number of candles the strategy requires before producing valid signals
  startup_candle_count: int = 800

  # Number of cores to use for pandas_ta indicators calculations
  num_cores_indicators_calc = 0

  # Long Normal mode tags
  long_normal_mode_tags = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]
  # Long Pump mode tags
  long_pump_mode_tags = ["21", "22", "23", "24", "25", "26"]
  # Long Quick mode tags
  long_quick_mode_tags = ["41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53"]
  # Long rebuy mode tags
  long_rebuy_mode_tags = ["61", "62", "63", "64", "65", "68"]
  # Long high profit mode tags
  long_high_profit_mode_tags = ["81", "82"]
  # Long rapid mode tags
  long_rapid_mode_tags = ["101", "102", "103", "104", "105", "106", "107", "108", "109", "110"]
  # Long grind mode tags
  long_grind_mode_tags = ["120"]
  # Long btc mode tags
  long_btc_mode_tags = ["121"]
  # Long top coins mode tags
  long_top_coins_mode_tags = ["141", "142", "143", "144", "145"]
  # Long scalp mode tags
  long_scalp_mode_tags = [
    "161",
    "162",
    "163",
    "164",
    "165",
    "166",
    "167",
    "168",
    "169",
    "170",
    "171",
    "172",
    "173",
    "174",
  ]

  long_rebuy_grind_mode_tags = long_rebuy_mode_tags + long_grind_mode_tags
  long_scalp_rebuy_grind_mode_tags = long_scalp_mode_tags + long_rebuy_mode_tags + long_grind_mode_tags
  long_rapid_rebuy_grind_mode_tags = long_rapid_mode_tags + long_rebuy_mode_tags + long_grind_mode_tags
  long_rapid_rebuy_grind_scalp_mode_tags = (
    long_rapid_mode_tags + long_rebuy_mode_tags + long_grind_mode_tags + long_scalp_mode_tags
  )
  long_adjust_mode_tags = (
    long_normal_mode_tags
    + long_pump_mode_tags
    + long_quick_mode_tags
    + long_high_profit_mode_tags
    + long_rapid_mode_tags
    + long_top_coins_mode_tags
    + long_scalp_mode_tags
  )
  long_known_mode_tags = (
    long_normal_mode_tags
    + long_pump_mode_tags
    + long_quick_mode_tags
    + long_rebuy_mode_tags
    + long_high_profit_mode_tags
    + long_rapid_mode_tags
    + long_grind_mode_tags
    + long_btc_mode_tags
    + long_top_coins_mode_tags
    + long_scalp_mode_tags
  )

  long_normal_mode_name = "long_normal"
  long_pump_mode_name = "long_pump"
  long_quick_mode_name = "long_quick"
  long_rebuy_mode_name = "long_rebuy"
  long_high_profit_mode_name = "long_hp"
  long_rapid_mode_name = "long_rapid"
  long_grind_mode_name = "long_grind"
  long_btc_mode_name = "long_btc"
  long_top_coins_mode_name = "long_tc"
  long_scalp_mode_name = "long_scalp"

  # Shorting

  # Short normal mode tags
  short_normal_mode_tags = ["501", "502", "505", "506"]
  # Short Pump mode tags
  short_pump_mode_tags = ["521", "522", "523", "524", "525", "526"]
  # Short Quick mode tags
  short_quick_mode_tags = ["541", "542", "543", "544", "545", "546", "547", "548", "549", "550"]
  # Short rebuy mode tags
  short_rebuy_mode_tags = ["561", "562", "563"]
  # Short mode tags
  short_high_profit_mode_tags = ["581", "582"]
  # Short rapid mode tags
  short_rapid_mode_tags = ["601", "602", "603", "604", "605", "606", "607", "608", "609", "610"]
  # Short grind mode tags
  short_grind_mode_tags = ["620"]
  # Short top coins mode tags
  short_top_coins_mode_tags = ["641", "642"]
  # Short scalp mode tags
  short_scalp_mode_tags = ["661", "662", "663", "664", "665", "666", "667", "670", "669", "671"]

  short_rebuy_grind_mode_tags = short_rebuy_mode_tags + short_grind_mode_tags
  short_scalp_rebuy_grind_mode_tags = short_scalp_mode_tags + short_rebuy_mode_tags + short_grind_mode_tags
  short_rapid_rebuy_grind_mode_tags = short_rapid_mode_tags + short_rebuy_mode_tags + short_grind_mode_tags
  short_adjust_mode_tags = (
    short_normal_mode_tags
    + short_pump_mode_tags
    + short_quick_mode_tags
    + short_high_profit_mode_tags
    + short_rapid_mode_tags
    + short_top_coins_mode_tags
    + short_scalp_mode_tags
  )
  short_known_mode_tags = (
    short_normal_mode_tags
    + short_pump_mode_tags
    + short_quick_mode_tags
    + short_rebuy_mode_tags
    + short_high_profit_mode_tags
    + short_rapid_mode_tags
    + short_grind_mode_tags
    + short_top_coins_mode_tags
    + short_scalp_mode_tags
  )
  short_exit_known_mode_tags = (
    short_normal_mode_tags
    + short_pump_mode_tags
    + short_quick_mode_tags
    + short_rebuy_mode_tags
    + short_high_profit_mode_tags
    + short_rapid_mode_tags
    + short_grind_mode_tags
    + short_top_coins_mode_tags
    + short_scalp_mode_tags
  )

  short_normal_mode_name = "short_normal"
  short_pump_mode_name = "short_pump"
  short_quick_mode_name = "short_quick"
  short_rebuy_mode_name = "short_rebuy"
  short_high_profit_mode_name = "short_hp"
  short_rapid_mode_name = "short_rapid"
  short_top_coins_mode_name = "short_tc"
  short_scalp_mode_name = "short_scalp"

  is_futures_mode = False
  futures_mode_leverage = 3.0
  futures_mode_leverage_rebuy_mode = 3.0
  futures_mode_leverage_grind_mode = 3.0

  # Optional direction/mode overrides. None preserves the existing leverage selection.
  futures_mode_leverage_long = None
  futures_mode_leverage_long_rebuy_mode = None
  futures_mode_leverage_long_grind_mode = None
  futures_mode_leverage_short = None
  futures_mode_leverage_short_rebuy_mode = None
  futures_mode_leverage_short_grind_mode = None

  # Limit the number of long/short trades for futures (0 for no limit)
  futures_max_open_trades_long = 0
  futures_max_open_trades_short = 0

  # Based on the the first entry (regardless of rebuys)
  stop_threshold_spot = 0.10
  stop_threshold_futures = 0.10
  stop_threshold_doom_spot = 0.20
  stop_threshold_doom_futures = 0.20
  stop_threshold_spot_rebuy = 1.0
  stop_threshold_futures_rebuy = 1.0
  stop_threshold_rapid_spot = 0.20
  stop_threshold_rapid_futures = 0.20
  stop_threshold_scalp_spot = 0.20
  stop_threshold_scalp_futures = 0.20

  # user specified fees to be used for profit calculations
  custom_fee_open_rate = None
  custom_fee_close_rate = None

  # Rebuy mode minimum number of free slots
  rebuy_mode_min_free_slots = 2

  # Position adjust feature
  position_adjustment_enable = True

  # Grinding feature
  grinding_enable = True
  derisk_enable = True
  stops_enable = True
  doom_stops_enable = True
  u_e_stops_enable = False

  # Grinding
  grinding_v1_max_stake = 1.0  # ratio of first entry
  derisk_use_grind_stops = True

  grind_1_stop_grinds_spot = -0.06
  grind_1_profit_threshold_spot = 0.018
  grind_1_stakes_spot = [0.24, 0.26, 0.28]
  grind_1_sub_thresholds_spot = [-0.12, -0.16, -0.20]

  grind_1_stop_grinds_futures = -0.06
  grind_1_profit_threshold_futures = 0.018
  grind_1_stakes_futures = [0.24, 0.26, 0.28]
  grind_1_sub_thresholds_futures = [-0.12, -0.16, -0.20]

  grind_2_stop_grinds_spot = -0.06
  grind_2_profit_threshold_spot = 0.018
  grind_2_stakes_spot = [0.20, 0.24, 0.28]
  grind_2_sub_thresholds_spot = [-0.12, -0.16, -0.20]

  grind_2_stop_grinds_futures = -0.06
  grind_2_profit_threshold_futures = 0.018
  grind_2_stakes_futures = [0.20, 0.24, 0.28]
  grind_2_sub_thresholds_futures = [-0.12, -0.16, -0.20]

  grind_3_stop_grinds_spot = -0.06
  grind_3_profit_threshold_spot = 0.018
  grind_3_stakes_spot = [0.20, 0.22, 0.24]
  grind_3_sub_thresholds_spot = [-0.12, -0.16, -0.20]

  grind_3_stop_grinds_futures = -0.06
  grind_3_profit_threshold_futures = 0.018
  grind_3_stakes_futures = [0.20, 0.22, 0.24]
  grind_3_sub_thresholds_futures = [-0.12, -0.16, -0.20]

  grind_4_stop_grinds_spot = -0.06
  grind_4_profit_threshold_spot = 0.018
  grind_4_stakes_spot = [0.20, 0.22, 0.24]
  grind_4_sub_thresholds_spot = [-0.12, -0.16, -0.20]

  grind_4_stop_grinds_futures = -0.06
  grind_4_profit_threshold_futures = 0.018
  grind_4_stakes_futures = [0.20, 0.22, 0.24]
  grind_4_sub_thresholds_futures = [-0.12, -0.16, -0.20]

  grind_5_stop_grinds_spot = -0.06
  grind_5_profit_threshold_spot = 0.048
  grind_5_stakes_spot = [0.20, 0.22, 0.24]
  grind_5_sub_thresholds_spot = [-0.12, -0.16, -0.20]

  grind_5_stop_grinds_futures = -0.06
  grind_5_profit_threshold_futures = 0.048
  grind_5_stakes_futures = [0.20, 0.22, 0.24]
  grind_5_sub_thresholds_futures = [-0.12, -0.16, -0.20]

  grind_6_stop_grinds_spot = -0.06
  grind_6_profit_threshold_spot = 0.018
  grind_6_stakes_spot = [0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18]
  grind_6_sub_thresholds_spot = [-0.03, -0.08, -0.10, -0.12, -0.14, -0.16, -0.18, -0.20, -0.22]

  grind_6_stop_grinds_futures = -0.06
  grind_6_profit_threshold_futures = 0.018
  grind_6_stakes_futures = [0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18]
  grind_6_sub_thresholds_futures = [-0.03, -0.08, -0.10, -0.12, -0.14, -0.16, -0.18, -0.20, -0.22]

  grind_1_derisk_1_stop_grinds_spot = -0.06
  grind_1_derisk_1_profit_threshold_spot = 0.018
  grind_1_derisk_1_stakes_spot = [0.20, 0.24, 0.28]
  grind_1_derisk_1_sub_thresholds_spot = [-0.12, -0.16, -0.20]

  grind_1_derisk_1_stop_grinds_futures = -0.06
  grind_1_derisk_1_profit_threshold_futures = 0.018
  grind_1_derisk_1_stakes_futures = [0.20, 0.24, 0.28]
  grind_1_derisk_1_sub_thresholds_futures = [-0.12, -0.16, -0.20]

  grind_2_derisk_1_stop_grinds_spot = -0.06
  grind_2_derisk_1_profit_threshold_spot = 0.018
  grind_2_derisk_1_stakes_spot = [0.20, 0.24, 0.28]
  grind_2_derisk_1_sub_thresholds_spot = [-0.12, -0.16, -0.20]

  grind_2_derisk_1_stop_grinds_futures = -0.06
  grind_2_derisk_1_profit_threshold_futures = 0.018
  grind_2_derisk_1_stakes_futures = [0.20, 0.24, 0.28]
  grind_2_derisk_1_sub_thresholds_futures = [-0.12, -0.16, -0.20]

  grinds_stop_spot = -0.12
  grinds_stop_futures = -0.12

  # Non rebuy modes
  regular_mode_stake_multiplier_spot = [1.0]
  regular_mode_stake_multiplier_futures = [1.0]
  regular_mode_use_grind_stops = False

  regular_mode_rebuy_stakes_spot = [0.10, 0.10, 0.10]
  regular_mode_rebuy_thresholds_spot = [-0.12, -0.14, -0.16]
  regular_mode_grind_1_stakes_spot = [0.22, 0.24, 0.26]
  regular_mode_grind_1_thresholds_spot = [-0.06, -0.10, -0.12]
  regular_mode_grind_1_stop_grinds_spot = -0.20
  regular_mode_grind_1_profit_threshold_spot = 0.018
  regular_mode_grind_2_stakes_spot = [0.14, 0.20, 0.26]
  regular_mode_grind_2_thresholds_spot = [-0.04, -0.10, -0.12]
  regular_mode_grind_2_stop_grinds_spot = -0.20
  regular_mode_grind_2_profit_threshold_spot = 0.018
  regular_mode_grind_3_stakes_spot = [0.18, 0.20, 0.22]
  regular_mode_grind_3_thresholds_spot = [-0.03, -0.10, -0.12]
  regular_mode_grind_3_stop_grinds_spot = -0.20
  regular_mode_grind_3_profit_threshold_spot = 0.018
  regular_mode_grind_4_stakes_spot = [0.18, 0.20, 0.22]
  regular_mode_grind_4_thresholds_spot = [-0.03, -0.10, -0.12]
  regular_mode_grind_4_stop_grinds_spot = -0.20
  regular_mode_grind_4_profit_threshold_spot = 0.018
  regular_mode_grind_5_stakes_spot = [0.18, 0.20, 0.22]
  regular_mode_grind_5_thresholds_spot = [-0.03, -0.10, -0.12]
  regular_mode_grind_5_stop_grinds_spot = -0.20
  regular_mode_grind_5_profit_threshold_spot = 0.048
  regular_mode_grind_6_stakes_spot = [0.05, 0.057, 0.065, 0.074, 0.084, 0.095, 0.107, 0.121, 0.137]
  regular_mode_grind_6_thresholds_spot = [-0.025, -0.05, -0.06, -0.07, -0.08, -0.09, -0.10, -0.11, -0.12]
  regular_mode_grind_6_stop_grinds_spot = -0.20
  regular_mode_grind_6_profit_threshold_spot = 0.018
  regular_mode_derisk_1_spot = -0.24
  regular_mode_derisk_1_spot_old = -0.80
  regular_mode_derisk_1_reentry_spot = -0.08
  regular_mode_derisk_spot = -0.24
  regular_mode_derisk_spot_old = -1.60
  regular_mode_derisk_1_scalp_mode_spot = -0.05

  regular_mode_rebuy_stakes_futures = [0.10, 0.10, 0.10]
  regular_mode_rebuy_thresholds_futures = [-0.12, -0.14, -0.16]
  regular_mode_grind_1_stakes_futures = [0.22, 0.24, 0.26]
  regular_mode_grind_1_thresholds_futures = [-0.06, -0.10, -0.12]
  regular_mode_grind_1_stop_grinds_futures = -0.20
  regular_mode_grind_1_profit_threshold_futures = 0.018
  regular_mode_grind_2_stakes_futures = [0.14, 0.20, 0.26]
  regular_mode_grind_2_thresholds_futures = [-0.04, -0.10, -0.12]
  regular_mode_grind_2_stop_grinds_futures = -0.20
  regular_mode_grind_2_profit_threshold_futures = 0.018
  regular_mode_grind_3_stakes_futures = [0.18, 0.20, 0.22]
  regular_mode_grind_3_thresholds_futures = [-0.03, -0.10, -0.12]
  regular_mode_grind_3_stop_grinds_futures = -0.20
  regular_mode_grind_3_profit_threshold_futures = 0.018
  regular_mode_grind_4_stakes_futures = [0.18, 0.20, 0.22]
  regular_mode_grind_4_thresholds_futures = [-0.03, -0.10, -0.12]
  regular_mode_grind_4_stop_grinds_futures = -0.20
  regular_mode_grind_4_profit_threshold_futures = 0.018
  regular_mode_grind_5_stakes_futures = [0.18, 0.20, 0.22]
  regular_mode_grind_5_thresholds_futures = [-0.03, -0.10, -0.12]
  regular_mode_grind_5_stop_grinds_futures = -0.20
  regular_mode_grind_5_profit_threshold_futures = 0.048
  regular_mode_grind_6_stakes_futures = [0.05, 0.057, 0.065, 0.074, 0.084, 0.095, 0.107, 0.121, 0.137]
  regular_mode_grind_6_thresholds_futures = [-0.025, -0.05, -0.06, -0.07, -0.08, -0.09, -0.10, -0.11, -0.12]
  regular_mode_grind_6_stop_grinds_futures = -0.20
  regular_mode_grind_6_profit_threshold_futures = 0.018
  regular_mode_derisk_1_futures = -0.60
  regular_mode_derisk_1_futures_old = -0.80
  regular_mode_derisk_1_reentry_futures = -0.08  # without leverage
  regular_mode_derisk_futures = -0.60
  regular_mode_derisk_futures_old = -1.20
  regular_mode_derisk_1_scalp_mode_futures = -0.05

  # Grinding v2
  grinding_v2_max_stake = 1.0  # ratio of first entry
  grinding_v2_max_grinds_and_buybacks = 20  # current open

  grinding_v2_derisk_level_1_enable = True
  grinding_v2_derisk_level_1_spot = [-0.06, -0.15]
  grinding_v2_derisk_level_1_futures = [-0.18, -0.35]
  grinding_v2_derisk_level_2_enable = True
  grinding_v2_derisk_level_2_spot = [-0.08, -0.18]
  grinding_v2_derisk_level_2_futures = [-0.24, -0.54]
  grinding_v2_derisk_level_3_enable = True
  grinding_v2_derisk_level_3_spot = [-0.10, -0.20]
  grinding_v2_derisk_level_3_futures = [-0.30, -0.60]
  grinding_v2_derisk_level_1_stake_spot = 0.20
  grinding_v2_derisk_level_1_stake_futures = 0.20
  grinding_v2_derisk_level_2_stake_spot = 0.30
  grinding_v2_derisk_level_2_stake_futures = 0.30
  grinding_v2_derisk_level_3_stake_spot = 0.50
  grinding_v2_derisk_level_3_stake_futures = 0.50
  grinding_v2_derisk_global_enable = False
  grinding_v2_derisk_global_spot = -0.10
  grinding_v2_derisk_global_futures = -0.30

  grinding_v2_grind_1_enable = True
  grinding_v2_grind_1_stakes_spot = [0.20, 0.22, 0.24, 0.26, 0.28]
  grinding_v2_grind_1_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  grinding_v2_grind_1_stakes_futures = [0.20, 0.22, 0.24, 0.26, 0.28]
  grinding_v2_grind_1_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  grinding_v2_grind_1_profit_threshold_spot = 0.02
  grinding_v2_grind_1_profit_threshold_futures = 0.02
  grinding_v2_grind_1_use_derisk = True
  grinding_v2_grind_1_derisk_spot = -0.26
  grinding_v2_grind_1_derisk_futures = -0.26

  grinding_v2_grind_2_enable = True
  grinding_v2_grind_2_stakes_spot = [0.10, 0.12, 0.14, 0.16, 0.18]
  grinding_v2_grind_2_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  grinding_v2_grind_2_stakes_futures = [0.10, 0.12, 0.14, 0.16, 0.18]
  grinding_v2_grind_2_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  grinding_v2_grind_2_profit_threshold_spot = 0.02
  grinding_v2_grind_2_profit_threshold_futures = 0.02
  grinding_v2_grind_2_use_derisk = True
  grinding_v2_grind_2_derisk_spot = -0.26
  grinding_v2_grind_2_derisk_futures = -0.26

  grinding_v2_grind_3_enable = True
  grinding_v2_grind_3_stakes_spot = [0.10, 0.12, 0.14, 0.16, 0.18]
  grinding_v2_grind_3_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  grinding_v2_grind_3_stakes_futures = [0.10, 0.12, 0.14, 0.16, 0.18]
  grinding_v2_grind_3_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  grinding_v2_grind_3_profit_threshold_spot = 0.02
  grinding_v2_grind_3_profit_threshold_futures = 0.02
  grinding_v2_grind_3_use_derisk = True
  grinding_v2_grind_3_derisk_spot = -0.26
  grinding_v2_grind_3_derisk_futures = -0.26

  grinding_v2_grind_4_enable = True
  grinding_v2_grind_4_stakes_spot = [0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11]
  grinding_v2_grind_4_thresholds_spot = [-0.06, -0.07, -0.09, -0.12, -0.16, -0.21, -0.27]
  grinding_v2_grind_4_stakes_futures = [0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11]
  grinding_v2_grind_4_thresholds_futures = [-0.06, -0.07, -0.09, -0.12, -0.16, -0.21, -0.27]
  grinding_v2_grind_4_profit_threshold_spot = 0.10
  grinding_v2_grind_4_profit_threshold_futures = 0.10
  grinding_v2_grind_4_use_derisk = True
  grinding_v2_grind_4_derisk_spot = -0.26
  grinding_v2_grind_4_derisk_futures = -0.26

  grinding_v2_grind_5_enable = True
  grinding_v2_grind_5_stakes_spot = [0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11]
  grinding_v2_grind_5_thresholds_spot = [-0.06, -0.07, -0.09, -0.12, -0.16, -0.21, -0.27]
  grinding_v2_grind_5_stakes_futures = [0.05, 0.06, 0.07, 0.08, 0.09, 0.10, 0.11]
  grinding_v2_grind_5_thresholds_futures = [-0.06, -0.07, -0.09, -0.12, -0.16, -0.21, -0.27]
  grinding_v2_grind_5_profit_threshold_spot = 0.10
  grinding_v2_grind_5_profit_threshold_futures = 0.10
  grinding_v2_grind_5_use_derisk = True
  grinding_v2_grind_5_derisk_spot = -0.26
  grinding_v2_grind_5_derisk_futures = -0.26

  grinding_v2_buyback_1_enable = True
  grinding_v2_buyback_1_stake_spot = 0.10
  grinding_v2_buyback_1_stake_futures = 0.10
  grinding_v2_buyback_1_distance_ratio_spot = -0.06
  grinding_v2_buyback_1_distance_ratio_futures = -0.06
  grinding_v2_buyback_1_profit_threshold_spot = 0.05
  grinding_v2_buyback_1_profit_threshold_futures = 0.05
  grinding_v2_buyback_1_use_derisk = True
  grinding_v2_buyback_1_derisk_spot = -0.26
  grinding_v2_buyback_1_derisk_futures = -0.26

  grinding_v2_buyback_2_enable = True
  grinding_v2_buyback_2_stake_spot = 0.10
  grinding_v2_buyback_2_stake_futures = 0.10
  grinding_v2_buyback_2_distance_ratio_spot = -0.12
  grinding_v2_buyback_2_distance_ratio_futures = -0.12
  grinding_v2_buyback_2_profit_threshold_spot = 0.05
  grinding_v2_buyback_2_profit_threshold_futures = 0.05
  grinding_v2_buyback_2_use_derisk = True
  grinding_v2_buyback_2_derisk_spot = -0.26
  grinding_v2_buyback_2_derisk_futures = -0.26

  grinding_v2_buyback_3_enable = True
  grinding_v2_buyback_3_stake_spot = 0.10
  grinding_v2_buyback_3_stake_futures = 0.10
  grinding_v2_buyback_3_distance_ratio_spot = -0.16
  grinding_v2_buyback_3_distance_ratio_futures = -0.16
  grinding_v2_buyback_3_profit_threshold_spot = 0.05
  grinding_v2_buyback_3_profit_threshold_futures = 0.05
  grinding_v2_buyback_3_use_derisk = True
  grinding_v2_buyback_3_derisk_spot = -0.26
  grinding_v2_buyback_3_derisk_futures = -0.26

  # System v3
  system_v3_name = "system_v3"
  system_v3_1_name = "system_v3_1"
  system_v3_2_name = "system_v3_2"
  system_name_use = system_v3_2_name

  system_v3_max_stake = 1.0  # ratio of first entry
  system_v3_1_max_stake = 3.0  # ratio of first entry

  system_v3_stop_threshold_doom_spot = 0.14
  system_v3_stop_threshold_doom_futures = 0.35
  system_v3_stop_threshold_spot_rebuy = 0.70
  system_v3_stop_threshold_futures_rebuy = 1.75
  system_v3_stop_threshold_rapid_spot = 0.14
  system_v3_stop_threshold_rapid_futures = 0.35
  system_v3_stop_threshold_scalp_spot = 0.14
  system_v3_stop_threshold_scalp_futures = 0.35

  system_v3_1_stop_threshold_doom_spot = 0.24
  system_v3_1_stop_threshold_doom_futures = 0.70
  system_v3_1_stop_threshold_spot_rebuy = 0.47
  system_v3_1_stop_threshold_futures_rebuy = 1.40
  system_v3_1_stop_threshold_rapid_spot = 0.24
  system_v3_1_stop_threshold_rapid_futures = 0.70
  system_v3_1_stop_threshold_scalp_spot = 0.24
  system_v3_1_stop_threshold_scalp_futures = 0.70

  system_v3_2_stops_enable = False
  system_v3_2_stop_threshold_doom_spot = 0.12
  system_v3_2_stop_threshold_doom_futures = 0.35
  system_v3_2_stop_threshold_spot_rebuy = 0.48
  system_v3_2_stop_threshold_futures_rebuy = 1.40
  system_v3_2_stop_threshold_rapid_spot = 0.12
  system_v3_2_stop_threshold_rapid_futures = 0.35
  system_v3_2_stop_threshold_scalp_spot = 0.12
  system_v3_2_stop_threshold_scalp_futures = 0.35

  system_v3_1_stake_multiplier = 0.50
  system_v3_1_rebuy_stakes_spot = [0.5, 0.5]
  system_v3_1_rebuy_stakes_futures = [0.5, 0.5]
  system_v3_1_rebuy_thresholds_spot = [-0.25, -0.16, -0.16, -0.20]
  system_v3_1_rebuy_thresholds_futures = [-0.25, -0.16, -0.16, -0.20]

  system_v3_derisk_level_1_enable = True
  system_v3_derisk_level_1_spot = [-0.04, -0.06]
  system_v3_derisk_level_1_futures = [-0.12, -0.18]
  system_v3_derisk_level_1_stake_spot = 0.10
  system_v3_derisk_level_1_stake_futures = 0.10
  system_v3_derisk_level_2_enable = True
  system_v3_derisk_level_2_spot = [-0.06, -0.08]
  system_v3_derisk_level_2_futures = [-0.18, -0.24]
  system_v3_derisk_level_2_stake_spot = 0.10
  system_v3_derisk_level_2_stake_futures = 0.10
  system_v3_derisk_level_3_enable = True
  system_v3_derisk_level_3_spot = [-0.08, -0.10]
  system_v3_derisk_level_3_futures = [-0.24, -0.30]
  system_v3_derisk_level_3_stake_spot = 0.10
  system_v3_derisk_level_3_stake_futures = 0.10

  system_v3_2_stake_multiplier = 1.0
  system_v3_2_derisk_level_1_enable = True
  system_v3_2_derisk_level_1_spot = [-0.06, -0.12]
  system_v3_2_derisk_level_1_futures = [-0.18, -0.35]
  system_v3_2_derisk_level_1_stake_spot = 0.20
  system_v3_2_derisk_level_1_stake_futures = 0.20
  system_v3_2_derisk_level_2_enable = True
  system_v3_2_derisk_level_2_spot = [-0.08, -0.18]
  system_v3_2_derisk_level_2_futures = [-0.24, -0.54]
  system_v3_2_derisk_level_2_stake_spot = 0.30
  system_v3_2_derisk_level_2_stake_futures = 0.30
  system_v3_2_derisk_level_3_enable = True
  system_v3_2_derisk_level_3_spot = [-0.10, -0.20]
  system_v3_2_derisk_level_3_futures = [-0.30, -0.60]
  system_v3_2_derisk_level_3_stake_spot = 0.50
  system_v3_2_derisk_level_3_stake_futures = 0.50
  system_v3_2_derisk_level_4_enable = False
  system_v3_2_derisk_level_4_spot = [-0.02, -0.08]
  system_v3_2_derisk_level_4_futures = [-0.06, -0.24]
  system_v3_2_derisk_level_4_stake_spot = 1.0
  system_v3_2_derisk_level_4_stake_futures = 1.0

  system_v3_grind_1_enable = True
  system_v3_grind_1_stakes_spot = [0.20, 0.20, 0.20, 0.20, 0.20]
  system_v3_grind_1_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v3_grind_1_stakes_futures = [0.20, 0.20, 0.20, 0.20, 0.20]
  system_v3_grind_1_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v3_grind_1_profit_threshold_spot = 0.025
  system_v3_grind_1_profit_threshold_futures = 0.025
  system_v3_grind_1_use_derisk = True
  system_v3_grind_1_derisk_spot = -0.22
  system_v3_grind_1_derisk_futures = -0.22

  system_v3_grind_2_enable = True
  system_v3_grind_2_stakes_spot = [0.10, 0.12, 0.14, 0.16, 0.18]
  system_v3_grind_2_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v3_grind_2_stakes_futures = [0.10, 0.12, 0.14, 0.16, 0.18]
  system_v3_grind_2_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v3_grind_2_profit_threshold_spot = 0.035
  system_v3_grind_2_profit_threshold_futures = 0.035
  system_v3_grind_2_use_derisk = True
  system_v3_grind_2_derisk_spot = -0.22
  system_v3_grind_2_derisk_futures = -0.22

  system_v3_grind_3_enable = True
  system_v3_grind_3_stakes_spot = [0.10, 0.12, 0.14, 0.16, 0.18]
  system_v3_grind_3_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v3_grind_3_stakes_futures = [0.10, 0.12, 0.14, 0.16, 0.18]
  system_v3_grind_3_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v3_grind_3_profit_threshold_spot = 0.04
  system_v3_grind_3_profit_threshold_futures = 0.04
  system_v3_grind_3_use_derisk = True
  system_v3_grind_3_derisk_spot = -0.22
  system_v3_grind_3_derisk_futures = -0.22

  system_v3_grind_4_enable = True
  system_v3_grind_4_stakes_spot = [0.05, 0.06, 0.07, 0.08, 0.09]
  system_v3_grind_4_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v3_grind_4_stakes_futures = [0.05, 0.06, 0.07, 0.08, 0.09]
  system_v3_grind_4_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v3_grind_4_profit_threshold_spot = 0.05
  system_v3_grind_4_profit_threshold_futures = 0.05
  system_v3_grind_4_use_derisk = True
  system_v3_grind_4_derisk_spot = -0.22
  system_v3_grind_4_derisk_futures = -0.22

  system_v3_grind_5_enable = True
  system_v3_grind_5_stakes_spot = [0.05, 0.06, 0.07, 0.08, 0.09]
  system_v3_grind_5_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v3_grind_5_stakes_futures = [0.05, 0.06, 0.07, 0.08, 0.09]
  system_v3_grind_5_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v3_grind_5_profit_threshold_spot = 0.06
  system_v3_grind_5_profit_threshold_futures = 0.06
  system_v3_grind_5_use_derisk = True
  system_v3_grind_5_derisk_spot = -0.22
  system_v3_grind_5_derisk_futures = -0.22

  system_v3_buyback_1_enable = False
  system_v3_buyback_1_stake_spot = 1.00
  system_v3_buyback_1_stake_futures = 1.00
  system_v3_buyback_1_distance_ratio_negative_spot = -0.04
  system_v3_buyback_1_distance_ratio_negative_futures = -0.04
  system_v3_buyback_1_distance_ratio_positive_spot = 0.02
  system_v3_buyback_1_distance_ratio_positive_futures = 0.02
  # system_v3_buyback_1_profit_threshold_spot = 0.05
  # system_v3_buyback_1_profit_threshold_futures = 0.05
  system_v3_buyback_1_use_derisk = True
  system_v3_buyback_1_derisk_spot = -0.08
  system_v3_buyback_1_derisk_futures = -0.08

  # System v4
  system_v4_name = "system_v4"
  system_name_use = system_v4_name

  system_v4_max_stake = 1.0  # ratio of first entry
  system_v4_stake_multiplier = 1.0
  system_v4_grind_entry_before_derisk_enable = True
  system_v4_grind_entry_before_derisk_distance = 0.02  # unleveraged price move from the grind average

  # Bad-trade exits. Enable for new v4 trades without changing older open trades.
  system_v4_bad_trade_exit_enable = True
  legacy_system_bad_trade_exit_enable = False
  # Also assess a losing residual when realized gains keep the whole trade nonnegative.
  inclusive_bad_trade_exit_enable = False
  bad_trade_controller_structure_break_exit_enable = True
  bad_trade_controller_structure_break_ema_gap_pct = 35.0
  bad_trade_controller_structure_break_min_adverse_move_pct = 25.0
  bad_trade_controller_stale_exit_enable = True
  bad_trade_controller_stale_min_age_days = 14.0
  bad_trade_controller_stale_max_daily_range_pct = 7.0
  bad_trade_controller_stale_min_adverse_move_pct = 10.0
  # De-risk hold. A position that reaches a de-risk level while its own daily trend is still intact
  # is usually an overshoot that comes back; one that reaches it during a real daily breakdown is
  # not. Measured on the seven-year gms0 baseline with the ladder's real fires: the one fire the
  # rule holds (DOGE 2024-04-05, ROC_9_1d -1.3) recovered and the year closes +$617; the fires it
  # lets through include Black Thursday (ADA 2020-03-13, ROC_9_1d -52), where holding on a washed-out
  # 15m instead turned a +$21 exit into a -$1,827 stop. Every year without a fire is bit-identical.
  # The fast readings (RSI_14_15m, CMF_20_1h) were measured and rejected: they fire hardest exactly
  # when they are most wrong, inside a crash. The short side is the mirror (the coin not ripping up).
  bad_trade_controller_derisk_hold_enable = False
  bad_trade_controller_derisk_hold_short_enable = False
  bad_trade_controller_derisk_hold_roc_9_1d = -10.0
  # Capitulation add gate. Past the near end of the de-risk range, no grind add while the 4h is at
  # capitulation. Rebuilding every loss slice by slice over six years, adds made there lose (long
  # -$382 / short -$749 across 108 slices) while adds made in an orderly decline pay (+$15,559
  # across 503), and capitulation is where the runaway stake growth happens (INJ 58 adds, 28x).
  # Short side mirrors the threshold (100 - value).
  bad_trade_controller_capitulation_add_gate_enable = False
  bad_trade_controller_capitulation_add_gate_mfi_14_4h = 30.0

  system_v4_stops_enable = False
  system_v4_stop_threshold_doom_spot = 0.14
  system_v4_stop_threshold_doom_futures = 0.35
  system_v4_stop_threshold_spot_rebuy = 0.70
  system_v4_stop_threshold_futures_rebuy = 1.75
  system_v4_stop_threshold_rapid_spot = 0.14
  system_v4_stop_threshold_rapid_futures = 0.35
  system_v4_stop_threshold_scalp_spot = 0.14
  system_v4_stop_threshold_scalp_futures = 0.35

  system_v4_derisk_level_1_enable = True
  system_v4_derisk_level_1_spot = [-0.06, -0.12]
  system_v4_derisk_level_1_futures = [-0.18, -0.35]
  system_v4_derisk_level_1_stake_spot = 0.20
  system_v4_derisk_level_1_stake_futures = 0.20
  system_v4_derisk_level_2_enable = True
  system_v4_derisk_level_2_spot = [-0.08, -0.18]
  system_v4_derisk_level_2_futures = [-0.24, -0.54]
  system_v4_derisk_level_2_stake_spot = 0.30
  system_v4_derisk_level_2_stake_futures = 0.30
  system_v4_derisk_level_3_enable = True
  system_v4_derisk_level_3_spot = [-0.10, -0.20]
  system_v4_derisk_level_3_futures = [-0.30, -0.60]
  system_v4_derisk_level_3_stake_spot = 0.50
  system_v4_derisk_level_3_stake_futures = 0.50
  system_v4_derisk_level_3_liquidation_enable = True
  system_v4_derisk_level_3_liquidation_distance = 0.05
  system_v4_derisk_level_4_enable = False
  system_v4_derisk_level_4_spot = [-0.02, -0.08]
  system_v4_derisk_level_4_futures = [-0.06, -0.24]
  system_v4_derisk_level_4_stake_spot = 1.0
  system_v4_derisk_level_4_stake_futures = 1.0

  system_v4_grind_1_enable = True
  system_v4_grind_1_stakes_spot = [0.20, 0.20, 0.20, 0.20, 0.20]
  system_v4_grind_1_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v4_grind_1_stakes_futures = [0.20, 0.20, 0.20, 0.20, 0.20]
  system_v4_grind_1_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v4_grind_1_profit_threshold_spot = 0.025
  system_v4_grind_1_profit_threshold_futures = 0.025
  system_v4_grind_1_use_derisk = True
  system_v4_grind_1_derisk_spot = -0.22
  system_v4_grind_1_derisk_futures = -0.22

  system_v4_grind_2_enable = True
  system_v4_grind_2_stakes_spot = [0.10, 0.12, 0.14, 0.16, 0.18]
  system_v4_grind_2_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v4_grind_2_stakes_futures = [0.10, 0.12, 0.14, 0.16, 0.18]
  system_v4_grind_2_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v4_grind_2_profit_threshold_spot = 0.035
  system_v4_grind_2_profit_threshold_futures = 0.035
  system_v4_grind_2_use_derisk = True
  system_v4_grind_2_derisk_spot = -0.22
  system_v4_grind_2_derisk_futures = -0.22

  system_v4_grind_3_enable = True
  system_v4_grind_3_stakes_spot = [0.10, 0.12, 0.14, 0.16, 0.18]
  system_v4_grind_3_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v4_grind_3_stakes_futures = [0.10, 0.12, 0.14, 0.16, 0.18]
  system_v4_grind_3_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v4_grind_3_profit_threshold_spot = 0.04
  system_v4_grind_3_profit_threshold_futures = 0.04
  system_v4_grind_3_use_derisk = True
  system_v4_grind_3_derisk_spot = -0.22
  system_v4_grind_3_derisk_futures = -0.22

  system_v4_grind_4_enable = True
  system_v4_grind_4_stakes_spot = [0.05, 0.06, 0.07, 0.08, 0.09]
  system_v4_grind_4_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v4_grind_4_stakes_futures = [0.05, 0.06, 0.07, 0.08, 0.09]
  system_v4_grind_4_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v4_grind_4_profit_threshold_spot = 0.05
  system_v4_grind_4_profit_threshold_futures = 0.05
  system_v4_grind_4_use_derisk = True
  system_v4_grind_4_derisk_spot = -0.22
  system_v4_grind_4_derisk_futures = -0.22

  system_v4_grind_5_enable = True
  system_v4_grind_5_stakes_spot = [0.05, 0.06, 0.07, 0.08, 0.09]
  system_v4_grind_5_thresholds_spot = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v4_grind_5_stakes_futures = [0.05, 0.06, 0.07, 0.08, 0.09]
  system_v4_grind_5_thresholds_futures = [-0.06, -0.07, -0.08, -0.09, -0.10]
  system_v4_grind_5_profit_threshold_spot = 0.06
  system_v4_grind_5_profit_threshold_futures = 0.06
  system_v4_grind_5_use_derisk = True
  system_v4_grind_5_derisk_spot = -0.22
  system_v4_grind_5_derisk_futures = -0.22
  system_v4_grind_5_liquidation_rescue_enable = True
  system_v4_grind_5_liquidation_rescue_threshold = 0.05
  system_v4_grind_5_liquidation_rescue_max_stake = 0.50

  system_v4_buyback_1_enable = False
  system_v4_buyback_1_stake_spot = 1.00
  system_v4_buyback_1_stake_futures = 1.00
  system_v4_buyback_1_distance_ratio_negative_spot = -0.04
  system_v4_buyback_1_distance_ratio_negative_futures = -0.04
  system_v4_buyback_1_distance_ratio_positive_spot = 0.02
  system_v4_buyback_1_distance_ratio_positive_futures = 0.02
  # system_v4_buyback_1_profit_threshold_spot = 0.05
  # system_v4_buyback_1_profit_threshold_futures = 0.05
  system_v4_buyback_1_use_derisk = True
  system_v4_buyback_1_derisk_spot = -0.08
  system_v4_buyback_1_derisk_futures = -0.08

  # Rebuy mode
  rebuy_mode_stake_multiplier = 0.35
  rebuy_mode_derisk_spot = -0.60
  rebuy_mode_derisk_futures = -0.60
  rebuy_mode_stakes_spot = [1.0, 1.0]
  rebuy_mode_stakes_futures = [1.0, 1.0]
  rebuy_mode_thresholds_spot = [-0.08, -0.10]
  rebuy_mode_thresholds_futures = [-0.08, -0.10]

  # Rebuy mode v3
  system_v3_rebuy_mode_stake_multiplier = 0.25
  system_v3_rebuy_mode_derisk_spot = -0.48
  system_v3_rebuy_mode_derisk_futures = -1.40
  system_v3_rebuy_mode_stakes_spot = [1.0, 1.0, 1.0, 1.0]
  system_v3_rebuy_mode_stakes_futures = [1.0, 1.0, 1.0, 1.0]
  system_v3_rebuy_mode_thresholds_spot = [-0.08, -0.12, -0.16, -0.20]
  system_v3_rebuy_mode_thresholds_futures = [-0.08, -0.12, -0.16, -0.20]

  # Rebuy mode v4
  system_v4_rebuy_mode_stake_multiplier = 0.25
  system_v4_rebuy_mode_derisk_spot = -0.48
  system_v4_rebuy_mode_derisk_futures = -1.40
  system_v4_rebuy_mode_stakes_spot = [1.0, 1.0, 1.0, 1.0]
  system_v4_rebuy_mode_stakes_futures = [1.0, 1.0, 1.0, 1.0]
  system_v4_rebuy_mode_thresholds_spot = [-0.08, -0.12, -0.16, -0.20]
  system_v4_rebuy_mode_thresholds_futures = [-0.08, -0.12, -0.16, -0.20]

  # Rapid mode
  rapid_mode_stake_multiplier_spot = [0.75]
  rapid_mode_stake_multiplier_futures = [0.75]

  # Scalp mode
  min_free_slots_scalp_mode = 1

  # Grind mode
  grind_mode_stake_multiplier_spot = [0.20, 0.30, 0.40, 0.50, 0.60, 0.70]
  grind_mode_stake_multiplier_futures = [0.20, 0.30, 0.40, 0.50]
  grind_mode_first_entry_profit_threshold_spot = 0.018
  grind_mode_first_entry_profit_threshold_futures = 0.018
  grind_mode_first_entry_stop_threshold_spot = -0.20
  grind_mode_first_entry_stop_threshold_futures = -0.20
  grind_mode_max_slots = 1
  grind_mode_coins = [
    "AAVE",
    "ADA",
    "ALGO",
    "APE",
    "APT",
    "ARB",
    "ATOM",
    "AVAX",
    "BCH",
    "BNB",
    "BTC",
    "CAKE",
    "CRV",
    "DOGE",
    "DYDX",
    "ETC",
    "ETH",
    "FIL",
    "GALA",
    "HBAR",
    "HYPE",
    "ICP",
    "INJ",
    "IOTA",
    "JUP",
    "KAS",
    "LDO",
    "LINK",
    "LTC",
    "NEAR",
    "NEO",
    "OP",
    "POL",
    "RENDER",
    "RUNE",
    "SAND",
    "SEI",
    "SOL",
    "SUI",
    "THETA",
    "TIA",
    "TON",
    "TRX",
    "UNI",
    "VET",
    "XLM",
    "XMR",
    "XRP",
    "XTZ",
    "ZEC",
  ]

  btc_mode_max_slots = 0
  btc_mode_coins = [
    "BTC",
  ]

  # Top coins mode coins
  top_coins_mode_coins = [
    "1INCH",
    "AAVE",
    "ADA",
    "ALGO",
    "APE",
    "APT",
    "ARB",
    "ATOM",
    "AVAX",
    "BCH",
    "BNB",
    "BTC",
    "CAKE",
    "CRV",
    "DASH",
    "DOGE",
    "DOT",
    "DYDX",
    "ETC",
    "ETH",
    "FIL",
    "GALA",
    "HBAR",
    "HYPE",
    "ICP",
    "INJ",
    "IOTA",
    "JUP",
    "KAS",
    "LDO",
    "LINK",
    "LTC",
    "NEAR",
    "NEO",
    "ONDO",
    "OP",
    "POL",
    "RENDER",
    "RUNE",
    "SAND",
    "SEI",
    "SOL",
    "SUI",
    "THETA",
    "TIA",
    "TRX",
    "UNI",
    "VET",
    "WLD",
    "XLM",
    "XMR",
    "XRP",
    "XTZ",
    "ZEC",
  ]

  # Profit max thresholds
  profit_max_thresholds = [0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.05, 0.05]

  # Max allowed buy "slippage", how high to buy on the candle
  max_slippage = 0.02

  # BTC/ETH stakes
  btc_stakes = ["BTC", "ETH"]

  #############################################################
  # Buy side configuration

  long_entry_signal_params = {
    # Enable/Disable conditions
    # -------------------------------------------------------
    "long_entry_condition_1_enable": True,
    "long_entry_condition_2_enable": True,
    "long_entry_condition_3_enable": True,
    "long_entry_condition_4_enable": True,
    "long_entry_condition_5_enable": True,
    "long_entry_condition_6_enable": True,
    "long_entry_condition_7_enable": False,
    "long_entry_condition_8_enable": False,
    "long_entry_condition_9_enable": False,
    "long_entry_condition_10_enable": False,
    "long_entry_condition_11_enable": False,
    "long_entry_condition_21_enable": True,
    "long_entry_condition_41_enable": True,
    "long_entry_condition_42_enable": True,
    "long_entry_condition_43_enable": True,
    "long_entry_condition_44_enable": True,
    "long_entry_condition_45_enable": True,
    "long_entry_condition_46_enable": True,
    "long_entry_condition_47_enable": True,
    "long_entry_condition_48_enable": False,
    "long_entry_condition_61_enable": True,
    "long_entry_condition_62_enable": True,
    "long_entry_condition_63_enable": True,
    "long_entry_condition_64_enable": True,
    "long_entry_condition_65_enable": True,
    "long_entry_condition_68_enable": False,
    "long_entry_condition_101_enable": True,
    "long_entry_condition_102_enable": True,
    "long_entry_condition_103_enable": True,
    "long_entry_condition_104_enable": True,
    "long_entry_condition_105_enable": False,
    "long_entry_condition_120_enable": True,
    "long_entry_condition_121_enable": False,
    "long_entry_condition_141_enable": True,
    "long_entry_condition_142_enable": True,
    "long_entry_condition_143_enable": True,
    "long_entry_condition_144_enable": True,
    "long_entry_condition_145_enable": True,
    "long_entry_condition_146_enable": False,
    "long_entry_condition_161_enable": True,
    "long_entry_condition_162_enable": True,
    "long_entry_condition_163_enable": True,
    "long_entry_condition_164_enable": False,
    "long_entry_condition_165_enable": False,
    "long_entry_condition_166_enable": False,
    "long_entry_condition_167_enable": False,
    "long_entry_condition_168_enable": False,
    "long_entry_condition_169_enable": False,
    "long_entry_condition_170_enable": False,
    "long_entry_condition_171_enable": False,
    "long_entry_condition_172_enable": False,
    "long_entry_condition_173_enable": False,
    "long_entry_condition_174_enable": False,
    "long_entry_condition_192_enable": False,
    "long_entry_condition_193_enable": False,
  }

  short_entry_signal_params = {
    # Enable/Disable conditions
    # -------------------------------------------------------
    "short_entry_condition_501_enable": True,
    "short_entry_condition_502_enable": True,
    # "short_entry_condition_503_enable": True,
    # "short_entry_condition_504_enable": True,
    "short_entry_condition_505_enable": False,
    "short_entry_condition_506_enable": False,
    # "short_entry_condition_541_enable": True,
    "short_entry_condition_542_enable": True,
    "short_entry_condition_543_enable": False,
    "short_entry_condition_544_enable": False,
    "short_entry_condition_545_enable": False,
    "short_entry_condition_546_enable": False,
    "short_entry_condition_548_enable": False,
    "short_entry_condition_561_enable": False,
    "short_entry_condition_562_enable": True,
    "short_entry_condition_563_enable": False,
    "short_entry_condition_592_enable": False,
    "short_entry_condition_593_enable": False,
    # "short_entry_condition_603_enable": True,
    "short_entry_condition_605_enable": False,
    # "short_entry_condition_641_enable": True,
    # "short_entry_condition_642_enable": True,
    # "short_entry_condition_661_enable": True,
    "short_entry_condition_662_enable": False,
    "short_entry_condition_663_enable": False,
    "short_entry_condition_664_enable": False,
    "short_entry_condition_665_enable": False,
    "short_entry_condition_666_enable": False,
    "short_entry_condition_667_enable": False,
    "short_entry_condition_669_enable": False,
    "short_entry_condition_670_enable": False,
    "short_entry_condition_671_enable": False,
  }

  #############################################################
  # CACHES

  hold_trades_cache = None
  target_profit_cache = None
  #############################################################
  #
  #
  #  $$$$$$\   $$$$$$\  $$\      $$\ $$\      $$\  $$$$$$\  $$\   $$\
  # $$  __$$\ $$  __$$\ $$$\    $$$ |$$$\    $$$ |$$  __$$\ $$$\  $$ |
  # $$ /  \__|$$ /  $$ |$$$$\  $$$$ |$$$$\  $$$$ |$$ /  $$ |$$$$\ $$ |
  # $$ |      $$ |  $$ |$$\$$\$$ $$ |$$\$$\$$ $$ |$$ |  $$ |$$ $$\$$ |
  # $$ |      $$ |  $$ |$$ \$$$  $$ |$$ \$$$  $$ |$$ |  $$ |$$ \$$$$ |
  # $$ |  $$\ $$ |  $$ |$$ |\$  /$$ |$$ |\$  /$$ |$$ |  $$ |$$ |\$$$ |
  # \$$$$$$  | $$$$$$  |$$ | \_/ $$ |$$ | \_/ $$ | $$$$$$  |$$ | \$$ |
  #  \______/  \______/ \__|     \__|\__|     \__| \______/ \__|  \__|
  #
  #
  #
  # $$$$$$$$\ $$\   $$\ $$\   $$\  $$$$$$\ $$$$$$$$\ $$$$$$\  $$$$$$\  $$\   $$\  $$$$$$\
  # $$  _____|$$ |  $$ |$$$\  $$ |$$  __$$\\__$$  __|\_$$  _|$$  __$$\ $$$\  $$ |$$  __$$\
  # $$ |      $$ |  $$ |$$$$\ $$ |$$ /  \__|  $$ |     $$ |  $$ /  $$ |$$$$\ $$ |$$ /  \__|
  # $$$$$\    $$ |  $$ |$$ $$\$$ |$$ |        $$ |     $$ |  $$ |  $$ |$$ $$\$$ |\$$$$$$\
  # $$  __|   $$ |  $$ |$$ \$$$$ |$$ |        $$ |     $$ |  $$ |  $$ |$$ \$$$$ | \____$$\
  # $$ |      $$ |  $$ |$$ |\$$$ |$$ |  $$\   $$ |     $$ |  $$ |  $$ |$$ |\$$$ |$$\   $$ |
  # $$ |      \$$$$$$  |$$ | \$$ |\$$$$$$  |  $$ |   $$$$$$\  $$$$$$  |$$ | \$$ |\$$$$$$  |
  # \__|       \______/ \__|  \__| \______/   \__|   \______| \______/ \__|  \__| \______/
  #
  #

  ###############################################################################################
  # COMMON FUNCTIONS FOR BOTH LONG AND SHORT SIDE STARTS HERE
  ###############################################################################################

  def __init__(self, config: dict) -> None:
    # A list of parameters that can be changed through the config.
    NFI_SAFE_PARAMETERS = [
      "num_cores_indicators_calc",
      "custom_fee_open_rate",
      "custom_fee_close_rate",
      "futures_mode_leverage",
      "futures_mode_leverage_rebuy_mode",
      "futures_mode_leverage_grind_mode",
      "futures_mode_leverage_long",
      "futures_mode_leverage_long_rebuy_mode",
      "futures_mode_leverage_long_grind_mode",
      "futures_mode_leverage_short",
      "futures_mode_leverage_short_rebuy_mode",
      "futures_mode_leverage_short_grind_mode",
      "futures_max_open_trades_long",
      "futures_max_open_trades_short",
      "stop_threshold_doom_spot",
      "stop_threshold_doom_futures",
      "stop_threshold_rapid_spot",
      "stop_threshold_rapid_futures",
      "stop_threshold_scalp_spot",
      "stop_threshold_scalp_futures",
      "derisk_enable",
      "stops_enable",
      "regular_mode_derisk_1_spot",
      "regular_mode_derisk_spot",
      "regular_mode_derisk_1_futures",
      "regular_mode_derisk_futures",
      "grind_mode_max_slots",
      "grind_mode_coins",
      "max_slippage",
      "system_v4_bad_trade_exit_enable",
      "legacy_system_bad_trade_exit_enable",
      "inclusive_bad_trade_exit_enable",
      "bad_trade_controller_structure_break_exit_enable",
      "bad_trade_controller_structure_break_ema_gap_pct",
      "bad_trade_controller_structure_break_min_adverse_move_pct",
      "bad_trade_controller_stale_exit_enable",
      "bad_trade_controller_stale_min_age_days",
      "bad_trade_controller_stale_max_daily_range_pct",
      "bad_trade_controller_stale_min_adverse_move_pct",
      "bad_trade_controller_derisk_hold_enable",
      "bad_trade_controller_derisk_hold_short_enable",
      "bad_trade_controller_derisk_hold_roc_9_1d",
      "bad_trade_controller_capitulation_add_gate_enable",
      "bad_trade_controller_capitulation_add_gate_mfi_14_4h",
    ]

    exchange_config = config["exchange"]
    if "ccxt_config" not in exchange_config:
      exchange_config["ccxt_config"] = {}
    if "ccxt_async_config" not in exchange_config:
      exchange_config["ccxt_async_config"] = {}

    options = {
      "brokerId": None,
      "broker": {"spot": None, "margin": None, "future": None, "delivery": None},
      "partner": {
        "spot": {"id": None, "key": None},
        "future": {"id": None, "key": None},
        "id": None,
        "key": None,
      },
    }

    exchange_config["ccxt_config"]["options"] = options
    exchange_config["ccxt_async_config"]["options"] = options
    super().__init__(config)

    strategy_config = self.config
    if ("exit_profit_only" in strategy_config and strategy_config["exit_profit_only"]) or (
      "sell_profit_only" in strategy_config and strategy_config["sell_profit_only"]
    ):
      self.exit_profit_only = True

    # Advanced configuration mode. Allows to change any parameter.
    is_config_advanced_mode = "nfi_advanced_mode" in strategy_config and strategy_config["nfi_advanced_mode"] == True
    if is_config_advanced_mode:
      log.warning("The advanced configuration mode is enabled. I hope you know what you are doing.")

    # Configuration from the nfi_parameters block. New config style.
    nfi_parameters = strategy_config.get("nfi_parameters")
    if type(nfi_parameters) is dict:
      for nfi_param in nfi_parameters:
        if nfi_param in ["long_entry_signal_params", "short_entry_signal_params"]:
          continue
        if (nfi_param in NFI_SAFE_PARAMETERS or is_config_advanced_mode) and hasattr(self, nfi_param):
          log.info(
            f'Parameter {nfi_param} changed from "{getattr(self, nfi_param)}" to "{nfi_parameters[nfi_param]}".'
          )
          setattr(self, nfi_param, nfi_parameters[nfi_param])
        else:
          log.warning(f"Invalid or unsafe parameter: {nfi_param}.")

      self.update_signals_from_config(nfi_parameters)

    # Parameter settings. Backward compatibility with the old configuration style.
    for nfi_param in NFI_SAFE_PARAMETERS:
      if (nfi_param in strategy_config) and hasattr(self, nfi_param):
        setattr(self, nfi_param, strategy_config[nfi_param])

    if self.target_profit_cache is None:
      bot_name = ""
      if "bot_name" in strategy_config:
        bot_name = strategy_config["bot_name"] + "-"
      exchange_name = strategy_config["exchange"]["name"]
      runmode_value = strategy_config["runmode"].value
      self.target_profit_cache = Cache(
        strategy_config["user_data_dir"]
        / (
          "nfix8-profit_max-"
          + bot_name
          + exchange_name
          + "-"
          + strategy_config["stake_currency"]
          + ("-(backtest)" if (runmode_value == "backtest") else "")
          + ("-(hyperopt)" if (runmode_value == "hyperopt") else "")
          + ".json"
        )
      )
    else:
      exchange_name = strategy_config["exchange"]["name"]

    # OKX, Kraken provides a lower number of candle data per API call
    if exchange_name in ["okx", "okex"]:
      self.startup_candle_count = 480
    elif exchange_name == "kraken":
      self.startup_candle_count = 710
    elif exchange_name == "bybit":
      self.startup_candle_count = 199
    elif exchange_name == "bitget":
      self.startup_candle_count = 499
    elif exchange_name == "bingx":
      self.startup_candle_count = 499

    if ("trading_mode" in strategy_config) and (strategy_config["trading_mode"] in ["futures", "margin"]):
      self.is_futures_mode = True
      self.can_short = True

    # If the cached data hasn't changed, it's a no-op
    self.target_profit_cache.save()

    # Parameter settings. Backward compatibility with the old configuration style.
    self.update_signals_from_config(strategy_config)

  # Plot configuration for FreqUI
  # ---------------------------------------------------------------------------------------------
  @property
  def plot_config(self):
    plot_config = {}

    plot_config["main_plot"] = {
      "EMA_12": {"color": "LightGreen"},
      "EMA_26": {"color": "Yellow"},
      "EMA_50": {"color": "DodgerBlue"},
      "EMA_200": {"color": "DarkRed"},
    }

    plot_config["subplots"] = {
      "long_pump_protection": {"global_protections_long_pump": {"color": "green"}},
      "long_dump_protection": {"global_protections_long_dump": {"color": "red"}},
    }

    return plot_config

  # Get Ticker Indicator
  # ---------------------------------------------------------------------------------------------
  def get_ticker_indicator(self):
    return int(self.timeframe[:-1])

  # Mark Profit Target
  # ---------------------------------------------------------------------------------------------
  def mark_profit_target(
    self,
    mode_name: str,
    pair: str,
    sell: bool,
    signal_name: str,
    trade: Trade,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    last_candle,
    previous_candle_1,
  ) -> tuple:
    if sell and (signal_name is not None):
      return pair, signal_name

    return None, None

  # Exit Profit Target
  # ---------------------------------------------------------------------------------------------
  def exit_profit_target(
    self,
    mode_name: str,
    pair: str,
    trade: Trade,
    current_time: datetime,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    last_candle,
    previous_candle_1,
    previous_rate,
    previous_profit,
    previous_sell_reason,
    previous_time_profit_reached,
    enter_tags,
  ) -> tuple:
    remove_profit_target = self._remove_profit_target
    derisk_enable = self.derisk_enable
    is_futures_mode = self.is_futures_mode
    long_rapid_mode_tags = self.long_rapid_mode_tags
    long_rebuy_mode_tags = self.long_rebuy_mode_tags
    long_rebuy_grind_mode_tags = self.long_rebuy_grind_mode_tags
    long_scalp_mode_tags = self.long_scalp_mode_tags
    long_scalp_rebuy_grind_mode_tags = self.long_scalp_rebuy_grind_mode_tags
    trade_leverage = trade.leverage
    select_filled_orders = trade.select_filled_orders

    is_backtest = self.is_backtest_mode()
    is_system_v3, is_system_v3_1, is_system_v3_2 = self.get_system_version_flags(trade)
    is_system_v4 = self.is_system_v4(trade)
    is_derisk = False
    if previous_sell_reason in [
      f"exit_{mode_name}_stoploss_doom",
      f"exit_{mode_name}_stoploss",
      f"exit_{mode_name}_stoploss_u_e",
    ]:
      filled_entries = select_filled_orders(trade.entry_side)
      filled_exits = select_filled_orders(trade.exit_side)
      first_filled_entry = filled_entries[0]
      has_order_tags = hasattr(first_filled_entry, "ft_order_tag")
      for order in filled_exits:
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag.partition(" ")[0]
        if order_tag in ["d", "d1", "derisk_level_1", "derisk_level_2", "derisk_level_3"]:
          is_derisk = True
          break
      if not is_derisk:
        is_derisk = trade.amount < (first_filled_entry.safe_filled * 0.95)
    if previous_sell_reason in [f"exit_{mode_name}_stoploss_doom", f"exit_{mode_name}_stoploss"]:
      # return right away for system v3
      if is_system_v3 or is_system_v3_1 or is_system_v3_2 or is_system_v4:
        return True, previous_sell_reason

      is_rapid_mode = all(c in long_rapid_mode_tags for c in enter_tags)
      is_rebuy_mode = all(c in long_rebuy_mode_tags for c in enter_tags) or (
        any(c in long_rebuy_mode_tags for c in enter_tags) and all(c in long_rebuy_grind_mode_tags for c in enter_tags)
      )
      is_scalp_mode = all(c in long_scalp_mode_tags for c in enter_tags) or (
        any(c in long_scalp_mode_tags for c in enter_tags)
        and all(c in long_scalp_rebuy_grind_mode_tags for c in enter_tags)
      )
      if profit_init_ratio > 0.0:
        # profit is over the threshold, don't exit
        remove_profit_target(pair)
        return False, None
      elif is_derisk:
        remove_profit_target(pair)
        return False, None
      elif derisk_enable and (current_time - timedelta(minutes=60) > previous_time_profit_reached):
        if profit_ratio < previous_profit:
          return True, previous_sell_reason
        elif profit_ratio > previous_profit:
          remove_profit_target(pair)
          return False, None
      elif (
        not derisk_enable
        and not is_rapid_mode
        and not is_rebuy_mode
        and not is_scalp_mode
        and (
          profit_init_ratio
          <= -(self.stop_threshold_doom_futures if is_futures_mode else self.stop_threshold_doom_spot)
        )
      ):
        return True, previous_sell_reason
      elif (
        not derisk_enable
        and is_rapid_mode
        and (
          profit_init_ratio
          <= -(self.stop_threshold_rapid_futures if is_futures_mode else self.stop_threshold_rapid_spot)
        )
      ):
        return True, previous_sell_reason
      elif (
        not derisk_enable
        and is_rebuy_mode
        and (
          profit_init_ratio
          <= -(self.stop_threshold_futures_rebuy if is_futures_mode else self.stop_threshold_spot_rebuy)
        )
      ):
        return True, previous_sell_reason
      elif (
        not derisk_enable
        and is_scalp_mode
        and (
          profit_init_ratio
          <= -(self.stop_threshold_scalp_futures if is_futures_mode else self.stop_threshold_scalp_spot)
        )
      ):
        return True, previous_sell_reason
    elif previous_sell_reason == f"exit_{mode_name}_stoploss_u_e":
      if profit_init_ratio > 0.0:
        # profit is over the threshold, don't exit
        remove_profit_target(pair)
        return False, None
      elif is_derisk:
        remove_profit_target(pair)
        return False, None
      elif profit_ratio < (previous_profit - (0.04 / trade_leverage)):
        return True, previous_sell_reason
    elif previous_sell_reason == f"exit_profit_{mode_name}_max":
      if profit_init_ratio < -0.08:
        # profit is under the threshold, cancel it
        remove_profit_target(pair)
        return False, None

      last_rsi_14 = last_candle["RSI_14"]
      previous_rsi_14 = previous_candle_1["RSI_14"]
      last_cmf_20 = last_candle["CMF_20"]
      last_cmf_20_1h = last_candle["CMF_20_1h"]
      last_cmf_20_4h = last_candle["CMF_20_4h"]
      last_roc_9_4h = last_candle["ROC_9_4h"]
      last_cmf_20_gt_0 = last_cmf_20 > 0.0
      last_cmf_20_1h_gt_0 = last_cmf_20_1h > 0.0
      last_cmf_20_4h_gt_0 = last_cmf_20_4h > 0.0
      last_rsi_14_gt_50 = last_rsi_14 > 50.0
      last_rsi_14_lt_50 = last_rsi_14 < 50.0
      last_roc_9_4h_gt_40 = last_roc_9_4h > 40.0
      last_roc_9_4h_lt_neg_40 = last_roc_9_4h < -40.0
      if trade.is_short:
        is_scalp_mode = all(c in self.short_scalp_mode_tags for c in enter_tags)
        if is_scalp_mode:
          if 0.001 <= profit_init_ratio < 0.01:
            if profit_init_ratio < (previous_profit - 0.008):
              return True, f"exit_profit_{mode_name}_t_0_1"
          elif 0.01 <= profit_init_ratio < 0.02:
            if profit_init_ratio < (previous_profit - 0.01):
              return True, f"exit_profit_{mode_name}_t_1_1"
          elif 0.02 <= profit_init_ratio < 0.03:
            if profit_init_ratio < (previous_profit - 0.01):
              return True, f"exit_profit_{mode_name}_t_2_1"
          elif 0.03 <= profit_init_ratio < 0.04:
            if profit_init_ratio < (previous_profit - 0.015):
              return True, f"exit_profit_{mode_name}_t_3_1"
          elif 0.04 <= profit_init_ratio < 0.05:
            if profit_init_ratio < (previous_profit - 0.015):
              return True, f"exit_profit_{mode_name}_t_4_1"
          elif 0.05 <= profit_init_ratio < 0.06:
            if profit_init_ratio < (previous_profit - 0.015):
              return True, f"exit_profit_{mode_name}_t_5_1"
          elif 0.06 <= profit_init_ratio < 0.07:
            if profit_init_ratio < (previous_profit - 0.015):
              return True, f"exit_profit_{mode_name}_t_6_1"
          elif 0.07 <= profit_init_ratio < 0.08:
            if profit_init_ratio < (previous_profit - 0.02):
              return True, f"exit_profit_{mode_name}_t_7_1"
          elif 0.08 <= profit_init_ratio < 0.09:
            if profit_init_ratio < (previous_profit - 0.02):
              return True, f"exit_profit_{mode_name}_t_8_1"
          elif 0.09 <= profit_init_ratio < 0.10:
            if profit_init_ratio < (previous_profit - 0.02):
              return True, f"exit_profit_{mode_name}_t_9_1"
          elif 0.10 <= profit_init_ratio < 0.11:
            if profit_init_ratio < (previous_profit - 0.025):
              return True, f"exit_profit_{mode_name}_t_10_1"
          elif 0.11 <= profit_init_ratio < 0.12:
            if profit_init_ratio < (previous_profit - 0.025):
              return True, f"exit_profit_{mode_name}_t_11_1"
          elif 0.12 <= profit_init_ratio:
            if profit_init_ratio < (previous_profit - 0.025):
              return True, f"exit_profit_{mode_name}_t_12_1"
        else:
          if 0.001 <= profit_init_ratio < 0.01:
            if profit_init_ratio < (previous_profit - 0.020):
              return True, f"exit_profit_{mode_name}_t_0_1"
          elif 0.01 <= profit_init_ratio < 0.02:
            if profit_init_ratio < (previous_profit - 0.025):
              return True, f"exit_profit_{mode_name}_t_1_1"
          elif 0.02 <= profit_init_ratio < 0.03:
            if profit_init_ratio < (previous_profit - 0.025):
              return True, f"exit_profit_{mode_name}_t_2_1"
          elif 0.03 <= profit_init_ratio < 0.04:
            if profit_init_ratio < (previous_profit - 0.030):
              return True, f"exit_profit_{mode_name}_t_3_1"
          elif 0.04 <= profit_init_ratio < 0.05:
            if profit_init_ratio < (previous_profit - 0.035):
              return True, f"exit_profit_{mode_name}_t_4_1"
          elif 0.05 <= profit_init_ratio < 0.06:
            if profit_init_ratio < (previous_profit - 0.040):
              return True, f"exit_profit_{mode_name}_t_5_1"
          elif 0.06 <= profit_init_ratio < 0.07:
            if profit_init_ratio < (previous_profit - 0.045):
              return True, f"exit_profit_{mode_name}_t_6_1"
          elif 0.07 <= profit_init_ratio < 0.08:
            if profit_init_ratio < (previous_profit - 0.050):
              return True, f"exit_profit_{mode_name}_t_7_1"
          elif 0.08 <= profit_init_ratio < 0.09:
            if profit_init_ratio < (previous_profit - 0.055):
              return True, f"exit_profit_{mode_name}_t_8_1"
          elif 0.09 <= profit_init_ratio < 0.10:
            if profit_init_ratio < (previous_profit - 0.060):
              return True, f"exit_profit_{mode_name}_t_9_1"
          elif 0.10 <= profit_init_ratio < 0.11:
            if profit_init_ratio < (previous_profit - 0.065):
              return True, f"exit_profit_{mode_name}_t_10_1"
          elif 0.11 <= profit_init_ratio < 0.12:
            if profit_init_ratio < (previous_profit - 0.070):
              return True, f"exit_profit_{mode_name}_t_11_1"
          elif 0.12 <= profit_init_ratio:
            if profit_init_ratio < (previous_profit - 0.075):
              return True, f"exit_profit_{mode_name}_t_12_1"
      else:
        is_scalp_mode = all(c in long_scalp_mode_tags for c in enter_tags)
        if is_scalp_mode:
          if 0.001 <= profit_init_ratio < 0.01:
            if profit_init_ratio < (previous_profit - 0.008):
              return True, f"exit_profit_{mode_name}_t_0_1"
          elif 0.01 <= profit_init_ratio < 0.02:
            if profit_init_ratio < (previous_profit - 0.01):
              return True, f"exit_profit_{mode_name}_t_1_1"
          elif 0.02 <= profit_init_ratio < 0.03:
            if profit_init_ratio < (previous_profit - 0.01):
              return True, f"exit_profit_{mode_name}_t_2_1"
          elif 0.03 <= profit_init_ratio < 0.04:
            if profit_init_ratio < (previous_profit - 0.015):
              return True, f"exit_profit_{mode_name}_t_3_1"
          elif 0.04 <= profit_init_ratio < 0.05:
            if profit_init_ratio < (previous_profit - 0.015):
              return True, f"exit_profit_{mode_name}_t_4_1"
          elif 0.05 <= profit_init_ratio < 0.06:
            if profit_init_ratio < (previous_profit - 0.015):
              return True, f"exit_profit_{mode_name}_t_5_1"
          elif 0.06 <= profit_init_ratio < 0.07:
            if profit_init_ratio < (previous_profit - 0.015):
              return True, f"exit_profit_{mode_name}_t_6_1"
          elif 0.07 <= profit_init_ratio < 0.08:
            if profit_init_ratio < (previous_profit - 0.02):
              return True, f"exit_profit_{mode_name}_t_7_1"
          elif 0.08 <= profit_init_ratio < 0.09:
            if profit_init_ratio < (previous_profit - 0.02):
              return True, f"exit_profit_{mode_name}_t_8_1"
          elif 0.09 <= profit_init_ratio < 0.10:
            if profit_init_ratio < (previous_profit - 0.02):
              return True, f"exit_profit_{mode_name}_t_9_1"
          elif 0.10 <= profit_init_ratio < 0.11:
            if profit_init_ratio < (previous_profit - 0.025):
              return True, f"exit_profit_{mode_name}_t_10_1"
          elif 0.11 <= profit_init_ratio < 0.12:
            if profit_init_ratio < (previous_profit - 0.025):
              return True, f"exit_profit_{mode_name}_t_11_1"
          elif 0.12 <= profit_init_ratio:
            if profit_init_ratio < (previous_profit - 0.025):
              return True, f"exit_profit_{mode_name}_t_12_1"
        else:
          if 0.001 <= profit_init_ratio < 0.01:
            if profit_init_ratio < (previous_profit - 0.020):
              return True, f"exit_profit_{mode_name}_t_0_1"
          elif 0.01 <= profit_init_ratio < 0.02:
            if profit_init_ratio < (previous_profit - 0.025):
              return True, f"exit_profit_{mode_name}_t_1_1"
          elif 0.02 <= profit_init_ratio < 0.03:
            if profit_init_ratio < (previous_profit - 0.025):
              return True, f"exit_profit_{mode_name}_t_2_1"
          elif 0.03 <= profit_init_ratio < 0.04:
            if profit_init_ratio < (previous_profit - 0.030):
              return True, f"exit_profit_{mode_name}_t_3_1"
          elif 0.04 <= profit_init_ratio < 0.05:
            if profit_init_ratio < (previous_profit - 0.035):
              return True, f"exit_profit_{mode_name}_t_4_1"
          elif 0.05 <= profit_init_ratio < 0.06:
            if profit_init_ratio < (previous_profit - 0.040):
              return True, f"exit_profit_{mode_name}_t_5_1"
          elif 0.06 <= profit_init_ratio < 0.07:
            if profit_init_ratio < (previous_profit - 0.045):
              return True, f"exit_profit_{mode_name}_t_6_1"
          elif 0.07 <= profit_init_ratio < 0.08:
            if profit_init_ratio < (previous_profit - 0.050):
              return True, f"exit_profit_{mode_name}_t_7_1"
          elif 0.08 <= profit_init_ratio < 0.09:
            if profit_init_ratio < (previous_profit - 0.055):
              return True, f"exit_profit_{mode_name}_t_8_1"
          elif 0.09 <= profit_init_ratio < 0.10:
            if profit_init_ratio < (previous_profit - 0.060):
              return True, f"exit_profit_{mode_name}_t_9_1"
          elif 0.10 <= profit_init_ratio < 0.11:
            if profit_init_ratio < (previous_profit - 0.065):
              return True, f"exit_profit_{mode_name}_t_10_1"
          elif 0.11 <= profit_init_ratio < 0.12:
            if profit_init_ratio < (previous_profit - 0.070):
              return True, f"exit_profit_{mode_name}_t_11_1"
          elif 0.12 <= profit_init_ratio:
            if profit_init_ratio < (previous_profit - 0.075):
              return True, f"exit_profit_{mode_name}_t_12_1"
    else:
      return False, None

    return False, None

  # Filled Order Snapshot
  # ---------------------------------------------------------------------------------------------
  def filled_order_snapshot(self, trade: "Trade") -> tuple:
    filled_orders = trade.select_filled_orders()
    filled_entries = []
    filled_exits = []
    append_entry = filled_entries.append
    append_exit = filled_exits.append
    entry_side = trade.entry_side
    exit_side = trade.exit_side
    for order in filled_orders:
      order_side = order.ft_order_side
      if order_side == entry_side:
        append_entry(order)
      elif order_side == exit_side:
        append_exit(order)
    return filled_orders, filled_entries, filled_exits

  @staticmethod
  def _bad_trade_controller_ema_gap_and_adverse_move(
    trade: "Trade", current_rate: float, last_candle, filled_entries: "Orders"
  ) -> tuple:
    """Return position-signed daily EMA gap and adverse move from the first filled entry."""
    ema_50_1d = last_candle.get("EMA_50_1d")
    ema_200_1d = last_candle.get("EMA_200_1d")
    if (
      ema_50_1d is None
      or ema_200_1d is None
      or not np.isfinite(ema_50_1d)
      or not np.isfinite(ema_200_1d)
      or ema_200_1d <= 0.0
    ):
      daily_ema_gap_pct = None
    else:
      daily_ema_gap_pct = (ema_50_1d / ema_200_1d - 1.0) * 100.0
      if trade.is_short:
        daily_ema_gap_pct = -daily_ema_gap_pct

    if not filled_entries:
      return daily_ema_gap_pct, None
    first_entry_rate = filled_entries[0].safe_price
    if first_entry_rate is None or not np.isfinite(first_entry_rate) or first_entry_rate <= 0.0:
      return daily_ema_gap_pct, None
    first_entry_adverse_move_pct = (
      ((current_rate - first_entry_rate) if trade.is_short else (first_entry_rate - current_rate))
      / first_entry_rate
      * 100.0
    )
    return daily_ema_gap_pct, first_entry_adverse_move_pct

  def _bad_trade_controller_exit_reason(
    self,
    trade: "Trade",
    current_time: "datetime",
    current_rate: float,
    last_candle,
    filled_entries: "Orders",
  ) -> Optional[str]:
    """Return a structure-break or stale-position exit reason."""
    daily_ema_gap_pct, first_entry_adverse_move_pct = self._bad_trade_controller_ema_gap_and_adverse_move(
      trade, current_rate, last_candle, filled_entries
    )
    if first_entry_adverse_move_pct is None or not np.isfinite(first_entry_adverse_move_pct):
      return None
    if (
      self.bad_trade_controller_structure_break_exit_enable
      and daily_ema_gap_pct is not None
      and daily_ema_gap_pct <= -self.bad_trade_controller_structure_break_ema_gap_pct
      and first_entry_adverse_move_pct >= self.bad_trade_controller_structure_break_min_adverse_move_pct
    ):
      return f"exit_bad_trade_broken_{first_entry_adverse_move_pct:.0f}pct"

    daily_range_pct_14_1d = last_candle.get("RANGE_PCT_14_1d")
    trade_age_days = (current_time - trade.open_date_utc).total_seconds() / 86400.0
    if (
      self.bad_trade_controller_stale_exit_enable
      and daily_range_pct_14_1d is not None
      and np.isfinite(daily_range_pct_14_1d)
      and daily_range_pct_14_1d < self.bad_trade_controller_stale_max_daily_range_pct
      and first_entry_adverse_move_pct >= self.bad_trade_controller_stale_min_adverse_move_pct
      and trade_age_days >= self.bad_trade_controller_stale_min_age_days
    ):
      return f"exit_bad_trade_abandon_{trade_age_days:.0f}d"
    return None

  def _bad_trade_controller_derisk_hold(self, last_candle, is_short: bool = False) -> bool:
    """Hold a de-risk level only while the daily trend is still intact (mirror for shorts)."""
    enabled = (
      self.bad_trade_controller_derisk_hold_short_enable if is_short else self.bad_trade_controller_derisk_hold_enable
    )
    if not enabled or last_candle is None:
      return False
    roc_9_1d = last_candle.get("ROC_9_1d")
    if roc_9_1d is None or not np.isfinite(roc_9_1d):
      return False
    bound = self.bad_trade_controller_derisk_hold_roc_9_1d
    return (roc_9_1d < -bound) if is_short else (roc_9_1d > bound)

  def _bad_trade_controller_capitulation(self, last_candle, is_short: bool = False) -> bool:
    """True while the 4h is at capitulation, where a grind add has been measured to lose."""
    if not self.bad_trade_controller_capitulation_add_gate_enable or last_candle is None:
      return False
    mfi_14_4h = last_candle.get("MFI_14_4h")
    if mfi_14_4h is None or not np.isfinite(mfi_14_4h):
      return False
    bound = self.bad_trade_controller_capitulation_add_gate_mfi_14_4h
    return (mfi_14_4h > 100.0 - bound) if is_short else (mfi_14_4h < bound)

  def _grind_entry_before_derisk(
    self, is_short: bool, rate: float, grind_open_rate: float, derisk_threshold: float, use_derisk: bool
  ) -> bool:
    if not (self.system_v4_grind_entry_before_derisk_enable and use_derisk and grind_open_rate > 0.0):
      return False
    distance = self.system_v4_grind_entry_before_derisk_distance
    if is_short:
      in_range = grind_open_rate * (1 - derisk_threshold - distance) <= rate < grind_open_rate * (1 - derisk_threshold)
    else:
      in_range = grind_open_rate * (1 + derisk_threshold) < rate <= grind_open_rate * (1 + derisk_threshold + distance)
    if in_range:
      self._grind_entry_tag = "g_pre_derisk"
    return in_range

  def trade_order_state(self, trade: "Trade") -> tuple:
    orders = trade.orders

    last_order = orders[-1] if orders else None
    return (
      len(orders),
      getattr(last_order, "id", None),
      getattr(last_order, "status", None),
      getattr(last_order, "filled", None),
    )

  def cache_backtest_profit_snapshot(
    self,
    trade: "Trade",
    current_time: "datetime",
    exit_rate: float,
    filled_orders: "Orders",
    filled_entries: "Orders",
    filled_exits: "Orders",
    profit_values: tuple,
  ) -> None:
    if not self.is_backtest_mode():
      return

    trade_key = trade.id if trade.id is not None else id(trade)
    self._backtest_profit_snapshot = (
      trade_key,
      current_time,
      exit_rate,
      self.trade_order_state(trade),
      filled_orders,
      filled_entries,
      filled_exits,
      profit_values,
    )

  def backtest_profit_snapshot(self, trade: "Trade", current_time: "datetime", exit_rate: float) -> tuple | None:
    if not self.is_backtest_mode():
      return None

    snapshot = getattr(self, "_backtest_profit_snapshot", None)
    if snapshot is None:
      return None

    (
      snapshot_trade_id,
      snapshot_time,
      snapshot_exit_rate,
      snapshot_order_state,
      filled_orders,
      filled_entries,
      filled_exits,
      profit_values,
    ) = snapshot
    trade_key = trade.id if trade.id is not None else id(trade)
    if (
      snapshot_trade_id == trade_key
      and snapshot_time == current_time
      and snapshot_exit_rate == exit_rate
      and snapshot_order_state == self.trade_order_state(trade)
    ):
      return filled_orders, filled_entries, filled_exits, profit_values

    return None

  def profit_or_order_snapshot(self, trade: "Trade", current_time: "datetime", exit_rate: float) -> tuple:
    profit_snapshot = self.backtest_profit_snapshot(trade, current_time, exit_rate)
    if profit_snapshot is not None:
      return profit_snapshot

    filled_orders, filled_entries, filled_exits = self.filled_order_snapshot(trade)
    return filled_orders, filled_entries, filled_exits, None

  # Calc Total Profit
  # ---------------------------------------------------------------------------------------------
  def calc_total_profit(
    self, trade: "Trade", filled_entries: "Orders", filled_exits: "Orders", exit_rate: float
  ) -> tuple:
    """
    Calculates the absolute profit for open trades.

    :param trade: trade object.
    :param filled_entries: Filled entries list.
    :param filled_exits: Filled exits list.
    :param exit_rate: The exit rate.
    :return tuple: The total profit in stake, ratio, ratio based on current stake, and ratio based on the first entry stake.
    """
    custom_fee_open_rate = self.custom_fee_open_rate
    custom_fee_close_rate = self.custom_fee_close_rate
    is_futures_mode = self.is_futures_mode

    fee_open_rate = trade.fee_open if custom_fee_open_rate is None else custom_fee_open_rate
    fee_close_rate = trade.fee_close if custom_fee_close_rate is None else custom_fee_close_rate

    total_amount = 0.0
    total_stake = 0.0
    total_profit = 0.0
    if trade.is_short:
      fee_open_multiplier = 1 - fee_open_rate
      fee_close_multiplier = 1 + fee_close_rate
      for entry_order in filled_entries:
        filled = entry_order.safe_filled
        entry_stake = filled * entry_order.safe_price * fee_open_multiplier
        total_amount += filled
        total_stake += entry_stake
        total_profit += entry_stake
      for exit_order in filled_exits:
        filled = exit_order.safe_filled
        exit_stake = filled * exit_order.safe_price * fee_close_multiplier
        total_amount -= filled
        total_profit -= exit_stake
      current_stake = total_amount * exit_rate * fee_close_multiplier
      total_profit -= current_stake
    else:
      fee_open_multiplier = 1 + fee_open_rate
      fee_close_multiplier = 1 - fee_close_rate
      for entry_order in filled_entries:
        filled = entry_order.safe_filled
        entry_stake = filled * entry_order.safe_price * fee_open_multiplier
        total_amount += filled
        total_stake += entry_stake
        total_profit -= entry_stake
      for exit_order in filled_exits:
        filled = exit_order.safe_filled
        exit_stake = filled * exit_order.safe_price * fee_close_multiplier
        total_amount -= filled
        total_profit += exit_stake
      current_stake = total_amount * exit_rate * fee_close_multiplier
      total_profit += current_stake
    if is_futures_mode and trade.funding_fees is not None:
      total_profit += trade.funding_fees
    total_profit_ratio = total_profit / total_stake
    current_profit_ratio = total_profit / current_stake
    init_profit_ratio = total_profit / (filled_entries[0].safe_filled * filled_entries[0].safe_price)
    return total_profit, total_profit_ratio, current_profit_ratio, init_profit_ratio

  @staticmethod
  def scale_stakes_for_min_stake(stakes, slice_amount, min_stake, stake_leverage, trade_leverage):
    if (slice_amount * stakes[0] / stake_leverage) >= min_stake:
      return stakes

    multi = min_stake / slice_amount / stakes[0] * trade_leverage
    return [stake * multi for stake in stakes]

  # Custom Exit
  # ---------------------------------------------------------------------------------------------
  def custom_exit(
    self, pair: str, trade: "Trade", current_time: "datetime", current_rate: float, current_profit: float, **kwargs
  ):
    trade_is_short = trade.is_short

    long_normal_mode_tags = self.long_normal_mode_tags
    long_pump_mode_tags = self.long_pump_mode_tags
    long_quick_mode_tags = self.long_quick_mode_tags
    long_rebuy_mode_tags = self.long_rebuy_mode_tags
    long_rebuy_grind_mode_tags = self.long_rebuy_grind_mode_tags
    long_high_profit_mode_tags = self.long_high_profit_mode_tags
    long_rapid_mode_tags = self.long_rapid_mode_tags
    long_rapid_rebuy_grind_scalp_mode_tags = self.long_rapid_rebuy_grind_scalp_mode_tags
    long_grind_mode_tags = self.long_grind_mode_tags
    long_btc_mode_tags = self.long_btc_mode_tags
    long_top_coins_mode_tags = self.long_top_coins_mode_tags
    long_scalp_mode_tags = self.long_scalp_mode_tags
    long_scalp_rebuy_grind_mode_tags = self.long_scalp_rebuy_grind_mode_tags
    long_known_mode_tags = self.long_known_mode_tags
    short_normal_mode_tags = self.short_normal_mode_tags
    short_pump_mode_tags = self.short_pump_mode_tags
    short_quick_mode_tags = self.short_quick_mode_tags
    short_rebuy_mode_tags = self.short_rebuy_mode_tags
    short_high_profit_mode_tags = self.short_high_profit_mode_tags
    short_rapid_mode_tags = self.short_rapid_mode_tags
    short_top_coins_mode_tags = self.short_top_coins_mode_tags
    short_scalp_mode_tags = self.short_scalp_mode_tags
    short_scalp_rebuy_grind_mode_tags = self.short_scalp_rebuy_grind_mode_tags
    short_exit_known_mode_tags = self.short_exit_known_mode_tags

    calc_total_profit = self.calc_total_profit
    cache_backtest_profit_snapshot = self.cache_backtest_profit_snapshot
    filled_order_snapshot = self.filled_order_snapshot
    long_exit_normal = self.long_exit_normal
    long_exit_pump = self.long_exit_pump
    long_exit_quick = self.long_exit_quick
    short_exit_normal = self.short_exit_normal

    df, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
    if len(df) < 2:
      return None
    last_candle = df.iloc[-1]
    previous_candle_1 = df.iloc[-2]

    enter_tag = "empty"
    if hasattr(trade, "enter_tag"):
      trade_enter_tag = trade.enter_tag
      if trade_enter_tag is not None:
        enter_tag = trade_enter_tag
    enter_tags = enter_tag.split()

    filled_orders, filled_entries, filled_exits = filled_order_snapshot(trade)

    profit_stake = 0.0
    profit_ratio = 0.0
    profit_current_stake_ratio = 0.0
    profit_init_ratio = 0.0
    profit_values = calc_total_profit(trade, filled_entries, filled_exits, current_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values
    cache_backtest_profit_snapshot(
      trade, current_time, current_rate, filled_orders, filled_entries, filled_exits, profit_values
    )

    system_version = trade.get_custom_data(key="system_version")
    bad_trade_exit_enable = (
      self.system_v4_bad_trade_exit_enable
      if system_version == self.system_v4_name
      else self.legacy_system_bad_trade_exit_enable
    )
    if bad_trade_exit_enable and (
      profit_stake < 0.0 or (self.inclusive_bad_trade_exit_enable and current_profit < 0.0)
    ):
      bad_trade_exit_reason = self._bad_trade_controller_exit_reason(
        trade, current_time, current_rate, last_candle, filled_entries
      )
      if bad_trade_exit_reason is not None:
        return f"{bad_trade_exit_reason} ( {enter_tag})"

    # Signal 192 (Quad pullback long) tight doom stop: every 192 loss bottoms at a
    # 11.8-14% price drop (the shared 0.35 doom threshold) while winners' max adverse
    # excursion sits below 9.63% price. Scoping 192's doom to -0.30 margin (~10% price
    # at 3x, ~30% at 1x) flips the tag net-positive. NOTE: this fires on ANY trade
    # carrying 192 as one of several tags, and it returns before long_exit_normal, so
    # for 192 it pre-empts the de-risk ladder (measured on a gms0 replica with derisk
    # off; production runs derisk on, where the ladder exists for exactly this zone).
    # On spot the -0.30 is looser than the existing doom thresholds (0.12 spot / 0.35
    # futures) and effectively never binds.
    if "192" in enter_tags and current_profit <= -0.30:
      return f"exit_long_normal_stoploss_doom ( {enter_tag})"

    max_profit = 0.0
    max_loss = 0.0

    # Long Normal mode
    if any(c in long_normal_mode_tags for c in enter_tags):
      sell, signal_name = long_exit_normal(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Long Pump mode
    if any(c in long_pump_mode_tags for c in enter_tags):
      sell, signal_name = long_exit_pump(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Long Quick mode
    if any(c in long_quick_mode_tags for c in enter_tags):
      sell, signal_name = long_exit_quick(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Long Rebuy mode
    if all(c in long_rebuy_mode_tags for c in enter_tags) or (
      any(c in long_rebuy_mode_tags for c in enter_tags) and all(c in long_rebuy_grind_mode_tags for c in enter_tags)
    ):
      sell, signal_name = self.long_exit_rebuy(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Long high profit mode
    if any(c in long_high_profit_mode_tags for c in enter_tags):
      sell, signal_name = self.long_exit_high_profit(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Long rapid mode
    if all(c in long_rapid_mode_tags for c in enter_tags) or (
      any(c in long_rapid_mode_tags for c in enter_tags)
      and all(c in long_rapid_rebuy_grind_scalp_mode_tags for c in enter_tags)
    ):
      sell, signal_name = self.long_exit_rapid(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Long grind mode
    if all(c in long_grind_mode_tags for c in enter_tags):
      sell, signal_name = self.long_exit_grind(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Long btc mode
    if all(c in long_btc_mode_tags for c in enter_tags):
      sell, signal_name = self.long_exit_btc(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Long Top Coins mode
    if any(c in long_top_coins_mode_tags for c in enter_tags):
      sell, signal_name = self.long_exit_top_coins(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Long scalp mode
    if all(c in long_scalp_mode_tags for c in enter_tags) or (
      any(c in long_scalp_mode_tags for c in enter_tags)
      and all(c in long_scalp_rebuy_grind_mode_tags for c in enter_tags)
    ):
      sell, signal_name = self.long_exit_scalp(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Short normal mode
    if any(c in short_normal_mode_tags for c in enter_tags):
      sell, signal_name = short_exit_normal(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Short Pump mode
    if any(c in short_pump_mode_tags for c in enter_tags):
      sell, signal_name = self.short_exit_pump(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Short Quick mode
    if any(c in short_quick_mode_tags for c in enter_tags):
      sell, signal_name = self.short_exit_quick(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Short Rebuy mode
    if all(c in short_rebuy_mode_tags for c in enter_tags):
      sell, signal_name = self.short_exit_rebuy(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Short high profit mode
    if any(c in short_high_profit_mode_tags for c in enter_tags):
      sell, signal_name = self.short_exit_high_profit(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Short rapid mode
    if any(c in short_rapid_mode_tags for c in enter_tags):
      sell, signal_name = self.short_exit_rapid(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Short Top Coins mode
    if any(c in short_top_coins_mode_tags for c in enter_tags):
      sell, signal_name = self.short_exit_top_coins(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Short scalp mode
    if all(c in short_scalp_mode_tags for c in enter_tags) or (
      any(c in short_scalp_mode_tags for c in enter_tags)
      and all(c in short_scalp_rebuy_grind_mode_tags for c in enter_tags)
    ):
      sell, signal_name = self.short_exit_scalp(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Trades not opened by X8
    if not trade_is_short and (not any(c in long_known_mode_tags for c in enter_tags)):
      # use normal mode for such trades
      sell, signal_name = long_exit_normal(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    # Trades not opened by X8
    if trade_is_short and (not any(c in short_exit_known_mode_tags for c in enter_tags)):
      # use normal mode for such trades
      sell, signal_name = short_exit_normal(
        pair,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
      if sell and (signal_name is not None):
        return f"{signal_name} ( {enter_tag})"

    return None

  # Custom Stake Amount
  # ---------------------------------------------------------------------------------------------
  def custom_stake_amount(
    self,
    pair: str,
    current_time: datetime,
    current_rate: float,
    proposed_stake: float,
    min_stake: Optional[float],
    max_stake: float,
    leverage: float,
    entry_tag: Optional[str],
    side: str,
    **kwargs,
  ) -> float:
    long_rebuy_mode_tags = self.long_rebuy_mode_tags
    long_rebuy_grind_mode_tags = self.long_rebuy_grind_mode_tags
    system_v3_rebuy_mode_stake_multiplier = self.system_v3_rebuy_mode_stake_multiplier
    system_v3_name = self.system_v3_name
    system_v3_2_name = self.system_v3_2_name
    system_v3_2_stake_multiplier = self.system_v3_2_stake_multiplier
    system_v3_1_name = self.system_v3_1_name
    system_v3_1_stake_multiplier = self.system_v3_1_stake_multiplier
    system_v4_rebuy_mode_stake_multiplier = self.system_v4_rebuy_mode_stake_multiplier
    system_v4_name = self.system_v4_name
    system_v4_stake_multiplier = self.system_v4_stake_multiplier
    long_rapid_mode_tags = self.long_rapid_mode_tags
    short_rebuy_mode_tags = self.short_rebuy_mode_tags
    short_rebuy_grind_mode_tags = self.short_rebuy_grind_mode_tags
    short_rapid_mode_tags = self.short_rapid_mode_tags
    long_rapid_rebuy_grind_mode_tags = self.long_rapid_rebuy_grind_mode_tags
    long_grind_mode_tags = self.long_grind_mode_tags
    long_btc_mode_tags = self.long_btc_mode_tags
    short_rapid_rebuy_grind_mode_tags = self.short_rapid_rebuy_grind_mode_tags
    short_grind_mode_tags = self.short_grind_mode_tags

    enter_tags = (entry_tag or "empty").split()
    is_futures_mode = self.is_futures_mode
    system_name_use = self.system_name_use
    system_name_is_v3 = system_name_use == system_v3_name
    system_name_is_v3_1 = system_name_use == system_v3_1_name
    system_name_is_v3_2 = system_name_use == system_v3_2_name
    system_name_is_v4 = system_name_use == system_v4_name
    grind_mode_stake_multiplier_futures = self.grind_mode_stake_multiplier_futures
    grind_mode_stake_multiplier_spot = self.grind_mode_stake_multiplier_spot
    rapid_mode_stake_multiplier_futures = self.rapid_mode_stake_multiplier_futures
    rapid_mode_stake_multiplier_spot = self.rapid_mode_stake_multiplier_spot
    regular_mode_stake_multiplier_futures = self.regular_mode_stake_multiplier_futures
    regular_mode_stake_multiplier_spot = self.regular_mode_stake_multiplier_spot
    grind_mode_stake_multipliers = (
      grind_mode_stake_multiplier_futures if is_futures_mode else grind_mode_stake_multiplier_spot
    )
    rapid_mode_stake_multipliers = (
      rapid_mode_stake_multiplier_futures if is_futures_mode else rapid_mode_stake_multiplier_spot
    )
    regular_mode_stake_multipliers = (
      regular_mode_stake_multiplier_futures if is_futures_mode else regular_mode_stake_multiplier_spot
    )

    def scaled_stake(stake_multiplier: float) -> float:
      stake = proposed_stake * stake_multiplier
      return stake if (min_stake is None) or (stake > min_stake) else min_stake

    if side == "long":
      # Rebuy mode
      if all(c in long_rebuy_mode_tags for c in enter_tags) or (
        any(c in long_rebuy_mode_tags for c in enter_tags) and all(c in long_rebuy_grind_mode_tags for c in enter_tags)
      ):
        if system_name_is_v4:
          return scaled_stake(system_v4_rebuy_mode_stake_multiplier)
        else:
          return scaled_stake(system_v3_rebuy_mode_stake_multiplier)
      # Rapid mode
      if system_name_is_v3 and (
        all(c in long_rapid_mode_tags for c in enter_tags)
        or (
          any(c in long_rapid_mode_tags for c in enter_tags)
          and all(c in long_rapid_rebuy_grind_mode_tags for c in enter_tags)
        )
      ):
        return scaled_stake(rapid_mode_stake_multipliers[0])
      # Grind mode
      elif all(c in long_grind_mode_tags for c in enter_tags):
        for item in grind_mode_stake_multipliers:
          stake = proposed_stake * item
          if (min_stake is None) or (stake > min_stake):
            return stake
      # Btc mode
      elif all(c in long_btc_mode_tags for c in enter_tags):
        return proposed_stake * grind_mode_stake_multipliers[0]
      else:
        if system_name_is_v4:
          return scaled_stake(system_v4_stake_multiplier)
        elif system_name_is_v3_2:
          return scaled_stake(system_v3_2_stake_multiplier)
        elif system_name_is_v3_1:
          return scaled_stake(system_v3_1_stake_multiplier)
        else:
          return scaled_stake(regular_mode_stake_multipliers[0])
    else:
      # Rebuy mode
      if all(c in short_rebuy_mode_tags for c in enter_tags) or (
        any(c in short_rebuy_mode_tags for c in enter_tags)
        and all(c in short_rebuy_grind_mode_tags for c in enter_tags)
      ):
        if system_name_is_v4:
          return scaled_stake(system_v4_rebuy_mode_stake_multiplier)
        else:
          return scaled_stake(system_v3_rebuy_mode_stake_multiplier)
      # Grind mode
      elif all(c in short_grind_mode_tags for c in enter_tags):
        for item in grind_mode_stake_multipliers:
          stake = proposed_stake * item
          if (min_stake is None) or (stake > min_stake):
            return stake
      # Rapid mode
      if system_name_is_v3 and (
        all(c in short_rapid_mode_tags for c in enter_tags)
        or (
          any(c in short_rapid_mode_tags for c in enter_tags)
          and all(c in short_rapid_rebuy_grind_mode_tags for c in enter_tags)
        )
      ):
        return scaled_stake(rapid_mode_stake_multipliers[0])
      else:
        if system_name_is_v4:
          return scaled_stake(system_v4_stake_multiplier)
        elif system_name_is_v3_2:
          return scaled_stake(system_v3_2_stake_multiplier)
        elif system_name_is_v3_1:
          return scaled_stake(system_v3_1_stake_multiplier)
        else:
          return scaled_stake(regular_mode_stake_multipliers[0])

    return proposed_stake

  # Order filled Callback
  # ---------------------------------------------------------------------------------------------
  def order_filled(self, pair: str, trade: Trade, order: Order, current_time: datetime, **kwargs) -> None:
    # Backtesting calls this before closing the trade; live trading calls it after.
    if not trade.is_open or (
      self.is_backtest_mode()
      and order.ft_order_side == trade.exit_side
      and order.safe_amount_after_fee == trade.amount
    ):
      self._remove_profit_target(pair)

    # Check if it's the first entry
    system_name_use = self.system_name_use
    system_v3_2_name = self.system_v3_2_name
    system_v3_1_name = self.system_v3_1_name
    system_v3_name = self.system_v3_name
    system_v4_name = self.system_v4_name
    set_custom_data = trade.set_custom_data

    if trade.nr_of_successful_entries == 1 and trade.nr_of_successful_exits == 0:
      if system_name_use == system_v4_name:
        set_custom_data(key="system_version", value=system_v4_name)
      elif system_name_use == system_v3_2_name:
        set_custom_data(key="system_version", value=system_v3_2_name)
      elif system_name_use == system_v3_1_name:
        set_custom_data(key="system_version", value=system_v3_1_name)
      elif system_name_use == system_v3_name:
        set_custom_data(key="system_version", value=system_v3_name)
        # set initial data for the trade
        trade.set_custom_data(key="grind_1_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_1_cluster_max_profit_rate", value=0.0)

        trade.set_custom_data(key="grind_2_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_2_cluster_max_profit_rate", value=0.0)

        trade.set_custom_data(key="grind_3_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_3_cluster_max_profit_rate", value=0.0)

        trade.set_custom_data(key="grind_4_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_4_cluster_max_profit_rate", value=0.0)

        trade.set_custom_data(key="grind_5_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_5_cluster_max_profit_rate", value=0.0)

    if system_name_use == system_v3_2_name or system_name_use == system_v4_name:
      filled_entries = trade.select_filled_orders(trade.entry_side)

      order_tag = order.ft_order_tag
      if order_tag is None:
        return None
      order_mode = order_tag.split(" ", 1)
      order_tags = []
      if len(order_mode) > 0:
        order_mode = order_mode[0]
      order_tags = order_tag.split(" ")
      if len(order_tags) > 1:
        order_tags = order_tags[1:]
      if order_mode in ["derisk_level_1"]:
        trade.set_custom_data(key="derisk_level_1", value=True)
      elif order_mode in ["derisk_level_2"]:
        trade.set_custom_data(key="derisk_level_2", value=True)
      elif order_mode in ["derisk_level_3"]:
        trade.set_custom_data(key="derisk_level_3", value=True)

      # elif order_mode in ["grind_1_entry"]:
      elif order_mode in ["grind_1_exit"]:
        trade.set_custom_data(key="grind_1_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_1_cluster_max_profit_rate", value=0.0)
      elif order_mode in ["grind_1_derisk"]:
        trade.set_custom_data(key="grind_1_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_1_cluster_max_profit_rate", value=0.0)

      elif order_mode in ["grind_2_exit"]:
        trade.set_custom_data(key="grind_2_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_2_cluster_max_profit_rate", value=0.0)
      elif order_mode in ["grind_2_derisk"]:
        trade.set_custom_data(key="grind_2_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_2_cluster_max_profit_rate", value=0.0)

      elif order_mode in ["grind_3_exit"]:
        trade.set_custom_data(key="grind_3_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_3_cluster_max_profit_rate", value=0.0)
      elif order_mode in ["grind_3_derisk"]:
        trade.set_custom_data(key="grind_3_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_3_cluster_max_profit_rate", value=0.0)

      elif order_mode in ["grind_4_exit"]:
        trade.set_custom_data(key="grind_4_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_4_cluster_max_profit_rate", value=0.0)
      elif order_mode in ["grind_4_derisk"]:
        trade.set_custom_data(key="grind_4_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_4_cluster_max_profit_rate", value=0.0)

      elif order_mode in ["grind_5_exit"]:
        trade.set_custom_data(key="grind_5_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_5_cluster_max_profit_rate", value=0.0)
      elif order_mode in ["grind_5_derisk"]:
        trade.set_custom_data(key="grind_5_cluster_max_profit_stake", value=0.0)
        trade.set_custom_data(key="grind_5_cluster_max_profit_rate", value=0.0)

    return None

  # Adjust Trade Position
  # ---------------------------------------------------------------------------------------------
  def adjust_trade_position(
    self,
    trade: Trade,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ):
    # =========================================================================
    # FAST EXIT
    # =========================================================================
    if not self.position_adjustment_enable:
      return None

    # =========================================================================
    # BASIC TRADE STATE
    # =========================================================================
    trade_is_short = trade.is_short
    enter_tag = "empty"
    if hasattr(trade, "enter_tag"):
      trade_enter_tag = trade.enter_tag
      if trade_enter_tag is not None:
        enter_tag = trade_enter_tag
    enter_tags = enter_tag.split()

    # =========================================================================
    # SYSTEM VERSION
    # =========================================================================
    is_backtest = self.is_backtest_mode()
    is_system_v3, is_system_v3_1, is_system_v3_2 = self.get_system_version_flags(trade)
    is_system_v3_family = is_system_v3 or is_system_v3_1 or is_system_v3_2
    is_system_v4 = self.is_system_v4(trade)

    if is_backtest:
      is_v2_date = True
    else:
      is_v2_date = trade.open_date_utc.replace(tzinfo=None) >= datetime(2025, 2, 13)

    # =========================================================================
    # ARGS
    # =========================================================================
    args = (
      trade,
      enter_tags,
      current_time,
      current_rate,
      current_profit,
      min_stake,
      max_stake,
      current_entry_rate,
      current_exit_rate,
      current_entry_profit,
      current_exit_profit,
    )

    # =========================================================================
    # LONG
    # =========================================================================
    if not trade_is_short:
      # -----------------------------------------------------------------------
      # REBUY MODE
      # -----------------------------------------------------------------------
      is_long_rebuy = all(c in self.long_rebuy_mode_tags for c in enter_tags)
      if not is_long_rebuy:
        is_long_rebuy = any(c in self.long_rebuy_mode_tags for c in enter_tags) and all(
          c in self.long_rebuy_grind_mode_tags for c in enter_tags
        )

      if is_long_rebuy:
        if is_system_v4:
          return self.long_rebuy_adjust_trade_position_v4(*args)
        elif is_system_v3_family:
          return self.long_rebuy_adjust_trade_position_v3(*args)
        return self.long_rebuy_adjust_trade_position(*args)

      # -----------------------------------------------------------------------
      # LONG MODE CLASSIFICATION
      # -----------------------------------------------------------------------
      is_long_grind_mode = all(c in self.long_grind_mode_tags for c in enter_tags)
      is_long_btc_mode = all(c in self.long_btc_mode_tags for c in enter_tags)

      # -----------------------------------------------------------------------
      # V4 GRIND
      # -----------------------------------------------------------------------
      if is_system_v4:
        if not is_long_grind_mode and not is_long_btc_mode:
          is_long_adjust_mode = any(c in self.long_adjust_mode_tags for c in enter_tags)
          is_long_known_mode = any(c in self.long_known_mode_tags for c in enter_tags)

          if is_long_adjust_mode or not is_long_known_mode:
            return self.long_grind_adjust_trade_position_v4(*args)

        # ---------------------------------------------------------------------
        # LEGACY GRIND
        # ---------------------------------------------------------------------
        elif is_long_grind_mode or is_long_btc_mode or not is_v2_date:
          return self.long_grind_adjust_trade_position(*args)

      # -----------------------------------------------------------------------
      # V3 GRIND
      # -----------------------------------------------------------------------
      if is_system_v3_family:
        if not is_long_grind_mode and not is_long_btc_mode:
          is_long_adjust_mode = any(c in self.long_adjust_mode_tags for c in enter_tags)
          is_long_known_mode = any(c in self.long_known_mode_tags for c in enter_tags)

          if is_long_adjust_mode or not is_long_known_mode:
            return self.long_grind_adjust_trade_position_v3(*args)

        # ---------------------------------------------------------------------
        # LEGACY GRIND
        # ---------------------------------------------------------------------
        elif is_long_grind_mode or is_long_btc_mode or not is_v2_date:
          return self.long_grind_adjust_trade_position(*args)

      # -----------------------------------------------------------------------
      # V2 / LEGACY ROUTING
      # -----------------------------------------------------------------------
      if is_long_grind_mode or is_long_btc_mode or not is_v2_date:
        return self.long_grind_adjust_trade_position(*args)

      is_long_adjust_mode = any(c in self.long_adjust_mode_tags for c in enter_tags)
      is_long_known_mode = any(c in self.long_known_mode_tags for c in enter_tags)

      if is_long_adjust_mode or not is_long_known_mode:
        return self.long_grind_adjust_trade_position_v2(*args)

    # =========================================================================
    # SHORT
    # =========================================================================
    else:
      # -----------------------------------------------------------------------
      # REBUY MODE
      # -----------------------------------------------------------------------
      is_short_rebuy = all(c in self.short_rebuy_mode_tags for c in enter_tags)
      if not is_short_rebuy:
        is_short_rebuy = any(c in self.short_rebuy_mode_tags for c in enter_tags) and all(
          c in self.short_rebuy_grind_mode_tags for c in enter_tags
        )
      if is_short_rebuy:
        if is_system_v4:
          return self.short_rebuy_adjust_trade_position_v4(*args)
        if is_system_v3_family:
          return self.short_rebuy_adjust_trade_position_v3(*args)
        return self.short_rebuy_adjust_trade_position(*args)

      # -----------------------------------------------------------------------
      # SHORT MODE CLASSIFICATION
      # -----------------------------------------------------------------------
      is_short_grind_mode = all(c in self.short_grind_mode_tags for c in enter_tags)

      # -----------------------------------------------------------------------
      # V4 GRIND
      # -----------------------------------------------------------------------
      if is_system_v4:
        if not is_short_grind_mode:
          is_short_adjust_mode = any(c in self.short_adjust_mode_tags for c in enter_tags)
          is_short_known_mode = any(c in self.short_known_mode_tags for c in enter_tags)

          if is_short_adjust_mode or not is_short_known_mode:
            return self.short_grind_adjust_trade_position_v4(*args)

        # ---------------------------------------------------------------------
        # LEGACY GRIND
        # ---------------------------------------------------------------------
        elif is_short_grind_mode or not is_v2_date:
          return self.short_grind_adjust_trade_position(*args)

      # -----------------------------------------------------------------------
      # V3 GRIND
      # -----------------------------------------------------------------------
      if is_system_v3_family:
        if not is_short_grind_mode:
          is_short_adjust_mode = any(c in self.short_adjust_mode_tags for c in enter_tags)
          is_short_known_mode = any(c in self.short_known_mode_tags for c in enter_tags)

          if is_short_adjust_mode or not is_short_known_mode:
            return self.short_grind_adjust_trade_position_v3(*args)

        # ---------------------------------------------------------------------
        # LEGACY GRIND
        # ---------------------------------------------------------------------
        elif is_short_grind_mode or not is_v2_date:
          return self.short_grind_adjust_trade_position(*args)

      # -----------------------------------------------------------------------
      # V2 / LEGACY ROUTING
      # -----------------------------------------------------------------------
      if is_short_grind_mode or not is_v2_date:
        return self.short_grind_adjust_trade_position(*args)

      is_short_adjust_mode = any(c in self.short_adjust_mode_tags for c in enter_tags)
      is_short_known_mode = any(c in self.short_known_mode_tags for c in enter_tags)

      if is_short_adjust_mode or not is_short_known_mode:
        return self.short_grind_adjust_trade_position_v2(*args)

    return None

  def notification_msg(
    self,
    msg_type: str,
    tag: str,
    pair: str,
    rate: float,
    stake_amount: float,
    profit_stake: float,
    profit_ratio: float,
    grind_profit_stake: float = None,
    grind_profit_pct: float = None,
    stake_currency: str = None,
    coin_amount: float = None,
  ) -> str:
    """
    Generate a formatted notification message for trade events.

    This function is designed to standardize trade-related notifications
    such as grinding entries, exits, stop-losses, buybacks, and re-entries.
    It builds a Markdown-formatted message with emojis for readability.

    Parameters
    ----------
    msg_type : str
        Type of notification. Must be one of:
        - "grinding-entry"
        - "grinding-exit"
        - "grinding-derisk"
        - "grinding-stop"
        - "buyback-entry"
        - "buyback-exit"
        - "buyback-derisk"
        - "re-entry"
        - "de-risk"
        - "rebuy-derisk"
        - "rebuy"
    tag : str
        Identifier or label for the trade step (e.g., "g1", "dl1").
    pair : str
        Pair (e.g., "BTC/USDT").
    rate : float
        Entry or exit rate for the trade.
    stake_amount : float
        Amount of stake used in the trade.
    profit_stake : float
        Profit expressed in stake currency.
    profit_ratio : float
        Profit ratio (decimal form, e.g. 0.05 = 5%).
    grind_profit_stake : float, optional
        Grind profit expressed in stake currency (default: None).
    grind_profit_pct : float, optional
        Grind profit ratio (decimal form, e.g. 0.02 = 2%) (default: None).
    stake_currency : str, optional
        Symbol of the stake currency (e.g., "USDT"). If None, only numeric values are shown.
    coin_amount : float, optional
        Amount of base coins involved in the trade (e.g., exit/stop cases).

    Returns
    -------
    str
        A formatted multi-line string with trade details.
        Example:
        ```
        ✅ **Grinding entry:** `(dl1)`
        🏦 **Exchange:** `Binance`
        🪙 **Pair:** `BTC/USDT`
        〽️ **Rate:** `20000.0`
        💰 **Stake amount:** `100.00 USDT`
        💵 **Profit (stake):** `5.00 USDT`
        💸 **Profit (percent):** `5.00%`
        💶 **Grind profit (stake):** `2.00 USDT`
        💸 **Grind profit (percent):** `2.00%`
        ```

    Notes
    -----
    - The function uses Markdown formatting (e.g., **bold**, `inline code`)
      for compatibility with Discord, Telegram, etc.
    - If `grind_profit_stake` or `grind_profit_pct` are not provided,
      the related fields are omitted.
    - If `stake_currency` is provided, it will be appended to amounts.
    """
    # Skip in backtesting / hyperopt
    if self.is_backtest_mode():
      return ""

    # Headers for different message types
    header_labels = {
      "grinding-entry": "✅ ​**Grinding entry:** ",
      "grinding-exit": "❎​ ​**Grinding exit:** ",
      "grinding-derisk": "❌​​ ​**Grinding de-risk:** ",
      "grinding-stop": "❌ ​**Grinding stop exit:** ",
      "buyback-entry": "✅ ​**Buyback entry:** ",
      "buyback-exit": "❎​​ ​**Buyback exit:** ",
      "buyback-derisk": "❌​​ ​**Buyback de-risk:** ",
      "re-entry": "✅ ​**Re-entry:** ",
      "de-risk": "❌​​ ​**De-risk:** ",
      "rebuy-derisk": "❌​​ ​**Rebuy de-risk:** ",
      "rebuy": "✅ ​**Rebuy:** ",
    }

    # Start with the header
    header_label = header_labels.get(msg_type, None)
    msg = None if header_label is None else f"{header_label}`({tag})`\n"

    # Add exchange information
    exchange_name = getattr(self, "config", {}).get("exchange", {}).get("name", "Unknown").capitalize()
    msg += f"🏦 **Exchange:** `{exchange_name}`\n"

    # Common fields
    msg += (
      f"🪙 **Pair:** `{pair}`\n"
      f"〽️ **Rate:** `{rate}`\n"
      f"💰 **Stake amount:** `{stake_amount:.2f}{'' if stake_currency is None else ' ' + stake_currency}`\n"
    )

    # Add coin amount if available (exit/stop cases)
    if coin_amount is not None:
      msg += f"🪙 **Coin amount:** `{coin_amount}`\n"

    # Profit section
    profit_pct = profit_ratio * 100
    msg += (
      f"💵 **Profit (stake):** `{profit_stake:.2f}{'' if stake_currency is None else ' ' + stake_currency}`\n"
      f"💸 **Profit (percent):** `{profit_pct:.2f}%`\n"
    )

    # Grind profit calculation
    if grind_profit_stake is not None and grind_profit_stake != 0:
      msg += f"💶 **Grind profit (stake):** `{grind_profit_stake:.2f}{'' if stake_currency is None else ' ' + stake_currency}`\n"
    if grind_profit_pct is not None and grind_profit_pct != 0:
      msg += f"💸 **Grind profit (percent):** `{(grind_profit_pct * 100.0):.2f}%`"

    return msg

  def btc_informative_pair(self) -> str:
    stake_currency = self.config["stake_currency"]
    is_futures = self.config.get("trading_mode") in ("futures", "margin")

    if stake_currency in self.stable_stake_currencies:
      return f"BTC/{stake_currency}:{stake_currency}" if is_futures else f"BTC/{stake_currency}"

    return "BTC/USDT:USDT" if is_futures else "BTC/USDT"

  def prepare_informative_merge(self, informative: DataFrame, keep_ohlcv=None) -> DataFrame:
    if informative.empty:
      return informative

    keep_ohlcv = keep_ohlcv or ()
    keep_cols = [
      column
      for column in informative.columns
      if column == "date" or column not in self.informative_ohlcv_columns or column in keep_ohlcv
    ]

    return informative[keep_cols]

  # Informative Pairs
  # ---------------------------------------------------------------------------------------------
  def informative_pairs(self):
    # get access to all pairs available in whitelist.
    pairs = self.dp.current_whitelist()

    # Use set to automatically avoid duplicates
    informative_pairs = set()

    # Assign tf to each pair so they can be downloaded and cached for strategy.
    for info_timeframe in self.info_timeframes:
      informative_pairs.update((pair, info_timeframe) for pair in pairs)

    btc_info_pair = self.btc_informative_pair()

    informative_pairs.update((btc_info_pair, btc_info_timeframe) for btc_info_timeframe in self.btc_info_timeframes)
    # BTC on 5m: cascade guard, shared by every entry condition that reads it
    informative_pairs.add((btc_info_pair, self.timeframe))

    return list(informative_pairs)

  @staticmethod
  def chaikin_money_flow(high, low, close, volume, timeperiod=20):
    hl_range = high - low
    mfm = np.zeros_like(close, dtype=np.float64)
    valid = hl_range != 0
    mfm[valid] = ((close[valid] - low[valid]) - (high[valid] - close[valid])) / hl_range[valid]
    mfv = mfm * volume

    stacked = np.vstack([mfv, volume])
    stacked_clean = np.nan_to_num(stacked, nan=0.0)
    csum = np.cumsum(stacked_clean, axis=1)
    csum[:, timeperiod:] -= csum[:, :-timeperiod]

    out = np.full(stacked.shape, np.nan, dtype=np.float64)
    out[:, timeperiod - 1 :] = csum[:, timeperiod - 1 :]
    mfv_sum, vol_sum = out[0], out[1]
    vol_sum = np.where(vol_sum == 0, np.nan, vol_sum)
    return mfv_sum / vol_sum

  @staticmethod
  def fast_pct_change(arr: np.ndarray) -> np.ndarray:
    """
    Compute the percentage change between consecutive values.

    The first element is set to NaN. Division-by-zero cases also
    return NaN instead of producing invalid or infinite values.
    """
    arr = np.asarray(arr, dtype=np.float64)
    out = np.full(arr.shape, np.nan, dtype=np.float64)
    prev = arr[:-1]
    np.divide((arr[1:] - prev), prev, out=out[1:], where=prev != 0)
    out[1:] *= 100.0

    return out

  @staticmethod
  def obv_change_pct(obv: np.ndarray) -> np.ndarray:
    """Measure OBV movement relative to the magnitude of its previous value."""
    obv = np.asarray(obv, dtype=np.float64)
    out = np.full(obv.shape, np.nan, dtype=np.float64)
    prev = obv[:-1]
    valid = np.isfinite(prev) & np.isfinite(obv[1:]) & (prev != 0)
    np.divide(obv[1:] - prev, np.abs(prev), out=out[1:], where=valid)
    out[1:] *= 100.0
    return out

  @staticmethod
  def stochrsi_k(rsi_14: np.ndarray, ta_min: np.ndarray, ta_max: np.ndarray, ta_sma: np.ndarray) -> np.ndarray:
    """
    Calculate the %K line of the Stochastic RSI.

    Stochastic RSI normalizes RSI values relative to their recent
    14-period range, then applies a 3-period SMA smoothing.

    Periods where the RSI range is zero are marked as NaN to prevent
    invalid values from producing misleading momentum signals.
    """
    rsi_min = ta_min(rsi_14, timeperiod=14)
    rsi_max = ta_max(rsi_14, timeperiod=14)
    denom = rsi_max - rsi_min
    denom = np.where(denom == 0, np.nan, denom)
    stochrsi = ((rsi_14 - rsi_min) / denom) * 100.0

    return ta_sma(stochrsi, timeperiod=3)

  @staticmethod
  def calc_kst(close: np.ndarray, ta_roc, ta_sma) -> tuple[np.ndarray, np.ndarray]:
    roc10 = ta_roc(close, 10)
    roc15 = ta_roc(close, 15)
    roc20 = ta_roc(close, 20)
    roc30 = ta_roc(close, 30)
    kst1 = ta_sma(roc10, 10)
    kst2 = ta_sma(roc15, 10)
    kst3 = ta_sma(roc20, 10)
    kst4 = ta_sma(roc30, 15)
    kst_main = kst1 + (2.0 * kst2) + (3.0 * kst3) + (4.0 * kst4)
    kst_signal = ta_sma(kst_main, 9)

    return kst_main, kst_signal

  @staticmethod
  def validate_indicators(df: pd.DataFrame, columns: list[str], pair: str, timeframe: str) -> None:
    expected_len = len(df)
    for col in columns:
      # Missing column
      if col not in df.columns:
        log.warning(f"[{pair}] [{timeframe}] Missing column: {col}")
        continue

      series = df[col]

      # Length check
      if len(series) != expected_len:
        log.warning(f"[{pair}] [{timeframe}] {col} length mismatch: {len(series)} != {expected_len}")

      # Dtype check
      if not pd.api.types.is_numeric_dtype(series):
        log.warning(f"[{pair}] [{timeframe}] {col} non-numeric dtype: {series.dtype}")
        continue

      arr = series.to_numpy(copy=False)

      # Empty array protection
      if arr.size == 0:
        log.warning(f"[{pair}] [{timeframe}] {col} empty array")
        continue

      # Inf check
      inf_count = np.isinf(arr).sum()

      if inf_count:
        log.warning(f"[{pair}] [{timeframe}] {col} contains {inf_count} inf values")

      # NaN diagnostics
      nan_count = np.isnan(arr).sum()

      if nan_count == expected_len:
        log.warning(f"[{pair}] [{timeframe}] {col} is ALL NaN")

      elif nan_count:
        nan_pct = (nan_count / expected_len) * 100.0

        if nan_pct > 50.0:
          log.warning(f"[{pair}] [{timeframe}] {col} has {nan_pct:.1f}% NaN")
        else:
          log.debug("[%s] [%s] %s NaNs: %s (%.1f%%)", pair, timeframe, col, nan_count, nan_pct)

  @staticmethod
  def np_shift(arr, periods):
    out = np.empty_like(arr)
    out[:periods] = np.nan
    out[periods:] = arr[:-periods]
    return out

  # Informative 1d Timeframe Indicators
  # ---------------------------------------------------------------------------------------------
  def informative_1d_indicators(self, metadata: dict, info_timeframe) -> DataFrame:
    debug_time = False
    if debug_time:
      tik = time.perf_counter()
    dp = self.dp
    fast_pct_change = self.fast_pct_change
    stochrsi_k_func = self.stochrsi_k
    chaikin_money_flow = self.chaikin_money_flow
    ta_rsi = ta.RSI
    ta_aroon = ta.AROON
    ta_roc = ta.ROC
    ta_min = ta.MIN
    ta_max = ta.MAX
    ta_sma = ta.SMA
    ta_stochf = ta.STOCHF
    ta_mfi = ta.MFI
    ta_willr = ta.WILLR

    assert dp, "DataProvider is required for multiple timeframes."

    # Get dataframe
    metadata_pair = metadata["pair"]
    informative_1d = dp.get_pair_dataframe(pair=metadata_pair, timeframe=info_timeframe)

    # Empty dataframe protection
    if informative_1d.empty:
      return informative_1d

    # =========================================================================
    # BASE DATA
    # =========================================================================
    close_np = informative_1d["close"].to_numpy(copy=False)
    high_np = informative_1d["high"].to_numpy(copy=False)
    low_np = informative_1d["low"].to_numpy(copy=False)
    open_np = informative_1d["open"].to_numpy(copy=False)
    volume_np = informative_1d["volume"].to_numpy(copy=False)

    # =========================================================================
    # CORE INDICATORS
    # =========================================================================
    rsi_3 = ta_rsi(close_np, timeperiod=3)
    rsi_14 = ta_rsi(close_np, timeperiod=14)
    aroon_down, aroon_up = ta_aroon(high_np, low_np, timeperiod=14)

    # =========================================================================
    # STOCH
    # =========================================================================
    _, stoch_k = ta_stochf(high_np, low_np, close_np, fastk_period=14, fastd_period=3, fastd_matype=0)
    stochrsi_k = stochrsi_k_func(rsi_14, ta_min, ta_max, ta_sma)

    # =========================================================================
    # MONEY FLOW
    # =========================================================================
    mfi_14 = ta_mfi(high_np, low_np, close_np, volume_np, timeperiod=14)
    cmf_20 = chaikin_money_flow(high_np, low_np, close_np, volume_np, timeperiod=20)

    # =========================================================================
    # MOMENTUM
    # =========================================================================
    willr_14 = ta_willr(high_np, low_np, close_np, timeperiod=14)
    roc_2 = ta_roc(close_np, timeperiod=2)
    roc_7 = ta_roc(close_np, timeperiod=7)
    roc_9 = ta_roc(close_np, timeperiod=9)

    # =========================================================================
    # RSI CHANGE %
    # =========================================================================
    rsi3_change = fast_pct_change(rsi_3)

    # =========================================================================
    # CANDLE %
    # =========================================================================
    open_safe = np.where(open_np == 0, np.nan, open_np)
    change_pct = ((close_np - open_np) / open_safe) * 100.0

    # =========================================================================
    # WICK %
    # =========================================================================
    max_oc = np.maximum(open_np, close_np)
    min_oc = np.minimum(open_np, close_np)
    max_oc_calc = np.where(max_oc == 0, np.nan, max_oc)
    min_oc_calc = np.where(min_oc == 0, np.nan, min_oc)
    top_wick_pct = ((high_np - max_oc) / max_oc_calc) * 100.0
    bot_wick_pct = np.abs(((low_np - min_oc) / min_oc_calc) * 100.0)

    # =========================================================================
    # HIGH / LOW ROLLING
    # =========================================================================
    high_max_6 = ta_max(high_np, timeperiod=6)
    high_max_12 = ta_max(high_np, timeperiod=12)
    high_max_20 = ta_max(high_np, timeperiod=20)
    high_max_30 = ta_max(high_np, timeperiod=30)
    low_min_6 = ta_min(low_np, timeperiod=6)
    low_min_12 = ta_min(low_np, timeperiod=12)
    low_min_20 = ta_min(low_np, timeperiod=20)
    low_min_30 = ta_min(low_np, timeperiod=30)

    bad_trade_exit_indicators = {}
    if self.system_v4_bad_trade_exit_enable or self.legacy_system_bad_trade_exit_enable:
      nonzero_low_np = np.where(low_np == 0.0, np.nan, low_np)
      daily_range_pct_np = (high_np - low_np) / nonzero_low_np * 100.0
      bad_trade_exit_indicators = {
        "EMA_50": ta.EMA(close_np, timeperiod=50),
        "EMA_200": ta.EMA(close_np, timeperiod=200),
        "RANGE_PCT_14": ta_sma(daily_range_pct_np, timeperiod=14),
      }

    # =========================================================================
    # ASSIGN DATAFRAME
    # =========================================================================
    new_cols = pd.DataFrame(
      {
        "RSI_3": rsi_3,
        "RSI_14": rsi_14,
        "STOCHk_14_3_3": stoch_k,
        "STOCHRSIk_14_14_3_3": stochrsi_k,
        "MFI_14": mfi_14,
        "CMF_20": cmf_20,
        "WILLR_14": willr_14,
        "AROONU_14": aroon_up,
        "AROOND_14": aroon_down,
        "ROC_2": roc_2,
        "ROC_7": roc_7,
        "ROC_9": roc_9,
        "RSI_3_change_pct": rsi3_change,
        "change_pct": change_pct,
        "top_wick_pct": top_wick_pct,
        "bot_wick_pct": bot_wick_pct,
        "high_max_6": high_max_6,
        "high_max_12": high_max_12,
        "high_max_20": high_max_20,
        "high_max_30": high_max_30,
        "low_min_6": low_min_6,
        "low_min_12": low_min_12,
        "low_min_20": low_min_20,
        "low_min_30": low_min_30,
        **bad_trade_exit_indicators,
      },
      index=informative_1d.index,
    )
    informative_1d = pd.concat([informative_1d, new_cols], axis=1, copy=False)

    # Enable ONLY during debugging
    debug = False
    if debug:
      debug_cols = [
        "RSI_3",
        "RSI_14",
        "STOCHk_14_3_3",
        "STOCHRSIk_14_14_3_3",
        "MFI_14",
        "CMF_20",
        "WILLR_14",
        "AROONU_14",
        "AROOND_14",
        "ROC_2",
        "ROC_7",
        "ROC_9",
        "RSI_3_change_pct",
        "change_pct",
        "top_wick_pct",
        "bot_wick_pct",
        "high_max_6",
        "high_max_12",
        "high_max_20",
        "high_max_30",
        "low_min_6",
        "low_min_12",
        "low_min_20",
        "low_min_30",
      ]
      if bad_trade_exit_indicators:
        debug_cols.extend(["EMA_50", "EMA_200", "RANGE_PCT_14"])

      self.validate_indicators(df=informative_1d, columns=debug_cols, pair=metadata_pair, timeframe=info_timeframe)

    # =========================================================================
    # LOGGING
    # =========================================================================
    if debug_time:
      tok = time.perf_counter()
      log.debug("[%s] informative_1d_indicators took: %.4f seconds.", metadata_pair, tok - tik)

    return informative_1d

  # Informative 4h Timeframe Indicators
  # ---------------------------------------------------------------------------------------------
  def informative_4h_indicators(self, metadata: dict, info_timeframe) -> DataFrame:
    debug_time = False
    if debug_time:
      tik = time.perf_counter()
    dp = self.dp
    fast_pct_change = self.fast_pct_change
    stochrsi_k_func = self.stochrsi_k
    chaikin_money_flow = self.chaikin_money_flow
    calc_kst = self.calc_kst
    np_shift = self.np_shift
    ta_rsi = ta.RSI
    ta_aroon = ta.AROON
    ta_sma = ta.SMA
    ta_roc = ta.ROC
    ta_ema = ta.EMA
    ta_max = ta.MAX
    ta_min = ta.MIN
    ta_bbands = ta.BBANDS
    ta_stochf = ta.STOCHF
    ta_mfi = ta.MFI
    ta_willr = ta.WILLR
    ta_ultosc = ta.ULTOSC
    ta_cci = ta.CCI
    ta_adx = ta.ADX
    ta_plus_di = ta.PLUS_DI
    ta_minus_di = ta.MINUS_DI

    assert dp, "DataProvider is required for multiple timeframes."

    # Get dataframe
    metadata_pair = metadata["pair"]
    informative_4h = dp.get_pair_dataframe(pair=metadata_pair, timeframe=info_timeframe)

    # Empty dataframe protection
    if informative_4h.empty:
      return informative_4h

    # =========================================================================
    # BASE DATA
    # =========================================================================
    close_np = informative_4h["close"].to_numpy(copy=False)
    high_np = informative_4h["high"].to_numpy(copy=False)
    low_np = informative_4h["low"].to_numpy(copy=False)
    open_np = informative_4h["open"].to_numpy(copy=False)
    volume_np = informative_4h["volume"].to_numpy(copy=False)

    # =========================================================================
    # CORE INDICATORS
    # =========================================================================
    rsi_3 = ta_rsi(close_np, timeperiod=3)
    rsi_14 = ta_rsi(close_np, timeperiod=14)
    aroon_down, aroon_up = ta_aroon(high_np, low_np, timeperiod=14)
    bb_upper_20, _, bb_lower_20 = ta_bbands(close_np, timeperiod=20, nbdevup=2.0, nbdevdn=2.0, matype=0)
    bbp_20 = (close_np - bb_lower_20) / np.where(bb_upper_20 - bb_lower_20 == 0, np.nan, bb_upper_20 - bb_lower_20)

    # =========================================================================
    # STOCH
    # =========================================================================
    _, stoch_k = ta_stochf(high_np, low_np, close_np, fastk_period=14, fastd_period=3, fastd_matype=0)
    stochrsi_k = stochrsi_k_func(rsi_14, ta_min, ta_max, ta_sma)

    # =========================================================================
    # KST
    # =========================================================================
    kst_main, kst_signal = calc_kst(close_np, ta_roc, ta_sma)

    # =========================================================================
    # MONEY FLOW
    # =========================================================================
    mfi_14 = ta_mfi(high_np, low_np, close_np, volume_np, timeperiod=14)
    cmf_20 = chaikin_money_flow(high_np, low_np, close_np, volume_np, timeperiod=20)

    # =========================================================================
    # MOMENTUM
    # =========================================================================
    ema_12 = ta_ema(close_np, timeperiod=12)
    sma_200 = ta_sma(close_np, timeperiod=200)
    # SMA_200 below where it was 6 candles back = the slow trend is rolling over.
    sma_200_prev = np_shift(sma_200, 6)
    sma_200_dec_6 = sma_200 < sma_200_prev
    sma_200_inc_6 = sma_200 > sma_200_prev
    ema_50 = ta_ema(close_np, timeperiod=50)
    ema_100 = ta_ema(close_np, timeperiod=100)
    ema_200 = ta_ema(close_np, timeperiod=200)
    willr_14 = ta_willr(high_np, low_np, close_np, timeperiod=14)
    uo = ta_ultosc(high_np, low_np, close_np)
    roc_2 = ta_roc(close_np, timeperiod=2)
    roc_9 = ta_roc(close_np, timeperiod=9)
    cci_20 = ta_cci(high_np, low_np, close_np, timeperiod=20)

    # =========================================================================
    # CHANGE %
    # =========================================================================
    rsi_3_change = fast_pct_change(rsi_3)
    rsi_14_change = fast_pct_change(rsi_14)
    stochrsi_change = fast_pct_change(stochrsi_k)
    cci_change = fast_pct_change(cci_20)

    # =========================================================================
    # CANDLE %
    # =========================================================================
    open_safe = np.where(open_np == 0, np.nan, open_np)
    change_pct = ((close_np - open_np) / open_safe) * 100.0

    # =========================================================================
    # WICK %
    # =========================================================================
    max_oc = np.maximum(open_np, close_np)
    max_oc_calc = np.where(max_oc == 0, np.nan, max_oc)
    top_wick_pct = ((high_np - max_oc) / max_oc_calc) * 100.0

    # =========================================================================
    # ROLLING
    # =========================================================================
    high_max_6 = ta_max(high_np, timeperiod=6)
    high_max_12 = ta_max(high_np, timeperiod=12)
    high_max_24 = ta_max(high_np, timeperiod=24)
    low_min_12 = ta_min(low_np, timeperiod=12)
    low_min_24 = ta_min(low_np, timeperiod=24)

    # ADX/DMI — trend strength + direction (signals 7/505 experimental; NFI's first ADX use)
    adx_14 = ta_adx(high_np, low_np, close_np, timeperiod=14)
    plus_di_14 = ta_plus_di(high_np, low_np, close_np, timeperiod=14)
    minus_di_14 = ta_minus_di(high_np, low_np, close_np, timeperiod=14)

    # =========================================================================
    # ASSIGN DATAFRAME
    # =========================================================================
    new_cols = pd.DataFrame(
      {
        "RSI_3": rsi_3,
        "RSI_14": rsi_14,
        "ADX_14": adx_14,
        "PLUS_DI_14": plus_di_14,
        "MINUS_DI_14": minus_di_14,
        "AROONU_14": aroon_up,
        "AROOND_14": aroon_down,
        "BBP_20_2.0": bbp_20,
        "STOCHk_14_3_3": stoch_k,
        "STOCHRSIk_14_14_3_3": stochrsi_k,
        "KST_10_15_20_30_10_10_10_15": kst_main,
        "KSTs_9": kst_signal,
        "MFI_14": mfi_14,
        "CMF_20": cmf_20,
        "EMA_12": ema_12,
        "EMA_50": ema_50,
        "EMA_100": ema_100,
        "EMA_200": ema_200,
        "SMA_200_dec_6": sma_200_dec_6,
        "SMA_200_inc_6": sma_200_inc_6,
        "WILLR_14": willr_14,
        "UO_7_14_28": uo,
        "ROC_2": roc_2,
        "ROC_9": roc_9,
        "CCI_20": cci_20,
        "STOCHRSIk_14_14_3_3_change_pct": stochrsi_change,
        "CCI_20_change_pct": cci_change,
        "RSI_3_change_pct": rsi_3_change,
        "RSI_14_change_pct": rsi_14_change,
        "change_pct": change_pct,
        "top_wick_pct": top_wick_pct,
        "high_max_6": high_max_6,
        "high_max_12": high_max_12,
        "high_max_24": high_max_24,
        "low_min_12": low_min_12,
        "low_min_24": low_min_24,
      },
      index=informative_4h.index,
    )

    informative_4h = pd.concat([informative_4h, new_cols], axis=1, copy=False)

    # Enable ONLY during debugging
    debug = False
    if debug:
      debug_cols = [
        "RSI_3",
        "RSI_14",
        "AROONU_14",
        "AROOND_14",
        "STOCHk_14_3_3",
        "STOCHRSIk_14_14_3_3",
        "KST_10_15_20_30_10_10_10_15",
        "KSTs_9",
        "MFI_14",
        "CMF_20",
        "EMA_12",
        "EMA_50",
        "EMA_100",
        "EMA_200",
        "WILLR_14",
        "UO_7_14_28",
        "ROC_2",
        "ROC_9",
        "CCI_20",
        "STOCHRSIk_14_14_3_3_change_pct",
        "CCI_20_change_pct",
        "RSI_3_change_pct",
        "RSI_14_change_pct",
        "OBV_change_pct",
        "change_pct",
        "high_max_6",
        "high_max_12",
        "high_max_24",
        "low_min_12",
        "low_min_24",
      ]

      self.validate_indicators(df=informative_4h, columns=debug_cols, pair=metadata_pair, timeframe=info_timeframe)
    # =========================================================================
    # LOGGING
    # =========================================================================
    if debug_time:
      tok = time.perf_counter()
      log.debug("[%s] informative_4h_indicators took: %.4f seconds.", metadata_pair, tok - tik)

    return informative_4h

  # Informative 1h Timeframe Indicators
  # ---------------------------------------------------------------------------------------------
  def informative_1h_indicators(self, metadata: dict, info_timeframe) -> DataFrame:
    debug_time = False
    if debug_time:
      tik = time.perf_counter()
    dp = self.dp
    fast_pct_change = self.fast_pct_change
    stochrsi_k_func = self.stochrsi_k
    chaikin_money_flow = self.chaikin_money_flow
    calc_kst = self.calc_kst
    np_shift = self.np_shift
    ta_rsi = ta.RSI
    ta_bbands = ta.BBANDS
    ta_aroon = ta.AROON
    ta_sma = ta.SMA
    ta_roc = ta.ROC
    ta_ema = ta.EMA
    ta_willr = ta.WILLR
    ta_max = ta.MAX
    ta_min = ta.MIN
    ta_stochf = ta.STOCHF
    ta_mfi = ta.MFI
    ta_cci = ta.CCI
    ta_ultosc = ta.ULTOSC

    assert dp, "DataProvider is required for multiple timeframes."

    # =========================================================================
    # GET DATAFRAME
    # =========================================================================

    metadata_pair = metadata["pair"]
    informative_1h = dp.get_pair_dataframe(pair=metadata_pair, timeframe=info_timeframe)

    # Empty dataframe protection
    if informative_1h.empty:
      informative_1h["s174_event"] = Series(index=informative_1h.index, dtype=float)
      return informative_1h

    # =========================================================================
    # BASE DATA
    # =========================================================================
    close_np = informative_1h["close"].to_numpy(copy=False)
    high_np = informative_1h["high"].to_numpy(copy=False)
    low_np = informative_1h["low"].to_numpy(copy=False)
    open_np = informative_1h["open"].to_numpy(copy=False)
    volume_np = informative_1h["volume"].to_numpy(copy=False)

    # =========================================================================
    # CORE INDICATORS
    # =========================================================================
    rsi_3 = ta_rsi(close_np, timeperiod=3)
    rsi_14 = ta_rsi(close_np, timeperiod=14)
    bb_upper, bb_middle, bb_lower = ta_bbands(close_np, timeperiod=20, nbdevup=2.0, nbdevdn=2.0, matype=0)
    bb_middle_safe = np.where(bb_middle == 0, np.nan, bb_middle)
    aroon_down, aroon_up = ta_aroon(high_np, low_np, timeperiod=14)

    # =========================================================================
    # STOCH
    # =========================================================================
    _, stoch_k = ta_stochf(high_np, low_np, close_np, fastk_period=14, fastd_period=3, fastd_matype=0)
    stochrsi_k = stochrsi_k_func(rsi_14, ta_min, ta_max, ta_sma)

    # =========================================================================
    # KST
    # =========================================================================
    kst_main, kst_signal = calc_kst(close_np, ta_roc, ta_sma)

    # =========================================================================
    # MONEY FLOW
    # =========================================================================
    mfi_14 = ta_mfi(high_np, low_np, close_np, volume_np, timeperiod=14)
    cmf_20 = chaikin_money_flow(high_np, low_np, close_np, volume_np, timeperiod=20)

    # =========================================================================
    # MOMENTUM
    # =========================================================================
    ema_12 = ta_ema(close_np, timeperiod=12)
    ema_200 = ta_ema(close_np, timeperiod=200)
    sma_16 = ta_sma(close_np, timeperiod=16)
    sma_200 = ta_sma(close_np, timeperiod=200)
    # SMA_200 below where it was 12 candles back = the slow trend is rolling over.
    sma_200_prev = np_shift(sma_200, 12)
    sma_200_dec_12 = sma_200 < sma_200_prev
    sma_200_inc_12 = sma_200 > sma_200_prev
    willr_14 = ta_willr(high_np, low_np, close_np, timeperiod=14)
    willr_84 = ta_willr(high_np, low_np, close_np, timeperiod=84)
    uo = ta_ultosc(high_np, low_np, close_np)
    roc_2 = ta_roc(close_np, timeperiod=2)
    roc_9 = ta_roc(close_np, timeperiod=9)
    cci_20 = ta_cci(high_np, low_np, close_np, timeperiod=20)

    # =========================================================================
    # CHANGE %
    # =========================================================================
    rsi_3_change = fast_pct_change(rsi_3)
    rsi_14_change = fast_pct_change(rsi_14)
    cci_change = fast_pct_change(cci_20)

    # =========================================================================
    # CANDLE %
    # =========================================================================
    open_safe = np.where(open_np == 0, np.nan, open_np)
    change_pct = ((close_np - open_np) / open_safe) * 100.0

    # =========================================================================
    # ROLLING
    # =========================================================================
    high_max_6 = ta_max(high_np, timeperiod=6)
    high_max_12 = ta_max(high_np, timeperiod=12)
    high_max_24 = ta_max(high_np, timeperiod=24)
    low_min_6 = ta_min(low_np, timeperiod=6)
    low_min_12 = ta_min(low_np, timeperiod=12)
    low_min_24 = ta_min(low_np, timeperiod=24)

    new_cols = pd.DataFrame(
      {
        "RSI_3": rsi_3,
        "RSI_14": rsi_14,
        "RSI_3_change_pct": rsi_3_change,
        "RSI_14_change_pct": rsi_14_change,
        "EMA_12": ema_12,
        "EMA_200": ema_200,
        "SMA_200_dec_12": sma_200_dec_12,
        "SMA_200_inc_12": sma_200_inc_12,
        "SMA_16": sma_16,
        "BBL_20_2.0": bb_lower,
        "BBU_20_2.0": bb_upper,
        "BBB_20_2.0": ((bb_upper - bb_lower) / bb_middle_safe) * 100.0,
        "MFI_14": mfi_14,
        "CMF_20": cmf_20,
        "WILLR_14": willr_14,
        "WILLR_84": willr_84,
        "AROONU_14": aroon_up,
        "AROOND_14": aroon_down,
        "STOCHk_14_3_3": stoch_k,
        "STOCHRSIk_14_14_3_3": stochrsi_k,
        "KST_10_15_20_30_10_10_10_15": kst_main,
        "KSTs_9": kst_signal,
        "UO_7_14_28": uo,
        "ROC_2": roc_2,
        "ROC_9": roc_9,
        "CCI_20": cci_20,
        "CCI_20_change_pct": cci_change,
        "change_pct": change_pct,
        "high_max_6": high_max_6,
        "high_max_12": high_max_12,
        "high_max_24": high_max_24,
        "low_min_6": low_min_6,
        "low_min_12": low_min_12,
        "low_min_24": low_min_24,
      },
      index=informative_1h.index,
    )

    # Closed-hour 20-candle breakout after a strictly narrower prior NR4 candle.
    prices = informative_1h[["open", "high", "low", "close", "volume"]]
    valid = (
      prices.notna().all(axis=1)
      & ~prices.isin([np.inf, -np.inf]).any(axis=1)
      & (prices > 0).all(axis=1)
      & (informative_1h["high"] >= informative_1h[["open", "close", "low"]].max(axis=1))
      & (informative_1h["low"] <= informative_1h[["open", "close"]].min(axis=1))
    )
    contiguous = informative_1h["date"].diff().eq(timedelta(hours=1))
    ready = valid.rolling(21, min_periods=21).sum().eq(21) & contiguous.rolling(20, min_periods=20).sum().eq(20)
    previous_close = informative_1h["close"].shift(1)
    true_range = DataFrame(
      {
        "range": informative_1h["high"] - informative_1h["low"],
        "high_gap": (informative_1h["high"] - previous_close).abs(),
        "low_gap": (informative_1h["low"] - previous_close).abs(),
      }
    ).max(axis=1)
    atr = true_range.ewm(alpha=1 / 20, adjust=False, min_periods=20).mean().shift(1)
    prior_high = informative_1h["high"].rolling(20, min_periods=20).max().shift(1)
    state = ready & np.isfinite(atr) & (atr > 0) & (informative_1h["close"] > prior_high)
    hourly_range = informative_1h["high"] - informative_1h["low"]
    prior_range = hourly_range.shift(1)
    nr4 = (prior_range > 0) & (prior_range < hourly_range.shift(2).rolling(3, min_periods=3).min())
    # 0/1 like the rest of the pattern columns, so a NaN the merge leaves behind reads as false
    new_cols["s174_event"] = (state & ~state.shift(1, fill_value=False) & nr4).astype(float)

    informative_1h = pd.concat([informative_1h, new_cols], axis=1, copy=False)

    # Enable ONLY during debugging
    debug = False
    if debug:
      debug_cols = [
        "RSI_3",
        "RSI_14",
        "RSI_3_change_pct",
        "RSI_14_change_pct",
        "EMA_12",
        "EMA_200",
        "SMA_16",
        "BBL_20_2.0",
        "BBU_20_2.0",
        "BBB_20_2.0",
        "MFI_14",
        "CMF_20",
        "WILLR_14",
        "WILLR_84",
        "AROONU_14",
        "AROOND_14",
        "STOCHk_14_3_3",
        "STOCHRSIk_14_14_3_3",
        "KST_10_15_20_30_10_10_10_15",
        "KSTs_9",
        "UO_7_14_28",
        "ROC_2",
        "ROC_9",
        "CCI_20",
        "CCI_20_change_pct",
        "change_pct",
        "high_max_6",
        "high_max_12",
        "high_max_24",
        "low_min_6",
        "low_min_12",
        "low_min_24",
      ]

      self.validate_indicators(df=informative_1h, columns=debug_cols, pair=metadata_pair, timeframe=info_timeframe)

    # =========================================================================
    # LOGGING
    # =========================================================================
    if debug_time:
      tok = time.perf_counter()
      log.debug("[%s] informative_1h_indicators took: %.4f seconds.", metadata_pair, tok - tik)

    return informative_1h

  # Informative 15m Timeframe Indicators
  # ---------------------------------------------------------------------------------------------
  def informative_15m_indicators(self, metadata: dict, info_timeframe) -> DataFrame:
    debug_time = False
    if debug_time:
      tik = time.perf_counter()
    dp = self.dp
    fast_pct_change = self.fast_pct_change
    stochrsi_k_func = self.stochrsi_k
    chaikin_money_flow = self.chaikin_money_flow
    obv_change_pct = self.obv_change_pct
    ta_rsi = ta.RSI
    ta_aroon = ta.AROON
    ta_ema = ta.EMA
    ta_min = ta.MIN
    ta_max = ta.MAX
    ta_sma = ta.SMA
    ta_stochf = ta.STOCHF
    ta_mfi = ta.MFI
    ta_willr = ta.WILLR
    ta_ultosc = ta.ULTOSC
    ta_obv = ta.OBV
    ta_roc = ta.ROC
    ta_cci = ta.CCI

    assert dp, "DataProvider is required for multiple timeframes."

    # =========================================================================
    # GET DATAFRAME
    # =========================================================================

    metadata_pair = metadata["pair"]
    informative_15m = dp.get_pair_dataframe(pair=metadata_pair, timeframe=info_timeframe)

    # Empty dataframe protection
    if informative_15m.empty:
      return informative_15m

    # =========================================================================
    # BASE DATA
    # =========================================================================
    close_np = informative_15m["close"].to_numpy(copy=False)
    high_np = informative_15m["high"].to_numpy(copy=False)
    low_np = informative_15m["low"].to_numpy(copy=False)
    open_np = informative_15m["open"].to_numpy(copy=False)
    volume_np = informative_15m["volume"].to_numpy(copy=False)

    # =========================================================================
    # CORE INDICATORS
    # =========================================================================
    rsi_3 = ta_rsi(close_np, timeperiod=3)
    rsi_14 = ta_rsi(close_np, timeperiod=14)
    aroon_down, aroon_up = ta_aroon(high_np, low_np, timeperiod=14)

    # =========================================================================
    # STOCH
    # =========================================================================
    _, stoch_k = ta_stochf(high_np, low_np, close_np, fastk_period=14, fastd_period=3, fastd_matype=0)
    stochrsi_k = stochrsi_k_func(rsi_14, ta_min, ta_max, ta_sma)

    # =========================================================================
    # MONEY FLOW
    # =========================================================================
    mfi_14 = ta_mfi(high_np, low_np, close_np, volume_np, timeperiod=14)
    cmf_20 = chaikin_money_flow(high_np, low_np, close_np, volume_np, timeperiod=20)

    # =========================================================================
    # MOMENTUM
    # =========================================================================
    ema_12 = ta_ema(close_np, timeperiod=12)
    ema_20 = ta_ema(close_np, timeperiod=20)
    ema_26 = ta_ema(close_np, timeperiod=26)
    ema_50 = ta_ema(close_np, timeperiod=50)
    ema_200 = ta_ema(close_np, timeperiod=200)
    willr_14 = ta_willr(high_np, low_np, close_np, timeperiod=14)
    uo = ta_ultosc(high_np, low_np, close_np)
    obv = ta_obv(close_np, volume_np)
    roc_9 = ta_roc(close_np, timeperiod=9)
    cci_20 = ta_cci(high_np, low_np, close_np, timeperiod=20)

    # =========================================================================
    # CHANGE %
    # =========================================================================
    rsi_3_change = fast_pct_change(rsi_3)
    rsi_14_change = fast_pct_change(rsi_14)
    uo_change = fast_pct_change(uo)
    obv_change = obv_change_pct(obv)
    cci_change = fast_pct_change(cci_20)

    # =========================================================================
    # CANDLE %
    # =========================================================================
    open_safe = np.where(open_np == 0, np.nan, open_np)
    change_pct = ((close_np - open_np) / open_safe) * 100.0

    new_cols = pd.DataFrame(
      {
        "RSI_3": rsi_3,
        "RSI_14": rsi_14,
        "RSI_3_change_pct": rsi_3_change,
        "RSI_14_change_pct": rsi_14_change,
        "EMA_12": ema_12,
        "EMA_20": ema_20,
        "EMA_26": ema_26,
        "EMA_50": ema_50,
        "EMA_200": ema_200,
        "MFI_14": mfi_14,
        "CMF_20": cmf_20,
        "WILLR_14": willr_14,
        "AROONU_14": aroon_up,
        "AROOND_14": aroon_down,
        "STOCHk_14_3_3": stoch_k,
        "STOCHRSIk_14_14_3_3": stochrsi_k,
        "UO_7_14_28": uo,
        "UO_7_14_28_change_pct": uo_change,
        "OBV_change_pct": obv_change,
        "ROC_9": roc_9,
        "CCI_20": cci_20,
        "CCI_20_change_pct": cci_change,
        "change_pct": change_pct,
      },
      index=informative_15m.index,
    )

    informative_15m = pd.concat([informative_15m, new_cols], axis=1, copy=False)

    # Enable ONLY during debugging
    debug = False
    if debug:
      debug_cols = [
        "RSI_3",
        "RSI_14",
        "RSI_3_change_pct",
        "RSI_14_change_pct",
        "EMA_12",
        "EMA_20",
        "EMA_26",
        "EMA_50",
        "EMA_200",
        "MFI_14",
        "CMF_20",
        "WILLR_14",
        "AROONU_14",
        "AROOND_14",
        "STOCHk_14_3_3",
        "STOCHRSIk_14_14_3_3",
        "UO_7_14_28",
        "UO_7_14_28_change_pct",
        "OBV_change_pct",
        "ROC_9",
        "CCI_20",
        "CCI_20_change_pct",
        "change_pct",
      ]

      self.validate_indicators(df=informative_15m, columns=debug_cols, pair=metadata_pair, timeframe=info_timeframe)

    # =========================================================================
    # LOGGING
    # =========================================================================
    if debug_time:
      tok = time.perf_counter()
      log.debug("[%s] informative_15m_indicators took: %.4f seconds.", metadata_pair, tok - tik)

    return informative_15m

  @staticmethod
  def run_index(key: np.ndarray) -> tuple:
    """Start index and run id of each run of equal keys (key must be sorted)."""
    change = np.empty(key.size, dtype=bool)
    change[0] = True
    change[1:] = key[1:] != key[:-1]
    return np.flatnonzero(change), np.cumsum(change) - 1

  # Coin Pair Base Timeframe Indicators
  # ---------------------------------------------------------------------------------------------
  def base_tf_5m_indicators(self, metadata: dict, df: DataFrame) -> DataFrame:
    debug_time = False
    if debug_time:
      tik = time.perf_counter()
    metadata_pair = metadata["pair"]
    fast_pct_change = self.fast_pct_change
    stochrsi_k_func = self.stochrsi_k
    chaikin_money_flow = self.chaikin_money_flow
    calc_kst = self.calc_kst
    np_shift = self.np_shift
    obv_change_pct = self.obv_change_pct
    ta_rsi = ta.RSI
    ta_bbands = ta.BBANDS
    ta_aroon = ta.AROON
    ta_sma = ta.SMA
    ta_roc = ta.ROC
    ta_willr = ta.WILLR
    ta_ema = ta.EMA
    ta_max = ta.MAX
    ta_min = ta.MIN
    ta_stochf = ta.STOCHF
    ta_obv = ta.OBV
    ta_mfi = ta.MFI
    ta_sum = ta.SUM
    ta_stddev = ta.STDDEV

    # =========================================================================
    # BASE DATA
    # =========================================================================
    close_np = df["close"].to_numpy(copy=False)
    high_np = df["high"].to_numpy(copy=False)
    low_np = df["low"].to_numpy(copy=False)
    open_np = df["open"].to_numpy(copy=False)
    volume_np = df["volume"].to_numpy(copy=False)

    # =========================================================================
    # CORE INDICATORS
    # =========================================================================
    rsi_3 = ta_rsi(close_np, timeperiod=3)
    rsi_4 = ta_rsi(close_np, timeperiod=4)
    rsi_14 = ta_rsi(close_np, timeperiod=14)
    rsi_20 = ta_rsi(close_np, timeperiod=20)
    bb_upper_20, bb_middle_20, bb_lower_20 = ta_bbands(close_np, timeperiod=20, nbdevup=2.0, nbdevdn=2.0, matype=0)
    bb_middle_20_safe = np.where(bb_middle_20 == 0, np.nan, bb_middle_20)
    bb_above_mask = close_np > bb_upper_20
    bb_below_mask = close_np < bb_lower_20
    idx = np.arange(close_np.size)
    last_false_above_idx = np.maximum.accumulate(np.where(bb_above_mask, -1, idx))
    bb_above_count = idx - last_false_above_idx
    last_false_below_idx = np.maximum.accumulate(np.where(bb_below_mask, -1, idx))
    bb_below_count = idx - last_false_below_idx
    bb_upper_40, bb_middle_40, bb_lower_40 = ta_bbands(close_np, timeperiod=40, nbdevup=2.0, nbdevdn=2.0, matype=0)
    aroon_down, aroon_up = ta_aroon(high_np, low_np, timeperiod=14)
    bbb_20 = ((bb_upper_20 - bb_lower_20) / bb_middle_20_safe) * 100.0
    bbd_40 = np.abs(bb_middle_40 - bb_lower_40)
    bbt_40 = np.abs(close_np - bb_lower_40)

    # =========================================================================
    # STOCH RSI
    # =========================================================================
    stochrsi_k = stochrsi_k_func(rsi_14, ta_min, ta_max, ta_sma)

    # =========================================================================
    # KST
    # =========================================================================
    kst_main, kst_signal = calc_kst(close_np, ta_roc, ta_sma)

    # =========================================================================
    # MONEY FLOW
    # =========================================================================
    mfi_14 = ta_mfi(high_np, low_np, close_np, volume_np, timeperiod=14)
    cmf_20 = chaikin_money_flow(high_np, low_np, close_np, volume_np, timeperiod=20)

    # =========================================================================
    # MOMENTUM
    # =========================================================================
    ema_9 = ta_ema(close_np, timeperiod=9)
    ema_12 = ta_ema(close_np, timeperiod=12)
    ema_16 = ta_ema(close_np, timeperiod=16)
    ema_20 = ta_ema(close_np, timeperiod=20)
    ema_26 = ta_ema(close_np, timeperiod=26)
    ema_50 = ta_ema(close_np, timeperiod=50)
    ema_100 = ta_ema(close_np, timeperiod=100)
    ema_200 = ta_ema(close_np, timeperiod=200)
    sma_9 = ta_sma(close_np, timeperiod=9)
    sma_16 = ta_sma(close_np, timeperiod=16)
    sma_21 = ta_sma(close_np, timeperiod=21)
    sma_30 = ta_sma(close_np, timeperiod=30)
    sma_200 = ta_sma(close_np, timeperiod=200)
    # SMA_200 below where it was 24 candles back = the slow trend is rolling over.
    sma_200_prev = np_shift(sma_200, 24)
    sma_200_dec_24 = sma_200 < sma_200_prev
    sma_200_inc_24 = sma_200 > sma_200_prev
    willr_14 = ta_willr(high_np, low_np, close_np, timeperiod=14)
    willr_480 = ta_willr(high_np, low_np, close_np, timeperiod=480)
    roc_2 = ta_roc(close_np, timeperiod=2)
    roc_9 = ta_roc(close_np, timeperiod=9)
    obv = ta_obv(close_np, volume_np)

    # =========================================================================
    # CHANGE %
    # =========================================================================
    rsi_14_change = fast_pct_change(rsi_14)
    obv_change = obv_change_pct(obv)

    # =========================================================================
    # CANDLE %
    # =========================================================================
    open_safe = np.where(open_np == 0, np.nan, open_np)
    change_pct = ((close_np - open_np) / open_safe) * 100.0

    # =========================================================================
    # Close delta
    # =========================================================================
    close_delta = np.empty_like(close_np, dtype=np.float64)
    close_delta[0] = np.nan
    close_delta[1:] = np.abs(np.diff(close_np))

    # =========================================================================
    # Rolling values
    # =========================================================================
    close_max_6 = ta_max(close_np, timeperiod=6)
    close_max_12 = ta_max(close_np, timeperiod=12)
    close_max_48 = ta_max(close_np, timeperiod=48)
    close_min_6 = ta_min(close_np, timeperiod=6)
    close_min_12 = ta_min(close_np, timeperiod=12)
    close_min_48 = ta_min(close_np, timeperiod=48)
    num_empty_288 = ta_sum((volume_np <= 0).astype(np.float64), timeperiod=288)

    # =========================================================================
    # Leviathan volume/CVD-imitation columns
    # =========================================================================
    vol_ema_20 = ta_ema(volume_np, timeperiod=20)
    vol_std_20 = ta_stddev(volume_np, timeperiod=20, nbdev=1.0) * np.sqrt(20.0 / 19.0)
    large_bubble_thr = vol_ema_20 + 3.0 * vol_std_20
    hl_range = high_np - low_np
    body = np.abs(close_np - open_np)
    hl_range_safe = np.where(hl_range == 0.0, np.nan, hl_range)
    cvd_buy_vol = volume_np * (close_np - low_np) / hl_range_safe
    cvd_sell_vol = volume_np * (high_np - close_np) / hl_range_safe

    # =========================================================================
    # QUAD ROTATION STOCHASTICS + pivot windows (signals 192/193 long, 592/593 short — experimental)
    # =========================================================================
    quad_s93 = ta_stochf(high_np, low_np, close_np, fastk_period=9, fastd_period=3, fastd_matype=0)[0]
    quad_s143 = ta_stochf(high_np, low_np, close_np, fastk_period=14, fastd_period=3, fastd_matype=0)[0]
    quad_s44 = ta_stochf(high_np, low_np, close_np, fastk_period=4, fastd_period=4, fastd_matype=0)[0]
    quad_s6010 = ta_stochf(high_np, low_np, close_np, fastk_period=60, fastd_period=10, fastd_matype=0)[0]
    quad_low_min_12 = ta_min(low_np, timeperiod=12)
    quad_high_max_12 = ta_max(high_np, timeperiod=12)
    quad_s93_min_12 = ta_min(quad_s93, timeperiod=12)
    quad_s93_max_12 = ta_max(quad_s93, timeperiod=12)

    # =========================================================================
    # 4H OPENING RANGE (UTC day) — signals 164/662 (experimental, Data Trader port)
    # =========================================================================
    _HOUR_NS = 3_600_000_000_000
    _DAY_NS = 86_400_000_000_000
    _t_ns = df["date"].dt.tz_localize(None).to_numpy().astype("datetime64[ns]").view("int64")
    _day_key = _t_ns // _DAY_NS
    _hour_of_day = (_t_ns - _day_key * _DAY_NS) // _HOUR_NS
    _or_first4h = _hour_of_day < 4
    _day_starts, _day_id = self.run_index(_day_key)
    _day_h = np.fmax.reduceat(np.where(_or_first4h, high_np, np.nan), _day_starts)
    _day_l = np.fmin.reduceat(np.where(_or_first4h, low_np, np.nan), _day_starts)
    orange_h_col = np.where(_or_first4h, np.nan, _day_h[_day_id])
    orange_l_col = np.where(_or_first4h, np.nan, _day_l[_day_id])

    # =========================================================================
    # SQUEEZE MOMENTUM (LazyBear) — signals 166/664 (experimental): BB inside Keltner = coil
    # =========================================================================
    _sq_ma = ta_sma(close_np, timeperiod=20)
    _sq_rng = ta_sma(hl_range, timeperiod=20)
    _sq_kc_u = _sq_ma + 1.5 * _sq_rng
    _sq_kc_l = _sq_ma - 1.5 * _sq_rng
    sqz_on_col = ((bb_lower_20 > _sq_kc_l) & (bb_upper_20 < _sq_kc_u)).astype(np.float64)
    sqz_cnt24_col = ta_sum(sqz_on_col, timeperiod=24)

    # =========================================================================
    # Engulfing candle pattern — signals 167/665 (experimental): opposite-color body engulf
    # =========================================================================
    _eng_po = np.empty_like(open_np)
    _eng_pc = np.empty_like(close_np)
    _eng_po[0] = _eng_pc[0] = np.nan
    _eng_po[1:] = open_np[:-1]
    _eng_pc[1:] = close_np[:-1]
    engulf_bull_col = (
      (_eng_pc < _eng_po) & (close_np > open_np) & (close_np >= _eng_po) & (open_np <= _eng_pc)
    ).astype(float)
    engulf_bear_col = (
      (_eng_pc > _eng_po) & (close_np < open_np) & (close_np <= _eng_po) & (open_np >= _eng_pc)
    ).astype(float)

    # =========================================================================
    # Swing-failure pattern (SFP) — signals 168/666 (experimental): sweep & reclaim of the prior 48-candle extreme
    # =========================================================================
    _sfp_prev_low = np_shift(ta_min(low_np, timeperiod=48), 1)
    _sfp_prev_high = np_shift(ta_max(high_np, timeperiod=48), 1)
    sfp_bull_col = ((low_np < _sfp_prev_low) & (close_np > _sfp_prev_low)).astype(float)
    sfp_bear_col = ((high_np > _sfp_prev_high) & (close_np < _sfp_prev_high)).astype(float)

    # =========================================================================
    # 1h inside-bar breakout — signals 169/667 (experimental): source insists on 1h+ candles
    # =========================================================================
    _t_ns = df["date"].dt.tz_localize(None).to_numpy().astype("datetime64[ns]").view("int64")
    _hr_starts, _ib_codes = self.run_index(_t_ns // _HOUR_NS)
    _ib_hh = np.fmax.reduceat(high_np, _hr_starts)
    _ib_ll = np.fmin.reduceat(low_np, _hr_starts)
    _ib_flag = np.zeros(len(_ib_hh), dtype=np.float64)
    _ib_flag[1:] = (_ib_hh[1:] < _ib_hh[:-1]) & (_ib_ll[1:] > _ib_ll[:-1])
    _ib_mh = np.full(len(_ib_hh), np.nan, dtype=np.float64)
    _ib_ml = np.full(len(_ib_hh), np.nan, dtype=np.float64)
    _ib_mh[1:] = _ib_hh[:-1]
    _ib_ml[1:] = _ib_ll[:-1]
    _ib_prev_codes = _ib_codes - 1
    _ib_valid = _ib_prev_codes >= 0
    ib_ready_col = np.zeros(len(df), dtype=np.float64)
    ib_mother_h_col = np.full(len(df), np.nan, dtype=np.float64)
    ib_mother_l_col = np.full(len(df), np.nan, dtype=np.float64)
    ib_ready_col[_ib_valid] = _ib_flag[_ib_prev_codes[_ib_valid]]
    ib_mother_h_col[_ib_valid] = _ib_mh[_ib_prev_codes[_ib_valid]]
    ib_mother_l_col[_ib_valid] = _ib_ml[_ib_prev_codes[_ib_valid]]

    # =========================================================================
    # Crash-bounce hunter — signal 170 (experimental): rolling 24h return for capitulation context
    # =========================================================================
    roc_288_col = ta_roc(close_np, timeperiod=288)
    _vol_ma = ta_sma(volume_np, timeperiod=288)
    vol_rel_col = np.divide(volume_np, _vol_ma, out=np.full_like(_vol_ma, np.nan), where=_vol_ma > 0)

    # =========================================================================
    # Pump hunter — signal 171 (experimental): rolling 24h return + relative volume + first-fire dedup
    # =========================================================================
    _ph_prev_max = np_shift(close_max_48, 1)
    _ph_cross = ((close_np > _ph_prev_max) & (_eng_pc <= _ph_prev_max)).astype(float)
    _ph_h12 = np_shift(quad_high_max_12, 1)
    _ph_l12 = np_shift(quad_low_min_12, 1)
    ph_cross_cnt12_col = ta_sum(_ph_cross, timeperiod=12)
    _ph_low288 = ta_min(low_np, timeperiod=288)
    ph_base_pos_col = (
      np.divide(close_np - _ph_low288, close_np, out=np.full_like(close_np, np.nan), where=close_np > 0) * 100.0
    )
    ph_pre_tight_col = (
      np.divide(_ph_h12 - _ph_l12, close_np, out=np.full_like(close_np, np.nan), where=close_np > 0) * 100.0
    )

    # =========================================================================
    # Marubozu — signals 172/670 (experimental): full-body candle = pure momentum ignition
    # =========================================================================
    _mrb_rng = hl_range
    _mrb_body_ratio = np.divide(body, _mrb_rng, out=np.zeros_like(_mrb_rng), where=_mrb_rng > 0)
    _mrb_body_pct = np.divide(body, close_np, out=np.zeros_like(close_np), where=close_np > 0)
    mrb_bull_col = ((close_np > open_np) & (_mrb_body_ratio > 0.9) & (_mrb_body_pct > 0.005)).astype(float)
    mrb_bear_col = ((close_np < open_np) & (_mrb_body_ratio > 0.9) & (_mrb_body_pct > 0.005)).astype(float)
    # =========================================================================
    # Dump hunter — signal 669 (experimental): mirror of the pump hunter (171)
    # =========================================================================
    dh_prev_min_col = np_shift(close_min_48, 1)
    _pb_body = body
    _pb_lower = np.minimum(open_np, close_np) - low_np
    _pb_upper = high_np - np.maximum(open_np, close_np)
    _pb_body_safe = np.where(_pb_body > 0, _pb_body, np.nan)
    hammer_col = (
      (_pb_lower > 2.0 * _pb_body_safe) & (_pb_upper < 0.5 * _pb_body_safe) & (_pb_lower > close_np * 0.004)
    ).astype(float)
    star_col = (
      (_pb_upper > 2.0 * _pb_body_safe) & (_pb_lower < 0.5 * _pb_body_safe) & (_pb_upper > close_np * 0.004)
    ).astype(float)

    # =========================================================================
    # Donchian 7-day channel — signals 8/506 (experimental): turtle-style macro breakout
    # =========================================================================
    dc_high_7d_col = np_shift(ta_max(close_np, timeperiod=2016), 1)
    dc_low_7d_col = np_shift(ta_min(close_np, timeperiod=2016), 1)

    # =========================================================================
    # Assign dataframes
    # =========================================================================
    new_cols = pd.DataFrame(
      {
        "RSI_3": rsi_3,
        "RSI_4": rsi_4,
        "IB_READY": ib_ready_col,
        "IB_MOTHER_H": ib_mother_h_col,
        "IB_MOTHER_L": ib_mother_l_col,
        "ROC_288": roc_288_col,
        "VOL_REL": vol_rel_col,
        "PH_CROSS_CNT_12": ph_cross_cnt12_col,
        "PH_BASE_POS": ph_base_pos_col,
        "PH_PRE_TIGHT": ph_pre_tight_col,
        "MRB_BULL": mrb_bull_col,
        "MRB_BEAR": mrb_bear_col,
        "DH_PREV_MIN": dh_prev_min_col,
        "PB_HAMMER": hammer_col,
        "PB_STAR": star_col,
        "DC_HIGH_7D": dc_high_7d_col,
        "DC_LOW_7D": dc_low_7d_col,
        "ENGULF_BULL": engulf_bull_col,
        "ENGULF_BEAR": engulf_bear_col,
        "SFP_BULL": sfp_bull_col,
        "SFP_BEAR": sfp_bear_col,
        "RSI_14": rsi_14,
        "RSI_20": rsi_20,
        "RSI_14_change_pct": rsi_14_change,
        "EMA_9": ema_9,
        "EMA_12": ema_12,
        "EMA_16": ema_16,
        "EMA_20": ema_20,
        "EMA_26": ema_26,
        "EMA_50": ema_50,
        "EMA_100": ema_100,
        "EMA_200": ema_200,
        "SMA_9": sma_9,
        "SMA_16": sma_16,
        "SMA_21": sma_21,
        "SMA_30": sma_30,
        "SMA_200": sma_200,
        "SMA_200_dec_24": sma_200_dec_24,
        "SMA_200_inc_24": sma_200_inc_24,
        "BBL_20_2.0": bb_lower_20,
        "BBU_20_2.0": bb_upper_20,
        "BBB_20_2.0": bbb_20,
        "BBL_40_2.0": bb_lower_40,
        "BBD_40_2.0": bbd_40,
        "BBT_40_2.0": bbt_40,
        "BB_ABOVE_COUNT": bb_above_count,
        "BB_BELOW_COUNT": bb_below_count,
        "MFI_14": mfi_14,
        "CMF_20": cmf_20,
        "WILLR_14": willr_14,
        "WILLR_480": willr_480,
        "AROONU_14": aroon_up,
        "AROOND_14": aroon_down,
        "STOCHRSIk_14_14_3_3": stochrsi_k,
        "KST_10_15_20_30_10_10_10_15": kst_main,
        "KSTs_9": kst_signal,
        "ROC_2": roc_2,
        "ROC_9": roc_9,
        "change_pct": change_pct,
        "OBV_change_pct": obv_change,
        "close_delta": close_delta,
        "close_max_6": close_max_6,
        "close_max_12": close_max_12,
        "close_max_48": close_max_48,
        "close_min_6": close_min_6,
        "close_min_12": close_min_12,
        "close_min_48": close_min_48,
        "num_empty_288": num_empty_288,
        "LARGE_BUBBLE_THR": large_bubble_thr,
        "CVD_BUY_VOL": cvd_buy_vol,
        "CVD_SELL_VOL": cvd_sell_vol,
        "ORANGE_H": orange_h_col,
        "ORANGE_L": orange_l_col,
        "SQZ_ON": sqz_on_col,
        "SQZ_CNT_24": sqz_cnt24_col,
        "STOCH_9_3": quad_s93,
        "STOCH_14_3": quad_s143,
        "STOCH_4_4": quad_s44,
        "STOCH_60_10": quad_s6010,
        "QUAD_LOW_MIN_12": quad_low_min_12,
        "QUAD_HIGH_MAX_12": quad_high_max_12,
        "QUAD_S93_MIN_12": quad_s93_min_12,
        "QUAD_S93_MAX_12": quad_s93_max_12,
      },
      index=df.index,
    )

    df = pd.concat([df, new_cols], axis=1, copy=False)

    # Enable ONLY during debugging
    debug = False
    if debug:
      debug_cols = [
        "RSI_3",
        "RSI_4",
        "RSI_14",
        "RSI_20",
        "RSI_14_change_pct",
        "EMA_9",
        "EMA_12",
        "EMA_16",
        "EMA_20",
        "EMA_26",
        "EMA_50",
        "EMA_100",
        "EMA_200",
        "SMA_9",
        "SMA_16",
        "SMA_21",
        "SMA_30",
        "SMA_200",
        "BBL_20_2.0",
        "BBU_20_2.0",
        "BBB_20_2.0",
        "BBL_40_2.0",
        "BBD_40_2.0",
        "BBT_40_2.0",
        "MFI_14",
        "CMF_20",
        "WILLR_14",
        "WILLR_480",
        "AROONU_14",
        "AROOND_14",
        "STOCHRSIk_14_14_3_3",
        "KST_10_15_20_30_10_10_10_15",
        "KSTs_9",
        "ROC_2",
        "ROC_9",
        "change_pct",
        "close_delta",
        "close_max_6",
        "close_max_12",
        "close_max_48",
        "close_min_6",
        "close_min_12",
        "close_min_48",
        "num_empty_288",
        "LARGE_BUBBLE_THR",
        "CVD_BUY_VOL",
        "CVD_SELL_VOL",
      ]

      self.validate_indicators(df=df, columns=debug_cols, pair=metadata_pair, timeframe=self.timeframe)

    # =========================================================================
    # GLOBAL PROTECTIONS
    # =========================================================================
    if not self.config["runmode"].value in ("live", "dry_run"):
      df["bt_agefilter_ok"] = False
      df.loc[df.index > (12 * 24 * self.bt_min_age_days), "bt_agefilter_ok"] = True
    else:
      df["live_data_ok"] = ta_min(volume_np, timeperiod=72) > 0

    # =========================================================================
    # LOGGING
    # =========================================================================
    if debug_time:
      tok = time.perf_counter()
      log.debug("[%s] base_tf_5m_indicators took: %.4f seconds.", metadata_pair, tok - tik)

    return df

  # BTC Informative 1d Timeframe Indicators
  # ---------------------------------------------------------------------------------------------
  def btc_informative_1d_indicators(self, btc_pair: str, btc_info_timeframe: str) -> DataFrame:
    debug_time = False
    if debug_time:
      tik = time.perf_counter()
    dp = self.dp

    assert dp, "DataProvider is required for multiple timeframes."

    # =========================================================================
    # GET DATAFRAME
    # =========================================================================
    btc_informative_1d = dp.get_pair_dataframe(pair=btc_pair, timeframe=btc_info_timeframe)

    # Empty dataframe protection
    if btc_informative_1d.empty:
      return btc_informative_1d

    # =========================================================================
    # BASE DATA
    # =========================================================================
    close_np = btc_informative_1d["close"].to_numpy(copy=False)
    # high_np = btc_informative_1d["high"].to_numpy(copy=False)
    # low_np = btc_informative_1d["low"].to_numpy(copy=False)
    # open_np = btc_informative_1d["open"].to_numpy(copy=False)
    # volume_np = btc_informative_1d["volume"].to_numpy(copy=False)

    # =========================================================================
    # MOMENTUM
    # =========================================================================
    ema_200 = ta.EMA(close_np, timeperiod=200)
    new_cols = pd.DataFrame(
      {
        "BTC_EMA_200": ema_200,
      },
      index=btc_informative_1d.index,
    )

    btc_informative_1d = pd.concat([btc_informative_1d, new_cols], axis=1, copy=False)

    # Enable ONLY during debugging
    debug = False
    if debug:
      debug_cols = [
        "BTC_EMA_200",
      ]

      self.validate_indicators(df=btc_informative_1d, columns=debug_cols, pair=btc_pair, timeframe=btc_info_timeframe)

    # =========================================================================
    # LOGGING
    # =========================================================================
    if debug_time:
      tok = time.perf_counter()
      log.debug("[%s] btc_informative_1d_indicators took: %.4f seconds.", btc_pair, tok - tik)

    return btc_informative_1d

  # BTC Informative 4h Timeframe Indicators
  # ---------------------------------------------------------------------------------------------
  def btc_informative_4h_indicators(self, btc_pair: str, btc_info_timeframe: str) -> DataFrame:
    debug_time = False
    if debug_time:
      tik = time.perf_counter()
    dp = self.dp

    assert dp, "DataProvider is required for multiple timeframes."

    # =========================================================================
    # GET DATAFRAME
    # =========================================================================
    btc_informative_4h = dp.get_pair_dataframe(pair=btc_pair, timeframe=btc_info_timeframe)

    # Empty dataframe protection
    if btc_informative_4h.empty:
      return btc_informative_4h

    # =========================================================================
    # BASE DATA
    # =========================================================================
    close_np = btc_informative_4h["close"].to_numpy(copy=False)
    # high_np = btc_informative_4h["high"].to_numpy(copy=False)
    # low_np = btc_informative_4h["low"].to_numpy(copy=False)
    # open_np = btc_informative_4h["open"].to_numpy(copy=False)
    # volume_np = btc_informative_4h["volume"].to_numpy(copy=False)

    # =========================================================================
    # CORE INDICATORS
    # =========================================================================
    rsi_14 = ta.RSI(close_np, timeperiod=14)

    new_cols = pd.DataFrame(
      {
        "BTC_ROC_1": ta.ROC(close_np, timeperiod=1),
        "BTC_RSI_14": rsi_14,
      },
      index=btc_informative_4h.index,
    )

    btc_informative_4h = pd.concat([btc_informative_4h, new_cols], axis=1, copy=False)

    # Enable ONLY during debugging
    debug = False
    if debug:
      debug_cols = [
        "BTC_RSI_14",
      ]

      self.validate_indicators(df=btc_informative_4h, columns=debug_cols, pair=btc_pair, timeframe=btc_info_timeframe)

    # =========================================================================
    # LOGGING
    # =========================================================================
    if debug_time:
      tok = time.perf_counter()
      log.debug("[%s] btc_informative_4h_indicators took: %.4f seconds.", btc_pair, tok - tik)

    return btc_informative_4h

  # BTC Informative 1h Timeframe Indicators
  # ---------------------------------------------------------------------------------------------
  def btc_informative_1h_indicators(self, btc_pair: str, btc_info_timeframe: str) -> DataFrame:
    debug_time = False
    if debug_time:
      tik = time.perf_counter()
    dp = self.dp

    assert dp, "DataProvider is required for multiple timeframes."

    # =========================================================================
    # GET DATAFRAME
    # =========================================================================
    btc_informative_1h = dp.get_pair_dataframe(pair=btc_pair, timeframe=btc_info_timeframe)

    # Empty dataframe protection
    if btc_informative_1h.empty:
      return btc_informative_1h

    # =========================================================================
    # BASE DATA
    # =========================================================================
    close_np = btc_informative_1h["close"].to_numpy(copy=False)
    # high_np = btc_informative_1h["high"].to_numpy(copy=False)
    # low_np = btc_informative_1h["low"].to_numpy(copy=False)
    # open_np = btc_informative_1h["open"].to_numpy(copy=False)
    # volume_np = btc_informative_1h["volume"].to_numpy(copy=False)

    # =========================================================================
    # CORE INDICATORS
    # =========================================================================
    rsi_14 = ta.RSI(close_np, timeperiod=14)

    # =========================================================================
    # MOMENTUM
    # =========================================================================
    ema_20 = ta.EMA(close_np, timeperiod=20)
    roc_3 = ta.ROC(close_np, timeperiod=3)

    new_cols = pd.DataFrame(
      {
        "BTC_RSI_14": rsi_14,
        "BTC_EMA_20": ema_20,
        "BTC_ROC_3": roc_3,
      },
      index=btc_informative_1h.index,
    )

    btc_informative_1h = pd.concat([btc_informative_1h, new_cols], axis=1, copy=False)

    # Enable ONLY during debugging
    debug = False
    if debug:
      debug_cols = [
        "BTC_RSI_14",
        "BTC_EMA_20",
        "BTC_ROC_3",
      ]

      self.validate_indicators(df=btc_informative_1h, columns=debug_cols, pair=btc_pair, timeframe=btc_info_timeframe)

    # =========================================================================
    # LOGGING
    # =========================================================================
    if debug_time:
      tok = time.perf_counter()
      log.debug("[%s] btc_informative_1h_indicators took: %.4f seconds.", btc_pair, tok - tik)

    return btc_informative_1h

  # BTC Informative 15m Timeframe Indicators
  # ---------------------------------------------------------------------------------------------
  def btc_informative_15m_indicators(self, btc_pair: str, btc_info_timeframe: str) -> DataFrame:
    debug_time = False
    if debug_time:
      tik = time.perf_counter()
    dp = self.dp

    assert dp, "DataProvider is required for multiple timeframes."

    # =========================================================================
    # GET DATAFRAME
    # =========================================================================
    btc_informative_15m = dp.get_pair_dataframe(pair=btc_pair, timeframe=btc_info_timeframe)

    # Empty dataframe protection
    if btc_informative_15m.empty:
      return btc_informative_15m

    # =========================================================================
    # BASE DATA
    # =========================================================================
    close_np = btc_informative_15m["close"].to_numpy(copy=False)
    # high_np = btc_informative_15m["high"].to_numpy(copy=False)
    # low_np = btc_informative_15m["low"].to_numpy(copy=False)
    # open_np = btc_informative_15m["open"].to_numpy(copy=False)
    # volume_np = btc_informative_15m["volume"].to_numpy(copy=False)

    # =========================================================================
    # CORE INDICATORS
    # =========================================================================
    rsi_14 = ta.RSI(close_np, timeperiod=14)

    # =========================================================================
    # MOMENTUM
    # =========================================================================
    ema_20 = ta.EMA(close_np, timeperiod=20)
    roc_3 = ta.ROC(close_np, timeperiod=3)

    new_cols = pd.DataFrame(
      {
        "BTC_RSI_14": rsi_14,
        "BTC_EMA_20": ema_20,
        "BTC_ROC_3": roc_3,
      },
      index=btc_informative_15m.index,
    )

    btc_informative_15m = pd.concat([btc_informative_15m, new_cols], axis=1, copy=False)

    # Enable ONLY during debugging
    debug = False
    if debug:
      debug_cols = [
        "BTC_RSI_14",
        "BTC_EMA_20",
        "BTC_ROC_3",
      ]

      self.validate_indicators(df=btc_informative_15m, columns=debug_cols, pair=btc_pair, timeframe=btc_info_timeframe)

    # =========================================================================
    # LOGGING
    # =========================================================================
    if debug_time:
      tok = time.perf_counter()
      log.debug("[%s] btc_informative_15m_indicators took: %.4f seconds.", btc_pair, tok - tik)

    return btc_informative_15m

  # BTC Informative 5m Timeframe Indicators
  # ---------------------------------------------------------------------------------------------
  def btc_informative_5m_indicators(self, btc_pair: str, btc_info_timeframe: str) -> DataFrame:
    debug_time = False
    if debug_time:
      tik = time.perf_counter()
    dp = self.dp

    assert dp, "DataProvider is required for multiple timeframes."

    # =========================================================================
    # GET DATAFRAME
    # =========================================================================
    btc_informative_5m = dp.get_pair_dataframe(pair=btc_pair, timeframe=btc_info_timeframe)

    # Empty dataframe protection
    if btc_informative_5m.empty:
      return btc_informative_5m

    # =========================================================================
    # BASE DATA
    # =========================================================================
    close_np = btc_informative_5m["close"].to_numpy(copy=False)
    # high_np = btc_informative_5m["high"].to_numpy(copy=False)
    # low_np = btc_informative_5m["low"].to_numpy(copy=False)
    # open_np = btc_informative_5m["open"].to_numpy(copy=False)
    # volume_np = btc_informative_5m["volume"].to_numpy(copy=False)

    # =========================================================================
    # CORE INDICATORS
    # =========================================================================
    rsi_14 = ta.RSI(close_np, timeperiod=14)

    # =========================================================================
    # MOMENTUM
    # =========================================================================
    ema_20 = ta.EMA(close_np, timeperiod=20)
    roc_3 = ta.ROC(close_np, timeperiod=3)

    new_cols = pd.DataFrame(
      {
        "BTC_RSI_14": rsi_14,
        "BTC_EMA_20": ema_20,
        "BTC_ROC_3": roc_3,
      },
      index=btc_informative_5m.index,
    )

    btc_informative_5m = pd.concat([btc_informative_5m, new_cols], axis=1, copy=False)

    # Enable ONLY during debugging
    debug = False
    if debug:
      debug_cols = [
        "BTC_RSI_14",
        "BTC_EMA_20",
        "BTC_ROC_3",
      ]

      self.validate_indicators(df=btc_informative_5m, columns=debug_cols, pair=btc_pair, timeframe=btc_info_timeframe)

    # =========================================================================
    # LOGGING
    # =========================================================================
    if debug_time:
      tok = time.perf_counter()
      log.debug("[%s] btc_informative_5m_indicators took: %.4f seconds.", btc_pair, tok - tik)

    return btc_informative_5m

  # Coin Pair Indicator Switch Case
  # ---------------------------------------------------------------------------------------------
  def info_switcher(self, metadata: dict, info_timeframe) -> DataFrame:
    if info_timeframe == "1d":
      return self.informative_1d_indicators(metadata, info_timeframe)
    elif info_timeframe == "4h":
      return self.informative_4h_indicators(metadata, info_timeframe)
    elif info_timeframe == "1h":
      return self.informative_1h_indicators(metadata, info_timeframe)
    elif info_timeframe == "15m":
      return self.informative_15m_indicators(metadata, info_timeframe)
    else:
      raise RuntimeError(f"{info_timeframe} not supported as informative timeframe for BTC pair.")

  # BTC Indicator Switch Case
  # ---------------------------------------------------------------------------------------------
  def btc_info_switcher(self, btc_pair: str, btc_info_timeframe) -> DataFrame:
    # if btc_info_timeframe == "1d":
    # return self.btc_informative_1d_indicators(btc_pair, btc_info_timeframe)
    if btc_info_timeframe == "4h":
      return self.btc_informative_4h_indicators(btc_pair, btc_info_timeframe)
    # elif btc_info_timeframe == "1h":
    # return self.btc_informative_1h_indicators(btc_pair, btc_info_timeframe)
    # elif btc_info_timeframe == "15m":
    # return self.btc_informative_15m_indicators(btc_pair, btc_info_timeframe)
    # elif btc_info_timeframe == "5m":
    # return self.btc_informative_5m_indicators(btc_pair, btc_info_timeframe)
    else:
      raise RuntimeError(f"{btc_info_timeframe} not supported as informative timeframe for BTC pair.")

  # Populate Indicators
  # ---------------------------------------------------------------------------------------------
  def populate_indicators(self, df: DataFrame, metadata: dict) -> DataFrame:
    debug = False
    debug_time = True
    if debug_time:
      tik = time.perf_counter()
    base_timeframe = self.timeframe
    prepare_informative_merge = self.prepare_informative_merge
    metadata_pair = metadata["pair"]

    # ============================================================
    # BTC CASCADE GUARD: return of the last closed BTC candle
    # ============================================================
    btc_5m_df = self.dp.get_pair_dataframe(pair=self.btc_informative_pair(), timeframe=self.timeframe)
    if btc_5m_df is not None and not btc_5m_df.empty and "close" in btc_5m_df.columns:
      # the candles may carry "date" as a column, not as the index
      btc_dates = btc_5m_df["date"] if "date" in btc_5m_df.columns else pd.Series(pd.DatetimeIndex(btc_5m_df.index))
      btc_roc = (btc_5m_df["close"] / btc_5m_df["close"].shift(1) - 1.0).to_numpy() * 100.0
      btc_5m_roc = pd.Series(btc_roc, index=pd.DatetimeIndex(btc_dates))
      base_dates = df["date"] if "date" in df.columns else pd.Series(pd.DatetimeIndex(df.index))
      labels = pd.DatetimeIndex(base_dates) - pd.Timedelta(minutes=5)
      aligned = btc_5m_roc.reindex(labels)
      if float(aligned.isna().mean()) > 0.5 and not getattr(self, "_btc5m_warned", False):
        log.warning("btc_roc_1_5m unaligned: %.1f%% NaN", float(aligned.isna().mean()) * 100)
        self._btc5m_warned = True
      # no BTC data never blocks: the guard does not invent a block
      df["btc_roc_1_5m"] = aligned.fillna(100.0).to_numpy()
    else:
      df["btc_roc_1_5m"] = 100.0

    # ============================================================
    # BTC INFORMATIVE (BATCH PREPARATION)
    # ============================================================
    btc_info_pair = self.btc_informative_pair()
    btc_info_timeframes = self.btc_info_timeframes
    btc_info_switcher = self.btc_info_switcher
    btc_frames = {}
    for btc_tf in btc_info_timeframes:
      btc_df = btc_info_switcher(btc_info_pair, btc_tf)
      if btc_df.empty:
        continue

      btc_df = prepare_informative_merge(btc_df)
      btc_frames[btc_tf] = btc_df

    # ============================================================
    # INFO TF (BATCH PREPARATION)
    # ============================================================
    info_timeframes = self.info_timeframes
    info_switcher = self.info_switcher
    info_frames = {}
    for info_tf in info_timeframes:
      info_df = info_switcher(metadata, info_tf)
      if info_df.empty:
        continue

      keep_ohlcv = {"open", "close"} if info_tf == "15m" else set()
      info_df = prepare_informative_merge(info_df, keep_ohlcv)
      info_frames[info_tf] = info_df

    # ============================================================
    # BTC MERGE
    # ============================================================
    for tf, frame in btc_frames.items():
      df = merge_informative_pair(df, frame, base_timeframe, tf, ffill=False)
      # BTC date is not needed. only info_tf needs it because of add_informative_ready (not yet implemented) validation(Current PR not affected by this).
      col = f"date_{tf}"
      if col in df.columns:
        df = df.drop(columns=col)

    # ============================================================
    # NORMAL INFORMATIVE MERGE
    # ============================================================
    for tf, frame in info_frames.items():
      df = merge_informative_pair(df, frame, base_timeframe, tf, ffill=False)

    # ============================================================
    # FINAL FILL ONLY AFTER ALL MERGES
    # ============================================================
    df = df.ffill()

    # ============================================================
    # POST-FFILL VALIDATION
    # ============================================================
    if debug:
      groups = {
        "INFO": self.info_timeframes,
        "BTC": self.btc_info_timeframes,
      }

      for source, tfs in groups.items():
        for tf in tfs:
          if source == "BTC":
            tf_cols = [c for c in df.columns if c.startswith("BTC_") and c.endswith(f"_{tf}")]
          else:
            tf_cols = [c for c in df.columns if not c.startswith("BTC_") and c.endswith(f"_{tf}")]

          if not tf_cols:
            continue

          recent = df[tf_cols].tail(500)
          total_nans = recent.isna().sum().sum()

          if total_nans > 0:
            log.warning("[%s] %s %s recent500 contains %s NaNs", metadata_pair, source, tf, total_nans)
          else:
            log.info("[%s] %s %s merge OK", metadata_pair, source, tf)

    # ============================================================
    # BASE TF (LAST)
    # ============================================================
    df = self.base_tf_5m_indicators(metadata, df)

    # ============================================================
    # FINAL INDICATOR VALIDATION
    # ============================================================
    if debug:
      recent = df.tail(500)
      final_nan = recent.isna().sum()
      final_nan = final_nan[final_nan > 0]
      if not final_nan.empty:
        log.warning(
          "[%s] Unexpected indicator NaNs in recent candles:\n%s",
          metadata_pair,
          final_nan.sort_values(ascending=False).to_string(),
        )

    if debug_time:
      tok_before_protections = time.perf_counter()

    # np_view = lambda c: df[c].to_numpy(copy=False)
    # np_shift = self.np_shift
    # protection_rsi_3 = np_view("RSI_3")
    # protection_rsi_3_15m = np_view("RSI_3_15m")
    # protection_rsi_3_1h = np_view("RSI_3_1h")
    # protection_rsi_3_4h = np_view("RSI_3_4h")
    # protection_rsi_3_1d = np_view("RSI_3_1d")
    # protection_rsi_14_1h = np_view("RSI_14_1h")
    # protection_rsi_14_4h = np_view("RSI_14_4h")
    # protection_rsi_14_1d = np_view("RSI_14_1d")
    # protection_cci_20_1h = np_view("CCI_20_1h")
    # protection_cci_20_4h = np_view("CCI_20_4h")
    # protection_rsi_14_15m = np_view("RSI_14_15m")
    # protection_stochrsik_14_14_3_3_15m = np_view("STOCHRSIk_14_14_3_3_15m")
    # protection_stochrsik_14_14_3_3_1d = np_view("STOCHRSIk_14_14_3_3_1d")
    # protection_aroonu_14_15m = np_view("AROONU_14_15m")
    # protection_cmf_20_15m = np_view("CMF_20_15m")
    # protection_aroonu_14_4h = np_view("AROONU_14_4h")
    # protection_roc_9_1d = np_view("ROC_9_1d")
    # protection_aroonu_14_1h = np_view("AROONU_14_1h")
    # protection_stochrsik_14_14_3_3_1h = np_view("STOCHRSIk_14_14_3_3_1h")
    # protection_stochrsik_14_14_3_3_4h = np_view("STOCHRSIk_14_14_3_3_4h")
    # protection_roc_9_4h = np_view("ROC_9_4h")
    # protection_cmf_20_1d = np_view("CMF_20_1d")
    # protection_roc_9_15m = np_view("ROC_9_15m")
    # protection_roc_9_1h = np_view("ROC_9_1h")
    # protection_cmf_20_1h = np_view("CMF_20_1h")
    # protection_cmf_20_4h = np_view("CMF_20_4h")
    # protection_aroonu_14_1d = np_view("AROONU_14_1d")
    # protection_mfi_14_1d = np_view("MFI_14_1d")
    # protection_roc_2_1d = np_view("ROC_2_1d")
    # protection_mfi_14_1h = np_view("MFI_14_1h")
    # protection_mfi_14_4h = np_view("MFI_14_4h")
    # protection_stochk_14_3_3_1h = np_view("STOCHk_14_3_3_1h")
    # protection_stochk_14_3_3_4h = np_view("STOCHk_14_3_3_4h")
    # protection_cci_20_change_pct_4h = np_view("CCI_20_change_pct_4h")
    # protection_change_pct_4h = np_view("change_pct_4h")
    # protection_change_pct_4h_shift_48 = np_shift(protection_change_pct_4h, 48)
    # protection_top_wick_pct_4h = np_view("top_wick_pct_4h")
    # protection_change_pct_1d = np_view("change_pct_1d")
    # protection_change_pct_1d_shift_288 = np_shift(protection_change_pct_1d, 288)
    # protection_top_wick_pct_1d = np_view("top_wick_pct_1d")
    # protection_top_wick_pct_1d_shift_288 = np_shift(protection_top_wick_pct_1d, 288)
    # protection_high_max_6_1d = np_view("high_max_6_1d")
    # protection_low_min_6_1d = np_view("low_min_6_1d")
    # protection_close = np_view("close")
    # protection_high_max_6_4h = np_view("high_max_6_4h")
    # protection_high_max_12_1d = np_view("high_max_12_1d")
    # protection_low_min_12_1d = np_view("low_min_12_1d")
    # protection_high_max_24_4h = np_view("high_max_24_4h")
    # protection_high_max_30_1d = np_view("high_max_30_1d")
    # protection_low_min_30_1d = np_view("low_min_30_1d")
    # protection_close_max_48 = np_view("close_max_48")
    # protection_high_max_12_1h = np_view("high_max_12_1h")
    # protection_high_max_20_1d = np_view("high_max_20_1d")
    # protection_cci_20_15m = np_view("CCI_20_15m")
    # protection_aroond_14_4h = np_view("AROOND_14_4h")
    # protection_aroond_14_1d = np_view("AROOND_14_1d")
    # protection_willr_14_4h = np_view("WILLR_14_4h")
    # protection_willr_14_15m = np_view("WILLR_14_15m")
    # protection_stochk_14_3_3_15m = np_view("STOCHk_14_3_3_15m")
    # protection_willr_14_1h = np_view("WILLR_14_1h")
    # protection_mfi_14_15m = np_view("MFI_14_15m")
    # protection_cci_20_change_pct_1h = np_view("CCI_20_change_pct_1h")
    # protection_willr_14_1d = np_view("WILLR_14_1d")
    # protection_aroond_14_1h = np_view("AROOND_14_1h")
    # protection_stochk_14_3_3_1d = np_view("STOCHk_14_3_3_1d")
    # protection_uo_7_14_28_15m = np_view("UO_7_14_28_15m")
    # protection_uo_7_14_28_change_pct_15m = np_view("UO_7_14_28_change_pct_15m")
    # protection_uo_7_14_28_1h = np_view("UO_7_14_28_1h")
    # protection_uo_7_14_28_4h = np_view("UO_7_14_28_4h")
    # protection_roc_2_4h = np_view("ROC_2_4h")
    # protection_aroond_14_15m = np_view("AROOND_14_15m")

    # # Reused protection comparison masks
    # aroonu_14_15m_lt_30 = protection_aroonu_14_15m < 30.0
    # aroonu_14_15m_lt_40 = protection_aroonu_14_15m < 40.0
    # aroonu_14_15m_lt_50 = protection_aroonu_14_15m < 50.0
    # aroonu_14_15m_lt_60 = protection_aroonu_14_15m < 60.0
    # aroonu_14_15m_lt_70 = protection_aroonu_14_15m < 70.0
    # aroonu_14_1h_lt_100 = protection_aroonu_14_1h < 100.0
    # aroonu_14_1h_lt_20 = protection_aroonu_14_1h < 20.0
    # aroonu_14_1h_lt_25 = protection_aroonu_14_1h < 25.0
    # aroonu_14_1h_lt_30 = protection_aroonu_14_1h < 30.0
    # aroonu_14_1h_lt_40 = protection_aroonu_14_1h < 40.0
    # aroonu_14_1h_lt_50 = protection_aroonu_14_1h < 50.0
    # aroonu_14_1h_lt_60 = protection_aroonu_14_1h < 60.0
    # aroonu_14_1h_lt_70 = protection_aroonu_14_1h < 70.0
    # aroonu_14_1h_lt_75 = protection_aroonu_14_1h < 75.0
    # aroonu_14_1h_lt_80 = protection_aroonu_14_1h < 80.0
    # aroonu_14_1h_lt_85 = protection_aroonu_14_1h < 85.0
    # aroonu_14_1h_lt_90 = protection_aroonu_14_1h < 90.0
    # aroonu_14_4h_lt_100 = protection_aroonu_14_4h < 100.0
    # aroonu_14_4h_lt_20 = protection_aroonu_14_4h < 20.0
    # aroonu_14_4h_lt_25 = protection_aroonu_14_4h < 25.0
    # aroonu_14_4h_lt_30 = protection_aroonu_14_4h < 30.0
    # aroonu_14_4h_lt_40 = protection_aroonu_14_4h < 40.0
    # aroonu_14_4h_lt_50 = protection_aroonu_14_4h < 50.0
    # aroonu_14_4h_lt_60 = protection_aroonu_14_4h < 60.0
    # aroonu_14_4h_lt_70 = protection_aroonu_14_4h < 70.0
    # aroonu_14_4h_lt_75 = protection_aroonu_14_4h < 75.0
    # aroonu_14_4h_lt_80 = protection_aroonu_14_4h < 80.0
    # aroonu_14_4h_lt_85 = protection_aroonu_14_4h < 85.0
    # aroonu_14_4h_lt_90 = protection_aroonu_14_4h < 90.0
    # cmf_20_15m_gt_neg_0 = protection_cmf_20_15m > -0.0
    # cmf_20_15m_gt_neg_010 = protection_cmf_20_15m > -0.10
    # cmf_20_15m_gt_neg_015 = protection_cmf_20_15m > -0.15
    # cmf_20_15m_gt_neg_02 = protection_cmf_20_15m > -0.2
    # cmf_20_15m_gt_neg_020 = protection_cmf_20_15m > -0.20
    # cmf_20_15m_gt_neg_025 = protection_cmf_20_15m > -0.25
    # cmf_20_15m_gt_neg_03 = protection_cmf_20_15m > -0.3
    # cmf_20_15m_gt_neg_030 = protection_cmf_20_15m > -0.30
    # cmf_20_15m_gt_neg_035 = protection_cmf_20_15m > -0.35
    # cmf_20_15m_gt_neg_040 = protection_cmf_20_15m > -0.40
    # cmf_20_15m_gt_neg_05 = protection_cmf_20_15m > -0.5
    # cmf_20_15m_gt_neg_050 = protection_cmf_20_15m > -0.50
    # cmf_20_1h_gt_neg_0 = protection_cmf_20_1h > -0.0
    # cmf_20_1h_gt_neg_010 = protection_cmf_20_1h > -0.10
    # cmf_20_1h_gt_neg_015 = protection_cmf_20_1h > -0.15
    # cmf_20_1h_gt_neg_02 = protection_cmf_20_1h > -0.2
    # cmf_20_1h_gt_neg_020 = protection_cmf_20_1h > -0.20
    # cmf_20_1h_gt_neg_025 = protection_cmf_20_1h > -0.25
    # cmf_20_1h_gt_neg_03 = protection_cmf_20_1h > -0.3
    # cmf_20_1h_gt_neg_030 = protection_cmf_20_1h > -0.30
    # cmf_20_1h_gt_neg_04 = protection_cmf_20_1h > -0.4
    # cmf_20_1h_gt_neg_040 = protection_cmf_20_1h > -0.40
    # cmf_20_1h_gt_neg_05 = protection_cmf_20_1h > -0.5
    # cmf_20_4h_gt_neg_0 = protection_cmf_20_4h > -0.0
    # cmf_20_4h_gt_neg_01 = protection_cmf_20_4h > -0.1
    # cmf_20_4h_gt_neg_010 = protection_cmf_20_4h > -0.10
    # cmf_20_4h_gt_neg_015 = protection_cmf_20_4h > -0.15
    # cmf_20_4h_gt_neg_02 = protection_cmf_20_4h > -0.2
    # cmf_20_4h_gt_neg_020 = protection_cmf_20_4h > -0.20
    # cmf_20_4h_gt_neg_025 = protection_cmf_20_4h > -0.25
    # cmf_20_4h_gt_neg_03 = protection_cmf_20_4h > -0.3
    # cmf_20_4h_gt_neg_030 = protection_cmf_20_4h > -0.30
    # cmf_20_4h_gt_neg_035 = protection_cmf_20_4h > -0.35
    # cmf_20_4h_gt_neg_04 = protection_cmf_20_4h > -0.4
    # cmf_20_4h_gt_neg_040 = protection_cmf_20_4h > -0.40
    # cmf_20_4h_gt_neg_05 = protection_cmf_20_4h > -0.5
    # roc_9_1d_lt_100 = protection_roc_9_1d < 100.0
    # roc_9_1d_lt_15 = protection_roc_9_1d < 15.0
    # roc_9_1d_lt_150 = protection_roc_9_1d < 150.0
    # roc_9_1d_lt_20 = protection_roc_9_1d < 20.0
    # roc_9_1d_lt_200 = protection_roc_9_1d < 200.0
    # roc_9_1d_lt_25 = protection_roc_9_1d < 25.0
    # roc_9_1d_lt_250 = protection_roc_9_1d < 250.0
    # roc_9_1d_lt_30 = protection_roc_9_1d < 30.0
    # roc_9_1d_lt_40 = protection_roc_9_1d < 40.0
    # roc_9_1d_lt_50 = protection_roc_9_1d < 50.0
    # roc_9_1d_lt_60 = protection_roc_9_1d < 60.0
    # roc_9_1d_lt_70 = protection_roc_9_1d < 70.0
    # roc_9_1d_lt_75 = protection_roc_9_1d < 75.0
    # roc_9_1d_lt_80 = protection_roc_9_1d < 80.0
    # roc_9_1h_gt_neg_10 = protection_roc_9_1h > -10.0
    # roc_9_1h_gt_neg_15 = protection_roc_9_1h > -15.0
    # roc_9_1h_gt_neg_20 = protection_roc_9_1h > -20.0
    # roc_9_1h_gt_neg_25 = protection_roc_9_1h > -25.0
    # roc_9_1h_gt_neg_30 = protection_roc_9_1h > -30.0
    # roc_9_1h_gt_neg_50 = protection_roc_9_1h > -50.0
    # roc_9_1h_gt_neg_60 = protection_roc_9_1h > -60.0
    # roc_9_1h_lt_10 = protection_roc_9_1h < 10.0
    # roc_9_1h_lt_15 = protection_roc_9_1h < 15.0
    # roc_9_1h_lt_20 = protection_roc_9_1h < 20.0
    # roc_9_1h_lt_30 = protection_roc_9_1h < 30.0
    # roc_9_1h_lt_40 = protection_roc_9_1h < 40.0
    # roc_9_1h_lt_50 = protection_roc_9_1h < 50.0
    # roc_9_1h_lt_70 = protection_roc_9_1h < 70.0
    # roc_9_1h_lt_80 = protection_roc_9_1h < 80.0
    # roc_9_4h_gt_neg_10 = protection_roc_9_4h > -10.0
    # roc_9_4h_gt_neg_15 = protection_roc_9_4h > -15.0
    # roc_9_4h_gt_neg_20 = protection_roc_9_4h > -20.0
    # roc_9_4h_gt_neg_25 = protection_roc_9_4h > -25.0
    # roc_9_4h_gt_neg_30 = protection_roc_9_4h > -30.0
    # roc_9_4h_gt_neg_35 = protection_roc_9_4h > -35.0
    # roc_9_4h_gt_neg_40 = protection_roc_9_4h > -40.0
    # roc_9_4h_gt_neg_50 = protection_roc_9_4h > -50.0
    # roc_9_4h_gt_neg_60 = protection_roc_9_4h > -60.0
    # roc_9_4h_gt_neg_70 = protection_roc_9_4h > -70.0
    # roc_9_4h_lt_10 = protection_roc_9_4h < 10.0
    # roc_9_4h_lt_100 = protection_roc_9_4h < 100.0
    # roc_9_4h_lt_120 = protection_roc_9_4h < 120.0
    # roc_9_4h_lt_130 = protection_roc_9_4h < 130.0
    # roc_9_4h_lt_15 = protection_roc_9_4h < 15.0
    # roc_9_4h_lt_20 = protection_roc_9_4h < 20.0
    # roc_9_4h_lt_25 = protection_roc_9_4h < 25.0
    # roc_9_4h_lt_250 = protection_roc_9_4h < 250.0
    # roc_9_4h_lt_30 = protection_roc_9_4h < 30.0
    # roc_9_4h_lt_300 = protection_roc_9_4h < 300.0
    # roc_9_4h_lt_35 = protection_roc_9_4h < 35.0
    # roc_9_4h_lt_40 = protection_roc_9_4h < 40.0
    # roc_9_4h_lt_50 = protection_roc_9_4h < 50.0
    # roc_9_4h_lt_60 = protection_roc_9_4h < 60.0
    # roc_9_4h_lt_70 = protection_roc_9_4h < 70.0
    # roc_9_4h_lt_75 = protection_roc_9_4h < 75.0
    # roc_9_4h_lt_80 = protection_roc_9_4h < 80.0
    # rsi_14_15m_gt_70 = protection_rsi_14_15m > 70.0
    # rsi_14_15m_gt_80 = protection_rsi_14_15m > 80.0
    # rsi_14_15m_gt_85 = protection_rsi_14_15m > 85.0
    # rsi_14_15m_gt_90 = protection_rsi_14_15m > 90.0
    # rsi_14_15m_gt_95 = protection_rsi_14_15m > 95.0
    # rsi_14_1h_gt_70 = protection_rsi_14_1h > 70.0
    # rsi_14_1h_gt_75 = protection_rsi_14_1h > 75.0
    # rsi_14_1h_gt_80 = protection_rsi_14_1h > 80.0
    # rsi_14_1h_gt_85 = protection_rsi_14_1h > 85.0
    # rsi_14_1h_gt_90 = protection_rsi_14_1h > 90.0
    # rsi_14_1h_gt_95 = protection_rsi_14_1h > 95.0
    # rsi_14_4h_gt_60 = protection_rsi_14_4h > 60.0
    # rsi_14_4h_gt_70 = protection_rsi_14_4h > 70.0
    # rsi_14_4h_gt_80 = protection_rsi_14_4h > 80.0
    # rsi_14_4h_gt_90 = protection_rsi_14_4h > 90.0
    # rsi_14_4h_gt_95 = protection_rsi_14_4h > 95.0
    # rsi_3_15m_lt_70 = protection_rsi_3_15m < 70.0
    # rsi_3_15m_lt_75 = protection_rsi_3_15m < 75.0
    # rsi_3_15m_lt_80 = protection_rsi_3_15m < 80.0
    # rsi_3_15m_lt_85 = protection_rsi_3_15m < 85.0
    # rsi_3_15m_lt_90 = protection_rsi_3_15m < 90.0
    # rsi_3_1d_gt_10 = protection_rsi_3_1d > 10.0
    # rsi_3_1d_gt_15 = protection_rsi_3_1d > 15.0
    # rsi_3_1d_gt_20 = protection_rsi_3_1d > 20.0
    # rsi_3_1d_gt_25 = protection_rsi_3_1d > 25.0
    # rsi_3_1d_gt_3 = protection_rsi_3_1d > 3.0
    # rsi_3_1d_gt_30 = protection_rsi_3_1d > 30.0
    # rsi_3_1d_gt_35 = protection_rsi_3_1d > 35.0
    # rsi_3_1d_gt_40 = protection_rsi_3_1d > 40.0
    # rsi_3_1d_gt_45 = protection_rsi_3_1d > 45.0
    # rsi_3_1d_gt_5 = protection_rsi_3_1d > 5.0
    # rsi_3_1d_gt_50 = protection_rsi_3_1d > 50.0
    # rsi_3_1d_gt_55 = protection_rsi_3_1d > 55.0
    # rsi_3_1d_gt_60 = protection_rsi_3_1d > 60.0
    # rsi_3_1d_gt_65 = protection_rsi_3_1d > 65.0
    # rsi_3_1h_gt_20 = protection_rsi_3_1h > 20.0
    # rsi_3_1h_gt_25 = protection_rsi_3_1h > 25.0
    # rsi_3_1h_gt_35 = protection_rsi_3_1h > 35.0
    # rsi_3_1h_gt_40 = protection_rsi_3_1h > 40.0
    # rsi_3_1h_gt_45 = protection_rsi_3_1h > 45.0
    # rsi_3_1h_gt_50 = protection_rsi_3_1h > 50.0
    # rsi_3_1h_gt_55 = protection_rsi_3_1h > 55.0
    # rsi_3_1h_lt_60 = protection_rsi_3_1h < 60.0
    # rsi_3_1h_lt_70 = protection_rsi_3_1h < 70.0
    # rsi_3_1h_lt_75 = protection_rsi_3_1h < 75.0
    # rsi_3_1h_lt_80 = protection_rsi_3_1h < 80.0
    # rsi_3_1h_lt_85 = protection_rsi_3_1h < 85.0
    # rsi_3_1h_lt_90 = protection_rsi_3_1h < 90.0
    # rsi_3_4h_gt_20 = protection_rsi_3_4h > 20.0
    # rsi_3_4h_gt_25 = protection_rsi_3_4h > 25.0
    # rsi_3_4h_gt_30 = protection_rsi_3_4h > 30.0
    # rsi_3_4h_gt_35 = protection_rsi_3_4h > 35.0
    # rsi_3_4h_gt_40 = protection_rsi_3_4h > 40.0
    # rsi_3_4h_gt_45 = protection_rsi_3_4h > 45.0
    # rsi_3_4h_gt_50 = protection_rsi_3_4h > 50.0
    # rsi_3_4h_gt_55 = protection_rsi_3_4h > 55.0
    # rsi_3_4h_gt_65 = protection_rsi_3_4h > 65.0
    # stochrsi_k_15m_lt_10 = protection_stochrsik_14_14_3_3_15m < 10.0
    # stochrsi_k_15m_lt_20 = protection_stochrsik_14_14_3_3_15m < 20.0
    # stochrsi_k_15m_lt_30 = protection_stochrsik_14_14_3_3_15m < 30.0
    # stochrsi_k_15m_lt_40 = protection_stochrsik_14_14_3_3_15m < 40.0
    # stochrsi_k_15m_lt_50 = protection_stochrsik_14_14_3_3_15m < 50.0
    # stochrsi_k_15m_lt_60 = protection_stochrsik_14_14_3_3_15m < 60.0
    # stochrsi_k_15m_lt_70 = protection_stochrsik_14_14_3_3_15m < 70.0
    # stochrsi_k_15m_lt_80 = protection_stochrsik_14_14_3_3_15m < 80.0
    # stochrsi_k_15m_lt_90 = protection_stochrsik_14_14_3_3_15m < 90.0
    # stochrsi_k_1h_lt_15 = protection_stochrsik_14_14_3_3_1h < 15.0
    # stochrsi_k_1h_lt_20 = protection_stochrsik_14_14_3_3_1h < 20.0
    # stochrsi_k_1h_lt_30 = protection_stochrsik_14_14_3_3_1h < 30.0
    # stochrsi_k_1h_lt_40 = protection_stochrsik_14_14_3_3_1h < 40.0
    # stochrsi_k_1h_lt_50 = protection_stochrsik_14_14_3_3_1h < 50.0
    # stochrsi_k_1h_lt_60 = protection_stochrsik_14_14_3_3_1h < 60.0
    # stochrsi_k_1h_lt_70 = protection_stochrsik_14_14_3_3_1h < 70.0
    # stochrsi_k_1h_lt_80 = protection_stochrsik_14_14_3_3_1h < 80.0
    # stochrsi_k_1h_lt_85 = protection_stochrsik_14_14_3_3_1h < 85.0
    # stochrsi_k_1h_lt_90 = protection_stochrsik_14_14_3_3_1h < 90.0
    # stochrsi_k_4h_lt_10 = protection_stochrsik_14_14_3_3_4h < 10.0
    # stochrsi_k_4h_lt_15 = protection_stochrsik_14_14_3_3_4h < 15.0
    # stochrsi_k_4h_lt_20 = protection_stochrsik_14_14_3_3_4h < 20.0
    # stochrsi_k_4h_lt_30 = protection_stochrsik_14_14_3_3_4h < 30.0
    # stochrsi_k_4h_lt_40 = protection_stochrsik_14_14_3_3_4h < 40.0
    # stochrsi_k_4h_lt_50 = protection_stochrsik_14_14_3_3_4h < 50.0
    # stochrsi_k_4h_lt_60 = protection_stochrsik_14_14_3_3_4h < 60.0
    # stochrsi_k_4h_lt_70 = protection_stochrsik_14_14_3_3_4h < 70.0
    # stochrsi_k_4h_lt_80 = protection_stochrsik_14_14_3_3_4h < 80.0
    # stochrsi_k_4h_lt_85 = protection_stochrsik_14_14_3_3_4h < 85.0
    # stochrsi_k_4h_lt_90 = protection_stochrsik_14_14_3_3_4h < 90.0

    # # Reused long-global RSI comparison masks
    # rsi_14_15m_lt_30 = protection_rsi_14_15m < 30.0
    # rsi_14_1h_lt_40 = protection_rsi_14_1h < 40.0
    # rsi_14_4h_lt_50 = protection_rsi_14_4h < 50.0
    # rsi_14_15m_lt_40 = protection_rsi_14_15m < 40.0
    # rsi_14_4h_lt_40 = protection_rsi_14_4h < 40.0
    # rsi_14_1h_lt_30 = protection_rsi_14_1h < 30.0
    # rsi_14_1h_lt_50 = protection_rsi_14_1h < 50.0
    # rsi_3_15m_gt_20 = protection_rsi_3_15m > 20.0
    # rsi_3_15m_gt_15 = protection_rsi_3_15m > 15.0
    # rsi_3_15m_gt_10 = protection_rsi_3_15m > 10.0
    # rsi_3_15m_gt_25 = protection_rsi_3_15m > 25.0
    # rsi_14_4h_lt_30 = protection_rsi_14_4h < 30.0
    # rsi_3_15m_gt_30 = protection_rsi_3_15m > 30.0
    # rsi_3_1h_gt_30 = protection_rsi_3_1h > 30.0
    # rsi_14_15m_lt_20 = protection_rsi_14_15m < 20.0
    # rsi_3_4h_gt_60 = protection_rsi_3_4h > 60.0
    # rsi_3_15m_gt_5 = protection_rsi_3_15m > 5.0
    # rsi_3_15m_gt_35 = protection_rsi_3_15m > 35.0
    # rsi_3_15m_gt_40 = protection_rsi_3_15m > 40.0
    # rsi_3_15m_gt_45 = protection_rsi_3_15m > 45.0
    # rsi_3_1h_gt_5 = protection_rsi_3_1h > 5.0
    # rsi_3_1h_gt_10 = protection_rsi_3_1h > 10.0
    # rsi_3_1h_gt_15 = protection_rsi_3_1h > 15.0
    # rsi_3_1h_gt_60 = protection_rsi_3_1h > 60.0
    # rsi_3_1h_gt_65 = protection_rsi_3_1h > 65.0
    # rsi_3_4h_gt_3 = protection_rsi_3_4h > 3.0
    # rsi_3_4h_gt_5 = protection_rsi_3_4h > 5.0
    # rsi_3_4h_gt_10 = protection_rsi_3_4h > 10.0
    # rsi_3_4h_gt_15 = protection_rsi_3_4h > 15.0
    # rsi_14_4h_lt_20 = protection_rsi_14_4h < 20.0
    # rsi_14_4h_lt_60 = protection_rsi_14_4h < 60.0
    # rsi_14_4h_lt_70 = protection_rsi_14_4h < 70.0
    # rsi_14_4h_lt_80 = protection_rsi_14_4h < 80.0
    # rsi_14_1h_lt_20 = protection_rsi_14_1h < 20.0
    # rsi_14_1h_lt_60 = protection_rsi_14_1h < 60.0
    # rsi_14_1h_lt_70 = protection_rsi_14_1h < 70.0
    # rsi_14_15m_lt_50 = protection_rsi_14_15m < 50.0

    # # Global protections Long
    # # Reused protection RSI and ROC masks
    # rsi_3_15m_gt_3 = protection_rsi_3_15m > 3.0
    # rsi_3_4h_lt_80 = protection_rsi_3_4h < 80.0
    # rsi_3_4h_lt_90 = protection_rsi_3_4h < 90.0
    # roc_9_1d_gt_neg_50 = protection_roc_9_1d > -50.0
    # top_wick_pct_1d_lt_10 = protection_top_wick_pct_1d < 10.0
    # rsi_3_4h_lt_70 = protection_rsi_3_4h < 70.0
    # aroonu_14_15m_lt_20 = protection_aroonu_14_15m < 20.0
    # aroonu_14_15m_lt_25 = protection_aroonu_14_15m < 25.0
    # rsi_3_4h_lt_60 = protection_rsi_3_4h < 60.0
    # rsi_3_gt_10 = protection_rsi_3 > 10.0
    # rsi_14_15m_lt_10 = protection_rsi_14_15m < 10.0
    # roc_9_1d_gt_neg_40 = protection_roc_9_1d > -40.0
    # change_pct_1d_lt_10 = protection_change_pct_1d < 10.0
    # top_wick_pct_1d_lt_20 = protection_top_wick_pct_1d < 20.0
    # rsi_3_1h_gt_3 = protection_rsi_3_1h > 3.0
    # rsi_3_gt_5 = protection_rsi_3 > 5.0
    # roc_9_1d_gt_neg_30 = protection_roc_9_1d > -30.0
    # change_pct_1d_gt_neg_10 = protection_change_pct_1d > -10.0
    # change_pct_1d_lt_30 = protection_change_pct_1d < 30.0
    # cci_20_4h_lt_neg_200 = protection_cci_20_4h < -200.0
    # cci_20_1h_gt_250 = protection_cci_20_1h > 250.0
    # top_wick_pct_1d_lt_25 = protection_top_wick_pct_1d < 25.0
    # stochrsik_14_14_3_3_1h_gt_70 = protection_stochrsik_14_14_3_3_1h > 70.0
    # roc_9_1d_gt_neg_15 = protection_roc_9_1d > -15.0
    # change_pct_1d_lt_50 = protection_change_pct_1d < 50.0
    # cci_20_4h_gt_200 = protection_cci_20_4h > 200.0
    # cci_20_15m_gt_250 = protection_cci_20_15m > 250.0
    # aroonu_14_15m_lt_80 = protection_aroonu_14_15m < 80.0
    # rsi_3_15m_lt_95 = protection_rsi_3_15m < 95.0
    # rsi_14_4h_lt_75 = protection_rsi_14_4h < 75.0
    # rsi_14_4h_lt_45 = protection_rsi_14_4h < 45.0
    # rsi_14_1h_lt_35 = protection_rsi_14_1h < 35.0
    # rsi_14_1d_gt_50 = protection_rsi_14_1d > 50.0
    # rsi_14_15m_lt_25 = protection_rsi_14_15m < 25.0
    # roc_9_1d_gt_neg_25 = protection_roc_9_1d > -25.0
    # roc_9_15m_lt_10 = protection_roc_9_15m < 10.0
    # cmf_20_1d_gt_neg_0_20 = protection_cmf_20_1d > -0.20
    # change_pct_1d_gt_neg_20 = protection_change_pct_1d > -20.0
    # cci_20_1h_lt_neg_250 = protection_cci_20_1h < -250.0
    # aroond_14_4h_lt_50 = protection_aroond_14_4h < 50.0
    # willr_14_4h_gt_neg_10 = protection_willr_14_4h > -10.0
    # top_wick_pct_4h_lt_10 = protection_top_wick_pct_4h < 10.0
    # top_wick_pct_1d_lt_50 = protection_top_wick_pct_1d < 50.0
    # stochrsik_14_14_3_3_4h_gt_80 = protection_stochrsik_14_14_3_3_4h > 80.0
    # stochrsik_14_14_3_3_4h_gt_60 = protection_stochrsik_14_14_3_3_4h > 60.0

    df["protections_long_global"] = True
    df["global_protections_long_pump"] = True
    df["global_protections_long_dump"] = True
    df["protections_long_rebuy"] = True

    # Global protections Short
    df["protections_short_global"] = True
    df["global_protections_short_pump"] = True
    df["global_protections_short_dump"] = True
    df["protections_short_rebuy"] = True

    if debug_time:
      tok_after_protections = time.perf_counter()
      tok_total = time.perf_counter()
      log.debug(
        f"[{metadata_pair}] "
        f"populate_indicators pre-protections: "
        f"{tok_before_protections - tik:0.4f}s | "
        f"protections: "
        f"{tok_after_protections - tok_before_protections:0.4f}s | "
        f"total: "
        f"{tok_total - tik:0.4f}s"
      )

    return df

  # Confirm Trade Entry
  # ---------------------------------------------------------------------------------------------
  def confirm_trade_entry(
    self,
    pair: str,
    order_type: str,
    amount: float,
    rate: float,
    time_in_force: str,
    current_time: datetime,
    entry_tag: Optional[str],
    side: str,
    **kwargs,
  ) -> bool:
    # Force Entry
    if entry_tag == "force_entry":
      return True

    # Mode Validation
    entry_tags = (entry_tag or "empty").split()
    is_long_side = side == "long"
    is_short_side = side == "short"
    long_grind_mode_tags = self.long_grind_mode_tags
    long_top_coins_mode_tags = self.long_top_coins_mode_tags
    long_scalp_mode_tags = self.long_scalp_mode_tags
    if all(c in long_grind_mode_tags for c in entry_tags):
      return self._handle_grind_mode(pair, current_time)
    if all(c in long_top_coins_mode_tags for c in entry_tags):
      return self._handle_top_coins_mode(pair, current_time)
    if all(c in long_scalp_mode_tags for c in entry_tags):
      return self._handle_scalp_mode(pair, current_time)

    # Long/Short Slot Validation (only in futures mode)
    if self.is_futures_mode:
      max_side_trades = 0
      if is_long_side:
        max_side_trades = self.futures_max_open_trades_long
      elif is_short_side:
        max_side_trades = self.futures_max_open_trades_short

      if max_side_trades != 0:
        open_trades = Trade.get_trades_proxy(is_open=True)
        side_trades = sum(1 for t in open_trades if t.trade_direction == side)
        if side_trades >= max_side_trades:
          log.info(
            f"[{current_time}] Cancelling entry for {pair} due to {side} trades reaching the max limit of {max_side_trades}."
          )
          return False

    max_slippage = self.max_slippage

    # Slippage Validation
    df, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
    if len(df) >= 1:
      last_candle = df.iloc[-1]
      last_close = last_candle["close"]
      if (is_long_side and rate > last_close) or (is_short_side and rate < last_close):
        slippage = (rate / last_close) - 1.0
        if (is_long_side and slippage < max_slippage) or (is_short_side and slippage > -max_slippage):
          return True
        else:
          log.warning(f"[{current_time}] Cancelling entry for {pair} due to slippage {(slippage * 100.0):.2f}%")
          return False

    return True

  def _handle_grind_mode(self, pair: str, current_time: datetime) -> bool:
    grind_mode_coins = self.grind_mode_coins
    grind_mode_max_slots = self.grind_mode_max_slots
    long_grind_mode_tags = self.long_grind_mode_tags

    is_pair_grind_mode = pair.partition("/")[0] in grind_mode_coins
    if not is_pair_grind_mode:
      log.info(f"[{current_time}] Cancelling entry for {pair} due to not being in grind mode coins list.")
      return False

    open_trades = Trade.get_trades_proxy(is_open=True)
    num_open_grind_mode = sum(
      1
      for t in open_trades
      if t.enter_tag and t.enter_tag.strip() and all(c in long_grind_mode_tags for c in t.enter_tag.split())
    )
    if num_open_grind_mode >= grind_mode_max_slots:
      log.info(f"[{current_time}] Cancelling entry for {pair} due to grind mode slots limit reached.")
      return False

    return True

  def _handle_top_coins_mode(self, pair: str, current_time: datetime) -> bool:
    is_pair_top_coins_mode = pair.partition("/")[0] in self.top_coins_mode_coins
    if not is_pair_top_coins_mode:
      log.info(f"[{current_time}] Cancelling entry for {pair} due to not being in top coins list.")
      return False
    return True

  def _handle_scalp_mode(self, pair: str, current_time: datetime) -> bool:
    current_free_slots = self.config["max_open_trades"] - Trade.get_open_trade_count()
    if current_free_slots < self.min_free_slots_scalp_mode:
      log.info(f"[{current_time}] Cancelling entry for {pair} due to insufficient free slots.")
      return False
    return True

  # 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:
    trade_realized_profit = trade.realized_profit
    trade_stake_amount = trade.stake_amount
    trade_is_short = trade.is_short
    trade_liquidation_price = trade.liquidation_price

    is_backtest = self.is_backtest_mode()
    # Allow force exits
    if exit_reason != "force_exit":
      if self._should_hold_trade(trade, rate, exit_reason):
        return False
      if exit_reason in ["stop_loss", "trailing_stop_loss"]:
        # log.info(f"[{current_time}] Cancelling {exit_reason} exit for {pair}")
        is_liquidation = False
        if self.is_futures_mode and is_backtest:
          if (trade_is_short and rate > trade_liquidation_price) or (
            not trade_is_short and rate < trade_liquidation_price
          ):
            is_liquidation = True
        if not is_liquidation:
          return False
      if self.exit_profit_only:
        profit = 0.0
        if trade_realized_profit != 0.0:
          profit = trade.calculate_profit(rate).total_profit / trade_stake_amount
        else:
          profit = trade.calc_profit_ratio(rate)
        if profit < self.exit_profit_offset:
          return False

    return True

  # Check Entry Timeout
  # ---------------------------------------------------------------------------------------------
  def check_entry_timeout(self, pair: str, trade: Trade, order: Order, current_time: datetime, **kwargs) -> bool:
    ob = self.dp.orderbook(pair, 1)
    bids = ob["bids"][0][0]
    asks = ob["asks"][0][0]
    # Cancel order if price is more than 3% difference.
    if trade.is_short:
      if asks < order.price * 0.97:
        return True
    else:
      if bids > order.price * 1.03:
        return True
    return False

  # Check Exit Timeout
  # ---------------------------------------------------------------------------------------------
  def check_exit_timeout(self, pair: str, trade: Trade, order: Order, current_time: datetime, **kwargs) -> bool:
    # If force exit skip the check
    if order.ft_order_tag is not None and order.ft_order_tag == "force_exit":
      return False
    ob = self.dp.orderbook(pair, 1)
    bids = ob["bids"][0][0]
    asks = ob["asks"][0][0]
    # Cancel order if price is more than 3% difference.
    if trade.is_short:
      if bids > order.price * 1.03:
        return True
    else:
      if asks < order.price * 0.97:
        return True
    return False

  # Bot Loop Start
  # ---------------------------------------------------------------------------------------------
  def bot_loop_start(self, current_time: datetime, **kwargs) -> None:
    if self.config["runmode"].value not in ("live", "dry_run"):
      return super().bot_loop_start(datetime, **kwargs)

    if self.hold_support_enabled:
      self.load_hold_trades_config()

    return super().bot_loop_start(current_time, **kwargs)

  # Leverage
  # ---------------------------------------------------------------------------------------------
  def leverage(
    self,
    pair: str,
    current_time: datetime,
    current_rate: float,
    proposed_leverage: float,
    max_leverage: float,
    entry_tag: Optional[str],
    side: str,
    **kwargs,
  ) -> float:
    enter_tags = (entry_tag or "empty").split()
    if side == "long":
      if all(c in self.long_rebuy_mode_tags for c in enter_tags):
        leverage_override = self.futures_mode_leverage_long_rebuy_mode
      elif all(c in self.long_grind_mode_tags for c in enter_tags):
        leverage_override = self.futures_mode_leverage_long_grind_mode
      else:
        leverage_override = self.futures_mode_leverage_long
    else:
      if all(c in self.short_rebuy_mode_tags for c in enter_tags):
        leverage_override = self.futures_mode_leverage_short_rebuy_mode
      elif all(c in self.short_grind_mode_tags for c in enter_tags):
        leverage_override = self.futures_mode_leverage_short_grind_mode
      else:
        leverage_override = self.futures_mode_leverage_short
    if leverage_override is not None:
      return leverage_override

    long_rebuy_mode_tags = self.long_rebuy_mode_tags
    long_grind_mode_tags = self.long_grind_mode_tags
    if all(c in long_rebuy_mode_tags for c in enter_tags):
      return self.futures_mode_leverage_rebuy_mode
    elif all(c in long_grind_mode_tags for c in enter_tags):
      return self.futures_mode_leverage_grind_mode
    return self.futures_mode_leverage

  # Correct Min Stake
  # ---------------------------------------------------------------------------------------------
  def correct_min_stake(self, min_stake: Optional[float], trade_leverage: Optional[float] = None) -> float:
    if self.is_futures_mode and self.config["exchange"]["name"] in ("binance", "bybit", "krakenfutures"):
      min_futures_stake = 5.0 / (trade_leverage if trade_leverage is not None else self.futures_mode_leverage)
      if (min_stake is None) or (min_stake < min_futures_stake):
        min_stake = min_futures_stake
    return min_stake if min_stake is not None else 0.0

  def is_backtest_mode(self) -> bool:
    """Check if the current run mode is backtest or hyperopt"""
    return self.dp.runmode.value in ["backtest", "hyperopt"]

  def is_system_v3(self, trade: Trade) -> bool:
    """Check if the current system is v3"""
    return trade.get_custom_data(key="system_version") == self.system_v3_name

  def is_system_v3_1(self, trade: Trade) -> bool:
    """Check if the current system is v3_1"""
    return trade.get_custom_data(key="system_version") == self.system_v3_1_name

  def is_system_v3_2(self, trade: Trade) -> bool:
    """Check if the current system is v3_2"""
    return trade.get_custom_data(key="system_version") == self.system_v3_2_name

  def is_system_v4(self, trade: Trade) -> bool:
    """Check if the current system is v4"""
    return trade.get_custom_data(key="system_version") == self.system_v4_name

  def get_system_version_flags(self, trade: Trade) -> tuple[bool, bool, bool]:
    """Check the current system version flags with one custom-data lookup."""
    system_version = trade.get_custom_data(key="system_version")
    return (
      system_version == self.system_v3_name,
      system_version == self.system_v3_1_name,
      system_version == self.system_v3_2_name,
    )

  def has_valid_entry_conditions(
    self, trade: Trade, exit_rate: float, last_candle, previous_candle, filled_orders=None
  ) -> bool:
    """Check if there are valid entry conditions"""
    if filled_orders is None:
      filled_orders = trade.select_filled_orders()
    if not filled_orders:
      return False
    last_filled_price = filled_orders[-1].safe_price
    slice_profit = (exit_rate - last_filled_price) / last_filled_price
    if not trade.is_short:
      return last_candle["enter_long"] or self.long_grind_entry(last_candle, previous_candle, slice_profit, False)
    else:
      return last_candle["enter_short"] or self.short_grind_entry(last_candle, previous_candle, slice_profit, False)
    return False

  # Update signals (enable/disable) from config
  # ---------------------------------------------------------------------------------------------
  def update_signals_from_config(self, config):
    # Update long entry signal parameters (if they exist in the config)
    if hasattr(self, "long_entry_signal_params") and "long_entry_signal_params" in config:
      long_entry_signal_params = self.long_entry_signal_params
      config_long_entry_signal_params = config["long_entry_signal_params"]
      for condition_key in long_entry_signal_params:
        if condition_key in config_long_entry_signal_params:
          long_entry_signal_params[condition_key] = config_long_entry_signal_params[condition_key]

    # Update short entry signal parameters (if they exist in the config)
    if hasattr(self, "short_entry_signal_params") and "short_entry_signal_params" in config:
      short_entry_signal_params = self.short_entry_signal_params
      config_short_entry_signal_params = config["short_entry_signal_params"]
      for condition_key in short_entry_signal_params:
        if condition_key in config_short_entry_signal_params:
          short_entry_signal_params[condition_key] = config_short_entry_signal_params[condition_key]

  # Set Profit Target
  # ---------------------------------------------------------------------------------------------
  def _set_profit_target(
    self, pair: str, sell_reason: str, rate: float, current_profit: float, current_time: datetime
  ):
    self.target_profit_cache.data[pair] = {
      "rate": rate,
      "profit": current_profit,
      "sell_reason": sell_reason,
      "time_profit_reached": current_time.isoformat(),
    }
    self.target_profit_cache.save()

  # Remove Profit Target
  # ---------------------------------------------------------------------------------------------
  def _remove_profit_target(self, pair: str):
    target_profit_cache = self.target_profit_cache

    if target_profit_cache is not None:
      target_profit_cache.data.pop(pair, None)
      target_profit_cache.save()

  # Get Hold Trades Config File
  # ---------------------------------------------------------------------------------------------
  def get_hold_trades_config_file(self):
    proper_holds_file_path = self.config["user_data_dir"].resolve() / "nfi-hold-trades.json"
    if proper_holds_file_path.is_file():
      return proper_holds_file_path

    strat_file_path = pathlib.Path(__file__)
    hold_trades_config_file_resolve = strat_file_path.resolve().parent / "hold-trades.json"
    if hold_trades_config_file_resolve.is_file():
      log.warning(
        "Please move %s to %s which is now the expected path for the holds file",
        hold_trades_config_file_resolve,
        proper_holds_file_path,
      )
      return hold_trades_config_file_resolve

    # The resolved path does not exist, is it a symlink?
    hold_trades_config_file_absolute = strat_file_path.absolute().parent / "hold-trades.json"
    if hold_trades_config_file_absolute.is_file():
      log.warning(
        "Please move %s to %s which is now the expected path for the holds file",
        hold_trades_config_file_absolute,
        proper_holds_file_path,
      )
      return hold_trades_config_file_absolute

  # Load Hold Trades Config
  # ---------------------------------------------------------------------------------------------
  def load_hold_trades_config(self):
    hold_trades_cache = self.hold_trades_cache
    if hold_trades_cache is None:
      hold_trades_config_file = self.get_hold_trades_config_file()
      if hold_trades_config_file:
        log.warning("Loading hold support data from %s", hold_trades_config_file)
        hold_trades_cache = HoldsCache(hold_trades_config_file)
        self.hold_trades_cache = hold_trades_cache

    if hold_trades_cache:
      hold_trades_cache.load()

  # Should Hold Trade
  # ---------------------------------------------------------------------------------------------
  def _should_hold_trade(self, trade: "Trade", rate: float, sell_reason: str) -> bool:
    calc_total_profit = self.calc_total_profit
    trade_id = trade.id
    trade_pair = trade.pair

    if self.config["runmode"].value not in ("live", "dry_run"):
      return False

    if not self.hold_support_enabled:
      return False

    # Just to be sure our hold data is loaded, should be a no-op call after the first bot loop
    self.load_hold_trades_config()

    hold_trades_cache = self.hold_trades_cache
    if not hold_trades_cache:
      # Cache hasn't been setup, likely because the corresponding file does not exist, sell
      return False

    hold_trades_data = hold_trades_cache.data
    if not hold_trades_data:
      # We have no pairs we want to hold until profit, sell
      return False

    # By default, no hold should be done
    hold_trade = False
    profit_values = None

    def get_profit_values():
      nonlocal profit_values
      if profit_values is None:
        filled_entries = trade.select_filled_orders(trade.entry_side)
        filled_exits = trade.select_filled_orders(trade.exit_side)
        profit_values = calc_total_profit(trade, filled_entries, filled_exits, rate)

      return profit_values

    for hold_key_name, hold_key in (("trade_ids", trade_id), ("trade_pairs", trade_pair)):
      hold_targets: dict = hold_trades_data.get(hold_key_name)
      if not hold_targets or hold_key not in hold_targets:
        continue

      trade_profit_ratio = hold_targets[hold_key]
      current_profit_ratio = get_profit_values()[3]
      if sell_reason == "force_sell":
        formatted_profit_ratio = f"{trade_profit_ratio * 100}%"
        formatted_current_profit_ratio = f"{current_profit_ratio * 100}%"
        log.warning(
          "Force selling %s even though the current profit of %s < %s",
          trade,
          formatted_current_profit_ratio,
          formatted_profit_ratio,
        )
        return False
      elif current_profit_ratio >= trade_profit_ratio:
        # This trade is on the list to hold, and we reached minimum profit, sell
        formatted_profit_ratio = f"{trade_profit_ratio * 100}%"
        formatted_current_profit_ratio = f"{current_profit_ratio * 100}%"
        log.warning(
          "Selling %s because the current profit of %s >= %s",
          trade,
          formatted_current_profit_ratio,
          formatted_profit_ratio,
        )
        return False

      # This trade is on the list to hold, and we haven't reached minimum profit, hold
      hold_trade = True

    return hold_trade

  # Populate Exit Trend
  # ---------------------------------------------------------------------------------------------
  def populate_exit_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
    df.loc[:, "exit_long"] = 0
    df.loc[:, "exit_short"] = 0

    return df

  #
  # $$$$$$$$\ $$\   $$\ $$$$$$$$\ $$$$$$$\ $$\     $$\
  # $$  _____|$$$\  $$ |\__$$  __|$$  __$$\\$$\   $$  |
  # $$ |      $$$$\ $$ |   $$ |   $$ |  $$ |\$$\ $$  /
  # $$$$$\    $$ $$\$$ |   $$ |   $$$$$$$  | \$$$$  /
  # $$  __|   $$ \$$$$ |   $$ |   $$  __$$<   \$$  /
  # $$ |      $$ |\$$$ |   $$ |   $$ |  $$ |   $$ |
  # $$$$$$$$\ $$ | \$$ |   $$ |   $$ |  $$ |   $$ |
  # \________|\__|  \__|   \__|   \__|  \__|   \__|
  #

  #
  #  $$$$$$\   $$$$$$\  $$\   $$\ $$$$$$$\  $$$$$$\ $$$$$$$$\ $$$$$$\  $$$$$$\  $$\   $$\  $$$$$$\
  # $$  __$$\ $$  __$$\ $$$\  $$ |$$  __$$\ \_$$  _|\__$$  __|\_$$  _|$$  __$$\ $$$\  $$ |$$  __$$\
  # $$ /  \__|$$ /  $$ |$$$$\ $$ |$$ |  $$ |  $$ |     $$ |     $$ |  $$ /  $$ |$$$$\ $$ |$$ /  \__|
  # $$ |      $$ |  $$ |$$ $$\$$ |$$ |  $$ |  $$ |     $$ |     $$ |  $$ |  $$ |$$ $$\$$ |\$$$$$$\
  # $$ |      $$ |  $$ |$$ \$$$$ |$$ |  $$ |  $$ |     $$ |     $$ |  $$ |  $$ |$$ \$$$$ | \____$$\
  # $$ |  $$\ $$ |  $$ |$$ |\$$$ |$$ |  $$ |  $$ |     $$ |     $$ |  $$ |  $$ |$$ |\$$$ |$$\   $$ |
  # \$$$$$$  | $$$$$$  |$$ | \$$ |$$$$$$$  |$$$$$$\    $$ |   $$$$$$\  $$$$$$  |$$ | \$$ |\$$$$$$  |
  #  \______/  \______/ \__|  \__|\_______/ \______|   \__|   \______| \______/ \__|  \__| \______/
  #

  # Populate Entry Trend
  # ---------------------------------------------------------------------------------------------
  def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:
    debug = False
    if debug:
      tik = time.perf_counter()
    config = self.config
    long_entry_signal_params = self.long_entry_signal_params
    short_entry_signal_params = self.short_entry_signal_params
    top_coins_mode_coins = self.top_coins_mode_coins

    long_entry_conditions = []
    short_entry_conditions = []

    entry_tags = np.full(len(df), "", dtype=object)
    df.loc[:, "enter_long"] = 0
    df.loc[:, "enter_short"] = 0
    np_view = lambda c: df[c].to_numpy(copy=False)
    np_shift = self.np_shift
    rsi_3_1h = np_view("RSI_3_1h")
    rsi_3_15m = np_view("RSI_3_15m")
    rsi_3_4h = np_view("RSI_3_4h")
    roc_7_1d = np_view("ROC_7_1d")
    roc_9_1d = np_view("ROC_9_1d")
    aroonu_14_4h = np_view("AROONU_14_4h")
    aroonu_14_4h_shift_48 = np_shift(aroonu_14_4h, 48)
    roc_9_4h = np_view("ROC_9_4h")
    roc_9_4h_shift_48 = np_shift(roc_9_4h, 48)
    aroonu_14_1h = np_view("AROONU_14_1h")
    stochrsi_k_4h = np_view("STOCHRSIk_14_14_3_3_4h")
    stochrsi_k_1h = np_view("STOCHRSIk_14_14_3_3_1h")
    aroonu_14_1d = np_view("AROONU_14_1d")
    rsi_3_1d = np_view("RSI_3_1d")
    aroonu_14_15m = np_view("AROONU_14_15m")
    roc_9_1h = np_view("ROC_9_1h")
    stochrsi_k_15m = np_view("STOCHRSIk_14_14_3_3_15m")
    stochrsi_k_1d = np_view("STOCHRSIk_14_14_3_3_1d")
    rsi_3 = np_view("RSI_3")
    close = np_view("close")
    high_px = np_view("high")
    low_px = np_view("low")
    orange_h = np_view("ORANGE_H")
    orange_l = np_view("ORANGE_L")
    willr_14_4h = np_view("WILLR_14_4h")
    btc_roc_1_5m = np_view("btc_roc_1_5m")
    btc_roc_1_4h = np_view("BTC_ROC_1_4h")
    stoch_k_4h = np_view("STOCHk_14_3_3_4h")

    sqz_on = np_view("SQZ_ON")
    sqz_cnt_24 = np_view("SQZ_CNT_24")
    stoch_9_3 = np_view("STOCH_9_3")
    stoch_14_3 = np_view("STOCH_14_3")
    stoch_4_4 = np_view("STOCH_4_4")
    stoch_60_10 = np_view("STOCH_60_10")
    quad_low_min_12 = np_view("QUAD_LOW_MIN_12")
    quad_high_max_12 = np_view("QUAD_HIGH_MAX_12")
    quad_s93_min_12 = np_view("QUAD_S93_MIN_12")
    quad_s93_max_12 = np_view("QUAD_S93_MAX_12")
    bbp_20_2_0_4h = np_view("BBP_20_2.0_4h")
    obv_change_pct = np_view("OBV_change_pct")
    open_rate = np_view("open")
    roc_9_15m = np_view("ROC_9_15m")
    rsi_14_4h = np_view("RSI_14_4h")
    rsi_14_4h_shift_48 = np_shift(rsi_14_4h, 48)
    roc_2_1d = np_view("ROC_2_1d")
    uo_7_14_28_4h = np_view("UO_7_14_28_4h")
    willr_84_1h = np_view("WILLR_84_1h")
    mfi_14 = np_view("MFI_14")
    volume = np_view("volume")
    large_bubble_thr = np_view("LARGE_BUBBLE_THR")
    cvd_buy_vol = np_view("CVD_BUY_VOL")
    cvd_sell_vol = np_view("CVD_SELL_VOL")

    # Reused entry Series and comparison masks
    aroond_14 = np_view("AROOND_14")
    aroond_14_15m = np_view("AROOND_14_15m")
    aroond_14_1h = np_view("AROOND_14_1h")
    aroond_14_4h = np_view("AROOND_14_4h")
    aroonu_14 = np_view("AROONU_14")
    bbb_20_2_0 = np_view("BBB_20_2.0")
    bbb_20_2_0_1h = np_view("BBB_20_2.0_1h")
    bbl_20_2_0 = np_view("BBL_20_2.0")
    bbu_20_2_0 = np_view("BBU_20_2.0")
    _bb_rng = bbu_20_2_0 - bbl_20_2_0
    bbp_20_2_0 = np.divide(close - bbl_20_2_0, _bb_rng, out=np.full_like(_bb_rng, np.nan), where=_bb_rng != 0)
    # 1h band position for confluence signals (67/70/71 family)
    bbl_20_2_0_1h = np_view("BBL_20_2.0_1h")
    bbu_20_2_0_1h = np_view("BBU_20_2.0_1h")
    _bb_rng_1h = bbu_20_2_0_1h - bbl_20_2_0_1h
    bbp_20_2_0_1h = np.divide(
      close - bbl_20_2_0_1h, _bb_rng_1h, out=np.full_like(_bb_rng_1h, np.nan), where=_bb_rng_1h != 0
    )
    cci_20_change_pct_1h = np_view("CCI_20_change_pct_1h")
    cci_20_1h = np_view("CCI_20_1h")
    cci_20_4h = np_view("CCI_20_4h")
    cci_20_change_pct_4h = np_view("CCI_20_change_pct_4h")
    change_pct_1d = np_view("change_pct_1d")
    change_pct_1d_shift_288 = np_shift(change_pct_1d, 288)
    change_pct_1h = np_view("change_pct_1h")
    change_pct_1h_shift_12 = np_shift(change_pct_1h, 12)
    change_pct_4h = np_view("change_pct_4h")
    change_pct_4h_shift_48 = np_shift(change_pct_4h, 48)
    close_max_12 = np_view("close_max_12")
    close_max_48 = np_view("close_max_48")
    cmf_20 = np_view("CMF_20")
    cmf_20_15m = np_view("CMF_20_15m")
    cmf_20_1d = np_view("CMF_20_1d")
    cmf_20_1h = np_view("CMF_20_1h")
    cmf_20_4h = np_view("CMF_20_4h")
    ema_12 = np_view("EMA_12")
    ema_12_shift_1 = np_shift(ema_12, 1)
    ema_12_15m = np_view("EMA_12_15m")
    ema_12_15m_shift_1 = np_shift(ema_12_15m, 1)
    ema_12_4h = np_view("EMA_12_4h")
    ema_20 = np_view("EMA_20")
    ema_26 = np_view("EMA_26")
    ema_26_shift_1 = np_shift(ema_26, 1)
    ema_26_15m = np_view("EMA_26_15m")
    ema_26_15m_shift_1 = np_shift(ema_26_15m, 1)
    ema_50_15m = np_view("EMA_50_15m")
    ema_200_15m = np_view("EMA_200_15m")
    ema_200 = np_view("EMA_200")
    ema_200_1h = np_view("EMA_200_1h")
    ema_200_4h = np_view("EMA_200_4h")
    ema_200_1d = np_view("EMA_200_1d")
    ema_12_1h = np_view("EMA_12_1h")
    # pattern column, 0/1 like the rest, so a NaN the merge leaves behind reads as false
    s174_event_1h = np_view("s174_event_1h")
    # the NR4 break fires on the hour it closes, so the row has to be that hour's last 5m candle
    s174_hour_closed = df["date"].eq(df["date_1h"] + timedelta(minutes=55)).to_numpy()
    ema_9 = np_view("EMA_9")
    high_max_12_1d = np_view("high_max_12_1d")
    high_max_12_4h = np_view("high_max_12_4h")
    high_max_20_1d = np_view("high_max_20_1d")
    high_max_24_4h = np_view("high_max_24_4h")
    high_max_30_1d = np_view("high_max_30_1d")
    high_max_6_1d = np_view("high_max_6_1d")
    high_max_6_4h = np_view("high_max_6_4h")
    low_min_12_1d = np_view("low_min_12_1d")
    low_min_24_4h = np_view("low_min_24_4h")
    mfi_14_15m = np_view("MFI_14_15m")
    mfi_14_1h = np_view("MFI_14_1h")
    num_empty_288 = np_view("num_empty_288")
    protections_long_global = np_view("protections_long_global")
    protections_short_global = np_view("protections_short_global")
    global_protections_long_pump = np_view("global_protections_long_pump")
    global_protections_long_dump = np_view("global_protections_long_dump")

    engulf_bull = np_view("ENGULF_BULL")
    engulf_bear = np_view("ENGULF_BEAR")

    sfp_bull = np_view("SFP_BULL")
    sfp_bear = np_view("SFP_BEAR")
    ib_ready = np_view("IB_READY")
    ib_mother_h = np_view("IB_MOTHER_H")
    ib_mother_l = np_view("IB_MOTHER_L")
    roc_288 = np_view("ROC_288")
    vol_rel = np_view("VOL_REL")
    ph_cross_cnt_12 = np_view("PH_CROSS_CNT_12")
    ph_base_pos = np_view("PH_BASE_POS")
    ph_pre_tight = np_view("PH_PRE_TIGHT")
    mrb_bull = np_view("MRB_BULL")
    mrb_bear = np_view("MRB_BEAR")
    dh_prev_min = np_view("DH_PREV_MIN")
    pb_hammer = np_view("PB_HAMMER")
    pb_star = np_view("PB_STAR")
    adx_14_4h = np_view("ADX_14_4h")
    plus_di_14_4h = np_view("PLUS_DI_14_4h")
    minus_di_14_4h = np_view("MINUS_DI_14_4h")
    dc_high_7d = np_view("DC_HIGH_7D")
    dc_low_7d = np_view("DC_LOW_7D")
    global_protections_short_pump = np_view("global_protections_short_pump")
    global_protections_short_dump = np_view("global_protections_short_dump")
    roc_2 = np_view("ROC_2")
    roc_9 = np_view("ROC_9")
    rsi_14 = np_view("RSI_14")
    rsi_14_15m = np_view("RSI_14_15m")
    rsi_14_1d = np_view("RSI_14_1d")
    rsi_14_1h = np_view("RSI_14_1h")
    rsi_14_1h_shift_12 = np_shift(rsi_14_1h, 12)
    rsi_20 = np_view("RSI_20")
    rsi_20_shift_1 = np_shift(rsi_20, 1)
    rsi_3_change_pct_1h = np_view("RSI_3_change_pct_1h")
    rsi_3_change_pct_4h = np_view("RSI_3_change_pct_4h")
    rsi_4 = np_view("RSI_4")
    sma_16 = np_view("SMA_16")
    sma_21 = np_view("SMA_21")
    sma_21_shift_1 = np_shift(sma_21, 1)
    sma_200 = np_view("SMA_200")
    sma_200_shift_1 = np_shift(sma_200, 1)
    stochrsi_k = np_view("STOCHRSIk_14_14_3_3")
    top_wick_pct_1d = np_view("top_wick_pct_1d")
    top_wick_pct_1d_shift_288 = np_shift(top_wick_pct_1d, 288)
    willr_14 = np_view("WILLR_14")
    willr_14_1h = np_view("WILLR_14_1h")
    obv_change_pct_15m = np_view("OBV_change_pct_15m")
    high_max_6_1h = np_view("high_max_6_1h")
    high_max_12_1h = np_view("high_max_12_1h")
    high_max_24_1h = np_view("high_max_24_1h")
    sma_16_1h = np_view("SMA_16_1h")
    ema_16 = np_view("EMA_16")
    ema_20_15m = np_view("EMA_20_15m")
    ema_50 = np_view("EMA_50")
    open_15m = np_view("open_15m")
    top_wick_pct_4h = np_view("top_wick_pct_4h")
    low_min_6_1d = np_view("low_min_6_1d")
    willr_14_15m = np_view("WILLR_14_15m")
    close_15m = np_view("close_15m")
    change_pct = np_view("change_pct")
    low_min_20_1d = np_view("low_min_20_1d")
    low_min_24_1h = np_view("low_min_24_1h")
    low_min_6_1h = np_view("low_min_6_1h")
    sma_9 = np_view("SMA_9")
    mfi_14_4h = np_view("MFI_14_4h")
    cci_20_change_pct_15m = np_view("CCI_20_change_pct_15m")
    close_min_6 = np_view("close_min_6")
    close_min_12 = np_view("close_min_12")
    close_min_48 = np_view("close_min_48")
    uo_7_14_28_1h = np_view("UO_7_14_28_1h")
    rsi_14_change_pct = np_view("RSI_14_change_pct")
    range_pct_14_1d = np_view("RANGE_PCT_14_1d")
    mfi_14_1d = np_view("MFI_14_1d")
    rsi_14_change_pct_15m = np_view("RSI_14_change_pct_15m")
    rsi_3_change_pct_1d = np_view("RSI_3_change_pct_1d")
    rsi_14_change_pct_1h = np_view("RSI_14_change_pct_1h")
    roc_2_1h = np_view("ROC_2_1h")
    roc_2_4h = np_view("ROC_2_4h")
    change_pct_15m = np_view("change_pct_15m")
    cci_20_15m = np_view("CCI_20_15m")
    aroond_14_1d = np_view("AROOND_14_1d")
    bot_wick_pct_1d = np_view("bot_wick_pct_1d")
    low_min_12_1h = np_view("low_min_12_1h")
    low_min_30_1d = np_view("low_min_30_1d")
    rsi_14_change_pct_4h = np_view("RSI_14_change_pct_4h")
    stochk_14_3_3_15m = np_view("STOCHk_14_3_3_15m")
    stochk_14_3_3_1h = np_view("STOCHk_14_3_3_1h")
    uo_7_14_28_15m = np_view("UO_7_14_28_15m")
    stochk_14_3_3_4h = np_view("STOCHk_14_3_3_4h")
    stochk_14_3_3_1d = np_view("STOCHk_14_3_3_1d")
    willr_14_1d = np_view("WILLR_14_1d")
    uo_7_14_28_change_pct_15m = np_view("UO_7_14_28_change_pct_15m")
    stochrsi_k_change_pct_4h = np_view("STOCHRSIk_14_14_3_3_change_pct_4h")
    willr_480 = np_view("WILLR_480")
    rsi_3_change_pct_15m = np_view("RSI_3_change_pct_15m")
    close_max_6 = np_view("close_max_6")
    bbd_40_2_0 = np_view("BBD_40_2.0")
    bbt_40_2_0 = np_view("BBT_40_2.0")
    bbl_40_2_0 = np_view("BBL_40_2.0")
    close_shift_1 = np_shift(close, 1)
    bbl_40_2_0_shift_1 = np_shift(bbl_40_2_0, 1)
    close_delta = np_view("close_delta")

    rsi_3_gt_3 = rsi_3 > 3.0
    rsi_3_gt_5 = rsi_3 > 5.0
    rsi_3_gt_10 = rsi_3 > 10.0
    rsi_3_gt_15 = rsi_3 > 15.0
    rsi_3_15m_gt_3 = rsi_3_15m > 3.0
    rsi_3_15m_gt_5 = rsi_3_15m > 5.0
    rsi_3_15m_gt_10 = rsi_3_15m > 10.0
    rsi_3_15m_gt_15 = rsi_3_15m > 15.0
    rsi_3_15m_gt_20 = rsi_3_15m > 20.0
    rsi_3_15m_gt_25 = rsi_3_15m > 25.0
    rsi_3_15m_gt_30 = rsi_3_15m > 30.0
    rsi_3_15m_gt_35 = rsi_3_15m > 35.0
    rsi_3_15m_gt_40 = rsi_3_15m > 40.0
    rsi_3_15m_gt_45 = rsi_3_15m > 45.0
    rsi_3_15m_gt_50 = rsi_3_15m > 50.0
    rsi_3_15m_gt_55 = rsi_3_15m > 55.0
    rsi_3_1h_gt_3 = rsi_3_1h > 3.0
    rsi_3_1h_gt_5 = rsi_3_1h > 5.0
    rsi_3_1h_gt_10 = rsi_3_1h > 10.0
    rsi_3_1h_gt_15 = rsi_3_1h > 15.0
    rsi_3_1h_gt_20 = rsi_3_1h > 20.0
    rsi_3_1h_gt_25 = rsi_3_1h > 25.0
    rsi_3_1h_gt_30 = rsi_3_1h > 30.0
    rsi_3_1h_gt_35 = rsi_3_1h > 35.0
    rsi_3_1h_gt_40 = rsi_3_1h > 40.0
    rsi_3_1h_gt_45 = rsi_3_1h > 45.0
    rsi_3_1h_gt_50 = rsi_3_1h > 50.0
    rsi_3_1h_gt_55 = rsi_3_1h > 55.0
    rsi_3_1h_gt_60 = rsi_3_1h > 60.0
    rsi_3_1h_gt_65 = rsi_3_1h > 65.0
    rsi_3_4h_gt_3 = rsi_3_4h > 3.0
    rsi_3_4h_gt_5 = rsi_3_4h > 5.0
    rsi_3_4h_gt_10 = rsi_3_4h > 10.0
    rsi_3_4h_gt_15 = rsi_3_4h > 15.0
    rsi_3_4h_gt_20 = rsi_3_4h > 20.0
    rsi_3_4h_gt_25 = rsi_3_4h > 25.0
    rsi_3_4h_gt_30 = rsi_3_4h > 30.0
    rsi_3_4h_gt_35 = rsi_3_4h > 35.0
    rsi_3_4h_gt_40 = rsi_3_4h > 40.0
    rsi_3_4h_gt_45 = rsi_3_4h > 45.0
    rsi_3_4h_gt_50 = rsi_3_4h > 50.0
    rsi_3_4h_gt_55 = rsi_3_4h > 55.0
    rsi_3_4h_gt_60 = rsi_3_4h > 60.0
    rsi_3_4h_gt_65 = rsi_3_4h > 65.0
    rsi_3_1d_gt_3 = rsi_3_1d > 3.0
    rsi_3_1d_gt_5 = rsi_3_1d > 5.0
    rsi_3_1d_gt_10 = rsi_3_1d > 10.0
    rsi_3_1d_gt_15 = rsi_3_1d > 15.0
    rsi_3_1d_gt_20 = rsi_3_1d > 20.0
    rsi_3_1d_gt_25 = rsi_3_1d > 25.0
    rsi_3_1d_gt_30 = rsi_3_1d > 30.0
    rsi_3_1d_gt_35 = rsi_3_1d > 35.0
    rsi_3_1d_gt_40 = rsi_3_1d > 40.0
    rsi_3_1d_gt_45 = rsi_3_1d > 45.0
    rsi_3_1d_gt_50 = rsi_3_1d > 50.0
    rsi_3_1d_gt_55 = rsi_3_1d > 55.0
    rsi_3_1d_gt_60 = rsi_3_1d > 60.0
    rsi_3_1d_gt_65 = rsi_3_1d > 65.0
    rsi_3_lt_40 = rsi_3 < 40.0
    rsi_3_lt_46 = rsi_3 < 46.0
    rsi_3_lt_50 = rsi_3 < 50.0
    rsi_3_lt_90 = rsi_3 < 90.0
    rsi_3_lt_95 = rsi_3 < 95.0
    rsi_3_lt_97 = rsi_3 < 97.0
    rsi_3_lt_98 = rsi_3 < 98.0
    rsi_3_15m_lt_50 = rsi_3_15m < 50.0
    rsi_3_15m_lt_55 = rsi_3_15m < 55.0
    rsi_3_15m_lt_60 = rsi_3_15m < 60.0
    rsi_3_15m_lt_70 = rsi_3_15m < 70.0
    rsi_3_15m_lt_75 = rsi_3_15m < 75.0
    rsi_3_15m_lt_80 = rsi_3_15m < 80.0
    rsi_3_15m_lt_85 = rsi_3_15m < 85.0
    rsi_3_15m_lt_90 = rsi_3_15m < 90.0
    rsi_3_15m_lt_95 = rsi_3_15m < 95.0
    rsi_3_15m_lt_97 = rsi_3_15m < 97.0
    rsi_3_1h_lt_40 = rsi_3_1h < 40.0
    rsi_3_1h_lt_50 = rsi_3_1h < 50.0
    rsi_3_1h_lt_55 = rsi_3_1h < 55.0
    rsi_3_1h_lt_60 = rsi_3_1h < 60.0
    rsi_3_1h_lt_65 = rsi_3_1h < 65.0
    rsi_3_1h_lt_70 = rsi_3_1h < 70.0
    rsi_3_1h_lt_75 = rsi_3_1h < 75.0
    rsi_3_1h_lt_80 = rsi_3_1h < 80.0
    rsi_3_1h_lt_85 = rsi_3_1h < 85.0
    rsi_3_1h_lt_90 = rsi_3_1h < 90.0
    rsi_3_1h_lt_95 = rsi_3_1h < 95.0
    rsi_3_4h_lt_40 = rsi_3_4h < 40.0
    rsi_3_4h_lt_50 = rsi_3_4h < 50.0
    rsi_3_4h_lt_60 = rsi_3_4h < 60.0
    rsi_3_4h_lt_70 = rsi_3_4h < 70.0
    rsi_3_4h_lt_75 = rsi_3_4h < 75.0
    rsi_3_4h_lt_80 = rsi_3_4h < 80.0
    rsi_3_4h_lt_85 = rsi_3_4h < 85.0
    rsi_3_4h_lt_90 = rsi_3_4h < 90.0
    rsi_3_4h_lt_95 = rsi_3_4h < 95.0
    rsi_3_1d_lt_35 = rsi_3_1d < 35.0
    rsi_3_1d_lt_80 = rsi_3_1d < 80.0
    rsi_3_1d_lt_90 = rsi_3_1d < 90.0
    rsi_3_1d_lt_95 = rsi_3_1d < 95.0
    rsi_14_15m_lt_30 = rsi_14_15m < 30.0
    rsi_14_15m_lt_35 = rsi_14_15m < 35.0
    rsi_14_15m_lt_40 = rsi_14_15m < 40.0
    rsi_14_15m_lt_50 = rsi_14_15m < 50.0
    rsi_14_1h_gt_20 = rsi_14_1h > 20.0
    rsi_14_1h_gt_65 = rsi_14_1h > 65.0
    rsi_14_1h_lt_30 = rsi_14_1h < 30.0
    rsi_14_1h_lt_40 = rsi_14_1h < 40.0
    rsi_14_1h_lt_50 = rsi_14_1h < 50.0
    rsi_14_1h_lt_80 = rsi_14_1h < 80.0
    rsi_14_4h_gt_20 = rsi_14_4h > 20.0
    rsi_14_4h_gt_30 = rsi_14_4h > 30.0
    rsi_14_4h_gt_40 = rsi_14_4h > 40.0
    rsi_14_4h_gt_50 = rsi_14_4h > 50.0
    rsi_14_4h_gt_60 = rsi_14_4h > 60.0
    rsi_14_4h_gt_80 = rsi_14_4h > 80.0
    rsi_14_4h_lt_30 = rsi_14_4h < 30.0
    rsi_14_4h_lt_40 = rsi_14_4h < 40.0
    rsi_14_4h_lt_50 = rsi_14_4h < 50.0
    rsi_14_4h_lt_68 = rsi_14_4h < 68.0
    rsi_14_4h_lt_70 = rsi_14_4h < 70.0
    rsi_14_4h_lt_75 = rsi_14_4h < 75.0
    rsi_14_4h_lt_80 = rsi_14_4h < 80.0
    rsi_14_1d_gt_10 = rsi_14_1d > 10.0
    rsi_14_1d_gt_40 = rsi_14_1d > 40.0
    rsi_14_1d_gt_45 = rsi_14_1d > 45.0
    rsi_14_1d_gt_50 = rsi_14_1d > 50.0
    rsi_14_1d_gt_60 = rsi_14_1d > 60.0
    rsi_14_1d_lt_40 = rsi_14_1d < 40.0
    rsi_14_1d_lt_50 = rsi_14_1d < 50.0
    rsi_14_1d_lt_60 = rsi_14_1d < 60.0
    rsi_14_1d_lt_70 = rsi_14_1d < 70.0
    rsi_14_1d_lt_75 = rsi_14_1d < 75.0
    rsi_14_1d_lt_80 = rsi_14_1d < 80.0

    aroond_14_lt_25 = aroond_14 < 25.0
    aroond_14_gt_75 = aroond_14 > 75.0
    aroond_14_15m_lt_25 = aroond_14_15m < 25.0
    aroond_14_15m_lt_50 = aroond_14_15m < 50.0
    aroond_14_15m_lt_70 = aroond_14_15m < 70.0
    aroond_14_15m_lt_80 = aroond_14_15m < 80.0
    aroond_14_1h_lt_25 = aroond_14_1h < 25.0
    aroond_14_1h_lt_50 = aroond_14_1h < 50.0
    aroond_14_1h_lt_70 = aroond_14_1h < 70.0
    aroond_14_4h_lt_25 = aroond_14_4h < 25.0
    aroond_14_4h_lt_40 = aroond_14_4h < 40.0
    aroond_14_4h_lt_50 = aroond_14_4h < 50.0
    aroond_14_4h_lt_70 = aroond_14_4h < 70.0
    aroond_14_4h_lt_80 = aroond_14_4h < 80.0
    aroond_14_4h_lt_85 = aroond_14_4h < 85.0
    aroonu_14_gt_75 = aroonu_14 > 75.0
    aroonu_14_15m_gt_0 = aroonu_14_15m > 0.0
    aroonu_14_15m_gt_10 = aroonu_14_15m > 10.0
    aroonu_14_15m_gt_20 = aroonu_14_15m > 20.0
    aroonu_14_15m_gt_30 = aroonu_14_15m > 30.0
    aroonu_14_15m_gt_40 = aroonu_14_15m > 40.0
    aroonu_14_15m_gt_50 = aroonu_14_15m > 50.0
    aroonu_14_15m_gt_60 = aroonu_14_15m > 60.0
    aroonu_14_1h_gt_0 = aroonu_14_1h > 0.0
    aroonu_14_1h_gt_10 = aroonu_14_1h > 10.0
    aroonu_14_1h_gt_20 = aroonu_14_1h > 20.0
    aroonu_14_1h_gt_30 = aroonu_14_1h > 30.0
    aroonu_14_1h_gt_40 = aroonu_14_1h > 40.0
    aroonu_14_1h_gt_60 = aroonu_14_1h > 60.0
    aroonu_14_4h_gt_0 = aroonu_14_4h > 0.0
    aroonu_14_4h_gt_10 = aroonu_14_4h > 10.0
    aroonu_14_4h_gt_20 = aroonu_14_4h > 20.0
    aroonu_14_4h_gt_30 = aroonu_14_4h > 30.0
    aroonu_14_4h_gt_50 = aroonu_14_4h > 50.0
    aroonu_14_4h_gt_70 = aroonu_14_4h > 70.0
    aroonu_14_4h_gt_80 = aroonu_14_4h > 80.0
    aroonu_14_1d_gt_0 = aroonu_14_1d > 0.0
    aroonu_14_1d_gt_10 = aroonu_14_1d > 10.0
    aroonu_14_1d_gt_20 = aroonu_14_1d > 20.0
    aroonu_14_1d_gt_30 = aroonu_14_1d > 30.0
    aroonu_14_1d_gt_50 = aroonu_14_1d > 50.0
    aroonu_14_lt_25 = aroonu_14 < 25.0
    aroonu_14_lt_30 = aroonu_14 < 30.0
    aroonu_14_15m_lt_20 = aroonu_14_15m < 20.0
    aroonu_14_15m_lt_25 = aroonu_14_15m < 25.0
    aroonu_14_15m_lt_30 = aroonu_14_15m < 30.0
    aroonu_14_15m_lt_40 = aroonu_14_15m < 40.0
    aroonu_14_15m_lt_50 = aroonu_14_15m < 50.0
    aroonu_14_15m_lt_60 = aroonu_14_15m < 60.0
    aroonu_14_15m_lt_70 = aroonu_14_15m < 70.0
    aroonu_14_15m_lt_75 = aroonu_14_15m < 75.0
    aroonu_14_15m_lt_80 = aroonu_14_15m < 80.0
    aroonu_14_15m_lt_85 = aroonu_14_15m < 85.0
    aroonu_14_15m_lt_90 = aroonu_14_15m < 90.0
    aroonu_14_15m_lt_100 = aroonu_14_15m < 100.0
    aroonu_14_1h_lt_20 = aroonu_14_1h < 20.0
    aroonu_14_1h_lt_25 = aroonu_14_1h < 25.0
    aroonu_14_1h_lt_30 = aroonu_14_1h < 30.0
    aroonu_14_1h_lt_40 = aroonu_14_1h < 40.0
    aroonu_14_1h_lt_50 = aroonu_14_1h < 50.0
    aroonu_14_1h_lt_60 = aroonu_14_1h < 60.0
    aroonu_14_1h_lt_70 = aroonu_14_1h < 70.0
    aroonu_14_1h_lt_75 = aroonu_14_1h < 75.0
    aroonu_14_1h_lt_80 = aroonu_14_1h < 80.0
    aroonu_14_1h_lt_85 = aroonu_14_1h < 85.0
    aroonu_14_1h_lt_90 = aroonu_14_1h < 90.0
    aroonu_14_1h_lt_100 = aroonu_14_1h < 100.0
    aroonu_14_4h_lt_20 = aroonu_14_4h < 20.0
    aroonu_14_4h_lt_30 = aroonu_14_4h < 30.0
    aroonu_14_4h_lt_40 = aroonu_14_4h < 40.0
    aroonu_14_4h_lt_50 = aroonu_14_4h < 50.0
    aroonu_14_4h_lt_60 = aroonu_14_4h < 60.0
    aroonu_14_4h_lt_70 = aroonu_14_4h < 70.0
    aroonu_14_4h_lt_75 = aroonu_14_4h < 75.0
    aroonu_14_4h_lt_80 = aroonu_14_4h < 80.0
    aroonu_14_4h_lt_85 = aroonu_14_4h < 85.0
    aroonu_14_4h_lt_90 = aroonu_14_4h < 90.0
    aroonu_14_4h_lt_100 = aroonu_14_4h < 100.0
    aroonu_14_1d_lt_30 = aroonu_14_1d < 30.0
    aroonu_14_1d_lt_40 = aroonu_14_1d < 40.0
    aroonu_14_1d_lt_50 = aroonu_14_1d < 50.0
    aroonu_14_1d_lt_60 = aroonu_14_1d < 60.0
    aroonu_14_1d_lt_70 = aroonu_14_1d < 70.0
    aroonu_14_1d_lt_75 = aroonu_14_1d < 75.0
    aroonu_14_1d_lt_80 = aroonu_14_1d < 80.0
    aroonu_14_1d_lt_85 = aroonu_14_1d < 85.0
    aroonu_14_1d_lt_90 = aroonu_14_1d < 90.0
    aroonu_14_1d_lt_100 = aroonu_14_1d < 100.0

    cmf_20_15m_gt_neg_0_10 = cmf_20_15m > -0.10
    cmf_20_15m_gt_neg_0_20 = cmf_20_15m > -0.20
    cmf_20_15m_gt_neg_0_30 = cmf_20_15m > -0.30
    cmf_20_15m_gt_neg_0_35 = cmf_20_15m > -0.35
    cmf_20_15m_gt_neg_0_40 = cmf_20_15m > -0.40
    cmf_20_15m_gt_neg_0_50 = cmf_20_15m > -0.50
    cmf_20_15m_lt_0_10 = cmf_20_15m < 0.10
    cmf_20_15m_lt_0_20 = cmf_20_15m < 0.20
    cmf_20_15m_lt_0_30 = cmf_20_15m < 0.30
    cmf_20_1h_gt_neg_0_10 = cmf_20_1h > -0.10
    cmf_20_1h_gt_neg_0_20 = cmf_20_1h > -0.20
    cmf_20_1h_gt_neg_0_25 = cmf_20_1h > -0.25
    cmf_20_1h_gt_neg_0_30 = cmf_20_1h > -0.30
    cmf_20_1h_gt_neg_0_40 = cmf_20_1h > -0.40
    cmf_20_1h_lt_0_10 = cmf_20_1h < 0.10
    cmf_20_1h_lt_0_20 = cmf_20_1h < 0.20
    cmf_20_1h_lt_0_30 = cmf_20_1h < 0.30
    cmf_20_4h_gt_neg_0_0 = cmf_20_4h > -0.0
    cmf_20_4h_gt_neg_0_10 = cmf_20_4h > -0.10
    cmf_20_4h_gt_neg_0_20 = cmf_20_4h > -0.20
    cmf_20_4h_gt_neg_0_25 = cmf_20_4h > -0.25
    cmf_20_4h_gt_neg_0_30 = cmf_20_4h > -0.30
    cmf_20_4h_gt_neg_0_35 = cmf_20_4h > -0.35
    cmf_20_4h_gt_neg_0_40 = cmf_20_4h > -0.40
    cmf_20_4h_gt_neg_0_50 = cmf_20_4h > -0.50
    cmf_20_4h_lt_0_15 = cmf_20_4h < 0.15
    cmf_20_1d_gt_neg_0_0 = cmf_20_1d > -0.0
    cmf_20_1d_gt_neg_0_10 = cmf_20_1d > -0.10
    cmf_20_1d_gt_neg_0_20 = cmf_20_1d > -0.20
    cmf_20_1d_gt_neg_0_25 = cmf_20_1d > -0.25
    cmf_20_1d_gt_neg_0_30 = cmf_20_1d > -0.30
    cmf_20_1d_gt_neg_0_40 = cmf_20_1d > -0.40
    cmf_20_1d_gt_neg_0_50 = cmf_20_1d > -0.50
    cmf_20_1d_lt_0_10 = cmf_20_1d < 0.10

    stochrsi_k_lt_20 = stochrsi_k < 20.0
    stochrsi_k_lt_30 = stochrsi_k < 30.0
    stochrsi_k_gt_80 = stochrsi_k > 80.0
    stochrsi_k_15m_gt_10 = stochrsi_k_15m > 10.0
    stochrsi_k_15m_gt_20 = stochrsi_k_15m > 20.0
    stochrsi_k_15m_gt_30 = stochrsi_k_15m > 30.0
    stochrsi_k_15m_gt_40 = stochrsi_k_15m > 40.0
    stochrsi_k_15m_gt_50 = stochrsi_k_15m > 50.0
    stochrsi_k_15m_gt_60 = stochrsi_k_15m > 60.0
    stochrsi_k_15m_gt_70 = stochrsi_k_15m > 70.0
    stochrsi_k_15m_gt_80 = stochrsi_k_15m > 80.0
    stochrsi_k_15m_gt_90 = stochrsi_k_15m > 90.0
    stochrsi_k_4h_gt_10 = stochrsi_k_4h > 10.0
    stochrsi_k_4h_gt_20 = stochrsi_k_4h > 20.0
    stochrsi_k_4h_gt_30 = stochrsi_k_4h > 30.0
    stochrsi_k_4h_gt_40 = stochrsi_k_4h > 40.0
    stochrsi_k_4h_gt_50 = stochrsi_k_4h > 50.0
    stochrsi_k_4h_gt_60 = stochrsi_k_4h > 60.0
    stochrsi_k_4h_gt_70 = stochrsi_k_4h > 70.0
    stochrsi_k_4h_gt_75 = stochrsi_k_4h > 75.0
    stochrsi_k_4h_gt_80 = stochrsi_k_4h > 80.0
    stochrsi_k_4h_gt_90 = stochrsi_k_4h > 90.0
    stochrsi_k_15m_lt_20 = stochrsi_k_15m < 20.0
    stochrsi_k_15m_lt_30 = stochrsi_k_15m < 30.0
    stochrsi_k_15m_lt_40 = stochrsi_k_15m < 40.0
    stochrsi_k_15m_lt_50 = stochrsi_k_15m < 50.0
    stochrsi_k_15m_lt_60 = stochrsi_k_15m < 60.0
    stochrsi_k_15m_lt_70 = stochrsi_k_15m < 70.0
    stochrsi_k_15m_lt_80 = stochrsi_k_15m < 80.0
    stochrsi_k_1h_gt_10 = stochrsi_k_1h > 10.0
    stochrsi_k_1h_gt_20 = stochrsi_k_1h > 20.0
    stochrsi_k_1h_gt_30 = stochrsi_k_1h > 30.0
    stochrsi_k_1h_gt_40 = stochrsi_k_1h > 40.0
    stochrsi_k_1h_gt_50 = stochrsi_k_1h > 50.0
    stochrsi_k_1h_gt_60 = stochrsi_k_1h > 60.0
    stochrsi_k_1h_gt_70 = stochrsi_k_1h > 70.0
    stochrsi_k_1h_gt_75 = stochrsi_k_1h > 75.0
    stochrsi_k_1h_gt_80 = stochrsi_k_1h > 80.0
    stochrsi_k_1h_gt_90 = stochrsi_k_1h > 90.0
    stochrsi_k_1h_lt_20 = stochrsi_k_1h < 20.0
    stochrsi_k_1h_lt_30 = stochrsi_k_1h < 30.0
    stochrsi_k_1h_lt_40 = stochrsi_k_1h < 40.0
    stochrsi_k_1h_lt_50 = stochrsi_k_1h < 50.0
    stochrsi_k_1h_lt_60 = stochrsi_k_1h < 60.0
    stochrsi_k_1h_lt_70 = stochrsi_k_1h < 70.0
    stochrsi_k_1h_lt_80 = stochrsi_k_1h < 80.0
    stochrsi_k_1h_lt_90 = stochrsi_k_1h < 90.0
    stochrsi_k_4h_lt_10 = stochrsi_k_4h < 10.0
    stochrsi_k_4h_lt_20 = stochrsi_k_4h < 20.0
    stochrsi_k_4h_lt_30 = stochrsi_k_4h < 30.0
    stochrsi_k_4h_lt_40 = stochrsi_k_4h < 40.0
    stochrsi_k_4h_lt_50 = stochrsi_k_4h < 50.0
    stochrsi_k_4h_lt_60 = stochrsi_k_4h < 60.0
    stochrsi_k_4h_lt_70 = stochrsi_k_4h < 70.0
    stochrsi_k_4h_lt_80 = stochrsi_k_4h < 80.0
    stochrsi_k_4h_lt_90 = stochrsi_k_4h < 90.0
    stochrsi_k_1d_gt_10 = stochrsi_k_1d > 10.0
    stochrsi_k_1d_gt_20 = stochrsi_k_1d > 20.0
    stochrsi_k_1d_gt_30 = stochrsi_k_1d > 30.0
    stochrsi_k_1d_gt_40 = stochrsi_k_1d > 40.0
    stochrsi_k_1d_gt_50 = stochrsi_k_1d > 50.0
    stochrsi_k_1d_gt_60 = stochrsi_k_1d > 60.0
    stochrsi_k_1d_gt_70 = stochrsi_k_1d > 70.0
    stochrsi_k_1d_lt_20 = stochrsi_k_1d < 20.0
    stochrsi_k_1d_lt_30 = stochrsi_k_1d < 30.0
    stochrsi_k_1d_lt_40 = stochrsi_k_1d < 40.0
    stochrsi_k_1d_lt_50 = stochrsi_k_1d < 50.0
    stochrsi_k_1d_lt_60 = stochrsi_k_1d < 60.0
    stochrsi_k_1d_lt_70 = stochrsi_k_1d < 70.0
    stochrsi_k_1d_lt_80 = stochrsi_k_1d < 80.0
    stochrsi_k_1d_lt_90 = stochrsi_k_1d < 90.0

    roc_9_1h_lt_10 = roc_9_1h < 10.0
    roc_9_1h_gt_neg_50 = roc_9_1h > -50.0
    roc_9_1h_gt_neg_40 = roc_9_1h > -40.0
    roc_9_1h_gt_neg_30 = roc_9_1h > -30.0
    roc_9_1h_gt_neg_25 = roc_9_1h > -25.0
    roc_9_1h_gt_neg_20 = roc_9_1h > -20.0
    roc_9_1h_gt_neg_15 = roc_9_1h > -15.0
    roc_9_1h_gt_neg_10 = roc_9_1h > -10.0
    roc_9_1h_lt_15 = roc_9_1h < 15.0
    roc_9_1h_lt_20 = roc_9_1h < 20.0
    roc_9_1h_lt_25 = roc_9_1h < 25.0
    roc_9_1h_lt_30 = roc_9_1h < 30.0
    roc_9_1h_lt_40 = roc_9_1h < 40.0
    roc_9_1h_lt_50 = roc_9_1h < 50.0
    roc_9_1h_lt_60 = roc_9_1h < 60.0
    roc_9_1h_lt_80 = roc_9_1h < 80.0
    roc_9_1h_lt_100 = roc_9_1h < 100.0
    roc_9_4h_gt_neg_30 = roc_9_4h > -30.0
    roc_9_4h_gt_neg_70 = roc_9_4h > -70.0
    roc_9_4h_gt_neg_50 = roc_9_4h > -50.0
    roc_9_4h_gt_neg_40 = roc_9_4h > -40.0
    roc_9_4h_gt_neg_35 = roc_9_4h > -35.0
    roc_9_4h_gt_neg_25 = roc_9_4h > -25.0
    roc_9_4h_gt_neg_15 = roc_9_4h > -15.0
    roc_9_4h_gt_neg_10 = roc_9_4h > -10.0
    roc_9_4h_gt_neg_20 = roc_9_4h > -20.0
    roc_9_4h_lt_5 = roc_9_4h < 5.0
    roc_9_4h_lt_10 = roc_9_4h < 10.0
    roc_9_4h_lt_15 = roc_9_4h < 15.0
    roc_9_4h_lt_20 = roc_9_4h < 20.0
    roc_9_4h_lt_25 = roc_9_4h < 25.0
    roc_9_4h_lt_30 = roc_9_4h < 30.0
    roc_9_4h_lt_40 = roc_9_4h < 40.0
    roc_9_4h_lt_50 = roc_9_4h < 50.0
    roc_9_4h_lt_60 = roc_9_4h < 60.0
    roc_9_4h_lt_70 = roc_9_4h < 70.0
    roc_9_4h_lt_80 = roc_9_4h < 80.0
    roc_9_4h_lt_100 = roc_9_4h < 100.0
    roc_9_1d_gt_neg_50 = roc_9_1d > -50.0
    roc_9_1d_gt_neg_100 = roc_9_1d > -100.0
    roc_9_1d_gt_neg_80 = roc_9_1d > -80.0
    roc_9_1d_gt_neg_70 = roc_9_1d > -70.0
    roc_9_1d_gt_neg_60 = roc_9_1d > -60.0
    roc_9_1d_gt_neg_25 = roc_9_1d > -25.0
    roc_9_1d_gt_neg_15 = roc_9_1d > -15.0
    roc_9_1d_gt_neg_10 = roc_9_1d > -10.0
    roc_9_1d_gt_neg_40 = roc_9_1d > -40.0
    roc_9_1d_gt_neg_30 = roc_9_1d > -30.0
    roc_9_1d_gt_neg_20 = roc_9_1d > -20.0
    roc_9_1d_gt_0 = roc_9_1d > 0.0
    roc_9_1d_gt_25 = roc_9_1d > 25.0
    roc_9_1d_gt_30 = roc_9_1d > 30.0
    roc_9_1d_lt_0 = roc_9_1d < 0.0
    roc_9_1d_lt_10 = roc_9_1d < 10.0
    roc_9_1d_lt_15 = roc_9_1d < 15.0
    roc_9_1d_lt_20 = roc_9_1d < 20.0
    roc_9_1d_lt_25 = roc_9_1d < 25.0
    roc_9_1d_lt_30 = roc_9_1d < 30.0
    roc_9_1d_lt_35 = roc_9_1d < 35.0
    roc_9_1d_lt_40 = roc_9_1d < 40.0
    roc_9_1d_lt_50 = roc_9_1d < 50.0
    roc_9_1d_lt_60 = roc_9_1d < 60.0
    roc_9_1d_lt_70 = roc_9_1d < 70.0
    roc_9_1d_lt_80 = roc_9_1d < 80.0
    roc_9_1d_lt_100 = roc_9_1d < 100.0
    roc_9_1d_lt_150 = roc_9_1d < 150.0
    roc_9_1d_lt_200 = roc_9_1d < 200.0
    cci_20_change_pct_1h_gt_neg_0 = cci_20_change_pct_1h > -0.0
    cci_20_change_pct_1h_lt_neg_0 = cci_20_change_pct_1h < -0.0
    cci_20_change_pct_1h_lt_0 = cci_20_change_pct_1h < 0.0
    cci_20_change_pct_4h_lt_neg_0 = cci_20_change_pct_4h < -0.0
    cci_20_change_pct_4h_lt_0 = cci_20_change_pct_4h < 0.0
    change_pct_1d_gt_neg_50 = change_pct_1d > -50.0
    change_pct_1d_gt_neg_30 = change_pct_1d > -30.0
    change_pct_1d_gt_neg_20 = change_pct_1d > -20.0
    change_pct_1d_gt_neg_15 = change_pct_1d > -15.0
    change_pct_1d_gt_neg_10 = change_pct_1d > -10.0
    change_pct_1d_gt_neg_5 = change_pct_1d > -5.0
    change_pct_1d_lt_10 = change_pct_1d < 10.0
    change_pct_1d_lt_15 = change_pct_1d < 15.0
    change_pct_1d_lt_25 = change_pct_1d < 25.0
    change_pct_1d_lt_30 = change_pct_1d < 30.0
    change_pct_1d_lt_40 = change_pct_1d < 40.0
    change_pct_1d_lt_50 = change_pct_1d < 50.0
    top_wick_pct_1d_lt_8 = top_wick_pct_1d < 8.0
    top_wick_pct_1d_lt_10 = top_wick_pct_1d < 10.0
    top_wick_pct_1d_lt_15 = top_wick_pct_1d < 15.0
    top_wick_pct_1d_lt_20 = top_wick_pct_1d < 20.0
    top_wick_pct_1d_lt_25 = top_wick_pct_1d < 25.0
    top_wick_pct_1d_lt_30 = top_wick_pct_1d < 30.0
    top_wick_pct_1d_lt_50 = top_wick_pct_1d < 50.0
    # comparison masks used only by the breakout family (65)
    bbb_20_2_0_1h_gt_20 = bbb_20_2_0_1h > 20.0
    obv_change_pct_15m_lt_50 = obv_change_pct_15m < 50.0
    roc_9_15m_lt_20 = roc_9_15m < 20.0
    rsi_14_change_pct_gt_0 = rsi_14_change_pct > 0.0
    rsi_3_change_pct_1d_gt_neg_20 = rsi_3_change_pct_1d > -20.0

    is_backtest = self.dp.runmode.value in ["backtest", "hyperopt", "plot", "webserver"]
    # the number of free slots
    current_free_slots = config["max_open_trades"]
    if not is_backtest:
      current_free_slots = config["max_open_trades"] - Trade.get_open_trade_count()
    # Grind mode
    pair_coin = metadata["pair"].partition("/")[0]
    num_open_long_grind_mode = 0
    is_pair_long_grind_mode = pair_coin in self.grind_mode_coins
    if not is_backtest:
      open_trades = Trade.get_trades_proxy(is_open=True)
      for open_trade in open_trades:
        enter_tag = open_trade.enter_tag
        if enter_tag is not None:
          enter_tags = enter_tag.split()
          if all(c in self.long_grind_mode_tags for c in enter_tags):
            num_open_long_grind_mode += 1
    # Top Coins mode
    is_pair_long_top_coins_mode = pair_coin in top_coins_mode_coins
    is_pair_short_top_coins_mode = pair_coin in top_coins_mode_coins
    # if BTC/ETH stake
    is_btc_stake = config["stake_currency"] in self.btc_stakes
    allowed_empty_candles_288 = 144 if is_btc_stake else 60

    ###############################################################################################

    # LONG ENTRY CONDITIONS STARTS HERE

    ###############################################################################################

    #
    #  /$$       /$$$$$$ /$$   /$$ /$$$$$$        /$$$$$$$$/$$   /$$/$$$$$$$$/$$$$$$$$/$$$$$$$
    # | $$      /$$__  $| $$$ | $$/$$__  $$      | $$_____| $$$ | $|__  $$__| $$_____| $$__  $$
    # | $$     | $$  \ $| $$$$| $| $$  \__/      | $$     | $$$$| $$  | $$  | $$     | $$  \ $$
    # | $$     | $$  | $| $$ $$ $| $$ /$$$$      | $$$$$  | $$ $$ $$  | $$  | $$$$$  | $$$$$$$/
    # | $$     | $$  | $| $$  $$$| $$|_  $$      | $$__/  | $$  $$$$  | $$  | $$__/  | $$__  $$
    # | $$     | $$  | $| $$\  $$| $$  \ $$      | $$     | $$\  $$$  | $$  | $$     | $$  \ $$
    # | $$$$$$$|  $$$$$$| $$ \  $|  $$$$$$/      | $$$$$$$| $$ \  $$  | $$  | $$$$$$$| $$  | $$
    # |________/\______/|__/  \__/\______/       |________|__/  \__/  |__/  |________|__/  |__/
    #

    for enabled_long_entry_signal in long_entry_signal_params:
      long_entry_condition_index = int(enabled_long_entry_signal.rsplit("_", 2)[1])
      if long_entry_signal_params[enabled_long_entry_signal]:
        # Long Entry Conditions Starts Here
        # -----------------------------------------------------------------------------------------
        long_entry_logic = []
        long_entry_logic.append(True)

        # Condition #1 - Normal mode (Long).
        if long_entry_condition_index == 1:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 15m & 1h down move
            ((rsi_3_gt_3) | (rsi_3_15m_gt_3) | (rsi_3_change_pct_1h > -50.0))
            # 5m & 15m & 1h down move, 1d high & overbought
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_5) | (rsi_3_1h_gt_15) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 5m & 15m down move, 5h high
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_5) | (rsi_14_4h < 60.0))
            # 5m & 15m down move, 4h high
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_10) | aroonu_14_4h_lt_100)
            # 5m & 1h down move
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_5))
            # 5m & 1h down move, 15m still not low enough
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_10) | (aroonu_14_15m_lt_30))
            # 5m & 1h down move, 4h high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 1d still high
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_3) | (stochrsi_k_1d_lt_50))
            # 5m & 1h down move, 15m still not low enough
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_15) | (aroonu_14_15m_lt_30))
            # 5m & 4h down move, 4h high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_25) | aroonu_14_4h_lt_70)
            # 5m down move, 15m high
            & ((rsi_3_gt_3) | (aroonu_14_15m_lt_80))
            # 5m down move, 1h high, 4h overbought
            & ((rsi_3_gt_3) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_20))
            # 5m & 1h & 4h down move, 4h high
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_55) | (aroonu_14_4h_lt_80))
            # 5m & 4h down move, 4h high
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_70))
            # 15m down move, 1h downtrend, 1h high
            & ((rsi_3_15m > 1.0) | (cmf_20_1h_gt_neg_0_10) | (aroonu_14_1h_lt_70))
            # 15m & 1h & 4h down move 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_50))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_70))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_15))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_100))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_40))
            # 15m & 1h & 4h & 1d down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_15))
            # 15m & 1h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_50))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (aroonu_14_15m_lt_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 1d high & overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_25) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_70))
            # 15m & 1h & 1d down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_45) | (rsi_3_1d_gt_45) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_80))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_90))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_60))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_30) | (roc_9_1d_gt_neg_50))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_50))
            # 15m down move, 15m downtrend
            & ((rsi_3_15m_gt_3) | (cmf_20_15m_gt_neg_0_40) | (roc_9_15m > -20.0))
            # 15m down move, 15m still high, 15m downtrend
            & ((rsi_3_15m_gt_3) | (aroonu_14_15m_lt_40) | (roc_9_15m > -20.0))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_3) | (aroonu_14_1h_lt_85) | (aroonu_14_4h_lt_90))
            # 15m down move, 4h high, 15m downtrend
            & ((rsi_3_15m_gt_3) | (aroonu_14_4h_lt_70) | (roc_9_15m > -20.0))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_3) | (aroonu_14_4h_lt_85) | (roc_9_1d_lt_100))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_3) | (stochrsi_k_1h_lt_90) | (roc_9_4h_lt_10))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_3) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30))
            # 15m down move, drop in last half hour, 15m downtrend
            & ((rsi_3_15m_gt_3) | (close > (close_max_6 * 0.75)) | (roc_9_15m > -20.0))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (roc_9_1d_lt_40))
            # 15m & 1h & 4h & 1d down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_1h_lt_70))
            # 5m & 1h down move, 1h overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_60) | (roc_9_1h_lt_40))
            # 15m & 4h down move, 1d still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_1d_lt_40))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_5) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_50))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_60))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_30) | (stochrsi_k_15m_lt_50))
            # 15m & 1d down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1d_gt_30) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_100))
            # 15m down move, 15m still high, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_80) | (roc_9_1d_gt_neg_20))
            # 15m down move, 15m & 4h still high
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_60))
            # 15m down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_80))
            # 15m down move, 15m high
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_80))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_4h_lt_60) | (roc_9_1d_lt_80))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_70))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (roc_9_1d_gt_neg_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_14_4h_lt_80))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_15m_lt_50))
            # 15m & 1h down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (roc_9_4h_lt_80))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_55) | (rsi_3_4h_gt_55) | (stochrsi_k_1h_lt_90))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_1h_lt_75))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_50))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_40))
            # 15m & 4h down move, 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_20))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (roc_9_1d_lt_30))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (aroonu_14_1h_lt_85))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_90))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_50) | (stochrsi_k_1d_lt_80))
            # 15m & 1d down move, 1h & 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_60) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_lt_100))
            # 15m down move & downtrend, 4h high
            & ((rsi_3_15m_gt_10) | (cmf_20_15m_gt_neg_0_30) | (aroonu_14_4h_lt_100))
            # 15m down move, 15m & 4h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_80))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_90) | (roc_9_1h_lt_20))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_90) | (roc_9_1d_gt_neg_40))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_80))
            # 15m down move, 1h high, 4h downtrend
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_25))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_70) | roc_9_1d_gt_neg_50)
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_20))
            # 15m down move, 1h & 1d overbought
            & ((rsi_3_15m_gt_10) | (roc_9_1h_lt_10) | (roc_9_1d_lt_80))
            # 15m down move, 4h high
            & ((rsi_3_15m_gt_10) | (roc_9_4h_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_80))
            # 15m down move, 15m still high, 4h overbought
            & ((rsi_3_15m_gt_15) | (rsi_14_15m_lt_50) | (roc_9_4h_lt_50))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_80) | (aroonu_14_1h_lt_90))
            # 15m & 1h & 4h & 1d down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_65) | (aroonu_14_4h_lt_80))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_35) | (aroonu_14_15m_lt_40))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_100) | (roc_9_1h_lt_20))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 15m down move, 1d overbought
            & ((rsi_3_15m_gt_30) | (roc_9_1d_lt_80))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_40) | (rsi_3_4h_gt_45) | (stochrsi_k_15m_lt_70))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_10))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_50))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_90))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_100))
            # 1h & 1d down move, 4h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_1d_gt_15) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (roc_9_1d_lt_10))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_40))
            # 1h & 4h down move, 1h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (cmf_20_1h_gt_neg_0_30))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_30))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_50) | aroonu_14_4h_lt_70)
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_5) | rsi_3_4h_gt_20 | (roc_9_1d_lt_40))
            # 1h & 1d down move, 1d downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_1d_gt_5) | (roc_9_1d_gt_neg_30))
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_5) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_30))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_15m_lt_30))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_50))
            # 1h & 4h & 1d down move, 4h downtrend, 1d still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (rsi_14_4h_gt_30) | (aroonu_14_1d_lt_40))
            # 1h & 4h down move, 1h & 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_100))
            # 1h & 1d down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_20) | (aroonu_14_4h_lt_80))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_14_4h_lt_75))
            # 1h down move, 15m downtrend, 1d high
            & ((rsi_3_1h_gt_10) | (cmf_20_15m_gt_neg_0_40) | (aroonu_14_1d_lt_70))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 4h overbought
            & ((rsi_3_1h_gt_10) | (roc_9_4h_lt_50))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_80))
            # 1h & 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_50))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 1h & 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_lt_100))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_70) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_70) | roc_9_1d_lt_50)
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_80))
            # 1h down mve, 4h high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_30))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_40))
            # 1h down move, 1h & 4h downtrend
            & ((rsi_3_1h_gt_15) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 1h & 4h down move, 4h overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (roc_9_4h_lt_80))
            # 1h down move, 1h still high, 4h downtrend
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_40) | (roc_9_4h_gt_neg_30))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_200))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_60))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_50))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_80))
            # 1h & 4h down move, 1h still high, 4h high & overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_55) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_40))
            # 1h down move, 1h high, 15n downtrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70) | (roc_9_15m > -20.0))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_40))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_25) | (roc_9_4h_lt_80) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (roc_9_4h_gt_neg_20))
            # 1h & 4h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_90) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_80))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_35) | (roc_9_4h_lt_40) | (roc_9_1d_lt_80))
            # 1h & 4h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_60) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_50))
            # 1h down move, 1h downtrend, 1h high
            & ((rsi_3_1h_gt_40) | (cmf_20_1h_gt_neg_0_25) | (aroonu_14_1h_lt_90))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 15m downtrend
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (roc_9_15m > -15.0))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_100))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_70) | (roc_9_1d_gt_neg_50))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_20))
            # 1h & 4h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_30))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_90) | (roc_9_1h_lt_20))
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_50) | (rsi_14_4h < 90.0))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_40))
            # 4h & 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_40) | (roc_9_4h_gt_neg_10))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_40))
            # 4h & 1d down move, 4h still not low enough
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (aroonu_14_4h_lt_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_50))
            # 4h down move, 4h still high
            & ((rsi_3_4h_gt_10) | (aroonu_14_4h_lt_50))
            # 4h down move, 1d high
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_100))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_60) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_30) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_15) | (roc_9_4h_gt_neg_20) | (roc_9_4h_gt_neg_30))
            # 4h down move, 1d high & overbought
            & (rsi_3_4h_gt_20 | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_80))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_50))
            # 4h down move, 1d overbought
            & ((rsi_3_4h_gt_45) | (roc_9_1d_lt_80))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_40))
            # 4h down move, 1h high, 1d overbought
            & ((rsi_3_4h_gt_60) | (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_60))
            # 1d down move, 1h high, 4h & 1d downtrend
            & ((rsi_3_1d_gt_5) | (stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_40) | (roc_9_1d_gt_neg_50))
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_5) | (stochrsi_k_1h_lt_90) | (roc_9_1d_gt_neg_20))
            # 1d down move, 1h still high, 4h high
            & ((rsi_3_1d_gt_20) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_25) | aroonu_14_1h_lt_80 | (aroonu_14_4h_lt_90))
            # 1d down move, 1d high
            & ((rsi_3_1d_gt_40) | (aroonu_14_1d_lt_80))
            # 1d down move, 4h still high, 1d overbought
            & ((rsi_3_1d_gt_50) | (aroonu_14_4h_lt_50) | (roc_9_1d_lt_200))
            # 1d down move, 1d high & overbought
            & ((rsi_3_1d_gt_60) | (aroonu_14_1d_lt_80) | roc_9_1d_lt_50)
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_change_pct_1h > -75.0) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_100))
            # 15m & 1h & 4h downtrend
            & ((cmf_20_15m_gt_neg_0_30) | (cmf_20_1h_gt_neg_0_30) | (cmf_20_4h_gt_neg_0_30))
            # 15m high, 1d overbought
            & ((aroonu_14_15m_lt_70) | (roc_9_1d_lt_80))
            # 1h still high, 1h & 4h downtrend
            & ((aroonu_14_1h_lt_40) | (roc_9_1h_gt_neg_20) | (roc_9_4h_gt_neg_30))
            # 1h & 4h high & overbought
            & ((aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_10) | (roc_9_4h_lt_20))
            # 1h & 4h high, 1h overbought
            & ((aroonu_14_1h_lt_85) | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_20))
            # 1h high, 1h & 4h overbought
            & ((aroonu_14_1h_lt_85) | (roc_9_1h_lt_10) | (roc_9_1d_lt_30))
            # 1h high, 1h overbought, 1d downtrend
            & ((aroonu_14_1h_lt_85) | (roc_9_1h_lt_20) | (roc_9_1d_gt_neg_40))
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_50))
            # 4h high, 1h downtrend
            & ((aroonu_14_4h_lt_80) | (roc_9_1h_gt_neg_15))
            # 4h high & 1h & 4h overbought
            & ((aroonu_14_4h_lt_80) | (roc_9_1h_lt_40) | (roc_9_4h_lt_80))
            # 4h high, 1d downtrend
            & ((aroonu_14_4h_lt_80) | (roc_9_1d_gt_neg_40))
            # 1d high, 4h downtrend, 1d overbought
            & ((aroonu_14_1d_lt_85) | (roc_9_4h_gt_neg_25) | (roc_9_1d_lt_50))
            # 1d high, 1h & 4h downtrend
            & ((aroonu_14_1d_lt_90) | (roc_9_1h_gt_neg_10) | (roc_9_4h_gt_neg_20))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_90) | (roc_9_4h_lt_40) | (roc_9_1d_lt_80))
            # 1h high, 4h overbought
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_lt_80))
            # 4h high, 1h downtrend
            & ((stochrsi_k_4h_lt_70) | (roc_9_1h_gt_neg_15))
            # 4h high, 1d downtrend
            & ((stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_40))
            # 4h high & 1h & 4h overbought
            & ((stochrsi_k_4h_lt_80) | (roc_9_1h_lt_40) | (roc_9_4h_lt_80))
            # 5m down move, 15m still not low enough, 1h high
            & ((roc_2 > -10.0) | (aroonu_14_15m_lt_30) | aroonu_14_1h_lt_80)
            # 5m down move, 15m still high
            & ((roc_2 > -10.0) | (aroonu_14_15m_lt_50))
            # 5m down move, 15m & 1h down move, 15m still high
            & ((roc_9 > -15.0) | (rsi_3_15m_gt_5) | (rsi_3_1h_gt_35) | (aroonu_14_15m_lt_50))
            # 5m down move, 4h down move, 15m downtrend, 1h high
            & ((roc_9 > -15.0) | (rsi_3_4h_gt_45) | (cmf_20_15m_gt_neg_0_30) | (aroonu_14_1h_lt_60))
            # 1h downtrend, 4h high & overbought
            & ((roc_9_1h_gt_neg_25) | aroonu_14_4h_lt_80 | (roc_9_4h_lt_80))
            # 1h & 4h overbought, 1d downtrend
            & ((roc_9_1h_lt_20) | (roc_9_4h_lt_20) | (roc_9_1d_gt_neg_40))
            # 1d P&D, 1d downtrend
            & ((change_pct_1d_gt_neg_5) | (change_pct_1d_shift_288 < 30.0) | (cmf_20_1d_gt_neg_0_0))
            # 1d green with top wick, 1h down move
            & ((change_pct_1d < 20.0) | (top_wick_pct_1d_lt_15) | rsi_3_1h_gt_20)
            # 1d green with top wick, 4h high
            & ((change_pct_1d_lt_25) | (top_wick_pct_1d_lt_25) | aroonu_14_4h_lt_80)
            # 1d green, 1h down move, 1d downtrend
            & ((change_pct_1d_lt_40) | (rsi_3_1h_gt_25) | (cmf_20_1d_gt_neg_0_20))
            # 1d green with top wick, 4h overbought
            & ((change_pct_1d_lt_50) | (top_wick_pct_1d_lt_30) | (roc_9_4h_lt_80))
            # 1d top wick, 1h & 4h down move, 1d high
            & ((top_wick_pct_1d_lt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100))
            # big drop in the last hour, 15m downtrend
            & ((close > (close_max_12 * 0.65)) | (cmf_20_15m_gt_neg_0_50))
            # big drop in the last 6 hours, 1h down move, 1h high
            & ((close > (high_max_6_1h * 0.60)) | rsi_3_1h_gt_20 | (aroonu_14_1h_lt_60))
            # big drop in the last 24 hours,  1h still high
            & ((close > (high_max_24_1h * 0.40)) | (stochrsi_k_1h < 45.0))
            # big drop in the last 4 days, 1h high
            & ((close > (high_max_24_4h * 0.20)) | aroonu_14_1h_lt_70)
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
            # the daily low is not fresh at all, the hour has stopped falling, the 15m oscillator
            # is up and the hourly one is below mid-band: a market turning, not breaking
            & ((aroond_14_1d > 0.0) | (roc_2_1h > -2.5) | (uo_7_14_28_15m > 42.0) | (uo_7_14_28_1h < 46.0))
            # the daily low is recent, 4h money flow clearly negative, the base money flow already
            # at zero and a squeeze behind it: the sell-off is finished and coiling
            & ((aroond_14_1d > 50.0) | (cmf_20_4h < -0.1) | (mfi_14 > 5.0) | (sqz_cnt_24 > 4.0))
            # daily money flow rich, the base RSI already low, the daily RSI_3 snapping up and the
            # hourly stochastic off its floor: nothing left underneath on any timeframe
            & ((mfi_14_1d < 60.0) | (rsi_14 < 28.0) | (rsi_3_change_pct_1d < 50.0) | (stochk_14_3_3_1h > 15.0))
            # daily money flow negative while the base RSI is dropping, the 15m is not selling and
            # the hour is red: the day is already priced in (4 losses, free in all three years)
            & (
              (cmf_20_1d < -0.05)
              | (rsi_14_change_pct < -10.0)
              | (rsi_3_change_pct_15m > -70.0)
              | (change_pct_1h < -1.0)
            )
            # the daily RSI is not strong, the 15m RSI_3 is not washed, the hourly oscillator is
            # below mid-band and the hour is flat: a quiet market with no leg to sell (3 losses)
            & ((rsi_14_1d < 55.0) | (rsi_3_15m > 15.0) | (uo_7_14_28_1h < 46.0) | (change_pct_1h > -2.0))
            # daily money flow rich, the hour barely down, the 4h nowhere near its low and the day
            # up more than 2%: shorting strength on every timeframe at once (3 losses)
            & ((mfi_14_1d < 60.0) | (roc_9_1h > -2.0) | (willr_14_4h < -40.0) | (change_pct_1d > 2.0))
            # no daily high behind it, base money flow drained, a loose pre-break base and the 15m
            # no longer falling: a tired market, not a breaking one (4 losses, all in 2022)
            & ((aroonu_14_1d > 0.0) | (mfi_14 > 15.0) | (ph_pre_tight > 1.0) | (roc_9_15m > -1.0))
            # no daily high, the daily RSI_3 is washed, hourly RSI_3 snapping up and the 15m
            # oscillator off its floor: the daily leg is finished (4 losses)
            & ((aroonu_14_1d > 0.0) | (rsi_3_1d > 40.0) | (rsi_3_change_pct_1h < -20.0) | (stochrsi_k_15m > 10.0))
          )

          # Logic
          long_entry_logic.append(
            (ema_26 > ema_12)
            & ((ema_26 - ema_12) > (open_rate * 0.034))
            & ((ema_26_shift_1 - ema_12_shift_1) > (open_rate / 100.0))
            & (close < (bbl_20_2_0 * 0.999))
          )

        # Condition #2 - Normal mode (Long).
        if long_entry_condition_index == 2:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 1h down move, 1h still not low enough
            ((rsi_3_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_30))
            # 5m & 1h down move, 1d high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_20) | (aroonu_14_1d_lt_100))
            # 5m & 1h down move, 1h still high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_50))
            # 5m & 1h down move, 1d high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_35) | (aroonu_14_1d_lt_100))
            # 5m & 4h down move, 15m still not low enough
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_3) | (stochrsi_k_15m_lt_30))
            # 5m & 4h down move, 1d downtrend
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_30))
            # 5m & 4h & 1d down move, 4h still high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (rsi_14_4h_lt_40))
            # 5m & 4h down move, 4h high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_80))
            # 5m & 4h down move, 15m still high
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_50))
            # 5m & 1d down move, 1h still high
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_10) | (aroonu_14_1h_lt_40))
            # 5m & 1d down move, 1h still high
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_50))
            # 5m & 1d down move, 1d downtrend
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_15) | (cmf_20_1d_gt_neg_0_25))
            # 5m & 1d down move, 15m still high
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_20) | (stochrsi_k_15m_lt_40))
            # 5m down move, 1h high
            & ((rsi_3_gt_3) | (aroonu_14_1h_lt_80))
            # 5m down move, 4h high, 1d overbought
            & ((rsi_3_gt_3) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_30))
            # 5m down move, 4h high & overbought
            & ((rsi_3_gt_3) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_20))
            # 5m down move, 4h & 1d overbought
            & ((rsi_3_gt_3) | (roc_9_4h_lt_20) | (roc_9_1d_lt_40))
            # 5m down move, 1d downtrend
            & ((rsi_3_gt_3) | (roc_9_1d_gt_neg_40))
            # 5m & 15m down move, 15m still high
            & ((rsi_3_gt_5) | (rsi_3_15m_gt_10) | (stochrsi_k_15m_lt_40))
            # 5m & 15m down move, 1h high
            & ((rsi_3_gt_5) | (rsi_3_15m_gt_30) | (stochrsi_k_1h_lt_80))
            # 5m & 4h down move, 1d downtrend
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 5m & 4h down move, 4h still not low enough
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_15) | (stochrsi_k_4h < 20.0))
            # 5m down move, 4h high, 1h overbought
            & ((rsi_3_gt_10) | aroonu_14_4h_lt_100 | (roc_9_1h_lt_30))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m > 1.0) | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_40))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (rsi_3_4h_gt_15))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (aroonu_14_4h_lt_50))
            # 15m & 1h down move, 15m downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (cmf_20_15m_gt_neg_0_30))
            # 15m & 1h down move, 15m still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (aroonu_14_15m_lt_30))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (aroonu_14_1h_lt_25))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (stochrsi_k_1h_lt_30))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_10))
            # 15m & 1h & 4h down move, 4h still not low enough, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_20) | (rsi_14_1d_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_30))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (roc_9_1d_gt_neg_40))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_45) | (stochrsi_k_1d_lt_60))
            # 15m & 1h down move, 15m downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (cmf_20_15m_gt_neg_0_40))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_35) | (aroonu_14_1h_lt_40))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_35) | (stochrsi_k_1d_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_85))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_5) | (rsi_14_4h_lt_30))
            # 15m & 4h down move, 4h downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_5) | (cmf_20_4h_gt_neg_0_35))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_70))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_30) | (stochrsi_k_4h < 40.0))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_50))
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_3) | (aroonu_14_15m_lt_20) | (stochrsi_k_1h_lt_60))
            # 15m down move, 15m still not low enough, 1h still high
            & ((rsi_3_15m_gt_3) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_lt_50))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_3) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_20))
            # 15m down move, 4h still high, 15m downtrend
            & ((rsi_3_15m_gt_3) | (aroonu_14_4h_lt_40) | (cmf_20_15m_gt_neg_0_35))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_3) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_30))
            # 15m down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_3) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_50))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_10))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_70))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (rsi_14_4h_lt_40))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_60))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_60))
            # 15m & 1h & 4h & 1d down move, 1h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_40) | (stochrsi_k_1h_lt_30))
            # 15m & 1h & 4h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_80))
            # 15m & 4h down move, 1d still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_1d_lt_40))
            # 15m & 4h down move, 15m still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_30))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_70))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_15m_lt_40))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_50))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_50))
            # 15m & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_50))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_10))
            # 15m & 4h & 1d down move, 4h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_40) | (aroonu_14_4h_lt_30))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_40))
            # 15m & 1d down move, 15m still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1d_gt_10) | (aroonu_14_15m_lt_30))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1d_gt_40) | (stochrsi_k_1h_lt_90))
            # 15m down move, 15m downtrend, 4h still not low enough
            & ((rsi_3_15m_gt_5) | (cmf_20_15m_gt_neg_0_30) | (stochrsi_k_4h < 30.0))
            # 15m down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_20) | (stochrsi_k_4h_lt_70))
            # 15m down move, 15m stil high, 1h still high
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_50))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_20))
            # 15m down move, 15m still not low enough, 1h still high
            & ((rsi_3_15m_gt_5) | (stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_50))
            # 15m down move, 1h still high, 4h overbought
            & ((rsi_3_15m_gt_5) | (stochrsi_k_1h_lt_50) | (roc_9_4h_lt_30))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_5) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_20))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_15m_lt_50))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_60))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_1d_lt_70))
            # 15m & 1h & 4h & 1d down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_70))
            # 15m & 1h & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_1d_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (aroonu_14_4h_lt_75))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (aroonu_14_4h_lt_50))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (roc_9_1d_gt_neg_50))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (rsi_14_4h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_80))
            # 15m & 1h & 1d down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_70) | (roc_9_1d_gt_neg_10))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_80))
            # 16m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_55) | (stochrsi_k_4h_lt_90))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_70))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_70))
            # 15m & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_50))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_30))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_80))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (roc_9_1d_lt_20))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_30))
            # 15m & 4h down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (stochrsi_k_1h_lt_60) | (roc_9_1d_lt_10))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_90))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_90))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_30))
            # 15m & 4h & 1d down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_20))
            # 15m & 4h down move, 4h overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_55) | (roc_9_4h_lt_50))
            # 15m & 1d down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_10) | (rsi_14_1d_lt_40))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_90))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_4h_lt_90))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_70))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_70))
            # 15m down move, 15m downtrend, 1h high
            & ((rsi_3_15m_gt_10) | (cmf_20_15m_gt_neg_0_40) | (aroonu_14_1h_lt_80))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_20))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_70) | aroonu_14_1d_lt_100)
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10))
            # 15m down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_10) | (stochrsi_k_15m_lt_20) | (aroonu_14_4h_lt_70))
            # 15m down move, 15m sill high, 4h high
            & ((rsi_3_15m_gt_10) | (stochrsi_k_15m_lt_40) | (aroonu_14_4h_lt_60))
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_30))
            # 15m & 1h & 4h down move, 4h still high, 1d still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40) | (stochrsi_k_1d_lt_50))
            # 15m & 1h down move, 4h downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (roc_9_4h_gt_neg_20))
            # 15m & 1h & 4h & 1d down move, 4h still not low enough
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_30))
            # 15m & 1h down move, 1h still high, 1d downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_50) | (roc_9_1d_gt_neg_50))
            # 15m & 1h down move, 1h downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (cmf_20_1h_gt_neg_0_30))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (roc_9_1d_lt_100))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_60))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_40) | (aroonu_14_1d_lt_90))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_45) | (stochrsi_k_4h_lt_70))
            # 15m & 1h & 4h down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_50) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_55) | (aroonu_14_4h_lt_60) | (roc_9_4h_lt_30))
            # 15m & 1h down move, 1h high, 4h & 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_90) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_70))
            # 15m & 4h down move, 4h downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (roc_9_4h_gt_neg_20))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_90))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_1h_lt_40))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_30) | (aroonu_14_4h_lt_90))
            # 15m down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_25) | (aroonu_14_4h_lt_60))
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_70))
            # 15m down move, 15m & 4h still high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_40))
            # 15m down move, 1h still high, 4h overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_50) | (roc_9_4h_lt_60))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_90))
            # 15m down move, 1h & 1d high
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_90))
            # 15m down move, 4h high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_60) | (roc_9_4h_gt_neg_20))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_75) | (aroonu_14_1d_lt_100))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_10))
            # 15m down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_15m_lt_50) | (roc_9_1d_lt_100))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10))
            # 15m down move, 4h still high, 1d high & overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_40) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_70) | (roc_9_1d_lt_10))
            # 15m & 1h & 4h & 1d down move, 15m downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (cmf_20_15m_gt_neg_0_40))
            # 15m & 1h down move, 15m still not low enough
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (aroonu_14_15m_lt_30))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (roc_9_4h_lt_50))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (stochrsi_k_15m_lt_80))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_90))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (aroonu_14_1h_lt_90))
            # 15m & 1h down move, 4h & 1d high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_40) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80))
            # 15m & 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_80))
            # 15m down move, 1h & 1d high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_80))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_80) | (roc_9_1h_lt_20))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_90) | (roc_9_1d_gt_neg_30))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_100))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_20))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (rsi_14_4h_lt_40))
            # 15m & 1h & 4h down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_70))
            # 15m & 1h & 4h down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_55) | (aroonu_14_15m_lt_40) | (stochrsi_k_4h_lt_60))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_40) | (roc_9_1d_lt_80))
            # 15m & 4h down move, 1h overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_35) | (roc_9_1h_lt_100))
            # 15m & 1d down move, 4h & 1d still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_40) | (stochrsi_k_1d_lt_40))
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_20) | (stochrsi_k_1h_lt_90))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_50))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_50))
            # 15m down move, 4h high, 1h overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_80) | (roc_9_1h_lt_50))
            # 15m & 1h & 4h down move, 1d high, 4h still not low enough
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100) | (stochrsi_k_4h_lt_30))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_50))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_30) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_20))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_80))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_50))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_20))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_35) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_80))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_40) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_40))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h > 1.0) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_10))
            # 1h down move, 15m downtrend, 1h still high
            & ((rsi_3_1h_gt_3) | (cmf_20_15m_gt_neg_0_40) | (aroonu_14_1h_lt_40))
            # 1h & 4h down move, 15m downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_3) | (roc_9_15m > -30.0))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_5) | (aroonu_14_4h_lt_40))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_40))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_20))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (roc_9_1d_lt_10))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70))
            # 1h & 1d down move, 15m still high
            & ((rsi_3_1h_gt_3) | (rsi_3_1d_gt_10) | (stochrsi_k_15m_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_4h < 40.0))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_1d_lt_50))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (roc_9_1d_gt_neg_30))
            # 1h % 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (cmf_20_4h_gt_neg_0_30))
            # 1h & 4h & 1d down move, 1d still high, 1h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_50) | (roc_9_1h_gt_neg_20))
            # 1h & 4h & 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_70) | (roc_9_1h_gt_neg_10))
            # 1h & 4h & 1d down move, 1d still high, 1d overbought
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_50) | (roc_9_1d_lt_10))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_70))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_50))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (roc_9_4h_gt_neg_30))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_5) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_50))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_15))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_40))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_20))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 1h & 4h & 1d down move, 4h downtrend, 1d still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (rsi_14_4h_gt_30) | (aroonu_14_1d_lt_40))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_70))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_50))
            # 1h & 1d down move, 15m still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_15m_lt_40))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_35) | (rsi_14_4h_lt_40))
            # 1h down move, 1h still not low enough 1d overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_30) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_14_1d_lt_60))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_20))
            # 1h & 4h down move, 15m still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_50))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (roc_9_4h_gt_neg_20))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | rsi_3_4h_gt_20 | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (stochrsi_k_4h < 30.0))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_80))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (roc_9_4h_gt_neg_30))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | aroonu_14_4h_lt_70)
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_50))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_80))
            # 1h & 1d down move, 1d overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_35) | (roc_9_1d_lt_10))
            # 1h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_40))
            # 1h down move, 4h high, 1d high
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_lt_100))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_60) | roc_9_1d_lt_50)
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_15) | (stochrsi_k_4h < 60.0) | (roc_9_4h_lt_10))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_40))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_15) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_20))
            # 1h & 4h & 1d down move, 1h stil high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_85))
            # 1h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_30) | (stochrsi_k_1h_lt_50))
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70) | (roc_9_4h_gt_neg_10))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 1h high, 1h still not low enough
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_80) | (stochrsi_k_1h_lt_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1d_lt_80) | (roc_9_4h_gt_neg_20))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_50))
            # 1h & 1d down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_90))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_85))
            # 1h down move, 4h high, 4h downtrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_70) | (cmf_20_4h_gt_neg_0_50))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_40))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_25) | (roc_9_4h_lt_30) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_30))
            # 1h down move, 4h downtrend, 1d overbought
            & ((rsi_3_1h_gt_30) | (roc_9_4h_gt_neg_30) | (roc_9_1d_lt_200))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_30) | (roc_9_4h_gt_neg_25) | (roc_9_1d_gt_neg_60))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (stochrsi_k_1h_lt_40))
            # 1h down move, 1h still high, 4h downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_50) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1h high, 4h high & overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (roc_9_1d_gt_neg_25))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_85) | (roc_9_4h_lt_100))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_85) | (roc_9_1d_lt_100))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_40))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_200))
            # 1h & 4h & 1d down move, 1d overbought
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_60) | (roc_9_1d_lt_40))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_80))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_10))
            # 1h down move, 4h still high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_40) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_100))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_60) | (stochrsi_k_1h_lt_80))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (roc_9_1d_lt_200))
            # 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_60) | (stochrsi_k_1d_lt_70) | (roc_9_1d_lt_40))
            # 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_60))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_80) | (roc_9_1h_lt_10))
            # 1h down move, 4h high, 1h overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_85) | (roc_9_1h_lt_20))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h < 60.0) | (roc_9_1d_gt_neg_60))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_100))
            # 1h down move, 1h & 4h overbought
            & ((rsi_3_1h_gt_50) | (roc_9_1h_lt_10) | (roc_9_4h_lt_100))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_90) | (roc_9_1h_lt_10))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10))
            # 4h & 1d down move, 4h still not low enough
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_15) | (aroonu_14_4h_lt_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_40))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_lt_40))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_15) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_5) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_100))
            # 4h down move, 15m still high
            & ((rsi_3_4h_gt_5) | (stochrsi_k_15m_lt_50))
            # 4h & 1d down move, 1h still not low enough
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_1d_lt_40))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_20) | (roc_9_1d_gt_neg_25))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_35) | (aroonu_14_1d_lt_100))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_45) | (stochrsi_k_1d_lt_80))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_45) | (roc_9_1d_lt_10))
            # 4h down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_40))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_4h < 40.0) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_60))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_4h < 40.0))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_lt_80))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_1h_lt_90) | (roc_9_1d_gt_neg_10))
            # 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_4h_gt_neg_20))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_50))
            # 4h & 1d down move, 1h high & overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_35) | (aroonu_14_1h_lt_80) | (roc_9_1h_lt_10))
            # 4h & 1d down move, 1h high & overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_70) | (roc_9_1h_lt_10))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_30))
            # 4h down move, 4h still high, 1d overbought
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_40) | (roc_9_1d_lt_100))
            # 4h down move, 4h still high. 4h downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_50) | (cmf_20_4h_gt_neg_0_40))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h high, 4h downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_70) | (roc_9_4h_gt_neg_30))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_60) | (roc_9_1d_lt_60))
            # 4h down move, 1d downtrend
            & ((rsi_3_4h_gt_30) | (roc_9_1d_gt_neg_50))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_35) | (roc_9_4h_lt_30) | (roc_9_1d_lt_200))
            # 4h down move, 1h high, 1d overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_40))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 4h down move, 4h still high, 1d overbought
            & ((rsi_3_4h_gt_40) | (stochrsi_k_4h < 40.0) | roc_9_1d_lt_50)
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_60))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_40) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_100))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_100))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_45) | (aroonu_14_4h_lt_70) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_80))
            # 4h down move, 1d high, 4h overbought
            & ((rsi_3_4h_gt_55) | (stochrsi_k_1d_lt_90) | (roc_9_4h_lt_10))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_20))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_200))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_60) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 4h down move, 4h overbought
            & ((rsi_3_4h_gt_60) | (roc_9_4h_lt_60))
            # 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1d_gt_5) | (aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_20))
            # 1d down move, 1h & 4h still not low enough
            & ((rsi_3_1d_gt_5) | (stochrsi_k_1h_lt_20) | (stochrsi_k_4h < 20.0))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_10) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90))
            # 1d down move, 1h high
            & ((rsi_3_1d_gt_10) | (aroonu_14_1h_lt_70))
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_20))
            # 1d down move, 1h overbought, 1d downtrend
            & ((rsi_3_1d_gt_15) | (roc_9_1h_lt_20) | (roc_9_1d_gt_neg_50))
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_90) | (roc_9_1d_gt_neg_10))
            # 1d down move, 1h high, 1d overbought
            & ((rsi_3_1d_gt_25) | aroonu_14_1h_lt_70 | (roc_9_1d_lt_25))
            # 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_50) | (roc_9_1d_gt_neg_20))
            # 1d down move, 1h high & overbought
            & ((rsi_3_1d_gt_40) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_80))
            # 1d down move, 4h high & overbought
            & ((rsi_3_1d_gt_45) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_60))
            # 1d down move, 1d still high, 4h still high
            & ((rsi_3_1d_gt_50) | (rsi_14_1d_lt_50) | (stochrsi_k_4h_lt_50))
            # 1d downtrend, 1d high & overbought
            & ((cmf_20_1d_gt_neg_0_40) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_20))
            # 1h high, 4h & 1d overbought
            & (aroonu_14_1h_lt_70 | (roc_9_4h_lt_50) | (roc_9_1d_lt_200))
            # 1h & 4h high, 1d overbought
            & (aroonu_14_1h_lt_70 | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_50))
            # 1h & 4h high, 1d downtrend
            & (aroonu_14_1h_lt_70 | (aroonu_14_4h_lt_100) | (roc_9_1d_gt_neg_40))
            # 1h high, 4h & 1d downtrend
            & (aroonu_14_1h_lt_70 | (roc_9_4h_gt_neg_30) | roc_9_1d_gt_neg_50)
            # 1h & 4h high, 1h overbought
            & (aroonu_14_1h_lt_80 | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_30))
            # 1h & 4high, 1d downtrend
            & (aroonu_14_1h_lt_80 | aroonu_14_4h_lt_100 | (roc_9_1d_gt_neg_20))
            # 1h & 4h high, 1d overbought
            & (aroonu_14_1h_lt_80 | aroonu_14_4h_lt_100 | (roc_9_1d_lt_80))
            # 1h & 1d high, 1d overbought
            & (aroonu_14_1h_lt_80 | aroonu_14_1d_lt_100 | (roc_9_1d_lt_30))
            # 1h high, 1d downtrend
            & (aroonu_14_1h_lt_80 | (roc_9_1d_gt_neg_40))
            # 1h & 4h high, 1d overbought
            & ((aroonu_14_1h_lt_90) | aroonu_14_4h_lt_100 | (roc_9_1d_lt_30))
            # 1h high, 4h & 1d overbought
            & ((aroonu_14_1h_lt_90) | (roc_9_4h_lt_40) | (roc_9_1d_lt_40))
            # 4h still high, 5m downtrend
            & ((aroonu_14_4h_lt_40) | (roc_9 > -40.0))
            # 4h high & overbought
            & ((aroonu_14_4h_lt_70) | (roc_9_4h_lt_80))
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_40))
            # 4h high, 1h & 4h overbought
            & ((aroonu_14_4h_lt_100) | (roc_9_1h_lt_10) | (roc_9_4h_lt_20))
            # 1d high, 1d downtrend
            & ((aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_30))
            # 1d high, 1h & 4h downtrend
            & ((aroonu_14_1d_lt_85) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_50))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_85) | (roc_9_4h_lt_60) | (roc_9_1d_lt_60))
            # 1d high, 1h & 4h down move
            & ((aroonu_14_1d_lt_100) | (roc_9_1h_lt_25) | (roc_9_4h_lt_60))
            # 15m high, 1d overbought
            & ((stochrsi_k_15m_lt_70) | (roc_9_1d_lt_60))
            # 1h high, 1d downtrend
            & ((stochrsi_k_1h_lt_70) | (roc_9_1d_gt_neg_50))
            # 1h high, 1d overbought
            & ((stochrsi_k_1h_lt_70) | (roc_9_1d_lt_40))
            # 1h high, 4h downtrend
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_gt_neg_20))
            # 1h high, 4h overbought
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_lt_80))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h < 80.0) | (roc_9_1h_lt_10) | (roc_9_4h_lt_20))
            # 1d high, 1h & 1d overbought
            & ((stochrsi_k_1d_lt_80) | (roc_9_1h_lt_10) | (roc_9_1d_lt_80))
            # 1d high, 4h & 1d overbought
            & ((stochrsi_k_1d_lt_80) | (roc_9_4h_lt_60) | (roc_9_1d_lt_60))
            # 1d top wick, 1h & 4h down move, 1d high
            & ((top_wick_pct_1d_lt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100))
            # big drop in last hough, 4h down move, 1h still not low enough
            & ((close > (close_max_12 * 0.90)) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_30))
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
            # drop in last 20 days, 1h high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (aroonu_14_1h_lt_70) | (roc_9_1d_gt_neg_70))
            # drop in last 20 days. 4h high
            & ((close > (high_max_20_1d * 0.10)) | (stochrsi_k_4h_lt_90))
          )

          # Logic
          long_entry_logic.append(
            # (df["RSI_3"] > 5.0)
            (aroonu_14_lt_30)
            & (stochrsi_k_lt_30)
            # & (rsi_3_15m > 5.0)
            & (aroonu_14_15m_lt_50)
            & (close < (ema_20 * 0.948))
          )

        # Condition #3 - Normal mode (Long).
        if long_entry_condition_index == 3:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 4h down move, 1h still high
            ((rsi_3_gt_5) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_50))
            # 5m down move, 15m high, 1d overbought
            & ((rsi_3_gt_5) | (aroonu_14_15m_lt_70) | (roc_9_1d_lt_40))
            # 5m down move, 15m still high, 1d downtrend
            & ((rsi_3_gt_5) | (stochrsi_k_15m_lt_50) | (roc_9_1d_gt_neg_20))
            # 5m down move, 1h still high, 4h downtrend
            & ((rsi_3_gt_5) | (stochrsi_k_1h_lt_50) | (roc_9_4h_gt_neg_10))
            # 5m down move, 1h high. 1d downtrend
            & ((rsi_3_gt_5) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_30))
            # 5m down move, 15m & 1h high
            & ((rsi_3_gt_10) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 5m down move, 15m & 1d high
            & ((rsi_3_gt_10) | (aroonu_14_15m_lt_70) | aroonu_14_1d_lt_100)
            # 5m down move, 1h & 1d high
            & ((rsi_3_gt_15) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_90))
            # 15m & 1h dowbn move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_25) | (stochrsi_k_1d_lt_90))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1d_gt_15) | (stochrsi_k_1h_lt_60))
            # 15m & 1h & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (roc_9_1d_gt_neg_50))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_15m_lt_50))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_40))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_15m_lt_50))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_90))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_lt_80))
            # 15m down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_100))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_60) | roc_9_1d_lt_50)
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_20))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (aroonu_14_4h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_50) | (aroonu_14_1h_lt_75))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | aroonu_14_4h_lt_70)
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (roc_9_1d > -30.0))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_50))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_15) | rsi_3_4h_gt_20 | aroonu_14_1d_lt_100)
            # 15m & 1d down move, 15m high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_15m_lt_70))
            # 15m down move, 4h downtrend. 15m high
            & ((rsi_3_15m_gt_15) | (cmf_20_4h_gt_neg_0_30) | (aroonu_14_15m_lt_60))
            # 15m down move, 15m still high, 1h still high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_50))
            # 15m down move, 15m high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_60) | (roc_9_4h_gt_neg_20))
            # 15m down move, 15m high, 1d downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_60) | (roc_9_1d_gt_neg_70))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_60) | (roc_9_1d_lt_100))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_70) | aroonu_14_1h_lt_70)
            # 15m down move, 15m & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_70) | aroonu_14_4h_lt_70)
            # 15m down move, 15m & 1d high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_70) | aroonu_14_1d_lt_100)
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_80))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_70) | roc_9_1d_lt_50)
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_20))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_15) | (roc_9_4h_lt_25) | (roc_9_1d_lt_100))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_85))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | aroonu_14_4h_lt_80)
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | aroonu_14_1d_lt_100)
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_20) | rsi_3_4h_gt_20 | (aroonu_14_15m_lt_60))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_75))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_90))
            # 15m & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_40) | (roc_9_4h_gt_neg_10))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_25) | (stochrsi_k_15m_lt_50))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_50))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_40) | (aroonu_14_1h_lt_90))
            # 15m &1d down move, 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_50) | (roc_9_1d_lt_20))
            # 15m & 1d down move, 4h high, 4h & 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_60) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_20) | (roc_9_1d_lt_30))
            # 15m down move, 15m still not low enough, 4h overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_30) | (roc_9_4h_lt_60))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_40) | (stochrsi_k_4h_lt_90))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_100))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_50) | aroonu_14_4h_lt_70)
            # 15m down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_50) | roc_9_1d_lt_50)
            # 15m down move, 15m high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_60) | (roc_9_4h_gt_neg_40))
            # 15m down move, 15m high, 4h overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_60) | (roc_9_4h_lt_10))
            # 15m down move, 15m high, 4h overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_70) | (roc_9_4h_lt_20))
            # 15m down move, 15m high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_70) | (roc_9_4h_gt_neg_10))
            # 15m down move, 15m high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_70) | (roc_9_1d_gt_neg_20))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_70) | roc_9_1d_lt_50)
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_20) | aroonu_14_1h_lt_80 | (roc_9_4h_lt_20))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | aroonu_14_4h_lt_70 | (roc_9_4h_lt_50))
            # 15m down move, 1h high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_60) | (roc_9_4h_gt_neg_20))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_30))
            # 15m down move, 1h high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_90))
            # 15m down move, 4h still high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_30))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_20) | (roc_9_4h_lt_25) | (roc_9_1d_lt_100))
            # 15m & 1h down move, 15m still not low enough, 1h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_50))
            # 15m & 1h & 4h down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_60))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (aroonu_14_15m_lt_70))
            # 15m & 1h & 4h down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_60) | (aroonu_14_15m_lt_40) | (stochrsi_k_4h_lt_80))
            # 15m & 4h & 1d down move, 15m & 1d high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_60) | (aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_70))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_40) | (aroonu_14_15m_lt_75))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_50) | (aroonu_14_1h_lt_100))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_100))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_75))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_90))
            # 15m down move, 15m high, 4h downtrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_70) | (roc_9_4h_gt_neg_20))
            # 15m down move, 15m high, 4h overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_70) | (roc_9_4h_lt_10))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_70) | (roc_9_1d_lt_60))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_70))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_70) | (roc_9_4h_gt_neg_10))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_90) | (roc_9_1d_lt_20))
            # 15m down move, 4h high, 1d high
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_60) | (stochrsi_k_1d_lt_90))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_10))
            # 15m down move, 15m still high, 1h still high
            & ((rsi_3_15m_gt_25) | (stochrsi_k_15m_lt_50) | (aroonu_14_1h_lt_50))
            # 15m down move, 1h high, 4h high
            & ((rsi_3_15m_gt_25) | (stochrsi_k_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_25) | (roc_9_4h_lt_50) | (roc_9_1d_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_35) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_50))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (roc_9_1d_lt_40))
            # 15m & 1h & 4h down move, 15m & 1d high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_50) | (aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_70))
            # 15m & 1h & 4h down move, 15m high, 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_55) | (rsi_3_4h_gt_60) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 15m high, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_55) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_100))
            # 15m & 1h down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_55) | (stochrsi_k_15m_lt_40) | (roc_9_1d_lt_30))
            # 15m & 4h & 1d down move, 15m high, 1d high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_15m_lt_70) | (stochrsi_k_1d_lt_70))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_70))
            # 15m & 1d down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_90))
            # 15m down move, 1d high, 15m high
            & ((rsi_3_15m_gt_30) | (rsi_14_1d_lt_70) | (aroonu_14_15m_lt_70))
            # 15m down move, 15m high, 1d downtrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_60) | (roc_9_1d_gt_neg_40))
            # 15m down move, 15m high, 15m downtrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_70) | (cmf_20_15m_gt_neg_0_30))
            # 15m down move, 15m high, 4h & 1d downtrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_70) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_10))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_70) | (roc_9_1d_lt_70))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_30))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_60))
            # 15m down move, 15m high, 4h overbought
            & ((rsi_3_15m_gt_30) | (stochrsi_k_15m_lt_70) | (roc_9_4h_lt_70))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_30) | (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_50))
            # 15m & 1h down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_40) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_90))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_30))
            # 15m & 4h & 1d down move, 4h still high, 15m high
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_60) | (rsi_14_4h_lt_50) | (aroonu_14_15m_lt_70))
            # 15m down move, 15m high, 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_60) | (stochrsi_k_4h_lt_90))
            # 15m down move, 15m high, 4h overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_70) | (roc_9_4h_lt_80))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_1h_lt_90) | (roc_9_4h_lt_100))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_200))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_35) | (stochrsi_k_1h_lt_90) | roc_9_1d_gt_neg_50)
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_35) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_55) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_lt_80))
            # 15m down move, 15m high, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_60) | (roc_9_1d_gt_neg_20))
            # 15m down move, 15m high, 1d high & overbought
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_85) | (rsi_3_1d_gt_35))
            # 15m down move, 15m high, 1h downtrend
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_70) | (roc_9_1h_gt_neg_20))
            # 15m down move, 15m & 4h high
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_75) | (aroonu_14_4h_lt_75))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_40) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30))
            # 1h & 4h down move, 15m still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_50))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_50))
            # 1h down move, 4h still high, 4h downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_10) | aroonu_14_4h_lt_70 | (roc_9_4h_lt_20))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_14_1d_lt_60))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_15m_lt_70))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_15) | rsi_3_4h_gt_20 | (roc_9_1d_gt_neg_30))
            # 1h & 1d down move, 1d overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_35) | (roc_9_1d_lt_10))
            # 1h & 1d down move, 1d overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_60) | (roc_9_1d_lt_40))
            # 1h down move, 1h still not low enough, 1d downtrend
            & ((rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_30) | (roc_9_1d_gt_neg_30))
            # 1h & 4h & 1d down move, 1h stil high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (roc_9_1d_lt_30))
            # 1h & 4h & 1d down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_80))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80))
            # 1h & 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_50))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_50))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_20))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_60) | (roc_9_1d_gt_neg_20))
            # 1h down move, 4h downtrend, 1d overbought
            & ((rsi_3_1h_gt_25) | (roc_9_4h_gt_neg_40) | roc_9_1d_lt_50)
            # 1h & 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h down move, 15m & 1h still high
            & ((rsi_3_1h_gt_30) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_50))
            # 1h down move, 1h still high, 1 & 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_40) | (roc_9_1h_gt_neg_20) | (roc_9_1d_gt_neg_50))
            # 1h down move, 1h still high 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_50) | (roc_9_1d_lt_200))
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_60) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_30))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_60) | (roc_9_4h_lt_20))
            # 1h down move, 4h & 1h overbought
            & ((rsi_3_1h_gt_30) | (roc_9_4h_lt_30) | (roc_9_1d_lt_40))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_1h_lt_75))
            # 1h down move, 15m still high, 4h  high
            & ((rsi_3_1h_gt_35) | (aroonu_14_15m_lt_40) | aroonu_14_4h_lt_80)
            # 1h down move, 15m still high, 4h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_15m_lt_40) | (stochrsi_k_4h_lt_70))
            # 1h down move, 15m still high, 4h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_15m_lt_50) | aroonu_14_4h_lt_70)
            # 1h down move, 15m & 1d high
            & ((rsi_3_1h_gt_35) | (aroonu_14_15m_lt_60) | (aroonu_14_1d_lt_80))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_35) | aroonu_14_1h_lt_70 | (stochrsi_k_4h_lt_90))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_35) | aroonu_14_1h_lt_80 | (aroonu_14_1d_lt_90))
            # 1h down move, 1h downtrend, 4h overbought
            & ((rsi_3_1h_gt_35) | (cmf_20_1h_gt_neg_0_30) | (roc_9_4h_lt_20))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_35) | aroonu_14_1h_lt_70 | (roc_9_1d_gt_neg_80))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_35) | aroonu_14_1h_lt_80 | roc_9_1d_lt_50)
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_80) | roc_9_1d_gt_neg_50)
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_50) | (stochrsi_k_1h_lt_70))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_60))
            # 1h down move, 15m still high, 4h downtrend
            & ((rsi_3_1h_gt_40) | (stochrsi_k_15m_lt_40) | (roc_9_4h_gt_neg_15))
            # 1h down move, 15m still high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_15m_lt_50) | roc_9_1d_lt_50)
            # 1h down move, 15m & 4h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_15m_lt_70) | aroonu_14_4h_lt_70)
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50) | (stochrsi_k_4h_lt_80))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50) | (roc_9_1d_lt_100))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_20))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_85) | (roc_9_1d_gt_neg_60))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_80) | (cmf_20_1d_gt_neg_0_20))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_40) | (roc_9_4h_lt_10) | (roc_9_1d_lt_50))
            # 1h down move, 15m high, 4h overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_15m_lt_70) | (roc_9_4h_lt_30))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_100) | (roc_9_4h_lt_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_40))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_40) | (roc_9_1d_lt_200))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_10))
            # 1h & 4h & 1d down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_50) | (rsi_3_4h_gt_60) | (rsi_3_1d_gt_60) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_60))
            # 1h down move, 15m & 1h high
            & ((rsi_3_1h_gt_50) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_10))
            # 1h down move, 4h still high, 1d overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_50) | (roc_9_1d_lt_200))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_50))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_10))
            # 1h & 4h down move, 15m & 4h high
            & ((rsi_3_1h_gt_55) | (rsi_3_4h_gt_60) | (stochrsi_k_15m_lt_60) | (stochrsi_k_4h_lt_70))
            # 1h down move, 1h high, 1d high
            & ((rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_70) | (aroonu_14_1d_lt_100))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_55) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_100))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_100))
            # 1h down move, 15m & 1h high
            & ((rsi_3_1h_gt_65) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10))
            # 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_4h_gt_3) | (stochrsi_k_1h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1h still high, 4h downtrend
            & ((rsi_3_4h_gt_3) | (stochrsi_k_1h_lt_50) | (roc_9_4h_gt_neg_30))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_3) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h down move, 15m high, 1h still high
            & ((rsi_3_4h_gt_5) | (aroonu_14_15m_lt_70) | (stochrsi_k_1h_lt_50))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_5) | (stochrsi_k_15m_lt_70))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_5) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_lt_50))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_20) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_50))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_35) | (stochrsi_k_1d_lt_40))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_80))
            # 4h down move, 15m still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_30) | (roc_9_1d_gt_neg_40))
            # 4h down move, 15m high, 4h downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_60) | (roc_9_4h_gt_neg_50))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_70))
            # 4h & 1d down move, 15m high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_35) | (stochrsi_k_15m_lt_70))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_35) | (stochrsi_k_4h_lt_70))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_70))
            # 4h down move, 15m still high, 1h high
            & ((rsi_3_4h_gt_15) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_lt_60))
            # 4h down move, 15m & 1d high
            & ((rsi_3_4h_gt_15) | (aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_80))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_80))
            # 4h down move, 1d high
            & ((rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_80))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_15) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h & 1d down move, 1h still high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1h_lt_40))
            # 4h & 1d down move, 15m high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (stochrsi_k_15m_lt_70))
            # 4h & 1d down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_40) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_40))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_55) | (roc_9_1d_lt_50))
            # 4h down move, 15m & 4h still high
            & ((rsi_3_4h_gt_20) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_50))
            # 4h down move, 15m high, 1d high
            & ((rsi_3_4h_gt_20) | (aroonu_14_15m_lt_70) | (stochrsi_k_1d_lt_70))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_10))
            # 4h down move, 15m high, 4h downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_80) | (roc_9_4h_gt_neg_50))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_60) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h still not low enough, 4h downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_30) | (roc_9_4h_gt_neg_10))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_60) | (roc_9_1d_gt_neg_60))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_90))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_30))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_80))
            # 4h & 1d down move, 15m high, 1d overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_60) | (aroonu_14_15m_lt_70) | (roc_9_1d_lt_10))
            # 4h down move, 15m still high, 1h high
            & ((rsi_3_4h_gt_25) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_100))
            # 4h down move, 15m & 4h still high
            & ((rsi_3_4h_gt_25) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_50))
            # 4h down move, 15m high, 1d overbought
            & ((rsi_3_4h_gt_25) | (aroonu_14_15m_lt_70) | (roc_9_1d_lt_100))
            # 4h down move, 1h high, 1d overbought
            & ((rsi_3_4h_gt_25) | (aroonu_14_1h_lt_90) | (roc_9_1d_lt_50))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_lt_100))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_60) | (roc_9_1d_gt_neg_70))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_70) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_40))
            # 4h down move, 15m still high, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1h still high, 1d overbought
            & ((rsi_3_4h_gt_25) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_100))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_80) | roc_9_1d_gt_neg_50)
            # 4h down move, 1h high, 1h downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_1h_gt_neg_10))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_30) | (rsi_3_1d > 50.0) | (roc_9_1d_lt_100))
            # 4h down move, 1d downtrend, 1d overbought
            & ((rsi_3_4h_gt_30) | (cmf_20_1d_gt_neg_0_30) | (roc_9_1d_lt_40))
            # 4h down move, 15m high, 4h high
            & ((rsi_3_4h_gt_30) | (aroonu_14_15m_lt_60) | (aroonu_14_4h_lt_90))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_1h_lt_90) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_40))
            # 4h down move, 1h high, 1d overbought
            & ((rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_50))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_10))
            # 4h down move, 15m still high, 1h high
            & ((rsi_3_4h_gt_35) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_90))
            # 4h down move, 15m still high, 4h high
            & ((rsi_3_4h_gt_35) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_80))
            # 4h down move, 15m high, 1h high
            & ((rsi_3_4h_gt_35) | (aroonu_14_15m_lt_70) | (stochrsi_k_1h_lt_70))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_35) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 4h down move, 1d high, 1d downtrend
            & ((rsi_3_4h_gt_35) | (stochrsi_k_1d_lt_60) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_35) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_40))
            # 4h & 1d down move, 15m & 1h high
            & ((rsi_3_4h_gt_40) | (rsi_3_1d_gt_45) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_90))
            # 4h down move, 15m still high, 1d overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_50))
            # 4h down move, 15m high, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_40) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 15m high, 1d overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_15m_lt_70) | (roc_9_1d_lt_200))
            # 4h down move, 1h & 4h high
            & ((rsi_3_4h_gt_40) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_80))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 4h down move, 15m high, 1h high
            & ((rsi_3_4h_gt_40) | (stochrsi_k_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 4h down move, 1h high, 1d overbought
            & ((rsi_3_4h_gt_40) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_60))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_40) | (roc_9_4h_lt_10) | (roc_9_1d_lt_30))
            # 4h down move, 15m still high, 4h high
            & ((rsi_3_4h_gt_45) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_90))
            # 45 down move, 15m high, 1h high
            & ((rsi_3_4h_gt_45) | (aroonu_14_15m_lt_70) | (stochrsi_k_1h_lt_70))
            # 4h down move, 15m high, 4h high
            & ((rsi_3_4h_gt_45) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_70))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_4h_lt_60) | (roc_9_1d_lt_100))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_30))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_30))
            # 4h down move, 1d high, 1d downtrend
            & ((rsi_3_4h_gt_45) | (aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_15))
            # 4h down move, 1d high, 4h overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_1d_lt_90) | (roc_9_4h_lt_10))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_45) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_45) | (roc_9_4h_lt_30) | (roc_9_1d_lt_200))
            # 4h down move, 15m & 1h high
            & ((rsi_3_4h_gt_50) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 4h down move, 4h still high, 1h high
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_40) | (stochrsi_k_1h_lt_70))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_40))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_80))
            # 4h down move, 1d high, 4h overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_1d_lt_90) | (roc_9_4h_lt_10))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_60) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h downtrend, 1d overbought
            & ((rsi_3_4h_gt_50) | (roc_9_4h_gt_neg_20) | (roc_9_1d_lt_20))
            # 4h down move, 1h high, 4h overbought
            & ((rsi_3_4h_gt_55) | (aroonu_14_1h_lt_100) | (roc_9_4h_lt_20))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_55) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_20))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_55) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_60))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_55) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 4h down move, 15m high, 1h high
            & ((rsi_3_4h_gt_60) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_90))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_30))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_60) | (roc_9_4h_lt_30) | roc_9_1d_lt_50)
            # 4h down move, 15m high, 4h high
            & ((rsi_3_4h_gt_65) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_90))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_65) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_10))
            # 1d down move, 4h & 1d downtrend
            & ((rsi_3_1d_gt_3) | (roc_9_4h_gt_neg_40) | (roc_9_1d_gt_neg_50))
            # 1d down move, 15m still high, 4h high
            & ((rsi_3_1d_gt_10) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_80))
            # 1d down move, 4h & 1d downtrend
            & ((rsi_3_1d_gt_10) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_60))
            # 1d down move, 4h & 1d downtrend
            & ((rsi_3_1d_gt_10) | (roc_9_4h_gt_neg_30) | roc_9_1d_gt_neg_50)
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_15) | (aroonu_14_1h_lt_85) | (roc_9_1d_gt_neg_30))
            # 1d down move, 4h & 1d downtrend
            & ((rsi_3_1d_gt_15) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_40))
            # 1d down move, 15m high, 1h high
            & ((rsi_3_1d_gt_20) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_80))
            # 1d down move, 15m high, 1h high
            & ((rsi_3_1d_gt_20) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 1d down move, 4h high, 4h downtrend
            & ((rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_70) | (roc_9_4h_gt_neg_20))
            # 1d down move, 15m high, 4h high
            & ((rsi_3_1d_gt_25) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_80))
            # 1d down move, 15m high, 4h downtrend
            & ((rsi_3_1d_gt_25) | (aroonu_14_15m_lt_70) | (roc_9_4h_gt_neg_30))
            # 1d down move, 1h & 1d high
            & ((rsi_3_1d_gt_25) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_80))
            # 1d down move, 15m high
            & ((rsi_3_1d_gt_25) | (stochrsi_k_15m_lt_80))
            # 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_50) | (roc_9_1d_gt_neg_20))
            # 1d down move, 1d high & overbought
            & ((rsi_3_1d_gt_30) | (aroonu_14_1d_lt_60) | (roc_9_1d_lt_10))
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_30) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_20))
            # 1d down move, 1h & 1d high
            & ((rsi_3_1d_gt_35) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_90))
            # 1d down move, 1h high, 1d overbought
            & ((rsi_3_1d_gt_40) | (aroonu_14_1h_lt_90) | (roc_9_1d_lt_80))
            # 1d down move, 1d high & overbought
            & ((rsi_3_1d_gt_40) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 1d down move, 1d high & overbought
            & ((rsi_3_1d_gt_40) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_10))
            # 1d down move, 1h high, 1d overbought
            & ((rsi_3_1d_gt_40) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_50))
            # 15m still high, 4h high, 1d overbought
            & ((aroonu_14_15m_lt_50) | (rsi_14_4h < 60.0) | (roc_9_1d_lt_70))
            # 15m still high, 1h downtrend, 4h overbought
            & ((aroonu_14_15m_lt_50) | (roc_9_1h_gt_neg_10) | (roc_9_4h_lt_40))
            # 15m high, 4h high & overbought
            & ((aroonu_14_15m_lt_60) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_20))
            # 15m & 4h high, 1d overbought
            & ((aroonu_14_15m_lt_60) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_10))
            # 15m high, 15m & 4h overbought
            & ((aroonu_14_15m_lt_60) | (roc_9_15m < 10.0) | (roc_9_4h_lt_20))
            # 15m high, 4h downtrend
            & ((aroonu_14_15m_lt_60) | (roc_9_4h_gt_neg_30))
            # 15m & 1h & 4h high
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100))
            # 15m & 4h & 1d high
            & ((aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_90))
            # 15m & 4h high, 4h overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10))
            # 15m & 4h high, 1d downtrend
            & ((aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_70) | (roc_9_1d_gt_neg_20))
            # 15m & 1d high, 1d overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_100))
            # 15m high, 4h downtrend, 1d overbought
            & ((aroonu_14_15m_lt_70) | (roc_9_4h_gt_neg_30) | (roc_9_1d_lt_200))
            # 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_50))
            # 1h & 4h high, 4h overbought
            & (aroonu_14_1h_lt_80 | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 1h high, 1d high & overbought
            & ((aroonu_14_1h_lt_90) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 1h high, 4h downtrend
            & ((aroonu_14_1h_lt_90) | (roc_9_4h_gt_neg_20))
            # 1h high, 4h & 1d overbought
            & ((aroonu_14_1h_lt_90) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 4h & 1d high, 4h overbought
            & (aroonu_14_4h_lt_80 | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 4h & 1d high, 1d downtrend
            & (aroonu_14_4h_lt_80 | (aroonu_14_1d_lt_100) | (roc_9_1d_gt_neg_20))
            # 1d high, 4h & 1d downtrend
            & ((aroonu_14_1d_lt_80) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 1d high, 1h & 4h downtrend
            & ((aroonu_14_1d_lt_85) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_50))
            # 1d high, 4h downtrend
            & ((aroonu_14_1d_lt_85) | (roc_9_4h_gt_neg_30))
            # 1d high, 4h downtrend, 1d overbought
            & ((aroonu_14_1d_lt_85) | (roc_9_4h_gt_neg_30) | (roc_9_1d_lt_70))
            # 1d high, 4h & 1d overbought
            & (aroonu_14_1d_lt_100 | (roc_9_4h_lt_30) | (roc_9_1d_lt_40))
            # 15m & 1h high, 1d overbought
            & ((stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_70) | roc_9_1d_lt_50)
            # 15m & 1d high
            & ((stochrsi_k_15m < 90.0) | (stochrsi_k_1d_lt_90))
            # 1h high, 4h & 1d downtrend
            & ((stochrsi_k_1h_lt_60) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_30))
            # 1h high, 4h downtrend
            & ((stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_30))
            # 1h high, 1d downtrend
            & ((stochrsi_k_1h_lt_70) | (roc_9_1d_gt_neg_20))
            # 4h high, 4h overbought, 1d downtrend
            & ((stochrsi_k_4h_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_gt_neg_20))
            # 1d still high, 4h & 1d downtrend
            & ((stochrsi_k_1d_lt_50) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_30))
            # 1d P&D, 4h downtrend
            & ((change_pct_1d_gt_neg_50) | (change_pct_1d_shift_288 < 50.0) | (rsi_3_4h_gt_15))
            # 1d P&D, 15m high
            & ((change_pct_1d_gt_neg_20) | (change_pct_1d_shift_288 < 20.0) | (aroonu_14_15m_lt_70))
            # 1d red with top wick, 4h high
            & ((change_pct_1d_gt_neg_20) | (top_wick_pct_1d_lt_20) | aroonu_14_4h_lt_80)
            # 1d red, previous 1d top wick, 15m high
            & ((change_pct_1d_gt_neg_10) | (top_wick_pct_1d_shift_288 < 40.0) | (aroonu_14_15m_lt_70))
            # 1d green with top wick, 4h overbought
            & ((change_pct_1d_lt_15) | (top_wick_pct_1d_lt_15) | (roc_9_4h_lt_20))
            # 1d green, 15m down move, 1h high
            & ((change_pct_1d_lt_50) | (rsi_3_15m_gt_25) | aroonu_14_1h_lt_70)
            # 1d green, 4h down move, 4h still high
            & ((change_pct_1d_lt_40) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_40))
            # 1d top wick, 4h down move, 1d overbought
            & ((top_wick_pct_1d_lt_50) | (rsi_3_4h_gt_35) | (roc_9_1d_lt_60))
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
          )

          # Logic
          long_entry_logic.append(
            (rsi_20 < rsi_20_shift_1)
            & (rsi_4 < 45.0)
            & (rsi_14 > 30.0)
            & (aroonu_14 < 20.0)
            & (stochrsi_k_lt_20)
            & (close < sma_16 * 0.965)
            & (close < sma_16_1h * 0.985)
          )

        # Condition #4 - Normal mode (Long).
        if long_entry_condition_index == 4:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            rsi_3_15m_gt_3
            # 5m & 1h down move, 1d still high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_3) | (aroonu_14_1d_lt_40))
            # 5m & 1h & 4h down move
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_10))
            # 5m & 1h down move, 1h still not low enough
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_30))
            # 5m & 1h down move, 1d high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_15) | (aroonu_14_1d_lt_80))
            # 5m & 1h down move, 1d high
            & ((rsi_3_gt_3) | rsi_3_1h_gt_20 | aroonu_14_1d_lt_100)
            # 5m & 1h down move, 1h high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_50) | aroonu_14_1h_lt_70)
            # 5m & 1h down move, 1h still high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_50))
            # 5m & 1h down move, 1d downtrend
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_15) | (roc_9_1d > -30.0))
            # 5m & 4h down move, 4h high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_25) | aroonu_14_4h_lt_70)
            # 5m & 1d down move, 15m still high
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_20) | (stochrsi_k_15m_lt_40))
            # 5m down move, 1h high, 4h overbought
            & ((rsi_3_gt_3) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_20))
            # 5m down move, 1d overbought
            & ((rsi_3_gt_3) | (roc_9_1d_lt_80))
            # 5m & 1h & 4h down move
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_5))
            # 5m & 4h down move, 15m still high
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_50))
            # 5m down move, 4h high, 1h overbought
            & ((rsi_3_gt_10) | aroonu_14_4h_lt_100 | (roc_9_1h_lt_30))
            # 15m & 1h down move, 1d still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (aroonu_14_1d_lt_40))
            # 15m & 1h down move, 1d still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_50))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (roc_9_1d_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_70))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_45) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_50))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (aroonu_14_1h_lt_80))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15) | (roc_9_1d_lt_70))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_30) | aroonu_14_1d_lt_100)
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_5) | aroonu_14_1h_lt_70 | (roc_9_1h_lt_10))
            # 15m down move, 1h & 1d high
            & ((rsi_3_15m_gt_5) | (roc_9_1h_lt_10) | (roc_9_1d_lt_40))
            # 15m & 1h & 4h down move, 1h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_30))
            # 15m & 1h down move, 15m stil high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_15m_lt_50))
            # 15m & 1h down move, 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (roc_9_4h_gt_neg_40))
            # 15m & 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (rsi_14_1d_lt_50))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (aroonu_14_4h_lt_70))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_70))
            # 15m & 1h & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_90))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (roc_9_1d_lt_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_80))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_55) | (aroonu_14_1h_lt_60))
            # 15m & 1h & 4h down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_50) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_30))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_100))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_70) | (roc_9_1d_gt_neg_50))
            # 15m down move, 1h high
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_80))
            # 15m & 1h & 4h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_70))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_70))
            # 15m & 1h down move, 1h still high, 1d downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_50) | (roc_9_1d_gt_neg_50))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_40))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_80))
            # 15m & 4h & 1d down move, 1d high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_50))
            # 15m & 4h down move, 4h & 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 15m down move, 1h & 4h high, 4h & 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10) | (roc_9_1d_lt_10))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_20))
            # 15m down move, 15m high
            & ((rsi_3_15m_gt_15) | (stochrsi_k_15m_lt_80))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_10))
            # 15m down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_15) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_35) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_100))
            # 15m & 1h & 4h & 1d down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (stochrsi_k_1h_lt_70))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_45) | (stochrsi_k_1h_lt_80))
            # 15m & 1d down move, 1h high, 1h & 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_60) | (aroonu_14_1h_lt_80) | (roc_9_1h_lt_20) | (roc_9_1d_lt_20))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_100))
            # 15m down move, 4h high, 1h overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_30))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_80))
            # 15m down move, 4h high, 4h overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_60) | (roc_9_4h_lt_50))
            # 15m & 1h & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (aroonu_14_4h_lt_85))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_100))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_40) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_30))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_30))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_50) | (roc_9_4h_lt_50))
            # 1h & 4h down move
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_3))
            # 1h & 4h down move, 15m downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_3) | (roc_9_15m > -30.0))
            # 1h & 4h down move, 15m downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (cmf_20_15m_gt_neg_0_40))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_70))
            # 1h down move, 1h high, 4h high
            & ((rsi_3_1h_gt_3) | (aroonu_14_1h_lt_70) | (stochrsi_k_4h_lt_80))
            # 1h down move, 15m still high
            & ((rsi_3_1h_gt_3) | (stochrsi_k_15m_lt_50))
            # 1h down move, 1h still high, 4h overbought
            & ((rsi_3_1h_gt_3) | (stochrsi_k_1h_lt_50) | (roc_9_4h_lt_20))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (rsi_3_1d_gt_20))
            # 1h & 4h down move, 1h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (roc_9_1h_gt_neg_20))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_40))
            # 1h & 4h & 1d down move, 1d still high, 1d overbought
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_50) | (roc_9_1d_lt_10))
            # 1h down move, 4h high, 1h downtrend
            & ((rsi_3_1h_gt_5) | (stochrsi_k_4h_lt_70) | (roc_9_1h_gt_neg_40))
            # 1h down move, 4h high, 1h downtrend
            & ((rsi_3_1h_gt_5) | (stochrsi_k_4h_lt_70) | (cmf_20_1h_gt_neg_0_40))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_5) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 1h down move, 1d overbought
            & ((rsi_3_1h_gt_5) | (roc_9_1d_lt_100))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_15))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 1h downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (roc_9_1h_gt_neg_20))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_50))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_35) | (rsi_14_4h_lt_40))
            # 1h & 3h down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_100))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_70))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_85))
            # 1h down move, 1d high, 15m downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_70) | (roc_9_15m > -50.0))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_10) | (roc_9_4h_gt_neg_15) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_20))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_30))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_lt_40))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_80))
            # 1h down move, 1h still high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_40) | (roc_9_4h_gt_neg_30))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_60) | (roc_9_4h_lt_10) | (roc_9_1d_lt_30))
            # 1h down move, 1h still high, 4h downtrend
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_50) | (roc_9_4h_gt_neg_50))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_80))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (roc_9_1d_lt_20))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_40))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_70))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_30))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_200))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (stochrsi_k_15m_lt_80))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (stochrsi_k_1h_lt_70))
            # 1h down move, 15m still high, 1h high
            & ((rsi_3_1h_gt_30) | (stochrsi_k_15m_lt_40) | (aroonu_14_1h_lt_60))
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_70))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_30) | (roc_9_4h_gt_neg_25) | (roc_9_1d_gt_neg_60))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (roc_9_4h_lt_20) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_30))
            # 1h & 4h & 1d down move, 1h & 4h still high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_50))
            # 1h down move, 1h high, 4h high & overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_20))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_85) | (roc_9_1d_lt_100))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_200))
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h down move, 4h & 1d high & overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10) | (roc_9_1d_lt_30))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_60) | (roc_9_1d_gt_neg_60))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_40))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10))
            # 1h down move, 1h high, 4h high & overbought
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_40))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_60) | (roc_9_4h_lt_30) | (roc_9_1d_lt_60))
            # 4h & 1d down move, 4h still not low enough
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_15) | (aroonu_14_4h_lt_20))
            # 4h down move, 4h high, 4h downtrend
            & ((rsi_3_4h_gt_3) | (aroonu_14_4h_lt_50) | (roc_9_4h_gt_neg_40))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_3) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h & 1d down move, 1h still not low enough
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_30))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_70))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_4h_gt_neg_15) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1h still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (aroonu_14_1h_lt_40))
            # 4h & 1d down move, 1h high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_1h_lt_70))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_40))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_50))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_60))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_70))
            # 4h down move, 4h still high, 1h downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_1h_gt_neg_20))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_15) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_10))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_80))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_20) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_40) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_200))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_45) | (aroonu_14_4h_lt_70) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_100))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_60) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 4h up move, 1d downtrend, 4h high
            & ((rsi_3_4h_lt_90) | (cmf_20_1d_gt_neg_0_25) | (aroonu_14_4h_lt_100))
            # 1d down move, 4h high & overbought
            & ((rsi_3_1d_gt_20) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_90) | (roc_9_1d_gt_neg_20))
            # 1d down move, 1h high, 4h high & overbought
            & ((rsi_3_1d_gt_30) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_20))
            # 1h still high, 4h & 1d downtrend
            & ((aroonu_14_1h_lt_40) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_40))
            # 1h & 4h high & overbought
            & ((aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_30) | (roc_9_4h_lt_30))
            # 1h & 4h high, 1h overbought
            & ((aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_80))
            # 1h high, 1d overbought
            & ((aroonu_14_1h_lt_70) | (roc_9_1d_lt_70))
            # 1h & 4h high, 1h overbought
            & ((aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_30))
            # 1h & 4h high & overbought
            & ((aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_20) | (roc_9_4h_lt_20))
            # 1h & 1d high, 1h overbought
            & ((aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_90) | (roc_9_1h_lt_30))
            # 4h still not low enough, 4h & 1d downtrend
            & ((aroonu_14_4h_lt_30) | (roc_9_4h_gt_neg_40) | (roc_9_1d_gt_neg_40))
            # 4h still high, 5m downtrend
            & ((aroonu_14_4h_lt_40) | (roc_9 > -40.0))
            # 4h high, 4h & 1d overbought
            & ((aroonu_14_4h_lt_60) | (roc_9_4h_lt_30) | (roc_9_1d_lt_50))
            # 4h & 1d high, 4h overbought
            & ((aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_50))
            # 4h high, 1h & 1d overbought
            & ((aroonu_14_4h_lt_100) | (roc_9_1h_lt_30) | (roc_9_1d_lt_100))
            # 4h high, 1h & 4h high
            & ((aroonu_14_4h_lt_100) | (roc_9_1h_lt_50) | (roc_9_4h_lt_100))
            # 1d high, 4h & 1d downtrend
            & ((aroonu_14_1d_lt_70) | (roc_9_4h_gt_neg_40) | (roc_9_1d_gt_neg_40))
            # 1d high, 1h & 1d overbought
            & ((aroonu_14_1d_lt_80) | (roc_9_1h_lt_30) | (roc_9_1d_lt_200))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_90) | (roc_9_4h_lt_20) | roc_9_1d_lt_50)
            # 1h high, 4h overbought
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_lt_80))
            # 4h & 1d overbought
            & ((roc_9_4h_lt_100) | (roc_9_1d_lt_200))
            # 5m red, 1h & 4h down move
            & ((change_pct > -5.0) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_5))
            # 1d top wick, 1h & 4h down move, 1d high
            & ((top_wick_pct_1d_lt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100))
            # big drop in last hough, 4h down move, 1h still not low enough
            & ((close > (close_max_12 * 0.90)) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_30))
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
            # drop in last 20 days, 1h high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | aroonu_14_1h_lt_70 | (roc_9_1d_gt_neg_70))
          )

          # Logic
          long_entry_logic.append(
            (aroonu_14_lt_25) & (aroonu_14_15m_lt_25) & (close < (ema_9 * 0.946)) & (close < (ema_20 * 0.960))
          )

        # Condition #5 - Normal mode (Long).
        if long_entry_condition_index == 5:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            (rsi_3_15m_gt_20)
            # 5m & 1h down move, 1h still not low enough
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_30))
            # 5m & 1h down move, 1d high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_20) | (aroonu_14_1d_lt_100))
            # 5m & 1h down move, 1h still high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_50))
            # 5m & 4h down move, 15m still high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_3) | (stochrsi_k_15m_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_60))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (rsi_14_4h_lt_40))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (roc_9_4h_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_50) | (aroonu_14_1h_lt_85))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_80))
            # 15m & 1d down move, 1d high, 4h downtrend
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_80) | (roc_9_4h_gt_neg_40))
            # 15m down move, 15m stil not low enough, 4h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_60))
            # 15m down move, 15m high, 1h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_70))
            # 15m down move, 1h & 4h overbought
            & ((rsi_3_15m_gt_25) | (roc_9_1h_lt_40) | (roc_9_4h_lt_40))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_25) | (roc_9_4h_lt_10) | (roc_9_1d_lt_50))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_85))
            # 15m & 1h & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 15m & 1h down move, 1h still high, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_10))
            # 15m down move, 15m still high, 1d high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_50) | (stochrsi_k_1d_lt_70))
            # 15m down move, 15m high, 4h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_60) | (stochrsi_k_4h_lt_70))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_85) | (aroonu_14_4h_lt_100))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_30) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 15m down move, 4h high, 1h downtrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_4h_lt_85) | (roc_9_1h_gt_neg_40))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_25))
            # 15m & 1h & 1d down move, 15m high, 4h high
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_40) | (rsi_3_1d_gt_45) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_90))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_80))
            # 15m down move, 15m high, 4h overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_70) | (roc_9_4h_lt_10))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_1h_lt_85) | (roc_9_4h_lt_80))
            # 15m down move, 4h high, 1h overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_20))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_100))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_45) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_85))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_5) | (aroonu_14_1d_lt_70))
            # 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_5) | (rsi_3_1d_gt_50) | (stochrsi_k_1d_lt_50))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_40))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (roc_9_1d_lt_15))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_20))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (roc_9_4h_gt_neg_40))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (roc_9_1d_gt_neg_50))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_3) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 1h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_20) | (roc_9_1h_gt_neg_15))
            # 1h & 4h down move, 4h high & overbought
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_10))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_50))
            # 1h & 4h down move, 15m still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_50))
            # 1h & 4h down move, 1h downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_20))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_15))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_70))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (stochrsi_k_1h_lt_40) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_40))
            # 1h down move, 4h downtrend. 4h still not low enough
            & ((rsi_3_1h_gt_10) | (roc_9_4h_gt_neg_20) | (aroonu_14_4h_lt_30))
            # 1h down move, 15m still high, 4h high
            & ((rsi_3_1h_gt_10) | (aroonu_14_15m_lt_40) | (stochrsi_k_4h_lt_90))
            # 1h down move, 15m high, 4h downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_15m_lt_70) | (roc_9_4h_gt_neg_10))
            # 1h down move, 1h still high, 15m downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_40) | (cmf_20_15m_gt_neg_0_30))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20))
            # 1h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_50) | (roc_9_1d_gt_neg_40))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_30))
            # 1h & 4h & 1d down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_55) | (aroonu_14_1d_lt_90))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_50))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_30))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_30))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 4h still high, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_40) | (aroonu_14_1d_lt_100))
            # 1h & 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_100))
            # 1h & 1d down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_15) | (stochrsi_k_4h_lt_80))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_60) | roc_9_1d_lt_50)
            # 1h down move, 4h high, 1d high
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_80) | (stochrsi_k_1d_lt_80))
            # 1h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_60))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_10))
            # 1h down move, 1h downtrend, 1d overbought
            & ((rsi_3_1h_gt_15) | (roc_9_1h_gt_neg_30) | (roc_9_1d_lt_80))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_15) | (roc_9_4h_lt_10) | (roc_9_1d_lt_60))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_70))
            # 1h & 4h & 1d down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_50))
            # 1h & 4h down move, 4h high, 1h downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_70) | (roc_9_1h_gt_neg_20))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h high and overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_30))
            # 1h & 4h & 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_85) | (roc_2_1d > -30.0))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80))
            # 1h & 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_45) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_50))
            # 1h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_30) | (stochrsi_k_1h_lt_50))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_15m_lt_70))
            # 1h & 4h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_100))
            # 1h down move, 4h downtrend, 4h high
            & ((rsi_3_1h_gt_25) | (cmf_20_4h_gt_neg_0_50) | (aroonu_14_4h_lt_70))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_30))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_30))
            # 1h & 4h & 1d down move, 1h still not low enough, 1d downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1h_lt_30) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_85))
            # 1h & 4h down move, 4h & 1d high, 4h overbought
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_30))
            # 1h down move, 1h still high, 1h & 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_40) | (roc_9_1h_gt_neg_10) | (roc_9_1d_gt_neg_50))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_85))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_20))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_30))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_100))
            # 1h down move, 15m still high, 1h high
            & ((rsi_3_1h_gt_30) | (stochrsi_k_15m_lt_40) | (aroonu_14_1h_lt_60))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_70) | (roc_9_1d_gt_neg_40))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_90) | (roc_9_1d_gt_neg_50))
            # 1h down move, 4h downtrend, 1d over
            & ((rsi_3_1h_gt_30) | (roc_9_4h_gt_neg_30) | (roc_9_1d_lt_50))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_50) | (roc_9_1d_lt_20))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (roc_9_1d_gt_neg_25))
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_80) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_200))
            # 1h down move, 15m high, 1h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_70))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_40) | (roc_9_1d_lt_100))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_30))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1d_lt_80) | roc_9_1d_lt_50)
            # 1h down move, 1h & 4h overbought
            & ((rsi_3_1h_gt_40) | (roc_9_1h_lt_20) | (roc_9_4h_lt_20))
            # 1h down move, 1h overbought
            & ((rsi_3_1h_gt_40) | (roc_9_1h_lt_30))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (roc_9_1d_lt_200))
            # 1h down move, 15m still high, 1h high
            & ((rsi_3_1h_gt_45) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_85))
            # 1h down move, 1h & 4h high, 1h overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_20))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_50))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_70) | roc_9_1d_lt_50)
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_90) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h high, 1h overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_40))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_60) | (roc_9_1d_gt_neg_60))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_50) | (roc_9_4h_lt_20) | (roc_9_1d_lt_80))
            # 1h down move, 15m high, 1h high
            & ((rsi_3_1h_gt_55) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_80))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_60) | (roc_9_1d_lt_10))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_60) | (roc_9_4h_lt_10) | (roc_9_1d_lt_40))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_60) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_40))
            # 4h & 1d down move, 4h downtrend
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_10) | (roc_9_4h_gt_neg_20))
            # 4h & 1d down move, 1h still not low enough
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_30))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_20) | (roc_9_1h_gt_neg_50))
            # 4h & 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_40) | (roc_9_4h_gt_neg_10))
            # 4h down move, 1d high, 4h downtrend
            & ((rsi_3_4h_gt_5) | (aroonu_14_1d_lt_80) | (roc_9_4h_gt_neg_10))
            # 4h & 1d down move, 15m high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_15m_lt_80))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (roc_9_1d_gt_neg_15))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_50))
            # 4h & 1d down move, 1h & 1d downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_30) | (roc_9_1h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_40) | (stochrsi_k_4h_lt_40))
            # 4h down move, 15m downtrend, 1d high
            & ((rsi_3_4h_gt_10) | (cmf_20_15m_gt_neg_0_30) | (aroonu_14_1d_lt_80))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 4h down move, 15m still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_50) | (roc_9_1d_gt_neg_25))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_80))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_70) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h downtrend, 1d overbought
            & ((rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_20) | (roc_9_1d_lt_40))
            # 4h & 1d down move, 4h downtrend
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_20) | (roc_9_4h_gt_neg_40))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_1h_lt_90) | (roc_9_1d_gt_neg_10))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1h & 4h downtrend, 1d overbought
            & ((rsi_3_4h_gt_15) | (roc_9_1h_gt_neg_20) | (roc_9_4h_gt_neg_30) | (roc_9_1d_lt_20))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_15) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h & 1ddown move, 1d high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_80))
            # 4h & 1d down move, 1h still high, 4h still high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_50))
            # 4h & 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_10))
            # 4h down move, 1d high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_70))
            # 4h down move, 1h & 4h still high, 1h downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_40) | (roc_9_1h_gt_neg_25))
            # 4h down move, 4h still high. 4h downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_50) | (cmf_20_4h_gt_neg_0_40))
            # 4h down move, 15m still high, 4h & 1d downtrend
            & ((rsi_3_4h_gt_20) | (aroonu_14_15m_lt_50) | (roc_9_4h_gt_neg_40) | (roc_9_1d_gt_neg_50))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_60) | (roc_9_1d_gt_neg_70))
            # 4h down move, 1h high, 4h downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_4h_gt_neg_10))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_60) | (roc_9_1d_gt_neg_40))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_80))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_35) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_10))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_40))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_50) | (roc_9_4h_lt_10) | (roc_9_1d_lt_40))
            # 4h up move, 1d downtrend, 4h high
            & ((rsi_3_4h_lt_90) | (cmf_20_1d_gt_neg_0_25) | (aroonu_14_4h_lt_100))
            # 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1d_gt_10) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_10))
            # 1d down move, 1h still low, 4h high, 4h downtrend
            & ((rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_70) | (roc_9_4h_gt_neg_10))
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_70) | (roc_9_1d_gt_neg_80))
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_90) | (roc_9_1d_gt_neg_20))
            # 1d down move, 1h high, 4h downtrend
            & ((rsi_3_1d_gt_30) | (stochrsi_k_1h_lt_90) | (roc_9_4h_gt_neg_30))
            # 15m & 1h & 4h downtrend
            & ((cmf_20_15m_gt_neg_0_30) | (cmf_20_1h_gt_neg_0_30) | (cmf_20_4h_gt_neg_0_30))
            # 1d downtrend, 1d high & overbought
            & ((cmf_20_1d_gt_neg_0_40) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_20))
            # 15m not low enough, 1h & 4h downtrend
            & ((aroonu_14_15m_lt_20) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_50))
            # 15m high, 1h high & overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_85) | (roc_9_1h_lt_10))
            # 1h & 1d high, 1h & 1d overbought
            & ((aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_90) | (roc_9_1h_lt_20) | (roc_9_1d_lt_200))
            # 1h & 4h high, 4h overbought
            & ((aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 1h & 1d high, 1d overbought
            & ((aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_200))
            # 1h high, 1h overbought
            & ((aroonu_14_1h_lt_80) | (roc_9_1h_lt_10))
            # 1h high, 4h & 1d downtrend
            & ((aroonu_14_1h_lt_80) | (roc_9_4h_gt_neg_40) | (roc_9_1d_gt_neg_40))
            # 4h still high, 5m downtrend
            & ((aroonu_14_4h_lt_40) | (roc_9 > -40.0))
            # 4h high, 4h & 1d overbought
            & ((aroonu_14_4h_lt_70) | (roc_9_4h_lt_60) | (roc_9_1d_lt_80))
            # 4h & 1d high, 4h overbought
            & ((aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_80))
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_80))
            # 4h high, 1h & 4h overbought
            & ((aroonu_14_4h_lt_85) | (roc_9_1h_lt_80) | (roc_9_4h_lt_80))
            # 4h high, 4h & 1d overbought
            & ((aroonu_14_4h_lt_85) | (roc_9_4h_lt_10) | (roc_9_1d_lt_40))
            # 4h & 1d high, 4h overbought
            & ((aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_40))
            # 4h high, 1h & 1d overbought
            & ((aroonu_14_4h_lt_100) | (roc_9_1h_lt_40) | (roc_9_1d_lt_100))
            # 4h high, 4h & 1d overbought
            & ((aroonu_14_4h_lt_100) | (roc_9_4h_lt_20) | (roc_9_1d_lt_80))
            # 1d high, 1h & 4h down move
            & ((aroonu_14_1d_lt_100) | (roc_9_1h_lt_25) | (roc_9_4h_lt_60))
            # 1d high, 1h downtrend, 1d overbought
            & ((aroonu_14_1d_lt_100) | (roc_9_1h_gt_neg_30) | (roc_9_1d_lt_100))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_100) | (roc_9_4h_lt_20) | (roc_9_1d_lt_80))
            # 1d high, 1d downtrend
            & ((aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_40))
            # 15m high, 4h & 1d downtrend
            & ((stochrsi_k_15m_lt_70) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_30))
            # 1h high, 4h & 1d downtrend
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_gt_neg_40) | (roc_9_1d_gt_neg_40))
            # 1h high, 4h & 1d overbought
            & ((stochrsi_k_1h_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_lt_100))
            # 4h high, 1h overbought, 1d downtrend
            & ((stochrsi_k_4h_lt_80) | (roc_9_1h_lt_40) | (roc_9_1d_gt_neg_70))
            # 4h high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_80) | (roc_9_4h_lt_80) | (roc_9_1d_lt_100))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_1h_lt_10) | (roc_9_4h_lt_80))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_1h_lt_20) | (roc_9_4h_lt_50))
            # 1d high, 4h & 1d overbought
            & ((stochrsi_k_1d_lt_90) | (roc_9_4h_lt_40) | (roc_9_1d_lt_100))
            # 1d P&D, dh downtrend
            & ((change_pct_1d_gt_neg_50) | (change_pct_1d_shift_288 < 50.0) | (rsi_3_4h_gt_15))
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
            # drop in last 20 days, 1h high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | aroonu_14_1h_lt_70 | (roc_9_1d_gt_neg_70))
            # drop in last 20 days. 4h high
            & ((close > (high_max_20_1d * 0.10)) | (stochrsi_k_4h_lt_90))
          )

          # Logic
          long_entry_logic.append(
            (rsi_3_lt_50)
            & (aroonu_14_lt_25)
            & (stochrsi_k_lt_30)
            & (ema_26 > ema_12)
            & ((ema_26 - ema_12) > (open_rate * 0.020))
            & ((ema_26_shift_1 - ema_12_shift_1) > (open_rate / 100.0))
          )

        # Condition #6 - Normal mode (Long).
        if long_entry_condition_index == 6:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 15m down move, 15m still high
            ((rsi_3_gt_3) | (rsi_3_15m_gt_10) | (stochrsi_k_15m_lt_40))
            # 5m & 15m down move, 15m still high
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_15) | (aroonu_14_15m_lt_40))
            # 5m & 15m down move, 1d downtrend
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_15) | (roc_9_1d_gt_neg_20))
            # 5m & 15m down move, 1d downtrend
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_25) | (roc_9_1d_gt_neg_30))
            # 5m & 1h down move, 1h still not low enough
            & ((rsi_3_gt_3) | rsi_3_1h_gt_20 | (aroonu_14_1h_lt_30))
            # 5m & 1h down move, 1h still high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_50))
            # 5m & 4h down move, 4h still high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_50))
            # 5m & 4h & 1d down move
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_35))
            # 5m & 4h & 1d down move, 4h still high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (rsi_14_4h_lt_40))
            # 5m & 4h down move, 4h high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_70))
            # 5m & 4h down move, 4h still high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_55) | (aroonu_14_4h_lt_50))
            # 5m & 1d down move, 15m still high
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_20) | (stochrsi_k_15m_lt_40))
            # 5m down move, 4h & 1d overbought
            & ((rsi_3_gt_3) | (roc_9_4h_lt_20) | (roc_9_1d_lt_40))
            # 5m & 1h down move, 4h high
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_40) | (aroonu_14_4h_lt_60))
            # 5m & 1h down move, 1h high
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_80))
            # 5m & 4h down move, 1d downtrend
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_5) | (roc_9_1d_gt_neg_20))
            # 5m & 4h down move, 4h still high
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40))
            # 5m & 4h down move, 15m still high
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_50))
            # 5m & 4h down move, 1d overbought
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_60))
            # 5m & 4h down move, 4h high
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80))
            # 5m down move, 15m still not low enough, 4h high
            & ((rsi_3_gt_5) | (aroonu_14_15m_lt_20) | (stochrsi_k_4h_lt_70))
            # 5m down move, 1h & 1d high
            & ((rsi_3_gt_5) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_100))
            # 5m down move, 4h high & overbought
            & ((rsi_3_gt_5) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_25))
            # 5m down move, 1h high
            & ((rsi_3_gt_5) | (stochrsi_k_1h_lt_80))
            # 5m & 1d down move, 1d still high
            & ((rsi_3_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_1d_lt_40))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_20))
            # 15m & 1h & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_25) | (rsi_14_4h_lt_40) | (roc_9_1d_gt_neg_10))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_20))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_40) | (aroonu_14_4h_lt_70))
            # 15m & 4h down move, 1h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_30))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_10))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_20))
            # 15m & 4h down move, 15m still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_25))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_40))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_45) | (stochrsi_k_1h_lt_60))
            # 15m & 1d down move, 15m still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1d_gt_10) | (aroonu_14_15m_lt_30))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1d_gt_55) | (stochrsi_k_4h_lt_70))
            # 1h & 1d downtrend, 1d high
            & ((rsi_3_15m_gt_3) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_10))
            # 15m & 1h & 4h & 1d down move, 1h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_1h_lt_20))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_65) | (aroonu_14_1d_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_60))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_30))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_90))
            # 15m & 1h & 4h down move, 15m downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_50) | (cmf_20_15m_gt_neg_0_30))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_55) | (aroonu_14_4h_lt_100))
            # 15m & 4h down move, 15m still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_20) | (aroonu_14_15m_lt_30))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_60))
            # 15m down move, 15m still high, 1h still high
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_lt_50))
            # 15m down move, 1h still high, 1d high
            & ((rsi_3_15m_gt_5) | (stochrsi_k_1h_lt_40) | (aroonu_14_1d_lt_70))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_90))
            # 15m down move, 15m & 1h still not low enough
            & ((rsi_3_15m_gt_5) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_30))
            # 15m & 1h & 4h & 1d down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_50) | (roc_9_1d_gt_neg_20))
            # 15m & 1h & 4h down move, 15m still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_30))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_60))
            # 15m & 1h & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_30))
            # 15m & 1h & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_1d_lt_70))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (aroonu_14_4h_lt_50))
            # 15m & 1h & 4h down move, 1h still not low enough, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_30) | (aroonu_14_4h_lt_40))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_45) | (rsi_14_4h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_60))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (roc_9_1d_gt_neg_40))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_45) | (roc_9_1d_lt_150))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_65) | (aroonu_14_1h_lt_80))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_30))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_70))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (rsi_14_1d_lt_60))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_40))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_90))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_50))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_40))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_90))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_20))
            # 15m & 4h down move, 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (cmf_20_4h_gt_neg_0_30))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (roc_9_1d_lt_30))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_45) | aroonu_14_4h_lt_70)
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_75))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_40))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_75))
            # 15m & 1d down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1d > 50.0) | (roc_9_1d_lt_20))
            # 15m down move, 15m downtrend, 4h still high
            & ((rsi_3_15m_gt_10) | (cmf_20_15m_gt_neg_0_40) | (stochrsi_k_4h_lt_50))
            # 15m down move, 1h downtrend, 4h still high
            & ((rsi_3_15m_gt_10) | (cmf_20_1h_gt_neg_0_30) | (stochrsi_k_4h_lt_40))
            # 15m down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_60))
            # 15m down move, 15m still high, 1h still high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_50))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_20))
            # 15m down move, 1h still not low enough, 1d overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_30) | (roc_9_1d_lt_100))
            # 15m down move, 1h still high, 4h downtrend
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_50) | (roc_9_4h_gt_neg_20))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_10))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_4h_lt_70) | (roc_9_1d_lt_10))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_40))
            # 15m & 1h down move, 1h downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (cmf_20_1h_gt_neg_0_30))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | aroonu_14_4h_lt_70)
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (roc_9_1d_lt_100))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_60))
            # 15m & 1h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_1d_gt_35) | (stochrsi_k_4h_lt_40))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (stochrsi_k_1d_lt_80))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_50) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_55) | (aroonu_14_1h_lt_90))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_90))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_50))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_60))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_60))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_70))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_40) | aroonu_14_4h_lt_80)
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_40) | (roc_9_1d_lt_40))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_45) | (roc_9_1d_lt_80))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_55) | (stochrsi_k_4h_lt_70))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_15) | (stochrsi_k_1h_lt_30))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_50))
            # 15m & 1d down move, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_30) | (roc_9_1d_lt_10))
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_25) | (stochrsi_k_1h_lt_80))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_70))
            # 15m down move, 1h still high, 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_50) | (roc_9_1d_lt_80))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_90))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_85))
            # 15m down move, 1h & 1d high
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_70))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_85) | (stochrsi_k_4h_lt_90))
            # 15m down move, 4h high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_60) | (roc_9_4h_gt_neg_20))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_30))
            # 15m down move, 4h high, 1h overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_25))
            # 15m down move, 4h high, 1h overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_10))
            # 15m down move, 1h still high, 4h overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_50) | (roc_9_4h_lt_10))
            # 15m down move, 1h high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_80) | (roc_9_4h_gt_neg_20))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_20))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_20))
            # 15m & 1h & 4h down move, 15m & 1h still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_40))
            # 15m & 1h & 4h down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_45) | (aroonu_14_15m_lt_40) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (roc_9_1d_gt_neg_30))
            # 15m & 1h down move, 1h overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_50) | (roc_9_1h_lt_10))
            # 15m & 1h & 4h down move, 1h still not low enough
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_30))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80))
            # 15m & 1h & 4h down move, 15m & 1h still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_45) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_35) | (aroonu_14_1d_lt_100))
            # 15m & 1h & 4h & 1d down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (stochrsi_k_4h_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_70))
            # 15m & 1h & 4h down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_60) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_90))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_60) | (stochrsi_k_4h_lt_90))
            # 15m & 4h & 1d down move
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_20))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_90))
            # 15m & 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_40) | (roc_9_4h_gt_neg_10))
            # 15m & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (stochrsi_k_4h_lt_50))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_45) | (stochrsi_k_1d_lt_90))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1h_lt_70))
            # 15m & 1d down move, 15m still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_30) | (stochrsi_k_15m_lt_50))
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_25) | (stochrsi_k_1h_lt_90))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_70))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_70))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_80))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_10))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_30))
            # 15m down move, 4h high, 1h overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_30))
            # 15m down move, 1d high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_20))
            # 15m down move, 1d high, 4h overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20))
            # 15m down move, 1d high, 1d overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 15m down move, 15m high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_60) | (roc_9_4h_gt_neg_50))
            # 15 down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_10))
            # 15m down move, 4h high, 15m downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_4h_lt_70) | (cmf_20_15m_gt_neg_0_40))
            # 15m & 1h & 4h down move, 1h still not low enough, 4h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (stochrsi_k_1h_lt_30) | (stochrsi_k_4h_lt_40))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (stochrsi_k_15m_lt_70))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_40))
            # 15m & 1h & 4h down move, 4h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_50))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_40) | (stochrsi_k_1d_lt_90))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_40) | (roc_9_1d_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_50) | (aroonu_14_1h_lt_85))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_60) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_60) | (stochrsi_k_4h_lt_90))
            # 15m & 4h & 1d down move, 15m still not low enough
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (aroonu_14_15m_lt_30))
            # 15m & 4h down move, 4h overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_55) | (roc_9_4h_lt_30))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_25) | aroonu_14_1h_lt_80)
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_25) | (stochrsi_k_1h_lt_90))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_80))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_60) | (roc_9_1d_lt_60))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_25) | aroonu_14_1h_lt_70 | (roc_9_4h_lt_40))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_85) | aroonu_14_4h_lt_100)
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_90))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_25) | aroonu_14_4h_lt_70 | (roc_9_4h_lt_50))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_25) | aroonu_14_4h_lt_80 | (roc_9_1d_lt_100))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_25) | (stochrsi_k_1h_lt_70) | (roc_9_1d_gt_neg_20))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_25) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_20))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_25) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_10))
            # 15m & 1h down move, 4h still high, 1d high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_40) | (stochrsi_k_1d_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_35) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_35) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_50))
            # 15m & 1h & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 15m & 1h & 4h down move, 1h still high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_60) | (stochrsi_k_1h_lt_50))
            # 15m & 1h & 4h down move, 1h still high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_50) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_15m_lt_70))
            # 15m & 1d down move, 1h & 1d high
            & ((rsi_3_15m_gt_30) | (rsi_3_1d_gt_30) | (stochrsi_k_1h_lt_70) | (stochrsi_k_1d_lt_80))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_90) | (roc_9_1h_lt_10))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_85))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_40))
            # 15m down move, 15m still high, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (stochrsi_k_15m_lt_40) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_45) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_30))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_65) | (aroonu_14_1h_lt_80))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_80))
            # 15m & 1d down move, 1d high & overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_1d_gt_65) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_20))
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_25) | aroonu_14_1h_lt_80)
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_25) | (stochrsi_k_1h_lt_80))
            # 15m down move, 1m still high, 4h overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_40) | (roc_9_4h_lt_50))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_10))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_70))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_35) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_40) | aroonu_14_4h_lt_100)
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_40) | (rsi_3_4h_gt_45) | (stochrsi_k_1h_lt_90))
            # 15m down move, 15m still high, 1d high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_40) | (roc_9_1d_lt_100))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_40) | aroonu_14_4h_lt_100 | (roc_9_4h_lt_40))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_50) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_40))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_70))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_4h_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_30) | aroonu_14_4h_lt_70)
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | aroonu_14_4h_lt_70)
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (aroonu_14_1h_lt_50))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (stochrsi_k_15m_lt_30))
            # 1h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_20))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_70))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_30))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_70))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_50))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_10))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_20))
            # 1h & 4h & 1d down move, 1h stil high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_70))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_50) | (stochrsi_k_1d_lt_60))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_60) | roc_9_1d_lt_50)
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_20))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1d_lt_80) | (roc_9_4h_gt_neg_20))
            # 1h down move, 4h downtrend, 1d overbought
            & ((rsi_3_1h_gt_20) | (roc_9_4h_gt_neg_10) | (roc_9_1d_lt_20))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_40))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (stochrsi_k_15m_lt_70))
            # 1h down move, 4h downtrend, 4h high
            & ((rsi_3_1h_gt_25) | (cmf_20_4h_gt_neg_0_50) | aroonu_14_4h_lt_70)
            # 1h down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h still high, 4h overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_50) | (roc_9_4h_lt_60))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_40) | (roc_9_1d_lt_100))
            # 1h down move, 1d still high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1d_lt_50) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (rsi_14_1d_lt_80))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_60))
            # 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_60) | (stochrsi_k_1d_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1h_lt_60))
            # 1h down move, 4h & 1d down move
            & ((rsi_3_1h_gt_30) | aroonu_14_4h_lt_70 | aroonu_14_1d_lt_100)
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_85) | (roc_9_4h_lt_80))
            # 1h down move, 1d still high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_100) | (roc_9_4h_gt_neg_30))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_30) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_30) | (roc_9_4h_gt_neg_25) | (roc_9_1d_gt_neg_60))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_1h_lt_75))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_60) | aroonu_14_4h_lt_70)
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_35) | aroonu_14_4h_lt_70 | (roc_9_1d_gt_neg_30))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1d_lt_90) | (roc_9_4h_lt_40))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_35) | (roc_9_4h_lt_10) | (roc_9_1d_lt_50))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_35) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_90))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_50) | (stochrsi_k_1h_lt_60))
            # 1h & 1d down move, 1h high & overbought
            & ((rsi_3_1h_gt_40) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_10))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_60) | (roc_9_1d_lt_40))
            # 1h down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_85))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50) | (roc_9_1d_lt_20))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_30))
            # 1h down move, 1h high, 15m downtrend
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (roc_9_15m > -15.0))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1d_lt_80) | roc_9_1d_lt_50)
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1d_lt_90) | (roc_9_4h_lt_20))
            # 1h down move, 1h overbought
            & ((rsi_3_1h_gt_40) | (roc_9_1h_lt_30))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (roc_9_1d_lt_200))
            # 1h down move, 1h still not low enough, 1d downtrend
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_30) | (roc_9_1d_gt_neg_25))
            # 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_20))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_40) | (roc_9_1d_lt_100))
            # 1h down move, 4h high, 1h overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_85) | (roc_9_1h_lt_20))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1d_lt_90) | (roc_9_4h_lt_20))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10))
            # 1h down move, 1h & 4h overbought
            & ((rsi_3_1h_gt_50) | (roc_9_1h_lt_10) | (roc_9_4h_lt_100))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_50) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_55) | (rsi_3_4h_gt_55) | (stochrsi_k_1h_lt_70))
            # 1h & 1d down move, 1h & 1d high
            & ((rsi_3_1h_gt_55) | (rsi_3_1d_gt_55) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_10))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_60) | (rsi_3_1d_gt_60) | (aroonu_14_1h_lt_70))
            # 1h down move, 4 high, 1h overbought
            & ((rsi_3_1h_gt_60) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_10))
            # 1h down move, 1d high, 1h overbought
            & ((rsi_3_1h_gt_60) | (aroonu_14_1d_lt_90) | (roc_9_1h_lt_10))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_70) | (roc_9_1d_gt_neg_10))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_100))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_65) | aroonu_14_1h_lt_70 | (roc_9_4h_lt_25))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_20))
            # 4h & 1d down move, 1d still high, 4h downtrend
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_25) | (rsi_14_1d_lt_40) | (roc_9_4h_gt_neg_10))
            # 4h down move, 1h still not low enough, 4h downtrend
            & ((rsi_3_4h_gt_3) | (aroonu_14_1h_lt_20) | (roc_9_4h_gt_neg_10))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_3) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_10))
            # 4h & 1d down move, 15m still high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_25) | (stochrsi_k_15m_lt_40))
            # 4h & 1d down move, 1h still not low enough
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_20))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (roc_9_1d_gt_neg_40))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_lt_50))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_35) | (aroonu_14_1d_lt_100))
            # 4h & 1d down move, 1d still not low enough, 1d high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_45) | (rsi_14_4h_lt_30) | (aroonu_14_1d_lt_80))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_45) | (roc_9_1d_lt_10))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_70))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_70))
            # 4h & 1d down move, 1h still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (stochrsi_k_1h_lt_40))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_70))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (roc_9_1d_gt_neg_15))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_50) | (stochrsi_k_4h_lt_40))
            # 4h down move, 1d still high, 4h still not low enough
            & ((rsi_3_4h_gt_15) | (rsi_14_1d_lt_40) | (stochrsi_k_4h_lt_30))
            # 4h down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_20) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_15) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_60))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_40))
            # 4h & 1d down move, 1h still not low enough, 4h still high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_30) | (stochrsi_k_4h_lt_40))
            # 4h & 1d down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_40) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_40))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_45) | (roc_9_1d_lt_40))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_80))
            # 4h down move, 1h high, 4h downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_20))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_90))
            # 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_50) | (cmf_20_4h_gt_neg_0_40))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_30))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_90))
            # 4h down move, 1h high, 1h downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_1h_gt_neg_10))
            # 4h down move, 1h high, 4h downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_4h_gt_neg_10))
            # 4h down move, 1h still high, 1d overbought
            & ((rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_40) | (roc_9_1d_lt_30))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_35) | (rsi_3_1d_gt_50) | (roc_9_1d_lt_100))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_35) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_45) | (aroonu_14_4h_lt_70) | (roc_9_1d_gt_neg_30))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_40) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_100))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_60))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_20))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_60) | (roc_9_4h_lt_20))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_10))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_50) | aroonu_14_4h_lt_80 | (roc_9_4h_lt_10))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_55) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_20))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_55) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_100))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_55) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_60))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_60) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_70))
            # 4h down move, 1d high, 4h overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_200))
            # 4h down move, 4h still high, 4h overbought
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_50) | (roc_9_4h_lt_10))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_65) | (aroonu_14_4h_lt_75) | (roc_9_1d_lt_30))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_65) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 4h up move, 1d downtrend, 4h high
            & ((rsi_3_4h_lt_90) | (cmf_20_1d_gt_neg_0_25) | (aroonu_14_4h_lt_100))
            # 1d down move, 1d still not low enough, 1d downtrend
            & ((rsi_3_1d_gt_5) | (aroonu_14_1d < 20.0) | (roc_9_1d_gt_neg_20))
            # 1d down move, 15m still high
            & ((rsi_3_1d_gt_5) | (stochrsi_k_15m_lt_40))
            # 1d down move, 1h & 4h still not low enough
            & ((rsi_3_1d_gt_5) | (stochrsi_k_1h_lt_20) | (stochrsi_k_4h_lt_20))
            # 1d down move, 1h high
            & ((rsi_3_1d_gt_10) | (aroonu_14_1h_lt_70))
            # 1d down move, 4h downtrend, 4h high
            & ((rsi_3_1d_gt_20) | (cmf_20_4h_gt_neg_0_25) | (aroonu_14_4h_lt_70))
            # 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_50) | (roc_9_1d_gt_neg_20))
            # 1d down move, 15m still high, 1h & 4h high
            & ((rsi_3_1d_gt_30) | (rsi_14_15m_lt_50) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1d down move, 4h & 1d high
            & ((rsi_3_1d_gt_40) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 1d down move, 1d high & overbought
            & ((rsi_3_1d_gt_40) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_10))
            # 1d down move, 1h high, 1d overbought
            & ((rsi_3_1d_gt_60) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_100))
            # 4h downtrend, 4h high & over
            & ((cmf_20_4h_gt_neg_0_10) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_30))
            # 15m still high, 4h high, 1h overbought
            & ((aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_85) | (roc_9_1h_lt_20))
            # 15m still high, 4h high, 1h overbought
            & ((aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_20))
            # 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_50))
            # 1h high, 4h high & overbought
            & (aroonu_14_1h_lt_80 | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_30))
            # 1h & 4h high, 1h overbought
            & (aroonu_14_1h_lt_80 | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_30))
            # 1h & 4h & 1d high
            & (aroonu_14_1h_lt_80 | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100))
            # 1h & 4h high, 1d overbought
            & (aroonu_14_1h_lt_80 | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_30))
            # 1h high, 1h overbought
            & (aroonu_14_1h_lt_80 | (roc_9_1h_lt_10))
            # 1h & 1d high, 4h overbought
            & (aroonu_14_1h_lt_80 | aroonu_14_1d_lt_100 | (roc_9_4h_lt_10))
            # 1h high, 1h & 4h overbought
            & (aroonu_14_1h_lt_80 | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 1h high, 1h overbought, 1d downtrend
            & (aroonu_14_1h_lt_80 | (roc_9_1h_lt_50) | roc_9_1d_gt_neg_50)
            # 1h high, 4h &1d overbought
            & ((aroonu_14_1h_lt_85) | (roc_9_4h_lt_30) | (roc_9_1d_lt_30))
            # 1h high, 4h & 1d overbought
            & ((aroonu_14_1h_lt_90) | (roc_9_4h_lt_10) | (roc_9_1d_lt_15))
            # 4h & 1d high, 4h overbought
            & (aroonu_14_4h_lt_70 | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_50))
            # 4h & 1d high, 1d overbought
            & (aroonu_14_4h_lt_70 | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 4h high, 1h & 4h & 1d overbought
            & ((aroonu_14_4h_lt_80) | (roc_9_1h_lt_10) | (roc_9_4h_lt_20) | (roc_9_1d_lt_50))
            # 4h & 1d high, 4h overbought
            & ((aroonu_14_4h_lt_90) | aroonu_14_1d_lt_100 | (roc_9_4h_lt_30))
            # 4h high, 4h overbought, 1d downtrend
            & ((aroonu_14_4h_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_gt_neg_40))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_70) | (roc_9_4h_lt_30) | (roc_9_1d_lt_200))
            # 1d high, 1h & 1d overbought
            & ((aroonu_14_1d_lt_80) | (roc_9_1h_lt_20) | roc_9_1d_lt_50)
            # 1d high, 1d downtrend
            & ((aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_30))
            # 1d high, 1h & 4h downtrend
            & ((aroonu_14_1d_lt_85) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_50))
            # 1d high, 1h & 1d overbought
            & ((aroonu_14_1d_lt_90) | (roc_9_1h_lt_10) | roc_9_1d_lt_50)
            # 1d high, 4h & 1d overbought
            & (aroonu_14_1d_lt_100 | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 15m still not low enough, 4h high, 1d overbought
            & ((stochrsi_k_15m_lt_30) | aroonu_14_4h_lt_100 | (roc_9_1d_lt_30))
            # 15m still high, 4h high & overbought
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30))
            # 1h high, 1d overbought
            & ((stochrsi_k_1h_lt_70) | (roc_9_1d_lt_40))
            # 1h high, 1h overbought, 4h downtrend
            & ((stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10) | (roc_9_4h_gt_neg_10))
            # 1h high, 4h & 1d downtrend
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_80))
            # 1h down move, 1h & 1d overbought
            & ((stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10) | roc_9_1d_lt_50)
            # 1h high & overbought
            & ((stochrsi_k_1h_lt_90) | (roc_9_1h_lt_40))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_70) | (roc_9_1h_lt_10) | (roc_9_4h_lt_20))
            # 4h high, 1h & 1d overbought
            & ((stochrsi_k_4h_lt_70) | (roc_9_1h_lt_20) | (roc_9_1d_lt_200))
            # 4h high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30) | (roc_9_1d_lt_30))
            # 4h high, 1d downtrend
            & ((stochrsi_k_4h_lt_80) | roc_9_1d_gt_neg_50)
            # 4h high, 1h & 1d overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_1h_lt_20) | (roc_9_1d_lt_20))
            # 4h high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_4h_lt_10) | (roc_9_1d_lt_10))
            # 1d hihg, 1h & 1d overbought
            & ((stochrsi_k_1d_lt_90) | (roc_9_1h_lt_30) | (roc_9_1d_lt_100))
            # 1d P&D, dh downtrend
            & ((change_pct_1d_gt_neg_50) | (change_pct_1d_shift_288 < 50.0) | (rsi_3_4h_gt_15))
            # big drop in last hough, 4h down move, 1h still not low enough
            & ((close > (close_max_12 * 0.90)) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_30))
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
            # drop in last 20 days, 1h high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | aroonu_14_1h_lt_70 | (roc_9_1d_gt_neg_70))
            # drop in last 20 days. 4h high
            & ((close > (high_max_20_1d * 0.10)) | (stochrsi_k_4h_lt_90))
          )

          # Logic
          long_entry_logic.append(
            (rsi_20 < rsi_20_shift_1)
            & (rsi_3_lt_46)
            & (aroonu_14_lt_25)
            & (stochrsi_k_lt_20)
            & (aroonu_14_15m_lt_50)
            & (close < sma_16 * 0.960)
          )

        # Condition #7 - ADX trend-birth (Long, experimental, RAW — 4h trend ignition; big-win lane).
        if long_entry_condition_index == 7:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            # 5m down move, 15m down move, 1h washed out, 4h up move
            ((rsi_3 > 30.0) | (rsi_3_15m_gt_50) | (rsi_3_4h_lt_95) | (stochrsi_k_1h_gt_75))
            # 5m hot, 15m trend absent, hour overbought
            & ((rsi_3_lt_50) | (aroonu_14_15m_gt_40) | (rsi_3_1h_lt_80))
            # 5m money leaving, 15m up move
            & ((mfi_14 > 25.0) | (rsi_3_15m_lt_70))
            # 5m downtrend, 1d RSI low & up move & washed out & uptrend
            & (
              (aroonu_14_gt_75) | (rsi_14_1d_gt_60) | (rsi_3_1d < 75.0) | (stochrsi_k_1d > 80.0) | (aroonu_14_1d < 5.0)
            )
            # 5m uptrend, 15m uptrend & washed out, 1h down move, 1d down move
            & (
              (aroonu_14_lt_25)
              | (rsi_3_1h_gt_65)
              | (aroonu_14_15m_lt_60)
              | (rsi_3_1d > 80.0)
              | (stochrsi_k_15m > 65.0)
            )
            # 5m uptrend, 15m washed out, 1h still high & downtrend & up move
            & (
              (aroonu_14_lt_25)
              | (stochrsi_k_1h_lt_70)
              | (aroonu_14_1h > 80.0)
              | (rsi_3_1h_lt_80)
              | (stochrsi_k_15m_gt_60)
            )
            # 5m uptrend, 1h uptrend, 4h still high, 1d down move & up move
            & (
              (aroonu_14_lt_30) | (aroonu_14_1h_lt_90) | (roc_9_1d > 0.0) | (rsi_3_1d < 65.0) | (stochrsi_k_4h < 75.0)
            )
            # 5m uptrend & up move, 15m washed out, 1h uptrend
            & ((aroonu_14_lt_25) | (aroonu_14_1h_lt_60) | (rsi_3_lt_95) | (stochrsi_k_15m > 35.0))
            # 5m still not low enough, 1h & 1d high
            & ((aroonu_14_lt_25) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_60))
            # 5m uptrend & down move, 15m downtrend, 4h uptrend & up move
            & ((aroonu_14_lt_25) | (aroonu_14_4h_lt_90) | (aroonu_14_15m_gt_10) | (rsi_3_4h_lt_90) | (rsi_3 > 90.0))
            # 5m uptrend & down move, 15m up move, 4h uptrend
            & ((aroonu_14_lt_25) | (aroonu_14_4h_lt_90) | (rsi_3 > 20.0) | (rsi_3_15m_lt_50))
            # 5m uptrend & up move, 15m down move
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_25) | (rsi_3 < 25.0))
            # 5m still not low enough, 15m down move, 4h high
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_30) | (aroonu_14_4h_lt_100))
            # 5m still not low enough, 15m down move, 1h still high
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_40) | (stochrsi_k_1h_lt_40))
            # 5m low, 15m down move, 1h still not high
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_50) | (stochrsi_k_1h_lt_90))
            # 5m still not low enough, 15m down move & high
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_80))
            # 5m & 15m still not low enough, 1d down move
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_lt_20) | (rsi_3_1d_gt_55))
            # 5m still not low enough, 15m high, 4h down move
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_lt_60) | (rsi_3_4h_gt_60))
            # 5m uptrend & up move, 1h still high & down move, 1d down move
            & ((aroonu_14_lt_25) | (stochrsi_k_1h_lt_30) | (rsi_3_1h > 70.0) | (rsi_3_1d > 75.0) | (rsi_3 < 45.0))
            # 5m still not low enough, 15m down move
            & ((aroonu_14_lt_25) | (stochrsi_k_lt_20) | (rsi_3_15m_gt_50))
            # 5m still not low enough, 1h & 4h high
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_90) | (stochrsi_k_4h_lt_90))
            # 5m still not low enough, 15m down move, 1d high
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_50) | (stochrsi_k_1d_lt_80))
            # 5m still not low enough, 15m & 1h down move
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_55) | (rsi_3_1h_gt_60))
            # 5m still not low enough, 15m down move, 4h high
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_55) | (stochrsi_k_4h_lt_80))
            # 5m & 1d still not low enough, 1d down move
            & ((aroonu_14_lt_30) | (rsi_3_1d_gt_65) | (aroonu_14_1d_lt_30))
            # 5m still not low enough, 1d down move & still high
            & ((aroonu_14_lt_30) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_50))
            # 5m still not low enough, 1h down move, 4h high
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_60) | (aroonu_14_4h_lt_100))
            # 5m still not low enough, 15m high, 4h down move
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_lt_60) | (rsi_3_4h_gt_65))
            # 5m still not low enough, 1h & 1d still high
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_lt_50) | (aroonu_14_1d_lt_40))
            # 5m still not low enough, 1h high, 1d down move
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_lt_80) | (rsi_3_1d_gt_60))
            # 5m still not low enough, 15m high, 1d overbought
            & ((stochrsi_k_lt_20) | (aroonu_14_15m_lt_60) | (roc_9_1d_lt_10))
            # 5m still not low enough, 4h high, 1d still high
            & ((stochrsi_k_lt_20) | (aroonu_14_4h_lt_100) | (stochrsi_k_1d_lt_50))
            # 5m & 1d still not low enough, 15m down move
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_50) | (aroonu_14_1d_lt_30))
            # 5m still not low enough, 1h & 4h down move
            & ((stochrsi_k_lt_20) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_65))
            # 5m still not low enough, 1h down move & high
            & ((stochrsi_k_lt_20) | (rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_80))
            # 5m & 15m still not low enough, 1h high
            & ((stochrsi_k_lt_20) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_60))
            # 5m still not low enough, 1h still high, 1d down move
            & ((stochrsi_k_lt_20) | (stochrsi_k_1h_lt_40) | (rsi_3_1d_gt_55))
            # 5m still not low enough, 1h & 1d high
            & ((stochrsi_k_lt_20) | (stochrsi_k_1h_lt_90) | (stochrsi_k_1d_lt_80))
            # 5m still not low enough, 15m & 1d high
            & ((stochrsi_k_lt_30) | (aroonu_14_15m_lt_80) | (aroonu_14_1d_lt_80))
            # 5m & 1d still not low enough, 1d high
            & ((stochrsi_k_lt_30) | (aroonu_14_1d_lt_30) | (stochrsi_k_1d_lt_70))
            # 5m still not low enough, 1d high
            & ((stochrsi_k_lt_30) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d_lt_60))
            # 5m still not low enough, 1h & 1d high
            & ((stochrsi_k_lt_30) | (aroonu_14_1h_lt_70) | (stochrsi_k_1d_lt_70))
            # 5m not low after a day that already ran 40%
            & ((stochrsi_k_lt_30) | (roc_9_1d_lt_40))
            # 5m still not low enough, 1h & 1d overbought
            & ((stochrsi_k_lt_30) | (roc_9_1h_lt_10) | (roc_9_1d_lt_15))
            # 5m still not low enough, 15m down move, 1d high
            & ((stochrsi_k_lt_30) | (rsi_3_15m_gt_55) | (aroonu_14_1d_lt_60))
            # 5m still not low enough, 15m down move, 4h high
            & ((stochrsi_k_lt_30) | (rsi_3_15m_gt_55) | (aroonu_14_4h_lt_100))
            # 5m & 15m & 1h still not low enough
            & ((stochrsi_k_lt_30) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_30))
            # 5m still not low enough, 1d high & overbought
            & ((stochrsi_k_lt_30) | (stochrsi_k_1d_lt_60) | (roc_9_1d_lt_0))
            # 5m still not low enough, 1h high, 1d overbought
            & ((stochrsi_k_lt_30) | (stochrsi_k_1h_lt_60) | (roc_9_1d_lt_30))
            # 5m still not low enough, 1h & 1d high
            & ((stochrsi_k_lt_30) | (stochrsi_k_1h_lt_80) | (stochrsi_k_1d_lt_70))
            # 5m still not low enough, 1h & 4h high
            & ((stochrsi_k_lt_30) | (stochrsi_k_1h_lt_90) | (stochrsi_k_4h_lt_90))
            # 15m down move, 4h overbought, 1d up move & still high & downtrend
            & (
              (rsi_3_15m_gt_30)
              | (stochrsi_k_4h_lt_80)
              | (roc_9_1d < 5.0)
              | (stochrsi_k_1d < 25.0)
              | (aroonu_14_1d > 65.0)
            )
            # 15m down move, 4h down move & overbought, 1d up move & washed out
            & (
              (rsi_3_15m_gt_50) | (roc_9_1d_lt_0) | (stochrsi_k_1d > 35.0) | (rsi_3_4h > 85.0) | (stochrsi_k_4h_lt_80)
            )
            # 15m down move & still high, 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_50) | (stochrsi_k_4h_lt_80))
            # 15m down move, 1h up move
            & ((rsi_3_15m_gt_20) | (roc_9_1h_lt_10))
            # 5m downtrend, 15m down move, 1h falling fast
            & ((rsi_3_15m_gt_20) | (rsi_14_change_pct_1h > -5.0) | (aroonu_14 > 0.0))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80))
            # 15m down move & still not low enough, 1h high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_60))
            # 15m down move & still not low enough, 1h overbought
            & ((rsi_3_15m_gt_30) | (stochrsi_k_15m_lt_20) | (roc_9_1h_lt_20))
            # 5m down move, 15m down move, 1h downtrend
            & ((rsi_3_15m_gt_35) | (aroonu_14_1h_gt_20) | (rsi_3 > 30.0))
            # 5m up move, 15m down move, 4h down move
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_60) | (rsi_3 < 10.0))
            # 15m down move & still high, 1d high
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_40) | (aroonu_14_1d_lt_75))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_60))
            # 15m & 1d down move, 1d still not low enough
            & ((rsi_3_15m_gt_40) | (aroonu_14_1d_lt_30) | (rsi_3_1d_gt_65))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_40) | (aroonu_14_4h_lt_100) | (rsi_3_1d_gt_55))
            # 15m down move, 1h money leaving & washed out
            & ((rsi_3_15m_gt_40) | (mfi_14_1h > 50.0) | (stochrsi_k_1h_gt_20))
            # 5m up move, 15m down move, 1h up move
            & ((rsi_3_15m_gt_40) | (roc_9_1h_lt_10) | (rsi_3 < 45.0))
            # 15m down move, 4h overbought, 1d still high
            & ((rsi_3_15m_gt_40) | (roc_9_4h_lt_5) | (aroonu_14_1d_lt_40))
            # 15m spent after a 4h run already that large
            & ((rsi_3_15m_gt_40) | (roc_9_4h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_70))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_50) | (aroonu_14_1d_lt_80))
            # 5m up move, 15m down move & uptrend, 1h down move, 4h up move
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_65) | (rsi_3_4h_lt_95) | (aroonu_14_15m < 45.0) | (rsi_3_lt_40))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_65) | (stochrsi_k_1d_lt_90))
            # 5m up move, 15m down move, 1h up move & washed out
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_lt_55) | (rsi_3_lt_40) | (stochrsi_k_1h_gt_75))
            # 15m down move & still high, 1h high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_40) | (aroonu_14_1h_lt_80))
            # 15m down move & downtrend, 1d still high & downtrend
            & ((rsi_3_15m_gt_40) | (stochrsi_k_1d_lt_30) | (aroonu_14_15m_gt_10) | (aroonu_14_1d_gt_30))
            # 15m down move, 4h high, 1d still not low enough
            & ((rsi_3_15m_gt_40) | (stochrsi_k_4h_lt_90) | (aroonu_14_1d_lt_30))
            # 5m up move, 15m down move, 4h overbought
            & ((rsi_3_15m_gt_40) | (stochrsi_k_4h_lt_90) | (rsi_3 < 55.0))
            # 5m still high & down move, 15m down move, 4h overbought
            & ((rsi_3_15m_gt_40) | (stochrsi_k_4h_lt_90) | (stochrsi_k < 25.0) | (rsi_3 > 30.0))
            # 5m on the floor, 15m down move, 1h downtrend, 4h AROOND high
            & ((rsi_3_15m_gt_50) | (aroond_14_4h_lt_25) | (aroonu_14_1h_gt_60) | (stochrsi_k > 10.0))
            # a 4h birth on a hot day after the 15m and 1h push has already died — the top of a one-day relief rip
            & ((rsi_3_15m_gt_50) | (aroonu_14_1h_gt_60) | (stochrsi_k_1h_gt_40) | (rsi_3_1d_lt_80))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_40) | (roc_9_1d_lt_10))
            # 15m & 1h & 1d down move
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_60) | (rsi_3_1d_gt_55))
            # 15m & 1h down move, 15m still not low enough
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_30) | (rsi_3_1h_gt_65))
            # 15m & 1d down move, 15m still high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_40) | (rsi_3_1d_gt_55))
            # 15m down move & still high, 1d high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_50) | (aroonu_14_1d_lt_60))
            # 15m & 1d down move, 15m high
            & ((rsi_3_15m_gt_55) | (aroonu_14_15m_lt_80) | (rsi_3_1d_gt_65))
            # 15m down move, 1h downtrend
            & ((rsi_3_15m_gt_55) | (aroonu_14_1h_gt_10))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_55) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_15))
            # 15m & 1d down move, 1d overbought
            & ((rsi_3_15m_gt_55) | (rsi_3_1d_gt_65) | (roc_9_1d_lt_10))
            # 15m down move & still not low enough, 1h high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_90))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_55) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 5m down move, 15m up move, 1h down move
            & ((rsi_3_15m_lt_50) | (rsi_3_1h_gt_40) | (rsi_3 > 65.0))
            # 5m down move, 15m up move & uptrend, 1h money coming in
            & ((rsi_3_15m_lt_55) | (mfi_14_1h < 80.0) | (rsi_3 > 35.0) | (aroonu_14_15m < 55.0))
            # 15m up move & uptrend, 1h down move & downtrend
            & ((rsi_3_15m_lt_55) | (rsi_3_1h_gt_60) | (aroonu_14_1h > 15.0) | (aroonu_14_15m_lt_25))
            # 15m up move, 1h down move & still high
            & ((rsi_3_15m_lt_60) | (rsi_3_1h_gt_55) | (stochrsi_k_1h < 55.0))
            # 15m up move, 1h down move
            & ((rsi_3_15m_lt_75) | (rsi_3_1h_gt_45))
            # daily RSI_3 tripled in one candle, 15m not holding it: a relief rip
            & ((rsi_14_15m > 60) | (rsi_3_change_pct_1d < 300))
            # 15m uptrend & down move & still high, 4h overbought, 1d down move
            & (
              (aroonu_14_15m_lt_30)
              | (stochrsi_k_4h_lt_90)
              | (rsi_3_15m_gt_25)
              | (stochrsi_k_15m < 10.0)
              | (rsi_3_1d > 75.0)
            )
            # 5m down move, 15m uptrend, 1h still high, 1d washed out & up move
            & (
              (aroonu_14_15m_lt_60)
              | (stochrsi_k_1h_lt_60)
              | (stochrsi_k_1d_gt_20)
              | (rsi_3_1d < 70.0)
              | (rsi_3 > 50.0)
            )
            # 5m still high, 15m downtrend, 1h downtrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_40) | (stochrsi_k < 35.0))
            # 15m down move & still not low enough, 1d downtrend
            & ((aroonu_14_15m_lt_20) | (rsi_3_15m_gt_50) | (roc_9_1d_gt_neg_15))
            # 15m still not low enough, 1h down move, 4h high
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_90))
            # 15m still not low enough & still high, 1h high
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_80))
            # 15m still high, 4h high, 1d down move
            & ((aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_100) | (rsi_3_1d_gt_55))
            # 15m & 1h down move, 15m still high
            & ((aroonu_14_15m_lt_40) | (rsi_3_15m_gt_20) | (rsi_3_1h_gt_65))
            # 15m & 1h still high, 1h down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_50))
            # 15m still high, 1h down move, 1d downtrend
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_65) | (roc_9_1d_gt_neg_10))
            # 15m still high & still not low enough, 1h high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_90))
            # 15m still high, 1h high, 1d down move
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_90) | (rsi_3_1d_gt_60))
            # 15m & 4h down move, 15m still high
            & ((aroonu_14_15m_lt_50) | (rsi_3_15m_gt_30) | (rsi_3_4h_gt_65))
            # 15m & 1h down move, 15m still high
            & ((aroonu_14_15m_lt_50) | (rsi_3_15m_gt_50) | (rsi_3_1h_gt_40))
            # 15m down move, 15m & 1h high
            & ((aroonu_14_15m_lt_60) | (rsi_3_15m_gt_40) | (aroonu_14_1h_lt_90))
            # 15m & 4h high, 15m still not low enough
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_15m_lt_20) | (stochrsi_k_4h_lt_90))
            # 15m & 1d high, 15m still not low enough
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_15m_lt_30) | (aroonu_14_1d_lt_75))
            # 15m & 1h high
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_15m_lt_60) | (stochrsi_k_1h_lt_70))
            # 15m & 1h & 4h high
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_90) | (stochrsi_k_4h_lt_90))
            # 15m & 4h & 1d high
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_4h_lt_90) | (stochrsi_k_1d_lt_60))
            # 5m downtrend, 15m uptrend, 4h up move, 1d downtrend
            & ((aroonu_14_15m_lt_80) | (roc_9_4h_lt_5) | (aroonu_14 > 45.0) | (aroonu_14_1d > 45.0))
            # 15m at its ceiling while the 4h is not strong
            & ((aroonu_14_15m_lt_80) | (rsi_3_4h_gt_65))
            # 15m & 1h high, 15m still high
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_70))
            # 15m high, 1h down move
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_60))
            # 15m & 4h high, 1d overbought
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_15))
            # 15m & 1h & 4h high
            & ((aroonu_14_15m_lt_90) | (aroonu_14_1h_lt_90) | (stochrsi_k_4h_lt_80))
            # 15m washed out, 4h washed out, 1d RSI low & up move & downtrend
            & (
              (stochrsi_k_15m_gt_30)
              | (rsi_14_1d_gt_60)
              | (rsi_3_1d < 75.0)
              | (aroonu_14_1d_gt_30)
              | (stochrsi_k_4h > 95.0)
            )
            # 5m still high, 15m still high, 1h down move, 1d down move & downtrend
            & (
              (stochrsi_k_15m_lt_40)
              | (rsi_3_1h_gt_65)
              | (rsi_3_1d > 75.0)
              | (aroonu_14_1d > 45.0)
              | (stochrsi_k < 35.0)
            )
            # 15m still not low enough, 1h still high, 4h overbought
            & ((stochrsi_k_15m_lt_20) | (aroonu_14_1h_lt_50) | (roc_9_4h_lt_10))
            # 15m still high, 1h down move & downtrend
            & ((stochrsi_k_15m_lt_20) | (rsi_3_1h_gt_55) | (aroonu_14_1h_gt_0))
            # 15m still not low enough, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_20) | (rsi_3_1h_gt_60) | (aroonu_14_4h_lt_90))
            # 15m still not low enough, 1h down move, 1d still high
            & ((stochrsi_k_15m_lt_20) | (rsi_3_1h_gt_60) | (stochrsi_k_1d_lt_40))
            # 15m still not low enough, 1h still high, 4h overbought
            & ((stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_50) | (roc_9_4h_lt_10))
            # 15m still not low enough, 1h & 1d high
            & ((stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_70) | (aroonu_14_1d_lt_75))
            # 15m still not low enough, 1h & 4h high
            & ((stochrsi_k_15m_lt_30) | (aroonu_14_1h_lt_75) | (stochrsi_k_4h_lt_80))
            # 15m still high & uptrend, 1h down move & downtrend
            & ((stochrsi_k_15m_lt_30) | (rsi_3_1h_gt_60) | (aroonu_14_1h > 15.0) | (aroonu_14_15m_lt_25))
            # 15m still high, 1h high, 1d overbought
            & ((stochrsi_k_15m_lt_40) | (aroonu_14_1h_lt_90) | (roc_9_1d_lt_0))
            # 15m still high, 4h high, 1d overbought
            & ((stochrsi_k_15m_lt_40) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_15))
            # 15m still high, 1h down move, 1d high
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_65) | (aroonu_14_1d_lt_80))
            # 15m & 1h still high, 4h high
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_40) | (aroonu_14_4h_lt_80))
            # 15m still high, 1h high, 1d overbought
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_10))
            # 15m & 1h still high, 1h down move
            & ((stochrsi_k_15m_lt_50) | (rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_50))
            # 15m still high, 1h high, 1d still not low enough
            & ((stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_60) | (stochrsi_k_1d_lt_30))
            # 15m high, 1h down move, 1d still high
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_65) | (aroonu_14_1d_lt_40))
            # 15m & 1h & 4h high
            & ((stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_70) | (stochrsi_k_4h_lt_90))
            # 15m high, 1d still high
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_lt_50))
            # 15m high, 4h overbought, 1d still not low enough
            & ((stochrsi_k_15m_lt_80) | (roc_9_4h_lt_10) | (stochrsi_k_1d_lt_30))
            # 15m & 4h high, 1d down move
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_4h_lt_90) | (rsi_3_1d_gt_65))
            # 15m WILLR high & washed out & up move, 4h money coming in
            & ((willr_14_15m < -50.0) | (cmf_20_4h_lt_0_15) | (stochrsi_k_15m > 35.0) | (rsi_3_15m_lt_75))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_75))
            # 5m uptrend, 1h down move, 4h uptrend
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_90) | (aroonu_14_lt_25))
            # 1h down move, 4h high, 1d still high
            & ((rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_80) | (aroonu_14_1d_lt_40))
            # 5m up move, 1h down move, 4h up move
            & ((rsi_3_1h_gt_45) | (roc_9_4h_lt_10) | (rsi_3 < 80.0))
            # 1h down move & high, 1d overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_0))
            # 5m up move & uptrend, 1h down move, 4h up move
            & ((rsi_3_1h_gt_55) | (roc_9_4h_lt_5) | (rsi_3 < 85.0) | (aroonu_14 < 5.0))
            # 1h down move, 4h up move, 1d downtrend
            & ((rsi_3_1h_gt_60) | (roc_9_4h_lt_10) | (aroonu_14_1d_gt_0))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_65) | (stochrsi_k_1d_lt_80))
            # 5m down move, 15m still high, 1h down move, 1d still high & down move
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1d_lt_30) | (rsi_3 > 20.0) | (rsi_3_1d > 80.0) | (stochrsi_k_15m < 5.0))
            # 1h down move, 1d still high & overbought
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1d_lt_40) | (roc_9_1d_lt_15))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_90) | (stochrsi_k_1d_lt_70))
            # 1h money leaving and not yet high
            & ((cmf_20_1h > -0.15) | (stochrsi_k_1h_lt_90))
            # 1h down move, 1h & 4h high
            & ((aroonu_14_1h_lt_70) | (rsi_3_1h_gt_45) | (stochrsi_k_4h_lt_90))
            # 1h down move & high, 1d still not low enough
            & ((aroonu_14_1h_lt_80) | (rsi_3_1h_gt_55) | (aroonu_14_1d_lt_30))
            # 15m washed out, 1h uptrend, 4h overbought & downtrend
            & ((aroonu_14_1h_lt_90) | (stochrsi_k_4h_lt_90) | (aroonu_14_4h > 90.0) | (stochrsi_k_15m_gt_60))
            # 5m downtrend, 15m still high, 1h still high, 1d down move & downtrend
            & (
              (stochrsi_k_1h_lt_60)
              | (roc_9_1d > 25.0)
              | (aroonu_14 > 10.0)
              | (aroonu_14_1d > 60.0)
              | (stochrsi_k_15m < 15.0)
            )
            # 1h high & overbought, 1d still high
            & ((stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10) | (stochrsi_k_1d_lt_40))
            # 1h overbought, 4h overbought, 1d downtrend & still high
            & ((stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_90) | (aroonu_14_1d_gt_0) | (stochrsi_k_1d < 75.0))
            # 1h & 1d overbought, 4h high
            & ((roc_9_1h_lt_10) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_15))
            # 4h high, 1d down move & still high
            & ((aroonu_14_4h_lt_100) | (rsi_3_1d_gt_65) | (aroonu_14_1d_lt_50))
            # 4h high, 1d down move & still not low enough
            & ((stochrsi_k_4h_lt_80) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_30))
            # 1h downtrend, 4h overbought, 1d overbought
            & ((stochrsi_k_4h_lt_90) | (stochrsi_k_1d_lt_90) | (aroonu_14_1h_gt_40))
            # 5m up move, 15m on the floor, 4h up move, 1d up move & downtrend
            & ((roc_9_4h_lt_10) | (roc_9_1d_lt_10) | (aroonu_14_1d_gt_30) | (stochrsi_k_15m > 15.0) | (rsi_3 < 25.0))
            # day washed out while the 1d trend sits at its high
            & ((rsi_3_1d_gt_25) | (aroonu_14_1d_lt_75))
            # day's momentum gone while the day is stretched
            & ((rsi_3_1d_gt_45) | (stochrsi_k_1d_lt_70))
            # 5m base position high, 15m washed out, 1d RSI low & up move & downtrend
            & (
              (ph_base_pos < 6.0)
              | (rsi_14_1d_gt_60)
              | (stochrsi_k_15m_gt_20)
              | (rsi_3_1d < 65.0)
              | (aroonu_14_1d_gt_30)
            )
            # 5m quad s93 max 12 low, 15m washed out, 4h up move, 1d RSI low & up move
            & (
              (quad_s93_max_12 > 95.0)
              | (rsi_14_1d_gt_60)
              | (rsi_3_1d < 70.0)
              | (roc_9_4h_lt_10)
              | (stochrsi_k_15m_gt_20)
            )
            # 1h money leaving, 15m momentum fading
            & ((uo_7_14_28_change_pct_15m < 13) | (cmf_20_1h > -0.2))
          )

          # Logic
          long_entry_logic.append(
            # 4h ADX crossing UP through 20 = a trend being born (not yet mature)
            (adx_14_4h > 20.0)
            & (np_shift(adx_14_4h, 48) <= 20.0)
            # direction: bulls own it
            & (plus_di_14_4h > minus_di_14_4h)
            & (close > ema_200)
            # 5m washed out
            & (stoch_60_10 > 40.0)
            # the 4h regime has to agree: a bounce inside a collapse puts price over the 5m
            # EMA200 for minutes, which is where every loss in the crash window came from
            & (ema_12_4h > ema_200_4h)
            # 1d washed out
            & (rsi_14_1d_gt_50)
            & (stochk_14_3_3_1d > 40.0)
          )

        # Condition #8 - Donchian 7-day breakout (Long, experimental — turtle-style; big-win lane).
        if long_entry_condition_index == 8:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          # Logic
          long_entry_logic.append(
            # first close above the prior 7-DAY high (macro breakout event)
            (close > open_rate)
            & (np_shift(close, 1) <= dc_high_7d)
            & (close > dc_high_7d)
            # not a one-candle spike fake, and the 4h is not already overheated
            & (((high_px - low_px) / close) < 0.025)
            & (roc_9_4h < 20.0)
          )

        # Condition #9 - Momentum Continuation (Long, experimental).
        if long_entry_condition_index == 9:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            ((roc_9_1d > -5.0) | (rsi_3_1d > 40.0))
            & ((roc_9_4h > -3.0) | (rsi_3_4h > 50.0))
            & (roc_9_1d < 25.0)
            & (roc_9_4h < 15.0)
            & (roc_9_1h < 10.0)
            & (rsi_3 < 88.0)
            & (rsi_3_15m < 85.0)
            & (rsi_3_1h < 80.0)
            & (rsi_3_4h < 80.0)
            & (stochrsi_k < 90.0)
            & (stochrsi_k_1h < 85.0)
            & (stochrsi_k_4h < 85.0)
            & (willr_14 < -10.0)
            & (mfi_14 > 40.0)
            & (cmf_20 > -0.10)
            & (bbb_20_2_0 < 20.0)
            & (close < (close_max_48 * 0.985))
            & ((rsi_3 > 10.0) | (rsi_3_1h > 20.0) | (roc_9_1d > 0.0))
            & ((rsi_3_15m > 10.0) | (rsi_3_1h > 15.0) | (roc_9_4h > -5.0))
            & ((rsi_3_1h > 20.0) | (rsi_3_4h > 25.0) | (aroonu_14_4h < 60.0))
            & ((rsi_3_15m > 20.0) | (rsi_3_1h > 30.0) | (rsi_3_4h > 35.0))
            # 1h already rolling over — continuation into a fading hour
            & ((willr_14_1h > -35.0) | (aroonu_14_4h > 60.0) | (rsi_3_1h > 65.0))
            # washed-out daily + rolling 4h — the trend is already dead
            & ((rsi_3_1d > 40.0) | (roc_9_4h > 2.0) | (cci_20_4h > -20.0))
          )
          # Logic — full EMA-fan alignment, mature uptrend continuation
          long_entry_logic.append(((ema_9 - ema_50) / close * 100.0) > 0.5)
          long_entry_logic.append(rsi_14_1d > 50.0)
          long_entry_logic.append(rsi_3_1h < 80.0)
          long_entry_logic.append(cmf_20_1h > 0.0)
          long_entry_logic.append(close > ema_9)
          long_entry_logic.append(close > ema_12)
          long_entry_logic.append(close > ema_26)
          long_entry_logic.append(close > ema_50)
          long_entry_logic.append(close > ema_200)
          long_entry_logic.append(ema_9 > ema_26)
          long_entry_logic.append(ema_26 > ema_200)
          long_entry_logic.append(rsi_14 > 55.0)
          long_entry_logic.append(rsi_14 < 65.0)
          long_entry_logic.append(aroonu_14 > 75.0)
          long_entry_logic.append(rsi_14_1h > 50.0)
          long_entry_logic.append(rsi_14_1h < 70.0)
          long_entry_logic.append(rsi_14_4h > 48.0)
          long_entry_logic.append(rsi_14_4h < 68.0)
          long_entry_logic.append(bbp_20_2_0 > 0.55)
          long_entry_logic.append(bbp_20_2_0 < 0.85)
          long_entry_logic.append(obv_change_pct > 0.0)
          long_entry_logic.append(willr_14 > -40.0)
          long_entry_logic.append(willr_14 < -15.0)

        # Condition #10 - CCI Divergence + AROON Trend Birth (Long, experimental).
        if long_entry_condition_index == 10:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(global_protections_long_pump == True)
          long_entry_logic.append(global_protections_long_dump == True)
          long_entry_logic.append(rsi_14_1d > 30.0)
          long_entry_logic.append(roc_9_1d > -20.0)
          long_entry_logic.append(rsi_14_4h > 25.0)
          long_entry_logic.append((ema_12_4h > ema_200_4h) | (rsi_14_4h > 35.0) | (roc_9_4h > -5.0))
          long_entry_logic.append(
            ((rsi_3 > 3.0) | (rsi_3_15m > 5.0) | (rsi_3_1h > 10.0))
            & ((rsi_3_15m > 5.0) | (rsi_3_1h > 15.0) | (aroonu_14_4h < 90.0))
            & ((rsi_3_1h > 10.0) | (rsi_3_4h > 20.0) | (stochrsi_k_4h < 60.0))
            & ((rsi_3_15m > 10.0) | (rsi_3_4h > 25.0) | (roc_9_1d > -10.0))
          )
          long_entry_logic.append((rsi_3_1d > 20.0) | (roc_2_1d > -3.0) | (cmf_20_1d > -0.10))
          # deep daily outflow (distribution) with no washout — knife, not a dip
          long_entry_logic.append((cmf_20_1d > -0.30) | (rsi_3_1d > 65.0) | (roc_9_4h < -15.0))
          # Logic — 1h CCI recovering from oversold + fresh 15m AROON upswing
          long_entry_logic.append(cci_20_1h < -50.0)
          long_entry_logic.append(cci_20_1h > -200.0)
          long_entry_logic.append(cci_20_change_pct_1h > 0.0)
          long_entry_logic.append(aroonu_14_15m > 50.0)
          long_entry_logic.append(aroonu_14 > 30.0)
          long_entry_logic.append(rsi_14 < 45.0)
          long_entry_logic.append(rsi_14 > 20.0)
          long_entry_logic.append(mfi_14 > 30.0)
          long_entry_logic.append(cmf_20_1h > -0.05)
          long_entry_logic.append(close < (close_max_48 * 0.95))
          long_entry_logic.append(close > close_min_48)
          long_entry_logic.append(stochrsi_k < 30.0)

        # Condition #11 - MFI/CMF Double Divergence + BB Reversion (Long, experimental).
        if long_entry_condition_index == 11:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(global_protections_long_pump == True)
          long_entry_logic.append(global_protections_long_dump == True)
          long_entry_logic.append(rsi_14_1d > 30.0)
          long_entry_logic.append(roc_9_1d > -20.0)
          long_entry_logic.append((ema_12_4h > ema_200_4h) | (rsi_14_4h > 40.0))
          long_entry_logic.append(
            ((rsi_3 > 2.0) | (rsi_3_15m > 5.0) | (aroonu_14_1h < 80.0))
            & ((rsi_3_15m > 5.0) | (rsi_3_1h > 10.0) | (roc_9_4h > -10.0))
            & ((rsi_3_1h > 8.0) | (rsi_3_4h > 15.0) | (stochrsi_k_1d < 50.0))
            & ((rsi_3_15m > 8.0) | (cmf_20_4h > -0.15) | (aroonu_14_4h < 70.0))
            & ((rsi_3_4h > 15.0) | (roc_9_1d > -15.0))
          )
          long_entry_logic.append((rsi_14_1h > 22.0) | (rsi_14_4h > 25.0))
          # post-pump slow bleed: daily still inflated while 4h drifts slightly
          # negative (0..-15) = distribution, not a dip; real dips wash out below -15
          long_entry_logic.append((roc_9_1d < 25.0) | (roc_9_4h > 0.0) | (roc_9_4h < -15.0))
          # Logic — MFI & CMF both positive (accumulation) at the BB lower band
          long_entry_logic.append(mfi_14 > 30.0)
          long_entry_logic.append(cmf_20 > 0.02)
          long_entry_logic.append(willr_14 < -80.0)
          long_entry_logic.append(willr_14_1h < -45.0)
          long_entry_logic.append(close < (bbl_20_2_0 * 1.015))
          long_entry_logic.append(bbb_20_2_0 > 6.0)
          long_entry_logic.append(rsi_14 < 40.0)
          long_entry_logic.append(rsi_14 > 15.0)
          long_entry_logic.append(rsi_3 > 3.0)
          long_entry_logic.append(rsi_14_1h > 25.0)
          long_entry_logic.append(bbp_20_2_0_1h > 0.05)

        # Condition #21 - Pump mode (Long).
        if long_entry_condition_index == 21:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m down move, 4h high, 1h overbought
            ((rsi_3_gt_10) | aroonu_14_4h_lt_100 | (roc_9_1h_lt_30))
            # 15m down move, 1h & 4h overbought
            & ((rsi_3_15m_gt_5) | (roc_9_1h_lt_25) | (roc_9_4h_lt_50))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | rsi_3_1h_gt_20 | (roc_9_1d_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | aroonu_14_1h_lt_80)
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_80))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_45) | (roc_9_4h_lt_50))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_60) | (roc_9_4h_lt_70))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_55) | (aroonu_14_4h_lt_90))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_80))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_70) | roc_9_1d_gt_neg_50)
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30))
            # 15m down move, 1d high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (roc_9_4h_lt_100))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_35) | (aroonu_14_1h_lt_90))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_40) | aroonu_14_4h_lt_100)
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_40) | aroonu_14_4h_lt_100)
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_60) | (roc_9_4h_lt_80))
            # 15m down move, 4h high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_90) | (cmf_20_4h_gt_neg_0_25))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (roc_9_1h_lt_30) | (roc_9_4h_lt_50))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_15) | (roc_9_4h_lt_60) | (roc_9_1d_lt_80))
            # 15m & 1h down move, 1h & 4h high, 1h overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_10))
            # 15m & 1h down move, 4h & 1d high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_50) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_50) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_100))
            # 15m down move, 4h high, 1h overbought
            & ((rsi_3_15m_gt_20) | (stochrsi_k_4h_lt_80) | (roc_9_1h_lt_10))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_20) | (roc_9_4h_lt_80) | (roc_9_1d_lt_200))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (roc_9_1d_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_55) | (aroonu_14_1h_lt_90))
            # 15m down move, 15m still high, 1d downtrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_40) | (roc_9_1d_gt_neg_25))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_100))
            # 15m down move, 4h high, 1h overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_20))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_100))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_25) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_20))
            # 15m down move, 1h & 4h overbought
            & ((rsi_3_15m_gt_25) | (roc_9_1h_lt_40) | (roc_9_4h_lt_40))
            # 15m & 4h & 1d down move, 4h & 1d high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_55) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_80) | (roc_9_1h_lt_20))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (stochrsi_k_4h_lt_90) | (roc_9_4h < 200.0))
            # 15m down move, 1h & 4h overbought
            & ((rsi_3_15m_gt_30) | (roc_9_1h_lt_60) | (roc_9_4h_lt_80))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_40) | (roc_9_4h_lt_100) | (roc_9_1d_lt_100))
            # 1h down move, 4h overbought, 1d downtrend
            & ((rsi_3_1h_gt_15) | (roc_9_4h_lt_50) | (roc_9_1d > -30.0))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (roc_9_4h_lt_50) | aroonu_14_4h_lt_80)
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_20) | (roc_9_4h_lt_50) | (stochrsi_k_1h_lt_40))
            # 1h & 4h down move, 4h overbought
            & ((rsi_3_1h_gt_20) | (roc_9_4h_lt_50) | (roc_9_4h_lt_10))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_10))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_50))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_40) | (roc_9_4h_lt_10))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_20) | (roc_9_4h_lt_40) | (roc_9_1d_lt_100))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_60))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_30))
            # 1h & 4h down move, 4h high & overbought
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_50))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_80) | (roc_9_1d_gt_neg_40))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_80) | roc_9_1d_gt_neg_50)
            # 1h down move, 1h & 1d overbought
            & ((rsi_3_1h_gt_40) | (roc_9_1h_lt_30) | (roc_9_1d_lt_60))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_25))
            # 1h down move, 4h high, 1h overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_20))
            # 1h down move, 4h high, 1h overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_10))
            # 1h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_45) | (aroonu_14_1d_lt_100) | (roc_9_1d_gt_neg_25))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_90) | (roc_9_1h_lt_10))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_70) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1h & 1d overbought
            & ((rsi_3_1h_gt_50) | (roc_9_1h_lt_25) | (roc_9_1d_lt_200))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_40))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_70))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_60) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_100))
            # 1h down move, 1h & 1d overbought
            & ((rsi_3_1h_gt_60) | (roc_9_1h_lt_10) | (roc_9_1d < 250.0))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_65) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_30))
            # 1h down move, 1h overbought
            & ((rsi_3_1h_gt_65) | (roc_9_1h_lt_40))
            # 4h down move, 1h high & overbought
            & ((rsi_3_4h_gt_3) | (aroonu_14_1h_lt_85) | (roc_9_1h_lt_60))
            # 4h & 1d down move, 1h high & overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_35) | (aroonu_14_1h_lt_80) | (roc_9_1h_lt_10))
            # 4h & 1d down move, 1h high & overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_70) | (roc_9_1h_lt_10))
            # 1d down move, 4h high & overbought
            & ((rsi_3_1d_gt_5) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_50))
            # 1d down move, 1h high
            & ((rsi_3_1d_gt_10) | aroonu_14_1h_lt_70)
            # 1d down move, 4h high, 1h overbought
            & ((rsi_3_1d_gt_20) | aroonu_14_4h_lt_100 | (roc_9_1h_lt_25))
            # 1d down move, 4h high, 4h overbought
            & ((rsi_3_1d_gt_20) | aroonu_14_4h_lt_100 | (roc_9_4h_lt_40))
            # 1d down move, 1h & 4h overbought
            & ((rsi_3_1d_gt_30) | (roc_9_1h_lt_30) | (roc_9_4h_lt_60))
            # 1d down move, 4h high & overbought
            & ((rsi_3_1d_gt_35) | aroonu_14_4h_lt_100 | (roc_9_4h_lt_20))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_40) | aroonu_14_1h_lt_80 | aroonu_14_4h_lt_100)
            # 1d down move, 4h & 1d high
            & ((rsi_3_1d_gt_40) | aroonu_14_4h_lt_70 | aroonu_14_1d_lt_100)
            # 1d down move, 4h high & overbought
            & ((rsi_3_1d_gt_45) | aroonu_14_4h_lt_80 | (roc_9_4h_lt_30))
            # 1d down move, 1h high, 1d overbought
            & ((rsi_3_1d_gt_60) | (aroonu_14_1h_lt_75) | (roc_9_1d_lt_20))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_65) | (aroonu_14_1h_lt_90) | aroonu_14_4h_lt_100)
            # 1d downtrend, 1d high & overbought
            & ((cmf_20_1d_gt_neg_0_40) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_20))
            # 15m not low enough, 1h high, 1d overbought
            & ((aroonu_14_15m_lt_25) | (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_200))
            # 1h still high, 1h & 4h overbought
            & ((aroonu_14_1h_lt_50) | (roc_9_1h_lt_40) | (roc_9_4h_lt_40))
            # 1h & 4h high, 4h overbought
            & (aroonu_14_1h_lt_70 | aroonu_14_4h_lt_100 | (roc_9_4h_lt_20))
            # 1h & 4h high, 4h overbought
            & (aroonu_14_1h_lt_80 | aroonu_14_4h_lt_80 | (roc_9_4h_lt_30))
            # 1h & 4h high, 1h overbought
            & (aroonu_14_1h_lt_80 | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_30))
            # 1h & 4h high, 1d overbought
            & (aroonu_14_1h_lt_80 | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_100))
            # 1h & 1d high, 4h overbought
            & ((aroonu_14_1h_lt_90) | (aroonu_14_1d_lt_90) | (roc_9_4h_lt_30))
            # 1h & 4h high, 1h overbought
            & (aroonu_14_1h_lt_80 | (stochrsi_k_4h_lt_90) | (roc_9_1h_lt_10))
            # 1h high & overbought
            & (aroonu_14_1h_lt_80 | (roc_9_1h_lt_80))
            # 1h high, 1h & 4h overbought
            & (aroonu_14_1h_lt_80 | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 1h high, 4h overbought, 1d downtrend
            & (aroonu_14_1h_lt_80 | (roc_9_4h_lt_10) | roc_9_1d_gt_neg_50)
            # 1h & 4h high, 15m downtrend
            & ((aroonu_14_1h_lt_85) | (aroonu_14_4h_lt_85) | (roc_9_15m > -40.0))
            # 1h & 4h high, 1h overbought
            & ((aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_10))
            # 4h high, 1h overbought, 1d downtrend
            & (aroonu_14_4h_lt_80 | (roc_9_1h_lt_30) | (roc_9_1d > -30.0))
            # 4h & 1d high, 4h downtrend
            & ((aroonu_14_4h_lt_85) | aroonu_14_1d_lt_100 | (cmf_20_4h_gt_neg_0_30))
            # 4h & 1d high, 1h overbought
            & ((aroonu_14_4h_lt_85) | (aroonu_14_1d_lt_90) | (roc_9_1h_lt_20))
            # 4h & 1d high, 4h overbought
            & ((aroonu_14_4h_lt_85) | (aroonu_14_1d_lt_90) | (roc_9_4h_lt_60))
            # 4h high, 1h & 4h overbought
            & ((aroonu_14_4h_lt_85) | (roc_9_1h_lt_10) | (roc_9_4h_lt_20))
            # 4h high, 1d high & overbought
            & ((aroonu_14_4h_lt_90) | aroonu_14_1d_lt_100 | (roc_9_1d_lt_30))
            # 4h high, 1h & 4h overbought
            & ((aroonu_14_4h_lt_90) | (roc_9_1h_lt_40) | (roc_9_4h_lt_40))
            # 4h high, 4h & 1d overbought
            & ((aroonu_14_4h_lt_90) | (roc_9_4h_lt_30) | (roc_9_1d_lt_100))
            # 4h high, 1h & 4h overbought
            & (aroonu_14_4h_lt_100 | (roc_9_1h_lt_40) | (roc_9_4h_lt_80))
            # 1d high, 1h & 4h overbought
            & (aroonu_14_1d_lt_100 | (roc_9_1h_lt_10) | (roc_9_4h_lt_20))
            # 1h high, 1h & 4h overbought
            & ((stochrsi_k_1h_lt_60) | (roc_9_1h_lt_40) | (roc_9_4h_lt_40))
            # 1h high, 1h overbought
            & ((stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10))
            # 1h high, 4h overbought. 1d downtrend
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_lt_40) | (cmf_20_1d_gt_neg_0_25))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_1h_lt_10) | (roc_9_4h_lt_20))
            # 4h high & 4h & 1d overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 1d high, 1h & 4h overbought
            & ((stochrsi_k_1d_lt_80) | (roc_9_1h_lt_10) | (roc_9_4h_lt_20))
            # 1d hihg, 1h & 1d overbought
            & ((stochrsi_k_1d_lt_90) | (roc_9_1h_lt_30) | (roc_9_1d_lt_100))
            # 1d high, 4h & 1d overbought
            & ((stochrsi_k_1d_lt_90) | (roc_9_4h_lt_40) | (roc_9_1d_lt_100))
          )

          # Logic
          long_entry_logic.append(
            (aroonu_14_lt_25)
            & (stochrsi_k_lt_20)
            & (aroonu_14_15m_lt_50)
            & (close < ema_16 * 0.960)
            & (((ema_50 - ema_200) / close * 100.0) > 6.0)
          )

        # Condition #41 - Quick mode (Long).
        if long_entry_condition_index == 41:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 1d down move, 4h still high
            ((rsi_3_gt_15) | (rsi_3_1d_gt_30) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (stochrsi_k_1d_lt_50))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (stochrsi_k_1h_lt_30))
            # 15m & 1h & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_20))
            # 15m & 1h down move, 15m downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (cmf_20_15m_gt_neg_0_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_60))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (roc_9_1d_gt_neg_20))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_60))
            # 15m & 1h & 4h down move, 1h still not low enough, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_30) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (aroonu_14_1d_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (stochrsi_k_1d_lt_90))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_35) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_85))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_45) | (stochrsi_k_1h < 75.0))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_5) | (aroonu_14_4h_lt_80))
            # 15m & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_50))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_50))
            # 15m down move, 15m still high, 1d high
            & ((rsi_3_15m_gt_3) | (aroonu_14_15m_lt_40) | (aroonu_14_1d_lt_80))
            # 15m down move, 15m still high, 1d downtrend
            & ((rsi_3_15m_gt_3) | (aroonu_14_15m_lt_50) | (roc_9_1d_gt_neg_20))
            # 15m down move, 1h still high, 1d high
            & ((rsi_3_15m_gt_3) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_70))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_3) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_80))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_3) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_3) | (stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_80))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_3) | (stochrsi_k_1h_lt_90) | (roc_9_4h_lt_10))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_3) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_3) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_10))
            # 15m down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_3) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (roc_9_1d_gt_neg_10))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_80))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_40))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_1h_lt_50))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_25) | (roc_9_1d_gt_neg_70))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_100) | aroonu_14_4h_lt_100)
            # 15m down move, 1h still high, 1d downtrend
            & ((rsi_3_15m_gt_5) | (stochrsi_k_1h_lt_50) | (roc_9_1d_gt_neg_40))
            # 5m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_5) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_40))
            # 15m down move, 1h & 4h overbought
            & ((rsi_3_15m_gt_5) | (roc_9_1h_lt_25) | (roc_9_4h_lt_25))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_5) | (roc_9_4h_lt_30) | (roc_9_1d_lt_100))
            # 15m & 1h & 4h & 1d down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_55) | (rsi_3_1d_gt_60) | (aroonu_14_1h_lt_50))
            # 15m & 1h & 1d down move, 1d still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_30))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_1d_lt_70))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (roc_9_1d_gt_neg_30))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_70))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 1h high, 4h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_90))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_100))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_4h_lt_80))
            # 15m down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_30))
            # 15m down move, 15m high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_70))
            # 15m down move, 1h high, 15m downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_80) | (roc_9_15m > -10.0))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_80) | (roc_9_1d_gt_neg_30))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_85) | (roc_9_1d_lt_40))
            # 15m down move, 1h & 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_90) | aroonu_14_1d_lt_100)
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_100) | aroonu_14_4h_lt_100)
            # 15m down move, 4h high, 1h downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_85) | (roc_9_1h_gt_neg_25))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 15m down move, 4h high, 15m downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_100) | (roc_9_15m > -30.0))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_60))
            # 15m down move, 1d high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_1d_lt_85) | (cmf_20_1d_gt_neg_0_40))
            # 15m down move, 1h high, 15m downtrend
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_80) | (roc_9_15m > -10.0))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_90) | (roc_9_1d_gt_neg_30))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_30))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (aroonu_14_1d_lt_90))
            # 15m & 1h & 1d down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 15m still high, 1d high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (aroonu_14_15m_lt_50) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (aroonu_14_1h_lt_80))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_90))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_100))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_80))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_90))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_lt_80))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 15m down move, 4h high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_60) | (roc_9_4h_gt_neg_20))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 15m down move, 1h high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_30))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_80) | roc_9_1d_gt_neg_50)
            # 15m down move, 1d high, 4h overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1d_lt_90) | (roc_9_4h_lt_40))
            # 15m down move, 1h downtrend, 4h overbought
            & ((rsi_3_15m_gt_15) | (roc_9_1h_gt_neg_20) | (roc_9_4h_lt_80))
            # 15m down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_15) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_40))
            # 15m & 1h & 4h & 1d down move, 15m downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (cmf_20_15m_gt_neg_0_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (roc_9_1d_lt_50))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (aroonu_14_1d_lt_100))
            # 15m & 1h down move, 1h & 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_50) | (roc_9_1h_lt_10) | (roc_9_1d_lt_40))
            # 15m &4h down move, 4h still high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_50))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_70) | (roc_9_1d_lt_40))
            # 15m down move, 1h high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_80) | (roc_9_4h_gt_neg_15))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_100) | (roc_9_1h_lt_50))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_20))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_60))
            # 15m & 1h down move, 15m still high, 1h high, 1d overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_35) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_20))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_60))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_90))
            # 15m & 1h & 4h down move, 15m & 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_60) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_60))
            # 15m down move, 15m high, 1h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_90))
            # 15m down move, 15m high, 4h downtrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_60) | (roc_9_4h_gt_neg_20))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_90) | (roc_9_4h_lt_30))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_100) | (roc_9_4h_lt_15))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_20))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 15m & 1h & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_90))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_3) | (stochrsi_k_1d_lt_50))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (aroonu_14_1h_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_70))
            # 1h down move, 15m & 1h downtrend
            & ((rsi_3_1h_gt_3) | (cmf_20_15m_gt_neg_0_30) | (cmf_20_1h_gt_neg_0_30))
            # 1h down move, 1h still high, 1h downtrend
            & ((rsi_3_1h_gt_3) | (aroonu_14_1h_lt_50) | (roc_9_1h_gt_neg_20))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_3) | (aroonu_14_1h_lt_70))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_3) | (aroonu_14_4h_lt_70))
            # 1h down move, 1d high
            & ((rsi_3_1h_gt_3) | (aroonu_14_1d_lt_70))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_3) | (stochrsi_k_4h_lt_50) | (roc_9_1h_gt_neg_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_3) | (stochrsi_k_1d_lt_60) | (roc_9_1d_lt_20))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_20))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_20))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_30) | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 1h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_30) | (cmf_20_1h_gt_neg_0_30))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70))
            # 1h & 4h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_55) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 4h high & overbought
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_55) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_10))
            # 1h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_50))
            # 1h down move, 1h high, 1d high
            & ((rsi_3_1h_gt_5) | (aroonu_14_1h_lt_70) | (stochrsi_k_1d_lt_80))
            # 1h down move, 1h still high, 1h downtrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_1h_lt_50) | (roc_9_1h_gt_neg_30))
            # 1h down move, 4h still high, 1h downtrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_4h_lt_50) | (roc_9_1h_gt_neg_30))
            # 1h down move, 1d high, 1h downtrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_1d_lt_85) | (roc_9_1h_gt_neg_50))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_30))
            # 1h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_1d_lt_100) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_5) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_5) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_50))
            # 1h down move, 1d high
            & ((rsi_3_1h_gt_5) | (stochrsi_k_1d_lt_90))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_5) | (roc_9_4h_gt_neg_25) | (roc_9_1d_gt_neg_50))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_15))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_1h_lt_80))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 1d still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_20))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_35))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 15m downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (roc_9_15m > -20.0))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_90))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_80))
            # 1h & 4h & 1d down move, 1h & 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_lt_80))
            # 1h & 4h & 1d down move, 1h high, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_55) | (rsi_3_1d_gt_65) | (aroonu_14_1h_lt_60) | (stochrsi_k_1d_lt_70))
            # 1h & 4h down move, 4h high & overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_55) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 1h & 1d down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_10) | (roc_9_1d_gt_neg_30))
            # 1h & 1d down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_10) | (aroonu_14_4h_lt_40))
            # 1h & 1d down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_4h_lt_70))
            # 1h & 1d down move, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_20))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_70))
            # 1h & 1d down move, 1h downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_30) | (cmf_20_1h_gt_neg_0_40))
            # 1h down move, 1d downtrend, 4h high
            & ((rsi_3_1h_gt_10) | (cmf_20_1d_gt_neg_0_30) | (stochrsi_k_4h_lt_90))
            # 1h down move, 1h still high, 4h overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_50) | (roc_9_4h_lt_20))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_60))
            # 1h down move, 1h high, 1d high
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_60) | (stochrsi_k_1d_lt_90))
            # 1h down move, 1d overbought
            & ((rsi_3_1h_gt_10) | roc_9_1d_lt_50)
            # 1h & 4h down move, 1h downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (roc_9_1h_gt_neg_15))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (roc_9_4h_gt_neg_25))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_70))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_70))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_100))
            # 1h & 4h & 1d down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_1d_lt_70))
            # 1h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_30) | (stochrsi_k_1h_lt_40))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_30) | (aroonu_14_1h_lt_80))
            # 1h & 1d down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_50) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_20))
            # 1h down move, 1h downtrend, 1h still high
            & ((rsi_3_1h_gt_15) | (cmf_20_1h_gt_neg_0_30) | (stochrsi_k_1h_lt_40))
            # 1h down move, 1d downtrend, 1d high
            & ((rsi_3_1h_gt_15) | (cmf_20_1d_gt_neg_0_30) | (stochrsi_k_1d_lt_80))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_40))
            # 1h down move, 1h high, 1h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_80) | (cmf_20_1h_gt_neg_0_25))
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_80) | (roc_9_4h_gt_neg_30))
            # 1h down move, 4h still high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_1d_lt_60))
            # 1h down move, 4h high, 15m downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_85) | (roc_9_15m > -15.0))
            # 1h down move, 4h high, 1h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_85) | (roc_9_1h_gt_neg_30))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 1h down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_30) | (roc_9_1d > -30.0))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_100))
            # 1h down move, 1h downtrend, 1d overbought
            & ((rsi_3_1h_gt_15) | (roc_9_1h_gt_neg_30) | (roc_9_1d_lt_35))
            # 1h down move, 4h downtrend, 1d overbought
            & ((rsi_3_1h_gt_15) | (roc_9_4h_gt_neg_25) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h still high, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_70))
            # 1h & 4h down move, 4h still high, 1h downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50) | (roc_9_1h_gt_neg_25))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_70))
            # 1h & 1d down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_4h_lt_90))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_70))
            # 1h & 1d down move, 1h & 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_70))
            # 1h & 1d down move, 4h overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_30) | (roc_9_4h_lt_30))
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_100))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_60))
            # 1h down move, 1h still high, 4h high & overbought
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1d_lt_80) | roc_9_1d_gt_neg_50)
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_40))
            # 1h down move, 1h & 4h overbought
            & ((rsi_3_1h_gt_20) | (roc_9_1h_lt_20) | (roc_9_4h_lt_40))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_20) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_40))
            # 1h & 4h & 1d down move, 15m still high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_15m_lt_50))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_40) | (roc_9_1d_lt_100))
            # 1h & 1d down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h down move, 15m still high, 1h high
            & ((rsi_3_1h_gt_25) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_90))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_200))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_85) | (roc_9_1d_lt_50))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_90))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_40))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_40))
            # 1h down move, 15m downtrend, 4h overbought
            & ((rsi_3_1h_gt_25) | (roc_9_15m > -25.0) | (roc_9_4h_lt_30))
            # 1h down move, 1h & 1d downtrend
            & ((rsi_3_1h_gt_25) | (roc_9_1h_gt_neg_50) | roc_9_1d_gt_neg_50)
            # 1h down move, 1h downtrend, 4h overbought
            & ((rsi_3_1h_gt_25) | (roc_9_1h_gt_neg_25) | (roc_9_4h_lt_50))
            # 1h down move, 1h & 4h overbought
            & ((rsi_3_1h_gt_25) | (roc_9_1h_lt_30) | (roc_9_4h_lt_100))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_1h_lt_90))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (roc_9_4h_gt_neg_20))
            # 1h & 4h down move, 4h high, 1h downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80) | (roc_9_1h_gt_neg_40))
            # 1h down move, 1h downtrend, 1h high
            & ((rsi_3_1h_gt_30) | (cmf_20_1h_gt_neg_0_25) | (stochrsi_k_1h_lt_70))
            # 1h down move, 4h downtrend, 4h high
            & ((rsi_3_1h_gt_30) | (cmf_20_4h_gt_neg_0_50) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h still high, 1h & 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_40) | (roc_9_1h_gt_neg_10) | (roc_9_1d_gt_neg_50))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_1h_lt_10))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_1d_gt_neg_60))
            # 1h down move, 4h high, 1h overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80) | (roc_9_1h_lt_50))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_90) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_20))
            # 1h down move, 1d high, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (roc_9_4h_lt_10) | (roc_9_1d_lt_50))
            # 1h & 4h & 1d down move, 1h & 4h still high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 1h down move, 15m & 1h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (roc_9_4h_gt_neg_40))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_80) | (roc_9_1d_gt_neg_40))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_90) | (roc_9_4h_lt_10))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_200))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30))
            # 1h down move, 1h downtrend, 4h overbought
            & ((rsi_3_1h_gt_35) | (roc_9_1h_gt_neg_30) | (roc_9_4h_lt_100))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_35) | (roc_9_4h_lt_20) | (roc_9_1d_lt_70))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (roc_9_1h_lt_10))
            # 1h down move, 1h high, 1d high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_85) | (roc_9_1d_lt_80))
            # 1h down move, 1h high, 15m downtrend
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_90) | (roc_9_15m > -10.0))
            # 1h down move, 1h  high & overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_40) | (roc_9_4h_lt_20) | (roc_9_1d_lt_100))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_40) | (roc_9_4h_lt_30) | (roc_9_1d_lt_40))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_200))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_45) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_100))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_60) | (roc_9_1d_gt_neg_70))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_100))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_60) | (roc_9_1d_gt_neg_60))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_80))
            # 1h down move, 1h overbought
            & ((rsi_3_1h_gt_60) | (roc_9_1h_lt_30))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_60) | (roc_9_4h_lt_30) | (roc_9_1d_lt_60))
            # 4h & 1d down move, 1d still not low enough
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_30))
            # 4h down move, 4h high, 1h downtrend
            & ((rsi_3_4h_gt_3) | (aroonu_14_4h_lt_70) | (roc_9_1h_gt_neg_40))
            # 4h down move, 1h still high, 4h downtrend
            & ((rsi_3_4h_gt_3) | (stochrsi_k_1h_lt_50) | (roc_9_4h_gt_neg_30))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_50))
            # 4h down move, 15m still high, 1d downtrend
            & ((rsi_3_4h_gt_5) | (aroonu_14_15m_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_25) | roc_9_1d_gt_neg_50)
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_80))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_70) | (roc_9_1d_lt_35))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_15) | (roc_9_1d > -35.0))
            # 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 4h down move, 4h still high, 1d overbought
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40) | (roc_9_1d_lt_40))
            # 4h down move, 1h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_20) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_lt_70))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_200))
            # 4h down move, 15m & 1h high
            & ((rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_80))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_20) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_30))
            # 4h down move, 15m high, 1d overbought
            & ((rsi_3_4h_gt_25) | (aroonu_14_15m_lt_70) | (roc_9_1d_lt_100))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_80))
            # 4h down move, 1d high, 1h downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_1d_lt_100) | (roc_9_1h_gt_neg_40))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h still high, 1d overbought
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50) | (roc_9_1d_lt_200))
            # 4h down move, 4h still not low enough, 1d overbought
            & ((rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_20) | (roc_9_1d_lt_60))
            # 4h down move, 1d high, 1d downtrend
            & ((rsi_3_4h_gt_35) | (stochrsi_k_1d_lt_60) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_55) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_50))
            # 4h down move, 1h high, 1d overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_1h_lt_85) | roc_9_1d_lt_50)
            # 4h down move, 1d high, 1d downtrend
            & ((rsi_3_4h_gt_45) | (aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_15))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_45) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_25))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (rsi_14_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_50) | aroonu_14_4h_lt_80 | (roc_9_4h_lt_10))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_50) | (roc_9_4h_lt_10) | (roc_9_1d_lt_40))
            # 1d down move, 4h still high, 1d downtrend
            & ((rsi_3_1d_gt_3) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_25))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_10) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90))
            # 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1d_gt_10) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_40))
            # 1d down move, 4h high, 1d downtrend
            & ((rsi_3_1d_gt_10) | (stochrsi_k_4h_lt_90) | (roc_9_1d_gt_neg_80))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_15) | (aroonu_14_1h_lt_90) | aroonu_14_4h_lt_100)
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_20) | (aroonu_14_1h_lt_100) | (roc_9_1d_gt_neg_30))
            # 1d down move, 1h still high, 4h downtrend
            & ((rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_50) | (roc_9_4h_gt_neg_30))
            # 1d down move, 1h high & overbought
            & ((rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10))
            # 15m downtrend, 4h & 1d high
            & ((cmf_20_15m_gt_neg_0_30) | aroonu_14_4h_lt_80 | aroonu_14_1d_lt_100)
            # 15m & 1h high, 1h overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100) | (roc_9_1h_lt_50))
            # 15m & 1d high, 1d overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_30))
            # 1h & 4h high, 1h downtrend
            & (aroonu_14_1h_lt_70 | aroonu_14_4h_lt_100 | (cmf_20_1h_gt_neg_0_30))
            # 1h high, 4h high, 1h overbought
            & (aroonu_14_1h_lt_70 | aroonu_14_4h_lt_100 | (roc_9_1h_lt_20))
            # 1h & 1d high, 1h overbought
            & (aroonu_14_1h_lt_70 | (aroonu_14_1d_lt_70) | (roc_9_1h_lt_20))
            # 1h high, 1d high & overbought
            & (aroonu_14_1h_lt_70 | aroonu_14_1d_lt_100 | (roc_9_1d_lt_200))
            # 1h high, 1h & 1d overbought
            & (aroonu_14_1h_lt_70 | (roc_9_1h_lt_20) | (roc_9_1d_lt_200))
            # 1h high, 4h downtrend, 1d overbought
            & (aroonu_14_1h_lt_70 | (roc_9_4h_gt_neg_40) | (roc_9_1d_lt_100))
            # 1h high, 1h & 1d overbought
            & (aroonu_14_1h_lt_80 | (roc_9_1h_lt_20) | (roc_9_1d_lt_20))
            # 1h high, 1h overbought, 1d downtrend
            & (aroonu_14_1h_lt_80 | (roc_9_1h_lt_30) | (roc_9_1d_gt_neg_40))
            # 1h high, 4h & 1d overbought
            & (aroonu_14_1h_lt_80 | (roc_9_4h_lt_10) | (roc_9_1d_lt_40))
            # 1h high, 4h & 1d downtrend
            & ((aroonu_14_1h_lt_85) | (roc_9_4h_gt_neg_20) | roc_9_1d_gt_neg_50)
            # 1h & 4h high, 1h overbought
            & ((aroonu_14_1h_lt_100) | aroonu_14_4h_lt_100 | (roc_9_1h_lt_10))
            # 4h high, 4h & 1d overbought
            & ((aroonu_14_4h_lt_60) | (roc_9_4h_lt_30) | (roc_9_1d_lt_60))
            # 4h & 1d high, 4h overbought
            & (aroonu_14_4h_lt_80 | aroonu_14_1d_lt_100 | (roc_9_4h_lt_30))
            # 4h high, 4h & 1d overbought
            & (aroonu_14_4h_lt_80 | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 4h high, 15m downtrend, 4h overbought
            & (aroonu_14_4h_lt_100 | (roc_9_15m > -30.0) | (roc_9_4h_lt_30))
            # 4h high, 1h & 4h overbought
            & (aroonu_14_4h_lt_100 | (roc_9_1h_lt_30) | (roc_9_4h_lt_70))
            # 4h & 1d high, 1h overbought
            & (aroonu_14_4h_lt_100 | aroonu_14_1d_lt_100 | (roc_9_1h_lt_50))
            # 1d still high, 4h & 1d downtrend
            & ((aroonu_14_1d_lt_50) | (roc_9_4h_gt_neg_50) | roc_9_1d_gt_neg_50)
            # 1d high, 1h & 4h downtrend
            & ((aroonu_14_1d_lt_85) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_50))
            # 1d high, 4h downtrend, 1d overbought
            & ((aroonu_14_1d_lt_85) | (roc_9_4h_gt_neg_25) | roc_9_1d_lt_50)
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_90) | (roc_9_4h_lt_10) | roc_9_1d_lt_50)
            # 1h high, 1d overbought
            & ((stochrsi_k_1h_lt_70) | (roc_9_1d_lt_40))
            # 1h high, 4h overbought
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_lt_80))
            # 1h high, 1h overbought, 4h downtrend
            & ((stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10) | (roc_9_4h_gt_neg_15))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_1h_lt_20) | (roc_9_4h_lt_50))
            # 1d high, 4h & 1d overbought
            & ((stochrsi_k_1d_lt_90) | (roc_9_4h_lt_100) | (roc_9_1d_lt_100))
            # 1d P&D, 4h overbought
            & ((change_pct_1d_gt_neg_10) | (change_pct_1d_shift_288 < 30.0) | (roc_9_4h_lt_10))
            # big drop in last hough, 4h down move, 1h still not low enough
            & ((close > (close_max_12 * 0.90)) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_30))
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
          )

          # Logic
          long_entry_logic.append(
            (rsi_3_gt_5) & (rsi_14 < 36.0) & (aroonu_14_lt_25) & (aroond_14_gt_75) & (ema_9 < (ema_26 * 0.960))
          )

        # Condition #42 - Quick mode (Long).
        if long_entry_condition_index == 42:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 1h down move, 1d still high
            ((rsi_3_gt_3) | (rsi_3_1h_gt_3) | (stochrsi_k_1d_lt_40))
            # 5m & 1h down move, 1d high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_25) | (stochrsi_k_1d_lt_70))
            # 15m & 1h down move, 4h high
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_3) | (stochrsi_k_4h_lt_70))
            # 15m & 1h down move, 1h downtrend
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_3) | (roc_9_1h_gt_neg_50))
            # 15m & 1h down move, 1d still not low enough
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_5) | (stochrsi_k_1d_lt_30))
            # 15m & 1h down move, 4h still high
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_50))
            # 15m & 1h down move, 1d high
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_60))
            # 15m & 1h down move, 1h high
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_60))
            # 15m & 4h down move, 4h still high
            & (rsi_3_15m_gt_3 | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_40))
            # 15m & 4h down move, 1d still high
            & (rsi_3_15m_gt_3 | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_40))
            # 15m & 1h down move, 1d downtrend
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_15) | (roc_9_1d > -30.0))
            # 15m down move, 4h still high, 1d downtrend
            & (rsi_3_15m_gt_3 | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_40))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | rsi_3_4h_gt_20)
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (aroonu_14_1h_lt_40))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (aroonu_14_1d_lt_70))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_15))
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_70))
            # 15m & 4h down move, 1h downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_20))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1d > -30.0))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_100))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_40))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_1d_lt_90))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_60))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (roc_9_1d_gt_neg_30))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (roc_9_1d_lt_10))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_90))
            # 15m & 1d down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_4h_lt_40))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_40))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_70))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_30))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_80))
            # 15m & 1h & 4h & 1d down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_1h_lt_50))
            # 15m & 1h & 4h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_45) | (aroonu_14_1d_lt_70))
            # 15m & 1h & 4h down move, 1h still high, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_65) | (aroonu_14_1h_lt_50) | (stochrsi_k_4h_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_70))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (stochrsi_k_15m_lt_50))
            # 15m & 1h & 4h down move, 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_50))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_50))
            # 15m & 4h & 1d down move, 15m still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_15m_lt_40))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_60))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_70))
            # 15m down move, 15m high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_70))
            # 15m & 1h & 4h down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_70))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 1h still high, 1d overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_50) | (roc_9_1d_lt_40))
            # 15m down move, 15m still not low enough, 1d downtrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_25) | (roc_9_1d_gt_neg_50))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_80))
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_25) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_40))
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_25) | (stochrsi_k_4h_lt_90) | (roc_9_1d_gt_neg_10))
            # 15m & 4h down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_60) | (roc_9_1d_gt_neg_30))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 1h high, 4h high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (stochrsi_k_4h_lt_80))
            # 1h & 4h down move
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_3))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_50))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_50))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_3) | rsi_3_4h_gt_20 | (aroonu_14_1h_lt_40))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_3) | rsi_3_4h_gt_20 | (stochrsi_k_4h_lt_30))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | aroonu_14_4h_lt_70)
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_70))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_60))
            # 1h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_3) | (aroonu_14_1d_lt_70) | (roc_9_1h_gt_neg_50))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_15m_lt_20))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_40))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_25) | aroonu_14_1h_lt_70)
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_25) | (stochrsi_k_1d_lt_80))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_35) | (roc_9_1d_lt_40))
            # 1h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_1d_gt_5) | (aroonu_14_1h_lt_50))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_5) | (aroonu_14_4h_lt_90))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_75))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_80))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_20))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_1d_lt_10))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_20))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_70))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_90))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (roc_9_1d_lt_40))
            # 1h & 4h & 1d down move, 15m high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_1d_lt_50))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_35) | (aroonu_14_1d_lt_100))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_70))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_1d_lt_50))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_25) | (rsi_14_1d_lt_50))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_70))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_70))
            # 1h down move, 1h downtrend, 1h high
            & ((rsi_3_1h_gt_10) | (cmf_20_1h_gt_neg_0_30) | (aroonu_14_1h_lt_70))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_60) | aroonu_14_4h_lt_70)
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_60) | (roc_9_1d_lt_20))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_40) | (roc_9_1d_gt_neg_40))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_10) | aroonu_14_4h_lt_70 | (roc_9_1d_gt_neg_20))
            # 1h down move, 1d still high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_30))
            # 1h down move, 15m high
            & ((rsi_3_1h_gt_10) | (stochrsi_k_15m_lt_80))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_10) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 1d still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_14_1d_lt_40) | (roc_9_1d_gt_neg_15))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50))
            # 1h & 4h down move, 15m still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_40))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_20))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_70))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_80))
            # 1h & 4h down move, 4h overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_35) | (roc_9_4h_lt_10))
            # 1h & 4h down move, 1h & 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_80))
            # 1h & 1d down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_60))
            # 1h & 1d down move, 1d overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_35) | (roc_9_1d_lt_10))
            # 1h & 1d down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_10))
            # 1h down move, 1h downtrend, 1h high
            & ((rsi_3_1h_gt_15) | (cmf_20_1h_gt_neg_0_30) | (aroonu_14_1h_lt_70))
            # 1h down move, 1h still high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_40) | (roc_9_4h_gt_neg_30))
            # 1h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50) | (roc_9_1d_gt_neg_40))
            # 1h down move, 1d still high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_50) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_30))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_15) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_70))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_100))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_60))
            # 1h & 4h down move, 15m still not low enough, 1d still not low enough
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1d_lt_30))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_30))
            # 1h & 4h & 1d down move, 15m still high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_15m_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h & 4h & 1d down move, 1h still high, 15m still high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_1h_lt_50) | (stochrsi_k_15m_lt_50))
            # 1h & 4h & 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_85) | (roc_2_1d > -30.0))
            # 1h & 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_45) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_80))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_lt_60))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_100))
            # 1h & 1d down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_45) | (roc_9_1d_lt_20))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_60) | (roc_9_1d_lt_30))
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1d_lt_80) | (roc_9_4h_gt_neg_20))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_70))
            # 1h & 4h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_40) | (aroonu_14_1h_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_70))
            # 1h & 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_50))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_80))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_45) | (stochrsi_k_1d_lt_80))
            # 1h down move, 4h downtrend, 4h high
            & ((rsi_3_1h_gt_25) | (cmf_20_4h_gt_neg_0_50) | (aroonu_14_4h_lt_70))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_60) | (roc_9_1d_lt_50))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_60) | (roc_9_1d_gt_neg_40))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_200))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_20))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (roc_9_1d_gt_neg_50))
            # 1h & 4h & 1d down move, 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_50) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (aroonu_14_15m_lt_80))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_75))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (stochrsi_k_15m_lt_80))
            # 1h & 4h & 1d down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_80))
            # 1h & 4h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_30))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_80))
            # 1h & 1d down move, 1d overbought
            & ((rsi_3_1h_gt_30) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_50))
            # 1h down move, 1h still high, 1 & 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_40) | (roc_9_1h_gt_neg_20) | (roc_9_1d_gt_neg_50))
            # 1h down move, 1h still high, 4h overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_40) | (roc_9_4h_lt_20))
            # 1h down move, 4h high, 4h downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70) | (cmf_20_4h_gt_neg_0_40))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_30))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_80))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (roc_9_4h_lt_10) | (roc_9_1d_lt_30))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_45) | (aroonu_14_15m_lt_90))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_90))
            # 1h down move, 15m high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_15m_lt_60) | (roc_9_1d_gt_neg_40))
            # 1h down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | aroonu_14_4h_lt_100)
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | aroonu_14_1d_lt_100)
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_90) | (roc_9_1d_gt_neg_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_10))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_35) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_60))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_20))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_60) | roc_9_1d_gt_neg_50)
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_40))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_45) | aroonu_14_4h_lt_80 | (roc_9_4h_lt_100))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_50) | aroonu_14_4h_lt_100 | (roc_9_4h_lt_40))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_60) | (roc_9_4h_lt_30) | (roc_9_1d_lt_100))
            # 4h & 1d down move
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_15))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_60))
            # 4h down move, 1h downtrend, 4h still high
            & ((rsi_3_4h_gt_3) | (cmf_20_1h_gt_neg_0_30) | (aroonu_14_4h_lt_40))
            # 4h & 1d down move, 4h downtrend
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_15) | (roc_9_4h_gt_neg_10))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_15) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_40))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_lt_50))
            # 4h & 1d down move, 4h still not low enough
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_30) | (aroonu_14_4h_lt_20))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_70))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_1h_gt_neg_15) | (roc_9_4h_gt_neg_20))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 15m still not low enough
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (aroonu_14_15m_lt_30))
            # 4h & 1d down move, 15m still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_15m_lt_40))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 1d down move, 15m still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_15m_lt_50))
            # 4h & 1d down move, 4d & 1d downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_30) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 4h downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_30) | (roc_9_4h_gt_neg_20))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_45) | (roc_9_1d_lt_10))
            # 4h & 1d down move, 4h still not low enough
            & ((rsi_3_4h_gt_10) | (rsi_3_1d > 50.0) | (stochrsi_k_4h_lt_20))
            # 4h down move, 15m high, 1h downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_60) | (roc_9_1h_gt_neg_10))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_80))
            # 4h down move, 4h still not low e nough, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_30) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_40) | (aroonu_14_1d_lt_80))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_40))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_15) | (roc_9_1d > -30.0))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_40))
            # 15m & 1d down move, 15m high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (stochrsi_k_15m_lt_70))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_50))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_35) | (rsi_14_1d_lt_50))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_45) | (roc_9_1d_lt_30))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_50))
            # 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_1h_lt_40) | roc_9_1d_gt_neg_50)
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_1h_lt_90) | (roc_9_1d > -30.0))
            # 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 4h down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_70))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_15) | (roc_9_1h_gt_neg_40) | (roc_9_4h_gt_neg_40))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_lt_80))
            # 4h & 1d down move, 15m high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_30) | (stochrsi_k_15m_lt_80))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d > 50.0) | (stochrsi_k_1d_lt_90))
            # 4h down move, 15m high, 4h downtrend
            & ((rsi_3_4h_gt_20) | (aroonu_14_15m_lt_70) | (roc_9_4h_gt_neg_30))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_100))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_70))
            # 4h down move, 1d high, 4h downtrend
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_50))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_40))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_70))
            # 4h down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_30) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_20) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1d high, 4h downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_80) | (roc_9_4h_gt_neg_20))
            # 4h & 1d down move, 1h high
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_90))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_90))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h high, 1h downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_60) | (roc_9_1h_gt_neg_10))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_25) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_30))
            # 4h down move, 1d high, 4h downtrend
            & ((rsi_3_4h_gt_25) | aroonu_14_1d_lt_100 | (roc_9_4h_gt_neg_20))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1d overbought
            & ((rsi_3_4h_gt_25) | (roc_9_1d_lt_100))
            # 4h down move, 1h high, 4h downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_1h_lt_60) | (roc_9_4h_gt_neg_10))
            # 4h down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_100))
            # 4h down move, 4h high, 1h downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_80) | (roc_9_1h_gt_neg_40))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_100))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_30) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_60))
            # 4h down move, 15m still high, 4h high
            & ((rsi_3_4h_gt_35) | (aroonu_14_15m_lt_50) | aroonu_14_4h_lt_80)
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_35) | (aroonu_14_1h_lt_70))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_35) | (aroonu_14_4h_lt_80) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_35) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_30))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_35) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 4h down move, 4h still high, 1d overbought
            & ((rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_50) | (roc_9_1d_lt_200))
            # 4h down move, 4h still high, 1d high & overbought
            & ((rsi_3_4h_gt_40) | (rsi_14_4h_lt_50) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_150))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_40) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_20))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h overbought, 1d downtrend
            & ((rsi_3_4h_gt_40) | (roc_9_4h_lt_10) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_40) | (roc_9_4h_lt_60) | (roc_9_1d_lt_80))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_45) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 4h & 1d down move, 15m high, 1d high
            & ((rsi_3_4h_gt_50) | (rsi_3_1d_gt_55) | (aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_80))
            # 4h down move, 4h overbought
            & ((rsi_3_4h_gt_55) | (roc_9_4h_lt_30))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1d_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_20))
            # 1d down move, 1d still high
            & ((rsi_3_1d_gt_15) | (stochrsi_k_1d_lt_40))
            # 1d down move, 4h & 1d downtrend
            & ((rsi_3_1d_gt_15) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_40))
            # 1d down move, 15m high
            & ((rsi_3_1d_gt_20) | (aroonu_14_15m_lt_80))
            # 1d down move, 4h high, 4h downtrend
            & ((rsi_3_1d_gt_20) | (aroonu_14_4h_lt_50) | (roc_9_4h_gt_neg_40))
            # 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1d_gt_25) | (aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_30))
            # 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_50) | (roc_9_1d_gt_neg_20))
            # 1d down move, 4h & 1d high
            & ((rsi_3_1d_gt_30) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_90))
            # 1d down move, 15m still high, 1h high
            & ((rsi_3_1d_gt_40) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_90))
            # 1h & 4h downtrend, 4h high
            & ((cmf_20_1h_gt_neg_0_40) | (cmf_20_4h_gt_neg_0_40) | aroonu_14_4h_lt_80)
            # 4h & 1d downtrend, 1d high
            & ((cmf_20_4h_gt_neg_0_50) | (cmf_20_1d_gt_neg_0_50) | (aroonu_14_1d_lt_85))
            # 15m & 1d high, 4h overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20))
            # 15m & 4h & 1d high
            & ((aroonu_14_15m_lt_80) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 15m & 4h high, 1d downtrend
            & ((aroonu_14_15m_lt_85) | (aroonu_14_4h_lt_85) | (roc_9_1d_gt_neg_20))
            # 1h still high, 1h & 4h downtrend
            & ((aroonu_14_1h_lt_50) | (roc_9_1h_gt_neg_20) | (roc_9_4h_gt_neg_30))
            # 1h & 4h high, 4h overbought
            & ((aroonu_14_1h_lt_80) | aroonu_14_4h_lt_100 | (roc_9_4h_lt_10))
            # 4h high, 4h & 1d downtrend
            & ((aroonu_14_4h_lt_60) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_30))
            # 4h & 1d high, 4h overbought
            & ((aroonu_14_4h_lt_70) | aroonu_14_1d_lt_100 | (roc_9_4h_lt_30))
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_70) | aroonu_14_1d_lt_100 | (roc_9_1d_lt_80))
            # 4h high, 4h & 1d overbought
            & ((aroonu_14_4h_lt_90) | (roc_9_4h_lt_10) | (roc_9_1d_lt_10))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_70) | (roc_9_4h_lt_30) | (roc_9_1d_lt_200))
            # 1d high, 4h downtrend, 1d overbought
            & ((aroonu_14_1d_lt_85) | (roc_9_4h_gt_neg_20) | (roc_9_1d_lt_200))
            # 1d high, 1h & 4h downtrend
            & ((aroonu_14_1d_lt_100) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 1d high, 1h & 1d overbought
            & ((aroonu_14_1d_lt_100) | (roc_9_1h_lt_10) | (roc_9_1d_lt_30))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_100) | (roc_9_4h_lt_30) | (roc_9_1d_lt_60))
            # 15m still high, 1h & 4h downtrend
            & ((stochrsi_k_15m_lt_50) | (roc_9_1h_gt_neg_20) | (roc_9_4h_gt_neg_20))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_1h_lt_20) | (roc_9_4h_lt_30))
            # 4h high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_lt_80))
            # 1d still high, 4h & 1d downtrend
            & ((stochrsi_k_1d_lt_50) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_30))
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
          )

          # Logic
          long_entry_logic.append(
            (willr_14 < -50.0)
            & (stochrsi_k_lt_20)
            & (willr_84_1h < -70.0)
            & (stochrsi_k_1h_lt_20)
            & (bbb_20_2_0_1h > 16.0)
            & (close_max_48 >= (close * 1.10))
          )

        # Condition #43 - Quick mode (Long).
        if long_entry_condition_index == 43:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 15m down move, 15m still high
            ((rsi_3_gt_3) | (rsi_3_15m_gt_5) | (aroonu_14_15m_lt_40))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_55) | (stochrsi_k_4h_lt_60))
            # 5m & 1h down move, 1h still not low enough
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_30))
            # 5m & 1h down move, 1h still not low enough
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_30))
            # 5m & 1h down move, 4h high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_60))
            # 5m & 1d down move, 1d still not low enough
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_30))
            # 5m down move, 1h & 4h high
            & ((rsi_3_gt_3) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 5m down move, 4h high & overbought
            & ((rsi_3_gt_3) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_20))
            # 5m down move, 1d high & overbought
            & ((rsi_3_gt_3) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_100))
            # 5m down move, 1h high, 4h overbought
            & ((rsi_3_gt_3) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_20))
            # 5m down move, 1d high & overbought
            & ((rsi_3_gt_3) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 5m & 1h down move, 1d overbought
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_25) | (roc_9_1d_lt_100))
            # 5m & 1d down move, 1h high
            & ((rsi_3_gt_5) | (rsi_3_1d_gt_20) | (aroonu_14_1h_lt_90))
            # 5m & 1h down move, 1h high
            & ((rsi_3_gt_10) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_85))
            # 15m & 1h down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_10))
            # 15m & 1h & 1d down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_1d_gt_25))
            # 15m & 1h down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_14_1d_lt_50))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_15m_lt_50))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_70))
            # 15m & 1d down move, 1d overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_40))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (aroonu_14_1d_lt_90))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (roc_9_1d > -30.0))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_70))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (aroonu_14_15m_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_100))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (stochrsi_k_1d_lt_90))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (roc_9_1d_lt_200))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_45) | (aroonu_14_4h_lt_90))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_50))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_20) | (aroonu_14_15m_lt_70))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_35) | (roc_9_1d_lt_60))
            # 15m & 1d down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1d_gt_10) | (aroonu_14_1d_lt_40))
            # 15m & 1d down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_50))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_70))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_3) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_100))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_3) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_40))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_3) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_20))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_3) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_40))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_3) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_10))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_3) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_10))
            # 15m down move, 1h downtrend, 4h overbought
            & ((rsi_3_15m_gt_3) | (roc_9_1h_gt_neg_30) | (roc_9_4h_lt_100))
            # 15m down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_3) | (roc_9_4h_gt_neg_70) | (roc_9_1d_gt_neg_70))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (rsi_14_4h_lt_40))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_20))
            # 15m & 1h down move, 1d still high
            & ((rsi_3_15m_gt_5) | rsi_3_1h_gt_20 | (stochrsi_k_1d_lt_50))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_25) | (roc_9_1d_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_80))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_50))
            # 15m & 4h down move, 1h downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_20))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_50))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_70))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_50))
            # 15m down move, 15m & 1h still high
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_50))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_70) | (roc_9_1h_lt_10))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_10))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_50))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_100))
            # 15m down move, 1d still high, 1d downtrend
            & ((rsi_3_15m_gt_5) | (stochrsi_k_1d_lt_50) | (roc_9_1d_gt_neg_20))
            # 15m down move, 1d downtrend
            & ((rsi_3_15m_gt_5) | (roc_9_1d_gt_neg_60))
            # 15m down move, 1h & 1d high
            & ((rsi_3_15m_gt_5) | (roc_9_1h_lt_10) | (roc_9_1d_lt_40))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_15m_lt_70))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (stochrsi_k_1d_lt_90))
            # 15m & 1h down move, 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (roc_9_4h_gt_neg_20))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (roc_9_1d_gt_neg_40))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_70))
            # 15m & 1h & 4h & 1d down move, 1d still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_60) | (stochrsi_k_1h_lt_30))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_15m_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_1d_lt_80))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (roc_9_1d_lt_80))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (aroonu_14_4h_lt_90))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (roc_9_4h_lt_20))
            # 15m & 1h & 4h down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_70))
            # 15m & 1h & 1d down move, 1d still high, 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_50) | (roc_9_4h_gt_neg_20))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_60))
            # 15m & 1h & 4h & 1d down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_40) | (aroonu_14_1d_lt_90))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_90))
            # 15m & 1h & 4h down move, 4h high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_90))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_40))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_40))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_90))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_50))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_50) | aroonu_14_4h_lt_70)
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_70))
            # 15m down move, 15m still high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_40) | (roc_9_1d_gt_neg_30))
            # 15m down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_30))
            # 15m down move, 15m high, 1h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_80))
            # 15m down move, 15m high, 4h downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_60) | (roc_9_4h_gt_neg_10))
            # 15m down move, 15m high, 4h high & overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_100))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_90) | (roc_9_1d_gt_neg_40))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_100))
            # 15m down move, 4h still high, 1d overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_4h_lt_50) | (roc_9_1d_lt_30))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_10) | (roc_9_4h_lt_10) | (roc_9_1d_lt_200))
            # 15m & 1h & 4h down move, 15m still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_15m_lt_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_90))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (stochrsi_k_1d_lt_90))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_100))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_100))
            # 15m & 4h down move, 4h still not low enough, 4h downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_30) | (roc_9_4h_gt_neg_20))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_70))
            # 15m down move. 15m still high, 1h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_lt_80))
            # 15m down move, 15m & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_100))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_40))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_60) | (roc_9_4h_lt_30))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_200))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_100))
            # 15m down move, 1h high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_30))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_25))
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_90) | (roc_9_1d_gt_neg_40))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_30))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_100))
            # 15m down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_15) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_40))
            # 15m & 1h & 4h & 1d down move, 15m downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (cmf_20_15m_gt_neg_0_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (roc_9_1d_lt_100))
            # 15m & 1h down move, 1h still high, 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_100))
            # 15m & 1h down move, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_35) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_100))
            # 15m & 1h & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_4h_lt_90))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_10))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_10))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_10))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (stochrsi_k_15m_lt_70))
            # 15m & 1h down move, 1h downtrend
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (roc_9_1h_gt_neg_30))
            # 15m & 4h down move, 15m & 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_70))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_50))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_40))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_40))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_60))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_70))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (roc_9_1d_lt_20))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_3) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (aroonu_14_1h_lt_50))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_90))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_100))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_35) | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_60) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_4h_lt_70) | (roc_9_1d_gt_neg_30))
            # 1h down move, 1d high, 1h downtrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_1d_lt_90) | (roc_9_1h_gt_neg_40))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_5) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_15))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_60))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_90))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (roc_9_1d > -30.0))
            # 1h & 1d down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_4h_lt_70))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_50))
            # 1h down move, 15m downtrend, 1d high
            & ((rsi_3_1h_gt_10) | (cmf_20_15m_gt_neg_0_40) | (aroonu_14_1d_lt_70))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_10))
            # 1h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_20))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_60) | (roc_9_1d > -30.0))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_20))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 1h downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (roc_9_1h_gt_neg_15))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (roc_9_1d_lt_10))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | rsi_3_4h_gt_20 | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (aroonu_14_1h_lt_70))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_70))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_50))
            # 1h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_30) | (roc_9_1d > -30.0))
            # 1h down move, 1h still high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_40) | (roc_9_4h_gt_neg_30))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_10))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_50))
            # 1h & 4h & 1d  down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_50) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_75))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_100))
            # 1h down move, 4h downtrend, 1d overbought
            & ((rsi_3_1h_gt_20) | (roc_9_4h_gt_neg_40) | (roc_9_1d_lt_50))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_20))
            # 1h & 4h & 1d down move, 1d downtrend, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_45) | (cmf_20_1d_gt_neg_0_30) | (aroonu_14_1d_lt_70))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_80))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_60) | (roc_9_1d_gt_neg_40))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_80) | (roc_9_1h_lt_10))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_50))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_1d_lt_80) | (roc_9_4h_gt_neg_70))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_25) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_60))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_1h_lt_70))
            # 1h & 4h down move, 15m & 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_70))
            # 1h down move, 1h still high, 1h & 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_40) | (roc_9_1h_gt_neg_10) | (roc_9_1d_gt_neg_50))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_10))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_40))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_30))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_40))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_30))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (roc_9_4h_lt_30) | (roc_9_1d_lt_200))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_90) | (roc_9_1d_lt_80))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_200))
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1h_lt_90))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_70) | (roc_9_1d_gt_neg_50))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_40))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_20))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_20))
            # 1h & 4h down move, 4h high & overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_10))
            # 1h down move, 1h & 4h high, 1h overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_20))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_40))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_60) | (roc_9_1d_gt_neg_70))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_100))
            # 4h & 1d down move, 15m still high
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_15) | (stochrsi_k_15m_lt_40))
            # 4h & 1d down move, 1h still not low enough
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_15) | (stochrsi_k_1h_lt_30))
            # 4h down move, 4h still high
            & ((rsi_3_4h_gt_3) | (aroonu_14_4h_lt_50))
            # 4h down move, 1h still high, 4h downtrend
            & ((rsi_3_4h_gt_3) | (stochrsi_k_1h_lt_50) | (roc_9_4h_gt_neg_30))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_40))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_1h_gt_neg_10) | (roc_9_4h_gt_neg_10))
            # 4h & 1d down move, 4h downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (roc_9_4h_gt_neg_20))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h still high
            & ((rsi_3_4h_gt_10) | (aroonu_14_4h_lt_50))
            # 4h down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_30) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h & 1d  downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_30))
            # 4h & 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_10))
            # 4h down move, 1h still high
            & ((rsi_3_4h_gt_15) | (aroonu_14_1h_lt_50))
            # 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1h & 4h downtrend, 1d overbought
            & ((rsi_3_4h_gt_15) | (roc_9_1h_gt_neg_20) | (roc_9_4h_gt_neg_30) | (roc_9_1d_lt_20))
            # 4h & 1d down move, 1d high, 4h downtrend
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_80) | (roc_9_4h_gt_neg_30))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_50))
            # 4h & 1d down move, 1h high
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_90))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 1d high, 1d downtrend
            & ((rsi_3_4h_gt_35) | (stochrsi_k_1d_lt_60) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1d high, 1d downtrend
            & ((rsi_3_4h_gt_45) | (aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_15))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (rsi_14_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 1d down move, 1h & 1d downtrend
            & ((rsi_3_1d_gt_5) | (roc_9_1h_gt_neg_10) | (roc_9_1d_gt_neg_30))
            # 1d down move, 4h high, 1d downtrend
            & ((rsi_3_1d_gt_15) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_70))
            # 1d down move, 1h high & overbought
            & ((rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10))
            # 1d down move, 1h high & overbought
            & ((rsi_3_1d_gt_40) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_80))
            # 4h downtrend, 1h & 4h high
            & ((cmf_20_4h_gt_neg_0_30) | aroonu_14_1h_lt_70 | aroonu_14_4h_lt_100)
            # 15m still high, 1h & 4h overbought
            & ((aroonu_14_15m_lt_50) | (roc_9_1h_lt_100) | (roc_9_4h_lt_100))
            # 15m & 1d high, 1d overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_30))
            # 1h still high, 4h & 1d downtrend
            & ((aroonu_14_1h_lt_40) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_40))
            # 1h & 4h high, 1d downtrend
            & (aroonu_14_1h_lt_70 | aroonu_14_4h_lt_100 | (roc_9_1d_gt_neg_20))
            # 1h & 4h high, 1d overbought
            & (aroonu_14_1h_lt_70 | aroonu_14_4h_lt_100 | (roc_9_1d_lt_20))
            # 1h & 1d high, 1d overbought
            & (aroonu_14_1h_lt_70 | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_200))
            # 1h high, 4h downtrend, 1d overbought
            & (aroonu_14_1h_lt_70 | (roc_9_4h_gt_neg_40) | (roc_9_1d_lt_100))
            # 1h & 4h high, 4h overbought
            & (aroonu_14_1h_lt_80 | aroonu_14_4h_lt_100 | (roc_9_4h_lt_30))
            # 1h high, 1d downtrend
            & (aroonu_14_1h_lt_80 | (roc_9_1d_gt_neg_60))
            # 1h high, 1h & 4h overbought
            & ((aroonu_14_1h_lt_100) | (roc_9_1h_lt_100) | (roc_9_4h_lt_100))
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_60) | aroonu_14_1d_lt_100 | (roc_9_1d_lt_70))
            # 4h high, 1h & 4h overbought
            & ((aroonu_14_4h_lt_85) | (roc_9_1h_lt_80) | (roc_9_4h_lt_80))
            # 4h high, 1h downtrend, 4h overbought
            & ((aroonu_14_4h_lt_90) | (roc_9_1h_gt_neg_40) | (roc_9_4h_lt_100))
            # 4h & 1d high, 4h overbought
            & ((aroonu_14_4h_lt_90) | aroonu_14_1d_lt_100 | (roc_9_4h_lt_100))
            # 4h high, 1h & 4h overbought
            & ((aroonu_14_4h_lt_90) | (roc_9_1h_lt_10) | (roc_9_4h_lt_20))
            # 4h & 1d high, 4h overbought
            & (aroonu_14_4h_lt_100 | aroonu_14_1d_lt_100 | (roc_9_4h_lt_30))
            # 4h & 1d high, 1d overbought
            & (aroonu_14_4h_lt_100 | aroonu_14_1d_lt_100 | (roc_9_1d_lt_40))
            # 1d high, 1h & 4h downtrend
            & (aroonu_14_1d_lt_100 | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 1d high, 4h & 1d overbought
            & (aroonu_14_1d_lt_100 | (roc_9_4h_lt_20) | (roc_9_1d_lt_100))
            # 1h high, 1d overbought
            & ((stochrsi_k_1h_lt_70) | (roc_9_1d_lt_40))
            # 1h high, 4h overbought
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_lt_80))
            # 1h high, 4h & 1d downtrend
            & ((stochrsi_k_1h < 85.0) | (roc_9_4h_gt_neg_70) | (roc_9_1d_gt_neg_70))
            # 4h high, 4h overbought, 1d downtrend
            & ((stochrsi_k_4h_lt_70) | (roc_9_4h_lt_40) | (roc_9_1d_gt_neg_40))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_80) | (roc_9_1h_lt_40) | (roc_9_4h_lt_100))
            # 1d high, 4h & 1d overbought
            & ((stochrsi_k_1d_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_lt_100))
            # 1h & 4h overbought, 1d downtrend
            & ((roc_9_1h_lt_40) | (roc_9_4h_lt_50) | (roc_9_1d_gt_neg_30))
            # big drop in last hough, 4h down move, 1h still not low enough
            & ((close > (close_max_12 * 0.90)) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_30))
            # big drop in last hour, 15m high
            & ((close > (close_max_12 * 0.60)) | (aroonu_14_15m_lt_70))
            # big drop in last hour, 4h high
            & ((close > (close_max_12 * 0.60)) | (aroonu_14_4h_lt_70))
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
          )

          # Logic
          long_entry_logic.append(
            (rsi_14 < 40.0)
            & (mfi_14 < 40.0)
            & (aroonu_14_lt_25)
            & (ema_26 > ema_12)
            & ((ema_26 - ema_12) > (open_rate * 0.024))
            & ((ema_26_shift_1 - ema_12_shift_1) > (open_rate / 100.0))
            & (close < (ema_20 * 0.960))
            & (close < (bbl_20_2_0 * 0.999))
          )

        # Condition #44 - Quick mode (Long).
        if long_entry_condition_index == 44:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 1h & 4h down move
            ((rsi_3_gt_3) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (rsi_3_4h_gt_10))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (aroonu_14_1h_lt_60))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_10))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (roc_9_1d_gt_neg_30))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_55) | (stochrsi_k_4h_lt_60))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_100))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_80))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_40))
            # 15m & 4h down move, 15m downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_10) | (roc_9_15m > -30.0))
            # 15m & 4h down move, 1h downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_20))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_50))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_40) | (stochrsi_k_1h_lt_40))
            # 15m down move, 1h still high, 1d overbought
            & ((rsi_3_15m_gt_3) | (aroonu_14_1h_lt_40) | (roc_9_1d_lt_70))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_3) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_100))
            # 15m down move, 1h high
            & ((rsi_3_15m_gt_3) | (stochrsi_k_1h_lt_70))
            # 15m down move, 4h high, 15m downtrend
            & ((rsi_3_15m_gt_3) | (stochrsi_k_4h_lt_70) | (roc_9_15m > -30.0))
            # 15m & 1h & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_30))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 1h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (roc_9_1h_gt_neg_20))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 14m & 1h & 4h down move, 4h & 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 15m & 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_50))
            # 15m & 4h down move, 1h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_30))
            # 15m down move, 4h overbought
            & ((rsi_3_15m_gt_10) | (roc_9_4h_lt_30))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_40))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_80))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_70))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_75))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_90))
            # 15m down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_15) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_40))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_100))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_10))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_3) | (aroonu_14_1h_lt_20))
            # 1h & 4h down move
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_5))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_10))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_30))
            # 1h & 4h down move, 1h downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (cmf_20_1h_gt_neg_0_40))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_50))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_60))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_60))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_60))
            # 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (rsi_14_1d_lt_40))
            # 1h & 4h down move, 1h & 4h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_40))
            # 1h & 1d down move, 15m & 1h downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_1d_gt_20) | (cmf_20_15m_gt_neg_0_35) | (cmf_20_1h_gt_neg_0_40))
            # 1h down move, 1h & 4h still high
            & ((rsi_3_1h_gt_3) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_50))
            # 1h down move, 1h still high, 1h downtrend
            & ((rsi_3_1h_gt_3) | (aroonu_14_1h_lt_50) | (roc_9_1h_gt_neg_20))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_3) | (stochrsi_k_4h_lt_50) | (roc_9_1h_gt_neg_15))
            # 1h downtrend, 4h high
            & ((rsi_3_1h_gt_3) | (stochrsi_k_4h_lt_70))
            # 1h down move, 1h & 4h downtrend
            & ((rsi_3_1h_gt_3) | (roc_9_1h_gt_neg_20) | (roc_9_4h_gt_neg_20))
            # 1h & 4h & 1d down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_40) | (aroonu_14_4h_lt_20))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_50))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_90))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_30) | (rsi_14_4h_lt_40))
            # 1h & 1d down move, 1d downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_1d_gt_5) | (roc_9_1d_gt_neg_20))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_5) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_70))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_5) | (aroonu_14_1h_lt_60))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_5) | (aroonu_14_4h_lt_70))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_5) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_30))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_5) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_25))
            # 1h down move, 1d overbought
            & ((rsi_3_1h_gt_5) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_50))
            # 1h & 4h & 1d down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 1h downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (roc_9_1h_gt_neg_25))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_70))
            # 1h & 4h & 1d down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_4h_lt_20) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_50))
            # 1h & 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_70))
            # 1h & 1d down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_10) | (aroonu_14_4h_lt_40))
            # 1h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_15) | (aroonu_14_1h_lt_50))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_40) | (aroonu_14_1h_lt_70))
            # 1h down move, 1h still high, 4h downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_40) | (roc_9_4h_gt_neg_30))
            # 1h down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h high, 1h downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_60) | (roc_9_1h_gt_neg_10))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_70) | (roc_9_1d_gt_neg_30))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_80))
            # 1h down move, 4h still high, 15m downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_50) | (cmf_20_15m_gt_neg_0_40))
            # 1h down move, 4h still high, 4h downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_50) | (roc_9_4h_gt_neg_30))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_lt_100))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_100))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_100))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_60))
            # 1h down move, 4h overbought
            & ((rsi_3_1h_gt_10) | (roc_9_4h_lt_10))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_10) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_50))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_80))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50) | (roc_9_1d_gt_neg_40))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_lt_85))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_60) | (roc_9_1d > -30.0))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_60) | roc_9_1d_lt_50)
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_70) | (roc_9_4h_gt_neg_10))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_100))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_100))
            # 1h down move, 1h & 4h downtrend
            & ((rsi_3_1h_gt_15) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 1h down move, 1h & 4h overbought
            & ((rsi_3_1h_gt_15) | (roc_9_4h_lt_10) | (roc_9_1d_lt_50))
            # 1h down move, 1h & 4h overbought
            & ((rsi_3_1h_gt_15) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 1h & 1d down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_50) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_20))
            # 1h & 4h down move, 1h high, 1h downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_70) | (roc_9_1h_gt_neg_20))
            # 1h & 4h down move, 4h still high, 1h downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50) | (roc_9_1h_gt_neg_25))
            # 1h & 4h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_60) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_80))
            # 1h & 4h & 1d down move, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_50) | (stochrsi_k_1d_lt_70) | (roc_9_1d_lt_30))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_90))
            # 1h down move, 1h still high, 4h downtrend
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_40) | (roc_9_4h_gt_neg_30))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_40))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_20) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_40))
            # 1h & 4h & 1d down move, 5h still high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_35) | (stochrsi_k_4h_lt_50))
            # 1h & 4h & 1d down move, 1d downtrend, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_45) | (cmf_20_1d_gt_neg_0_30) | (aroonu_14_1d_lt_70))
            # 1h & 4h down ove, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_90))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_80))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_80) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_100))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_40))
            # 1h down move, 1h downtrend, 4h overbought
            & ((rsi_3_1h_gt_25) | (roc_9_1h_gt_neg_20) | (roc_9_4h_lt_20))
            # 1h down move, 1d overbought
            & ((rsi_3_1h_gt_25) | (roc_9_1d_lt_200))
            # 1h & 4h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_60) | (roc_9_1d_lt_50))
            # 1h down move, 1h still high, 1h & 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_40) | (roc_9_1h_gt_neg_10) | (roc_9_1d_gt_neg_50))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_100))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 4h down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_3) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_100))
            # 4h down move, 1d still high, 4h downtrend
            & ((rsi_3_4h_gt_3) | (stochrsi_k_1d_lt_50) | (roc_9_4h_gt_neg_30))
            # 4h down move, 1d overbought
            & ((rsi_3_4h_gt_3) | (roc_9_1d_lt_200))
            # 4h & 1d down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_35) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h still not low enough, 1h & 4h downtrend
            & ((rsi_3_4h_gt_5) | (aroonu_14_4h_lt_30) | (roc_9_1h_gt_neg_15) | (roc_9_4h_gt_neg_15))
            # 4h down move, 1h still high
            & ((rsi_3_4h_gt_5) | (stochrsi_k_1h_lt_40))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_1h_gt_neg_15) | (roc_9_4h_gt_neg_20))
            # 4h down move, 4h downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_4h_gt_neg_40))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_50))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_1h_lt_50))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_80))
            # 4h & 1d down move, 1h & 4h still not low enough
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_30) | (stochrsi_k_4h_lt_30))
            # 4h & 1d down move, 1h high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_50) | (stochrsi_k_1h_lt_90))
            # 4h down move, 1d high, 4h downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_20))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_25) | (roc_9_4h_gt_neg_50))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h down move, 4h still not low enough, 1d overbought
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_30) | (roc_9_1d_lt_50))
            # 4h down move, 4h still high, 1h downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_1h_gt_neg_25))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_60))
            # 4h down move, 4h still high, 1d overbought
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40) | (roc_9_1d_lt_40))
            # 15m down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_15) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_80))
            # 4h & 1d down move, 4h high, 1h downtrend
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_60) | (roc_9_1h_gt_neg_20))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_30) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 4h down move, 1h high & overbought
            & ((rsi_3_4h_gt_35) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_100))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (rsi_14_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_40))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_70))
            # 4h down move, 4h overbought
            & ((rsi_3_4h_gt_50) | (roc_9_4h_lt_60))
            # 1d down move, 1h & 1d downtrend
            & ((rsi_3_1d_gt_5) | (roc_9_1h_gt_neg_10) | (roc_9_1d_gt_neg_30))
            # 4h downtrend, 4h high
            & ((cmf_20_4h_gt_neg_0_50) | aroonu_14_4h_lt_70)
            # 1h & 1d high, 4h downtrend
            & ((aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h still high, 1h & 4h downtrend
            & ((aroonu_14_1h_lt_40) | (roc_9_1h_gt_neg_20) | (roc_9_4h_gt_neg_30))
            # 1h & 4h high, 1d overbought
            & (aroonu_14_1h_lt_70 | aroonu_14_4h_lt_100 | (roc_9_1d_lt_20))
            # 1h high, 4h & 1d downtrend
            & (aroonu_14_1h_lt_70 | (roc_9_4h_gt_neg_20) | roc_9_1d_gt_neg_50)
            # 1h high, 4h downtrend
            & (aroonu_14_1h_lt_70 | (roc_9_4h_gt_neg_40))
            # 1h & 1d high, 1d overbought
            & (aroonu_14_1h_lt_80 | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_80))
            # 1h & 1d high, 1h downtrend
            & (aroonu_14_1h_lt_80 | aroonu_14_1d_lt_100 | (roc_9_1h_gt_neg_20))
            # 4h & 1d high, 1h downtrend
            & (aroonu_14_4h_lt_80 | aroonu_14_1d_lt_100 | (roc_9_1h_gt_neg_30))
            # 4h & 1d high, 4h overbought
            & (aroonu_14_4h_lt_80 | aroonu_14_1d_lt_100 | (roc_9_4h_lt_40))
            # 4h high, 1h downtrend
            & (aroonu_14_4h_lt_80 | (roc_9_1h_gt_neg_40))
            # 4h high & overbought
            & (aroonu_14_4h_lt_80 | (roc_9_4h_lt_100))
            # 4h high, 1d downtrend
            & (aroonu_14_4h_lt_80 | (roc_9_1d > -30.0))
            # 1d still high, 1d downtrend
            & ((aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_30))
            # 1d high, 15m downtrend
            & ((aroonu_14_1d_lt_70) | (roc_9_15m > -50.0))
            # 1d high, 1h downtrend
            & ((aroonu_14_1d_lt_70) | (roc_9_1h > -70.0))
            # 1d high, 4h downtrend
            & ((aroonu_14_1d_lt_80) | (roc_9_4h_gt_neg_70))
            # 1d high, 4h downtrend
            & ((aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_40))
            # 1d high & overbought
            & ((aroonu_14_1d_lt_90) | (roc_9_1d_lt_200))
            # 1d high, 4h & 1d overbought
            & (aroonu_14_1d_lt_100 | (roc_9_4h_lt_20) | (roc_9_1d_lt_80))
            # 1h still high, 4h & 1d downtrend
            & ((stochrsi_k_1h_lt_50) | (roc_9_4h_gt_neg_20) | roc_9_1d_gt_neg_50)
            # 1h high, 15m downtrend
            & ((stochrsi_k_1h_lt_70) | (roc_9_15m > -30.0))
            # 4h high, 1d downtrend
            & ((stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_70))
            # 1d high, 1h downtrend
            & ((stochrsi_k_1d_lt_90) | (roc_9_1h_gt_neg_20))
            # 1d high, 1d downtrend
            & ((stochrsi_k_1d_lt_60) | (roc_9_1d_gt_neg_30))
            # 15m downtrend, 1d overbought
            & ((roc_9_15m > -60.0) | (roc_9_1d_lt_200))
            # 1h downtrend, 1d overbought
            & ((roc_9_1h > -60.0) | (roc_9_1d_lt_200))
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
          )

          # Logic
          long_entry_logic.append(
            (rsi_3_lt_40)
            & (rsi_3_15m_lt_50)
            & (aroonu_14_15m_lt_25)
            & (stochrsi_k_15m_lt_20)
            & (ema_26_15m > ema_12_15m)
            & ((ema_26_15m - ema_12_15m) > (open_15m * 0.050))
            & ((ema_26_15m_shift_1 - ema_12_15m_shift_1) > (open_15m / 100.0))
          )

        # Condition #45 - Quick mode (Long).
        if long_entry_condition_index == 45:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 15m down move, 4h still high
            ((rsi_3_gt_3) | (rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_50))
            # 15m & 1h down move, 1h still high
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_40))
            # 5m & 4h & 1d down move
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_20))
            # 15m & 1h & 4h down move, 4h & 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_60))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_45) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 15m & 4h down move
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_10))
            # 15m & 4h & 1d down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (stochrsi_k_4h_lt_30))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_30) | (rsi_14_4h < 35.0))
            # 15m down move, 4h still high, 15m downtrend
            & ((rsi_3_15m_gt_3) | (aroonu_14_4h_lt_40) | (cmf_20_15m_gt_neg_0_35))
            # 15m & 1h down move
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_15))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_80))
            # 15m down move, 1h still not low enough
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_30))
            # 15m down move, 4h high
            & ((rsi_3_15m_gt_5) | (aroonu_14_4h_lt_90))
            # 15m & 1h & 1d down move
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_1d_gt_10))
            # 15m & 1h & 1d down move, 1d still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_30))
            # 15m & 1h & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_90))
            # 15m & 1h & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (stochrsi_k_1d_lt_80))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (roc_9_1d_lt_30))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_60))
            # 15m & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_80))
            # 15m & 1h & 4h down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_50) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_30))
            # 15m & 4h & 1d down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_20))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_80))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_40))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_70) | (roc_9_1h_lt_10))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_20))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_75) | (aroonu_14_1d_lt_100))
            # 15m down move, 4h high, 1h overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_10))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_40) | (rsi_14_4h_lt_70) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_30))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_70) | (stochrsi_k_4h_lt_90))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_50))
            # 15m & 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_60))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_40) | (roc_9_1d_lt_80))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | aroonu_14_1h_lt_70)
            # 1h down move, 4h still not low enough
            & ((rsi_3_1h_gt_3) | (aroonu_14_4h_lt_30))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_30) | (aroonu_14_1h_lt_20))
            # 1h down move, 1h still not low enough
            & ((rsi_3_1h_gt_5) | (aroonu_14_1h_lt_30))
            # 1h down move, 1h still not low enough
            & ((rsi_3_1h_gt_5) | (stochrsi_k_1h < 25.0))
            # 1h & 4h down move
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | rsi_3_4h_gt_20 | (stochrsi_k_4h_lt_30))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_50))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_60))
            # 1h & 1d down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_10) | (aroonu_14_4h_lt_40))
            # 1h & 1d down move, 5m moving down
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_15) | (roc_2 > -0.0))
            # 1h & 1d down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_30) | (aroonu_14_4h_lt_50))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_70))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_30))
            # 1h & 4h & 1d down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_70))
            # 1h down move, 1h still not low enough, 1d high
            & ((rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_20) | (aroonu_14_1d_lt_85))
            # 1h down move, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (stochrsi_k_1h < 25.0))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_85))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_50))
            # 1h down move, 1d overbought
            & ((rsi_3_1h_gt_10) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40))
            # 1h & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_70))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_100))
            # 1h down move, 1h still high
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1h still high
            & ((rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_30))
            # 1h & 4h down move, 4h still high, 1h downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50) | (roc_9_1h_gt_neg_25))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_20))
            # 1h & 4h & 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_85) | (roc_2_1d > -30.0))
            # 1h & 4h & 1d down move, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_50) | (stochrsi_k_1d_lt_70) | (roc_9_1d_lt_30))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_90))
            # 1h down move, 4h still high
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_60))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_70))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80))
            # 1h & 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_30) | (rsi_3_1d > 50.0) | (stochrsi_k_1h_lt_50))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_30) | (rsi_14_4h_lt_80))
            # 14 down move, 1h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_80))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80))
            # 1h down move, 1d high, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_80))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_80))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50) | (roc_9_1d_lt_50))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_90))
            # 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_100))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_70) | (aroonu_14_4h_lt_90))
            # 4h down move, 1d high
            & ((rsi_3_4h_gt_5) | aroonu_14_1d_lt_100)
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_50))
            # 4h downmove, 4h still high
            & ((rsi_3_4h_gt_10) | (aroonu_14_4h_lt_40))
            # 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1h & 1d downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_35) | (rsi_14_1d_lt_50))
            # 4h down move, 1h still not low enough
            & ((rsi_3_4h_gt_15) | (aroonu_14_1h_lt_30))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_80))
            # 4h down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_100))
            # 4h down move, 1d high
            & ((rsi_3_4h_gt_25) | (stochrsi_k_1d_lt_90))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_25) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_40) | (stochrsi_k_1h_lt_70))
            # 4h down move, 4h still high
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_50))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_60) | (stochrsi_k_1h_lt_80))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80))
            # 1d down move, 1h still not low enough
            & ((rsi_3_1d_gt_5) | (stochrsi_k_1h_lt_30))
            # 1d down move, 1h & 1d downtrend
            & ((rsi_3_1d_gt_5) | (roc_9_1h_gt_neg_10) | (roc_9_1d_gt_neg_30))
            # 1d down move, 1h still not low enough
            & ((rsi_3_1d_gt_15) | (stochrsi_k_1h_lt_30))
            # 1d down move, 4h still high, 4h downtrend
            & ((rsi_3_1d_gt_15) | (stochrsi_k_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 1d down move, 4h still high
            & ((rsi_3_1d_gt_15) | (stochrsi_k_4h_lt_50))
            # 1d down move, 1h high & overbought
            & ((rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10))
            # 15m still high, 1h & 4h high
            & ((rsi_14_15m_lt_40) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_90))
            # 1h & 4h high, 4h overbought
            & (aroonu_14_1h_lt_70 | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_20))
            # 4h high, 1d overbought
            & (aroonu_14_4h_lt_70 | (roc_9_1d_lt_80))
            # 4h high, 1h & 1d downtrend
            & (aroonu_14_4h_lt_70 | (roc_9_1h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h high, 1h & 4h overbought
            & (aroonu_14_4h_lt_80 | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 4h high & overbought
            & ((aroonu_14_4h_lt_90) | (roc_9_4h_lt_80))
            # 1d high, 4h & 1d downtrend
            & ((aroonu_14_1d_lt_80) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 1h high, 4h overbought
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_lt_80))
            # 4h high, 1h & 1d downtrend
            & ((stochrsi_k_4h_lt_70) | (roc_9_1h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_80) | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 4h high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30) | (roc_9_1d_lt_30))
            # 1d top wick, 4h still high
            & ((top_wick_pct_1d < 40.0) | (aroonu_14_4h_lt_50))
            # pump, 4h still high
            & ((((high_max_24_4h - low_min_24_4h) / low_min_24_4h) < 2.0) | (stochrsi_k_4h_lt_50))
            # pump, drop but not yet near the previous lows
            & (
              (((high_max_24_4h - low_min_24_4h) / low_min_24_4h) < 2.0)
              | (close > (high_max_6_4h * 0.75))
              | (close < (low_min_24_4h * 1.25))
            )
            # pump, drop but not yet near the previous lows
            & (
              (((high_max_12_1d - low_min_12_1d) / low_min_12_1d) < 2.0)
              | (close > (high_max_24_4h * 0.70))
              | (close < (low_min_12_1d * 1.25))
            )
            # big drop in last hour
            & (close > (close_max_12 * 0.50))
            # big drop in last hour, 1d down move
            & ((close > (close_max_12 * 0.80)) | (rsi_3_1d_gt_15))
            # big drop in the last 12 hours, 4h still high
            & ((close > (high_max_12_1h * 0.50)) | (aroonu_14_4h_lt_50))
            # big drop in the last 6 days, 1h still high
            & ((close > (high_max_6_1d * 0.25)) | (aroonu_14_1h_lt_50))
            # big drop in the last 12 days, 1h down move
            & ((close > (high_max_12_1d * 0.45)) | (rsi_3_1h_gt_5))
            # big drop in the last 12 days, 4h down move
            & ((close > (high_max_12_1d * 0.40)) | (rsi_3_4h_gt_15))
            # big drop in the last 12 days, 1h still high
            & ((close > (high_max_12_1d * 0.25)) | (aroonu_14_1h_lt_75))
            # big drop in the last 20 days, 1h down move
            & ((close > (high_max_20_1d * 0.35)) | (rsi_3_1h_gt_10))
            # big drop in the last 20 days, 1h down move
            & ((close > (high_max_20_1d * 0.25)) | (rsi_3_1h_gt_15))
            # big drop in the last 20 days, 1h down move
            & ((close > (high_max_20_1d * 0.10)) | rsi_3_1h_gt_20)
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
            # big drop in the last 30 days, 4h down move, 4h still high
            & ((close > (high_max_30_1d * 0.25)) | (rsi_3_4h_gt_45) | (rsi_14_4h_lt_40))
          )

          # Logic
          long_entry_logic.append(
            (rsi_3_lt_50) & (aroonu_14_15m_lt_25) & (stochrsi_k_15m_lt_20) & (close_15m < (ema_20_15m * 0.924))
          )

        # Condition #46 - Quick mode (Long).
        if long_entry_condition_index == 46:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 1h down move
            ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_40))
            # 15m & 4h down move
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_40))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_30))
            # 15m & 1h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_14_4h_lt_30))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_40))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_40))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_100))
            # 15m & 1h down move, 1h still high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_50))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_60) | (rsi_3_4h_gt_65) | (rsi_3_1d_gt_65) | (aroonu_14_1d_lt_80))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_90))
            # 15m & 4h down move, 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (roc_9_4h_gt_neg_20))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_30))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_90))
            # 15m down move, 4h still high, 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_90))
            # 15m & 1h & 1d down move, 1d high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_60) | (roc_9_1d_lt_20))
            # 15m & 1h & 4h down move, 1d high, 1h downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_50) | (stochrsi_k_1d_lt_70) | (roc_9_1h_gt_neg_25))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_60))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_40))
            # 15m & 1h & 1d down move, 1h still not low enough, 1d high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_1d_gt_30) | (rsi_14_1h < 30.0) | (aroonu_14_1d_lt_80))
            # 15m & 1h down move, 4h still high, 4h overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_50) | (roc_9_4h_lt_10))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_70))
            # 15m down move, 1h & 4h still high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_40) | (stochrsi_k_4h_lt_50))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_40) | (aroonu_14_4h_lt_40))
            # 15m & 1h & 4h down move, 1d high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (roc_9_1d_lt_70))
            # 15m & 1h & 4h down move, 1h still high, 1d high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_40) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_80))
            # 15m & 1h & 4h down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_50) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 15m & 1h & 4h & 1d down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_60) | (aroonu_14_4h_lt_70))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_85))
            # 15m & 1h down move, 15m still not low enough
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (aroonu_14_15m < 15.0))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_35) | (aroonu_14_1h_lt_80))
            # 15m & 1d down move, 15m still high, 1d downtrend
            & ((rsi_3_15m_gt_30) | (rsi_3_1d_gt_30) | (rsi_14_15m_lt_40) | (roc_9_1d_gt_neg_50))
            # 15m & 1h & 1d down move, 1h high
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_1h_lt_70))
            # 1h down move, 1h still not low enough, 1d high
            & ((rsi_3_1h_gt_3) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_lt_90))
            # 1h & 4h down move
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (roc_9_4h_gt_neg_30))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_30))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_5) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_80))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_5) | (aroonu_14_4h_lt_70))
            # 1h down move, 1d still high
            & ((rsi_3_1h_gt_5) | (stochrsi_k_1d_lt_50))
            # 1h & 4h & 1d down move, 1d still not low enough, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_35) | (stochrsi_k_1d_lt_30) | (stochrsi_k_1d_lt_20))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (rsi_14_4h_lt_30))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_30))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_35) | (roc_9_1d_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_70))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_40))
            # 1h & 1d down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_4h_lt_30))
            # 1h & 1d down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_30) | (aroonu_14_4h_lt_50))
            # 1h & 1d down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_45) | (rsi_14_4h_lt_40))
            # 1h down move, 1h still high
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_50))
            # 1h down move, 4h still high, 1d high
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_lt_90))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_30))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_10))
            # 1h & 4h down move, 1d stll high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_14_1d_lt_40))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30))
            # 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_35) | (aroonu_14_1d_lt_40))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_30))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_50))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_80))
            # 1h & 4h down move, 1h & 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (rsi_14_1h_lt_40) | (rsi_14_4h_lt_50))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_40))
            # 1h & 4h & 1d down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_60) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_60) | (roc_9_1d_lt_20))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_50))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_40) | roc_9_1d_lt_50)
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_30))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_70))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_30))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (rsi_14_4h_lt_30) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_45) | (aroonu_14_4h < 65.0))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_70))
            # 1h down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_90))
            # 4h down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_100))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_25))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_50) | (stochrsi_k_1d_lt_80))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_70))
            # 1h & 4h & 1d down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_60) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_90))
            # 1h down move, 15m still not low enough, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_14_15m_lt_30) | (stochrsi_k_4h_lt_60))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_50))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_60))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_80))
            # 1h & 4h & 1d down move, 4h still high, 4h downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_30))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_30) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_80))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_100) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_90))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_55) | (aroonu_14_4h_lt_80))
            # 1h & 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_90))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_90))
            # 1h down move, 4h high, 4h downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_70) | (cmf_20_4h_gt_neg_0_30))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1d_lt_90) | (roc_9_4h_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_55) | (stochrsi_k_4h_lt_90))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_20))
            # 1h & 1d down move, 1d downtrend, 1d high
            & ((rsi_3_1h_gt_45) | (rsi_3_1d_gt_55) | (cmf_20_1d_gt_neg_0_30) | (aroonu_14_1d_lt_80))
            # 1h & 1d down move, 4h & 1d high, 4h overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_1d_gt_55) | (stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h overbought
            & ((rsi_3_1h_gt_50) | (roc_9_1h_lt_40))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_70))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_1h_gt_neg_15) | (roc_9_4h_gt_neg_20))
            # 4h & 1d down move
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_20))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d > 50.0) | (aroonu_14_1d_lt_90))
            # 4h down move, 4h & 1d still high
            & ((rsi_3_4h_gt_10) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_50))
            # 4h & 1d down move, 1d low
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (cmf_20_1d_gt_neg_0_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_50))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_50) | (roc_9_1d_lt_40))
            # 4h & 1d down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_55) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_30))
            # 4h down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_30) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_20) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d high & overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_20))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_90))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_35) | (aroonu_14_4h_lt_60) | (stochrsi_k_1d_lt_90))
            # 4h down move, 1d high, 4h overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 4h down move, 4h overbought
            & ((rsi_3_4h_gt_60) | (roc_9_4h_lt_40))
            # 1d down move, 4h & 1d downtrend
            & ((rsi_3_1d_gt_10) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 15m down move, 1d high, 1d downtrend
            & ((rsi_3_1d_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_40))
            # 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_1d_gt_20) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_30))
            # 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1d_gt_25) | (aroonu_14_1d_lt_80) | (roc_9_1d_gt_neg_30))
            # 1d down move, 1h high, 1h overbought, 1d downtrend
            & ((rsi_3_1d_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_1h_lt_10) | (roc_9_1d_gt_neg_40))
            # 4h & 1d downtrend, 1h high
            & ((cmf_20_4h_gt_neg_0_20) | (cmf_20_1d_gt_neg_0_30) | (aroonu_14_1h_lt_70))
            # 4h & 1d downtrend, 1d high
            & ((cmf_20_4h_gt_neg_0_20) | (cmf_20_1d_gt_neg_0_30) | (aroonu_14_1d_lt_70))
            # 4h & 1d high, 4h overbought
            & ((aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20))
            # 4h high, 1h overbought
            & ((aroonu_14_4h_lt_80) | (roc_9_1h_lt_40))
            # 4h high, 4h overbought
            & ((aroonu_14_4h_lt_80) | (roc_9_4h_lt_40))
            # 4h high, 1h overbought
            & ((stochrsi_k_4h_lt_70) | (roc_9_1h_lt_40))
            # 4h high, 4h overbought
            & ((stochrsi_k_4h_lt_70) | (roc_9_4h_lt_40))
            # 4h high, 4h overbought, 1d downtrend
            & ((stochrsi_k_4h_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_gt_neg_20))
            # 1d green, 4h down move, 4h still high
            & ((change_pct_1d_lt_40) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_40))
            # 4h top wick, 1h down move, 1h still high
            & ((top_wick_pct_4h < 20.0) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_50))
            # pump, drop but not yet near the previous lows
            & (
              (((high_max_6_1d - low_min_6_1d) / low_min_6_1d) < 2.0)
              | (close > (high_max_12_4h * 0.50))
              | (close < (low_min_24_4h * 1.05))
            )
            # 1d overbought, drop but not yet near the previous lows
            & (roc_9_1d_lt_50 | (close > (high_max_6_1d * 0.70)) | (close < (low_min_12_1d * 1.25)))
            # 1d overbought, drop but not yet near the previous lows
            & (
              (((high_max_12_1d - low_min_12_1d) / low_min_12_1d) < 2.5)
              | (close > (high_max_6_1d * 0.60))
              | (close < (low_min_12_1d * 1.25))
            )
            # big drop in the last 2 days, 1d down move
            & ((close > (high_max_12_4h * 0.30)) | (rsi_3_1d_gt_30))
            # big drop in the last 12 days, 1h down move
            & ((close > (high_max_12_1d * 0.30)) | rsi_3_1h_gt_20)
            # big drop in the last 12 days, 4h still high
            & ((close > (high_max_12_1d * 0.40)) | (stochrsi_k_4h_lt_50))
            # big drop in the last 20 days, 1h down move
            & ((close > (high_max_20_1d * 0.40)) | (rsi_3_1h_gt_10))
            # big drop in the last 20 days, 4h down move
            & ((close > (high_max_20_1d * 0.10)) | (rsi_3_4h_gt_25))
            # big drop in the last 30 days, 4h down move
            & ((close > (high_max_30_1d * 0.40)) | (rsi_3_4h_gt_15))
            # big drop in the last 30 days, 4h still not low enough
            & ((close > (high_max_30_1d * 0.25)) | (stochrsi_k_4h_lt_30))
          )

          # Logic
          long_entry_logic.append(
            (rsi_3_lt_40)
            & (rsi_3_15m_lt_50)
            & (willr_14_15m < -50.0)
            & (aroonu_14_15m_lt_25)
            & (stochrsi_k_15m_lt_20)
            & (willr_84_1h < -70.0)
            & (stochrsi_k_1h_lt_20)
            & (bbb_20_2_0_1h > 12.0)
            & (close_max_48 >= (close * 1.10))
          )

        # Condition #47 - Trend Reversal mode (Long).
        if long_entry_condition_index == 47:
          # --- Protections ---
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            ((rsi_3 > 5.0) | (rsi_3_1h > 10.0) | (aroonu_14_1h < 30.0))
            & ((rsi_3 > 5.0) | (rsi_3_4h > 20.0) | (aroonu_14_4h < 40.0))
            & ((rsi_3_15m > 5.0) | (rsi_3_1h > 5.0) | (rsi_3_4h > 10.0))
            & ((rsi_3_15m > 10.0) | (rsi_3_1h > 25.0) | (aroonu_14_15m < 40.0))
            & ((rsi_3_1h > 5.0) | (aroonu_14_1h < 20.0))
            & ((rsi_3_1h > 10.0) | (rsi_3_4h > 15.0) | (rsi_14_4h < 40.0))
            & ((rsi_3_4h > 15.0) | (aroonu_14_4h < 50.0) | (roc_9_1d > -30.0))
            & ((roc_9_1d > -15.0) | (rsi_14_1h > 45.0))
            & ((roc_9_1d > -10.0) | (rsi_14_4h > 40.0) | (cmf_20_1h > 0.0))
            & ((rsi_14_1h > 40.0) | (bbp_20_2_0_4h > 0.20))
            & ((rsi_3_1h > 30.0) | (rsi_3_1d > 20.0) | (rsi_14_1h > 45.0))
            & ((cmf_20_1h > -0.10) | (cmf_20_4h > -0.10) | (rsi_14_1h > 50.0))
            & ((close > (close_min_48 * 1.02)) | (rsi_14_4h > 40.0) | (rsi_3_1h > 40.0))
            & ((willr_14_1h > -80.0) | (roc_9_1d > -8.0) | (cmf_20_4h > 0.0))
            ########################################################################################################
            # 15m down move, 15m high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_100))
            # 15m & 1h & 4h down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_55) | (rsi_3_1d_gt_55) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_90))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_60) | (aroonu_14_15m_lt_100))
            # 15m & 1h down move, 1h high, 1d still high
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_50))
            # 15m & 1h down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_gt_55) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_70))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_35) | (stochrsi_k_15m_lt_70))
            # 1h & 1d down move, 1d overbought
            & ((rsi_3_1h_gt_30) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_50))
            # 1h & 1d down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (rsi_3_1d_gt_65) | (aroonu_14_1h_lt_60) | (roc_9_1d_lt_30))
            # 1h & 1d down move, 15m still high, 1h high
            & ((rsi_3_1h_gt_30) | (rsi_3_1d_gt_60) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_100))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 15m & 4h high
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_50))
            # 1h down move, 1h high, 1d high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_100) | (stochrsi_k_1d_lt_80))
            # 1h & 4h down move, 4h & 1d high
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 1h down move, 15m high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_15m_lt_100) | (roc_9_1d_lt_20))
            # 1h down move, 1h high, 1d high
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_60) | (stochrsi_k_1d_lt_90))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_80))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_50) | (stochrsi_k_15m_lt_80))
            # 1h & 4h down move, 1h high, 4h high
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_80) | (stochrsi_k_1h_lt_60))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_90))
            # 1h & 1d down move, 15m high
            & ((rsi_3_1h_gt_45) | (rsi_3_1d_gt_50) | (aroonu_14_15m_lt_100))
            # 1h down mov, 4h high & overbought
            & ((rsi_3_1h_gt_45) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 1h & 4h & 1d down move, 15m still high, 1h high
            & ((rsi_3_1h_gt_50) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_50) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_60))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_50) | (rsi_3_4h_gt_55) | (aroonu_14_1h_lt_80))
            # 1h & 1d down move, 15m high, 1h high
            & ((rsi_3_1h_gt_50) | (rsi_3_1d_gt_50) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_100))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 4h high
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_80) | (stochrsi_k_4h_lt_90))
            # 1h down move, 4h & 1d high, 4h overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20))
            # 1h down mov, 4h high & overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_40))
            # 1h & 4h down move, 15m still high, 1h high
            & ((rsi_3_1h_gt_55) | (rsi_3_4h_gt_65) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_80))
            # 1h & 1d down move, 1h & 1d high
            & ((rsi_3_1h_gt_55) | (rsi_3_1d_gt_55) | (stochrsi_k_1h_lt_70) | (stochrsi_k_1d_lt_80))
            # 1h & 1d down move, 4h high, 1d high
            & ((rsi_3_1h_gt_55) | (rsi_3_1d_gt_55) | (stochrsi_k_4h_lt_90) | (stochrsi_k_1d_lt_70))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_30))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 1h & 4h overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_80) | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_90) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1h high, 4h high & overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_10))
            # 1h down move, 1h high, 1d high
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_90) | (stochrsi_k_1d_lt_90))
            # 1h down move, 1h high, 4h high
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_100) | (stochrsi_k_4h_lt_70))
            # 1h & 4h down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_10))
            # 1h & 4h down move, 4h & 1d high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_90))
            # 1h & 4h down move, 4h & 1d high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_70) | (stochrsi_k_1d_lt_70))
            # 1h & 4h down move, 1h high, 1d high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_65) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_90))
            # 1h down move, 15m high, 1d high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_15m_lt_60) | (stochrsi_k_1d_lt_90))
            # 1h down move, 1h & 4h high, 1d high
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_70) | (stochrsi_k_1d_lt_80))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_60) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_30))
            # 1h down move, 1h still high, 4h high & overbought
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_40))
            # 1h & 1d down move, 1h high, 4h high & overbought
            & ((rsi_3_1h_gt_65) | (rsi_3_1d_gt_65) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_10))
            # 1h down move, 15m still high, 1h high, 1d high
            & ((rsi_3_1h_gt_65) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_80))
            # 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_65) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_15) | (aroonu_14_15m_lt_100))
            # 4h & 1d down move, 15m & 1h still high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_50))
            # 4h & 1d down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_30))
            # 4h & 1d down move, 1h high, 15m still high
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_80) | (stochrsi_k_15m_lt_40))
            # 4h & 1d down move, 15m still high, 1h high
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_90))
            # 4h down move, 1h & 1d high
            & ((rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_80) | (stochrsi_k_1d_lt_80))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_35) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_15))
            # 4h down move, 1d high, 4h & 1d overbought
            & ((rsi_3_4h_gt_35) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 4h down mov, 15m high, 4h overbought
            & ((rsi_3_4h_gt_35) | (stochrsi_k_15m_lt_80) | (roc_9_4h_lt_10))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_35) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_50))
            # 4h & 1d down move, 1h & 1d high
            & ((rsi_3_4h_gt_40) | (rsi_3_1d_gt_60) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_80))
            # 4h down move, 15m high, 4h high
            & ((rsi_3_4h_gt_40) | (aroonu_14_15m_lt_100) | (aroonu_14_4h_lt_70))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70) | (stochrsi_k_1d_lt_80))
            # 4h down move, 4h high, 1d high
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_70) | (stochrsi_k_1d_lt_90))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_55) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_15))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_30))
            # 4h down mov, 4h high & overbought
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_40))
            # 4h down move, 1d high, 4h downtrend
            & ((rsi_3_4h_gt_60) | (stochrsi_k_1d_lt_90) | (roc_9_4h_gt_neg_20))
            # 4h down move, 1h high, 4h overbought
            & ((rsi_3_4h_gt_65) | (aroonu_14_1h_lt_90) | (stochrsi_k_1h_lt_90) | (roc_9_4h_lt_15))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_65) | (aroonu_14_4h_lt_80) | (stochrsi_k_4h_lt_80))
            # 1d down move, 1h high
            & ((rsi_3_1d_gt_15) | (aroonu_14_1h_lt_70) | (stochrsi_k_1h_lt_70))
            # 1d down move, 1h high, 4h high
            & ((rsi_3_1d_gt_20) | (aroonu_14_1h_lt_80) | (stochrsi_k_4h_lt_70))
            # 1d down move, 1d downtrend, 1h high, 4h still high
            & ((rsi_3_1d_gt_30) | (cmf_20_1d_gt_neg_0_25) | (aroonu_14_1h_lt_80) | (stochrsi_k_4h_lt_40))
            # 1d down move, 1h high
            & ((rsi_3_1d_gt_30) | (aroonu_14_1h_lt_90) | (stochrsi_k_1h_lt_90))
            # 1d down move, 15m high, 1d high
            & ((rsi_3_1d_gt_35) | (aroonu_14_15m_lt_100) | (stochrsi_k_1d_lt_70))
            # 1d down move, 1d high, 1h high
            & ((rsi_3_1d_gt_35) | (aroonu_14_1d_lt_70) | (stochrsi_k_1h_lt_80))
            # 1d down move, 15m high, 1d high
            & ((rsi_3_1d_gt_45) | (aroonu_14_15m_lt_60) | (stochrsi_k_1d_lt_80))
            # 1d down move, 1d downtrend, 1h high
            & ((rsi_3_1d_gt_50) | (cmf_20_1d_gt_neg_0_40) | (aroonu_14_1h_lt_80) | (stochrsi_k_1h_lt_90))
            # 1d down move, 1h high, 1d high
            & ((rsi_3_1d_gt_55) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_70))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_65) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h downtrend, 4h high
            & ((cmf_20_1h_gt_neg_0_25) | (aroonu_14_4h_lt_80) | (stochrsi_k_4h_lt_70))
            # 15m still high, 1h high
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_90) | (stochrsi_k_1h_lt_80))
            # 15m & 4h high
            & ((aroonu_14_15m_lt_100) | (aroonu_14_4h_lt_100))
            # 15m high, 1h high
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_1h_lt_90))
            # 15m high, 4h high
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_4h_lt_70))
            # 1h high, 1h & 1d downtrend
            & ((aroonu_14_1h_lt_90) | (cmf_20_1h_gt_neg_0_30) | (cmf_20_1d_gt_neg_0_40))
            # 1h & 4h high, 1h overbought
            & ((aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_10))
            # 4h & 1d high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_80) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
          )

          # --- Logic ---
          long_entry_logic.append(
            (rsi_14 > 40.0)
            & (rsi_14 < 65.0)
            & (rsi_14_15m > 35.0)
            & (rsi_14_1h > 35.0)
            & (rsi_14_1h < 60.0)
            & (aroonu_14 > 50.0)
            & (aroonu_14_15m > 25.0)
            & (stochrsi_k > 20.0)
            & (stochrsi_k < 80.0)
            & (roc_9_1d > -25.0)
            & (obv_change_pct > 0.0)
            & (ema_12 > ema_26)
            & (np_shift(ema_12, 3) < np_shift(ema_26, 3))
            & (ema_12_4h < ema_200_4h)
            & (close > close_min_48)
            & (close < (close_max_48 * 0.97))
          )

        # Condition #48 - Market-order bubble on a 15m trend pullback (Long, experimental).
        if long_entry_condition_index == 48:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            # 5m & 15m down move, 1d high
            ((rsi_3_gt_15) | (rsi_3_15m_gt_10) | (stochrsi_k_1d_lt_70))
            # 5m & 15m down move, 4h high
            & ((rsi_3_gt_15) | (rsi_3_15m_gt_30) | (stochrsi_k_4h_lt_80))
            # 5m & 15m down move, 15m high
            & ((rsi_3_gt_15) | (rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_60))
            # 5m & 4h down move, 1h still not low enough
            & ((rsi_3_gt_15) | (stochrsi_k_1h_lt_20) | (rsi_3_4h_gt_50))
            # 5m & 4h down move, 1h still not low enough
            & ((rsi_3_gt_15) | (stochrsi_k_1h_lt_30) | (rsi_3_4h_gt_60))
            # 5m still not low enough, 4h & 1d high
            & ((aroonu_14_lt_25) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_80))
            # 5m & 1h still not low enough, 15m down move
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_20) | (aroonu_14_1h_lt_20))
            # 5m still not low enough, 15m down move, 4h high
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_20) | (aroonu_14_4h_lt_70))
            # 5m & 15m still not low enough, 15m down move
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_30))
            # 5m still not low enough, 15m down move & high
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_60))
            # 5m still not low enough, 1h down move & still high
            & ((aroonu_14_lt_25) | (rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_50))
            # 5m still not low enough, 1h & 4h still high
            & ((aroonu_14_lt_25) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_40))
            # 5m still not low enough, 15m down move
            & ((aroonu_14_lt_25) | (stochrsi_k_lt_30) | (rsi_3_15m_gt_50))
            # 5m still not low enough, 4h & 1d high
            & ((aroonu_14_lt_30) | (aroonu_14_4h_lt_60) | (stochrsi_k_1d_lt_90))
            # 5m still not low enough, 15m & 4h down move
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_50) | (rsi_3_4h_gt_50))
            # 5m still not low enough, 15m still high, 1h down move
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_40))
            # 5m still not low enough, 15m still high, 4h high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_60))
            # 5m still not low enough, 1h high, 1d overbought
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_lt_60) | (roc_9_1d_lt_20))
            # 5m still not low enough, 15m high
            & ((aroonu_14_lt_30) | (stochrsi_k_lt_30) | (stochrsi_k_15m_lt_80))
            # 5m still not low enough, 15m high, 1d overbought
            & ((stochrsi_k_lt_20) | (aroonu_14_15m_lt_80) | (roc_9_1d_lt_10))
            # 5m still not low enough, 1h & 4h high
            & ((stochrsi_k_lt_20) | (aroonu_14_1h_lt_60) | (stochrsi_k_4h_lt_60))
            # 5m still not low enough, 1h & 1d high
            & ((stochrsi_k_lt_20) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_90))
            # 5m still not low enough, 15m & 1h down move
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_10) | (rsi_3_1h_gt_20))
            # 5m still not low enough, 15m down move & high
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_30) | (aroonu_14_15m_lt_60))
            # 5m still not low enough, 15m down move, 1d high
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_30) | (aroonu_14_1d_lt_90))
            # 5m still not low enough, 15m down move, 4h high
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_50) | (stochrsi_k_4h_lt_80))
            # 5m still not low enough, 1h down move & still high
            & ((stochrsi_k_lt_20) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_50))
            # 5m still not low enough, 4h down move, 1d high
            & ((stochrsi_k_lt_20) | (rsi_3_4h_gt_40) | (stochrsi_k_1d_lt_80))
            # 5m & 1h still not low enough, 4h still high
            & ((stochrsi_k_lt_20) | (stochrsi_k_1h_lt_30) | (stochrsi_k_4h_lt_50))
            # 5m still not low enough, 4h still high, 1d high
            & ((stochrsi_k_lt_20) | (stochrsi_k_4h_lt_40) | (stochrsi_k_1d_lt_70))
            # 5m still not low enough, 4h high, 1d overbought
            & ((stochrsi_k_lt_20) | (stochrsi_k_4h_lt_70) | (roc_9_1d_lt_60))
            # 5m still not low enough, 4h high & overbought
            & ((stochrsi_k_lt_20) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_5))
            # 5m still not low enough, 15m still high, 4h high
            & ((stochrsi_k_lt_30) | (aroonu_14_15m_lt_40) | (stochrsi_k_4h_lt_70))
            # 5m still not low enough, 15m & 1d high
            & ((stochrsi_k_lt_30) | (aroonu_14_15m_lt_60) | (stochrsi_k_1d_lt_90))
            # 5m & 1h still not low enough, 4h high
            & ((stochrsi_k_lt_30) | (aroonu_14_1h_lt_20) | (stochrsi_k_4h_lt_60))
            # 5m still not low enough, 1h & 1d high
            & ((stochrsi_k_lt_30) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_80))
            # 5m still not low enough, 4h high, 1d overbought
            & ((stochrsi_k_lt_30) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_20))
            # 5m & 15m still not low enough, 15m down move
            & ((stochrsi_k_lt_30) | (rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_30))
            # 5m still low, 15m momentum rising, 4h downtrend, 1d not at a new high
            & ((willr_14 > -50) | (rsi_14_change_pct_15m < 3) | (aroond_14_4h_lt_25) | (aroonu_14_1d > 95))
            # 15m down move & still not low enough, 4h still high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_20) | (stochrsi_k_4h_lt_50))
            # 15m down move, 1h still not low enough, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_20) | (roc_9_1d_lt_10))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_25))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_4h_lt_60) | (roc_9_1d_lt_15))
            # 15m & 4h down move, 1h still not low enough
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_60))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_40))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_80))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_60) | (roc_9_1d_lt_80))
            # 15m down move, 4h still high, 1d overbought
            & ((rsi_3_15m_gt_20) | (stochrsi_k_4h_lt_40) | (roc_9_1d_lt_20))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_60))
            # 15m & 1d down move, 1h still not low enough
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_20) | (rsi_3_1d_gt_55))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_50))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_30) | (stochrsi_k_15m_lt_50) | (rsi_3_1h_gt_50))
            # 15m & 1d down move, 15m high
            & ((rsi_3_15m_gt_30) | (stochrsi_k_15m_lt_60) | (rsi_3_1d_gt_65))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_70) | (rsi_3_1h_gt_45))
            # 15m down move, 1h high & still not low enough
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_lt_80) | (stochrsi_k_1h_lt_30))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_70))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_40) | (rsi_3_4h_gt_50) | (stochrsi_k_1d_lt_90))
            # 15m & 1h down move, 15m still not low enough
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_20) | (rsi_3_1h_gt_40))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_50) | (aroonu_14_1h_lt_50) | (rsi_3_4h_gt_50))
            # 15m & 1h down move, 15m still not low enough
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_20) | (rsi_3_1h_gt_20))
            # 15m down move & high, 1h still not low enough
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_20))
            # 15m down move, 15m & 4h high
            & ((rsi_3_15m_gt_55) | (aroonu_14_15m_lt_60) | (stochrsi_k_4h_lt_90))
            # 15m still not low enough, 1h & 1d high
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_lt_80))
            # 15m still not low enough, 1h & 4h high
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_60) | (stochrsi_k_4h_lt_60))
            # 15m still not low enough, 1h & 4h down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_50))
            # 15m still not low enough, 1h down move, 1d high
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_50) | (aroonu_14_1d_lt_90))
            # 15m still not low enough, 4h down move & high
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_90))
            # 15m still not low enough, 1d high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_lt_20) | (stochrsi_k_1d_lt_90))
            # 15m still high, 1h still not low enough, 1d high
            & ((aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_20) | (stochrsi_k_1d_lt_80))
            # 15m still high, 4h & 1d high
            & ((aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_lt_80))
            # 15m still high, 1h down move, 4h overbought
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_30) | (roc_9_4h_lt_15))
            # 15m & 1h high, 1h down move
            & ((aroonu_14_15m_lt_60) | (rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_80))
            # 15m high, 1h still not low enough, 1d overbought
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_30) | (roc_9_1d_lt_10))
            # 15m high, 4h down move, 1d overbought
            & ((aroonu_14_15m_lt_80) | (rsi_3_4h_gt_40) | (roc_9_1d_lt_15))
            # 15m & 4h high, 4h down move
            & ((aroonu_14_15m_lt_80) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_90))
            # 15m high, 1h still high, 4h down move
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_1h_lt_50) | (rsi_3_4h_gt_60))
            # 15m still not low enough, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_20) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_60))
            # 15m still not low enough, 1h down move, 1d overbought
            & ((stochrsi_k_15m_lt_20) | (rsi_3_1h_gt_40) | (roc_9_1d_lt_10))
            # 15m still not low enough, 1h & 1d down move
            & ((stochrsi_k_15m_lt_20) | (rsi_3_1h_gt_40) | (rsi_3_1d_gt_60))
            # 15m still not low enough, 4h down move & high
            & ((stochrsi_k_15m_lt_20) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_80))
            # 15m still not low enough, 1h high, 4h still high
            & ((stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_80) | (aroonu_14_4h_lt_40))
            # 15m still not low enough, 4h & 1d high
            & ((stochrsi_k_15m_lt_20) | (stochrsi_k_4h_lt_90) | (aroonu_14_1d_lt_90))
            # 15m still not low enough, 1d high
            & ((stochrsi_k_15m_lt_30) | (aroonu_14_1d_lt_90) | (stochrsi_k_1d_lt_90))
            # 15m still not low enough, 4h & 1d high
            & ((stochrsi_k_15m_lt_30) | (aroonu_14_4h_lt_90) | (stochrsi_k_1d_lt_90))
            # 15m still not low enough, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_30) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_80))
            # 15m still not low enough, 4h down move, 1d high
            & ((stochrsi_k_15m_lt_30) | (rsi_3_4h_gt_50) | (stochrsi_k_1d_lt_90))
            # 15m still high, 4h & 1d high
            & ((stochrsi_k_15m_lt_40) | (aroonu_14_4h_lt_60) | (stochrsi_k_1d_lt_80))
            # 15m still high, 1h & 4h down move
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40))
            # 15m still high, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_45) | (stochrsi_k_4h_lt_60))
            # 15m still high, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_50) | (rsi_3_1h_gt_50) | (aroonu_14_4h_lt_80))
            # 15m high, 1h down move & still not low enough
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_20))
            # 15m high, 1h down move & still not low enough
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_30))
            # 15m high, 4h down move & still high
            & ((stochrsi_k_15m_lt_70) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_50))
            # 15m high, 1h still not low enough
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_20) | (stochrsi_k_1h_lt_20))
            # 15m & 1d high, 1h still high
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_80))
            # 15m & 4h & 1d high
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_80))
            # 1h down move & still not low enough, 1d overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_20) | (roc_9_1d_lt_25))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_10))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80) | (stochrsi_k_1d_lt_80))
            # 1h down move & still not low enough, 4h high
            & ((rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_20) | (aroonu_14_4h_lt_80))
            # 1h down move & still high, 1d overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_40) | (roc_9_1d_lt_35))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_60))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_70))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (rsi_3_1d_gt_55))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_60))
            # 1h down move & still high, 4h high
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_80))
            # 1h still high, 4h down move & high
            & ((aroonu_14_1h_lt_40) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_70))
            # 1h & 4h high, 4h down move
            & ((aroonu_14_1h_lt_60) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_90))
            # 1h & 1d high, 4h down move
            & ((aroonu_14_1h_lt_60) | (rsi_3_4h_gt_60) | (stochrsi_k_1d_lt_90))
            # 1h high & still not low enough, 1d down move
            & ((aroonu_14_1h_lt_70) | (stochrsi_k_1h_lt_20) | (rsi_3_1d_gt_65))
            # 1h & 4h & 1d high
            & ((aroonu_14_1h_lt_70) | (stochrsi_k_4h_lt_90) | (aroonu_14_1d_lt_80))
            # 1h & 4h & 1d high
            & ((aroonu_14_1h_lt_90) | (stochrsi_k_4h_lt_60) | (aroonu_14_1d_lt_80))
            # 1h still not low enough, 4h down move & high
            & ((stochrsi_k_1h_lt_20) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_90))
            # 1h still not low enough, 4h down move & still high
            & ((stochrsi_k_1h_lt_20) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_50))
            # 1h still not low enough, 4h down move & high
            & ((stochrsi_k_1h_lt_30) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_70))
            # 1h still high, 1d high & overbought
            & ((stochrsi_k_1h_lt_40) | (aroonu_14_1d_lt_60) | (roc_9_1d_lt_20))
            # 1h still high, 4h high, 1d overbought
            & ((stochrsi_k_1h_lt_40) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_10))
            # 1h still high, 4h down move, 1d high
            & ((stochrsi_k_1h_lt_40) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_80))
            # 1h still high, 4h & 1d down move
            & ((stochrsi_k_1h_lt_40) | (rsi_3_4h_gt_60) | (rsi_3_1d_gt_65))
            # 1h still high, 4h down move & overbought
            & ((stochrsi_k_1h_lt_40) | (rsi_3_4h_gt_65) | (roc_9_4h_lt_5))
            # 1h still high, 4h down move, 1d high
            & ((stochrsi_k_1h_lt_50) | (rsi_3_4h_gt_65) | (stochrsi_k_1d_lt_90))
            # 1h still high, 4h & 1d high
            & ((stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_70) | (aroonu_14_1d_lt_60))
            # 1h & 4h high, 4h down move
            & ((stochrsi_k_1h_lt_70) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_90))
            # 4h down move & still high, 1d high
            & ((rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_40) | (stochrsi_k_1d_lt_90))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_80) | (stochrsi_k_1d_lt_90))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_60) | (stochrsi_k_1d_lt_90))
            # 4h & 1d high, 4h overbought
            & ((stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10) | (stochrsi_k_1d_lt_60))
          )

          # Logic
          long_entry_logic.append(
            # the 1d is rising and not floored — a 15m pullback inside a falling daily is a knife
            (roc_9_1d_gt_0)
            & (stochrsi_k_1d_gt_50)
            & (rsi_14_1d_gt_50)
            # 15m in an uptrend, price back at the 50 EMA but still above the 200
            & (ema_50_15m > ema_200_15m)
            & (close <= (ema_50_15m * 1.002))
            & (close > ema_200_15m)
            # a market-order bubble, and the buyers are the ones making it
            & (volume > large_bubble_thr)
            & (cvd_buy_vol > cvd_sell_vol)
            # 5m not high
            & (rsi_14 < 60.0)
            # 5m not extended
            & (change_pct < 0.35)
          )

        # Condition #61 - Rebuy mode (Long).
        if long_entry_condition_index == 61:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 1h down move, 1h still not low enough
            ((rsi_3_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_30))
            # 5m & 1h down move, 1d high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_20) | (aroonu_14_1d_lt_100))
            # 5m & 4h down move, 4h high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_25) | aroonu_14_4h_lt_70)
            # 5m down move, 1d high & overbought
            & ((rsi_3_gt_3) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_100))
            # 5m down move, 1d high & overbought
            & ((rsi_3_gt_3) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 5m & 1h & 4h down move
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_5))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (rsi_3_4h_gt_10))
            # 15m & 1h & 4h down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_50))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (rsi_14_4h_lt_40))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (stochrsi_k_4h_lt_20))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_3))
            # 15m & 1h down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_14_1d_lt_50))
            # 15m & 1h down move, 4h downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (cmf_20_4h_gt_neg_0_30))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_30))
            # 15m & 1h down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (stochrsi_k_1d_lt_50))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (roc_9_1d_lt_40))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (roc_9_1d_lt_50))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (aroonu_14_1d_lt_80))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_40) | (rsi_14_4h_lt_40))
            # 15m down move, 15m downtrend. 4h high
            & ((rsi_3_15m_gt_3) | (cmf_20_15m_gt_neg_0_50) | (aroonu_14_4h_lt_60))
            # 15m down move, 15m still not low enough
            & ((rsi_3_15m_gt_3) | (aroonu_14_15m_lt_30))
            # 15m down move, 4h high
            & ((rsi_3_15m_gt_3) | (aroonu_14_4h_lt_80))
            # 15m down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_3) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_40))
            # 15m & 1h & 4h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 1h downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_20))
            # 15m & 4h & 1d down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_15) | (stochrsi_k_1h_lt_50))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15) | (roc_9_1d_lt_70))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_80))
            # 15m down move, 15m still low, 4h still high
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_50))
            # 15m down move, 15m still high
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_50))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_70) | (roc_9_1h_lt_10))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_100))
            # 15m down move, 1h & 1d high
            & ((rsi_3_15m_gt_5) | (roc_9_1h_lt_10) | (roc_9_1d_lt_40))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_1d_lt_70))
            # 15m & 1h down move, 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (roc_9_4h_gt_neg_50))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_60) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (roc_9_1d_lt_80))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (aroonu_14_15m_lt_50))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (roc_9_4h_lt_50))
            # 15m & 1h down move, 1h high, 4h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_10))
            # 15m & 1h & 4h down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_50) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_30))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_30))
            # 15m & 4h down move, 4h still high, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_10))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_70))
            # 15m & 4h down move, 4h overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_55) | (roc_9_4h_lt_50))
            # 15m down move, 15m still not low enough, 1d downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_30) | (roc_9_1d_gt_neg_30))
            # 15m down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_30))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_lt_100))
            # 15m down move, 1d high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_1d_lt_85) | (cmf_20_1d_gt_neg_0_40))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_20))
            # 15m down move, 4h high
            & ((rsi_3_15m_gt_10) | (stochrsi_k_4h_lt_70))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_10) | (roc_9_4h_lt_10) | (roc_9_1d_lt_40))
            # 15m & 1h & 4h down move, 4h still high, 1d still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_45) | (stochrsi_k_1d_lt_50))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_15m_lt_60))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_50))
            # 15m & 1h & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_80))
            # 15m & 1h & 4h down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 15m still high, 1d high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (aroonu_14_15m_lt_50) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (aroonu_14_1h_lt_80))
            # 15m & 4h down move, 15m still high, 1d high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_40) | (aroonu_14_15m_lt_50) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_80))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_80))
            # 15m down move, 4h high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_60) | (roc_9_4h_gt_neg_20))
            # 15m down move, 1d high, 4h overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1d_lt_90) | (roc_9_4h_lt_40))
            # 15m down move, 1h & 4h overbought
            & ((rsi_3_15m_gt_15) | (roc_9_1h_lt_20) | (roc_9_4h_lt_40))
            # 15m down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_15) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_40))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_15) | (roc_9_4h_lt_20) | (roc_9_1d_lt_60))
            # 15m & 1h & 4h & 1d down move, 15m downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (cmf_20_15m_gt_neg_0_40))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (aroonu_14_15m_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (aroonu_14_4h_lt_90))
            # 15m & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_80))
            # 15m down move, 1h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_90))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_20))
            # 15m down move, 1h high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_80))
            # 15m down move, 4h high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_4h_lt_90))
            # 15m & 1h & 4h down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 15m still high, 1h high, 1d overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_35) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_20))
            # 15m & 4h down move, 15m high, 1d high & overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_80))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_20))
            # 15m & 1h & 4h down move, 1d high, 4h still not low enough
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100) | (stochrsi_k_4h_lt_30))
            # 15m & 1h & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_50) | (aroonu_14_1h_lt_100))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_50) | aroonu_14_4h_lt_100)
            # 15m down move, 15m high, 4h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_60) | (stochrsi_k_4h_lt_70))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_30) | (stochrsi_k_1h_lt_70) | (stochrsi_k_4h_lt_80))
            # 1h & 4h down move
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_3))
            # 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_5) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_40))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_5) | (stochrsi_k_4h_lt_20))
            # 1h & 4h down move, 15m stil high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_50))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_40))
            # 1h down move, 1h still not low enough
            & ((rsi_3_1h_gt_3) | (aroonu_14_1h_lt_20))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (rsi_3_1d_gt_15))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_30))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_30))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_5) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_70))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_5) | (aroonu_14_4h_lt_60) | (roc_9_1d_lt_10))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_30))
            # 1h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_1d_lt_100) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_20))
            # 1h & 4h down move, 15m downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_15m > -15.0))
            # 1h & 3h down move, 4h downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_50))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 15m still high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_40) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_80))
            # 1h down move, 15m still high, 4h high
            & ((rsi_3_1h_gt_10) | (aroonu_14_15m_lt_40) | (stochrsi_k_4h_lt_90))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_100))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_10))
            # 1h down move, 4h still high, 4d downtrend
            & ((rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_50) | roc_9_1d_gt_neg_50)
            # 1h down move, 4h downtrend, 1d overbought
            & ((rsi_3_1h_gt_10) | (roc_9_4h_gt_neg_10) | (roc_9_1d_lt_40))
            # 1h down move, 1d overbought
            & ((rsi_3_1h_gt_10) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80))
            # 1h down move, 1d downtrend, 1d high
            & ((rsi_3_1h_gt_15) | (cmf_20_1d_gt_neg_0_30) | (stochrsi_k_1d_lt_80))
            # 1h down move, 1h still high
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_60) | (roc_9_1d_lt_50))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_90))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_20))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_80))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 1d high & overbought, 1h downtrend
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_200) | (roc_9_1h_gt_neg_20))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_40) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_45) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_100))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_40))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_75))
            # 1h & 4h down move, 4h high, 1h downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80) | (roc_9_1h_gt_neg_40))
            # 1h & 4h down move, 15m & 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_70))
            # 1h & 4h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_80) | (roc_9_1d_gt_neg_50))
            # 1h down move, 1h still high, 1h & 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_40) | (roc_9_1h_gt_neg_10) | (roc_9_1d_gt_neg_50))
            # 1h down move, 1d high, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_80) | (roc_9_4h_gt_neg_40))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_200))
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_35) | (roc_9_4h_lt_20) | (roc_9_1d_lt_80))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_90))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_85) | (roc_9_1d_lt_80))
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_80) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1h downtrend, 1h & 4h high
            & ((rsi_3_1h_gt_50) | (cmf_20_1h_gt_neg_0_40) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 1h overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_70) | (roc_9_1h_lt_25))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_60) | (roc_9_1d_gt_neg_60))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_60) | (roc_9_4h_lt_30) | (roc_9_1d_lt_60))
            # 4h & 1d down move, 15m still high
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_15) | (stochrsi_k_15m_lt_40))
            # 4h & 1d down move, 1h still not low enough
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_15) | (stochrsi_k_1h_lt_30))
            # 4h & 1d down move, 1d still not low enough
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_30))
            # 4h down move, 1d high
            & ((rsi_3_4h_gt_3) | (aroonu_14_1d_lt_90))
            # 4h down move, 1h still high, 4h downtrend
            & ((rsi_3_4h_gt_3) | (stochrsi_k_1h_lt_50) | (roc_9_4h_gt_neg_30))
            # 4h down move, 1d high
            & ((rsi_3_4h_gt_3) | (stochrsi_k_1d_lt_90))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_3) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h down move, 1d overbought
            & ((rsi_3_4h_gt_3) | (roc_9_1d_lt_40))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_40))
            # 4h down move, 4h downtrend, 4h still high
            & ((rsi_3_4h_gt_5) | (cmf_20_4h_gt_neg_0_20) | (aroonu_14_4h_lt_40))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (roc_9_1d_gt_neg_40))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_60) | (roc_9_1d_gt_neg_40))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_60))
            # 4h down move, 4h high, 1h downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_60) | (roc_9_1h_gt_neg_20))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_15) | aroonu_14_4h_lt_70 | (aroonu_14_1d_lt_70))
            # 4h down move, 1h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_20) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80) | roc_9_1d_lt_50)
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_30) | aroonu_14_4h_lt_80 | roc_9_1d_lt_50)
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_40) | (roc_9_4h_lt_10) | roc_9_1d_lt_50)
            # 4h down move, 1h high, 1d overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_1h_lt_85) | roc_9_1d_lt_50)
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (rsi_14_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_50) | aroonu_14_4h_lt_80 | (roc_9_4h_lt_10))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_30))
            # 1d down move, 1h still high, 1d downtrend
            & ((rsi_3_1d_gt_5) | (stochrsi_k_1h_lt_50) | (roc_9_1d_gt_neg_30))
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_10) | aroonu_14_1h_lt_80 | (roc_9_1d_gt_neg_10))
            # 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1d_gt_10) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_40))
            # 1d down move, 1h still low, 4h high, 4h downtrend
            & ((rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_70) | (roc_9_4h_gt_neg_10))
            # 1d down move, 1h high & overbought
            & ((rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10))
            # 1d downtrend, 1d high & overbought
            & ((cmf_20_1d_gt_neg_0_30) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_100))
            # 15m high, 1h high & overbought
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_85) | (roc_9_1h_lt_10))
            # 1h high, 4h high, 1h overbought
            & (aroonu_14_1h_lt_70 | aroonu_14_4h_lt_100 | (roc_9_1h_lt_20))
            # 1h & 1d high, 1h overbought
            & (aroonu_14_1h_lt_70 | (aroonu_14_1d_lt_70) | (roc_9_1h_lt_20))
            # 1h & 4h high, 1d downtrend
            & ((aroonu_14_1h_lt_85) | aroonu_14_4h_lt_100 | (roc_9_1d_gt_neg_80))
            # 4h still high, 5m downtrend
            & ((aroonu_14_4h_lt_40) | (roc_9 > -40.0))
            # 4h high, 4h & 1d overbought
            & ((aroonu_14_4h_lt_60) | (roc_9_4h_lt_30) | (roc_9_1d_lt_60))
            # 4h & 1d high, 4h overbought
            & (aroonu_14_4h_lt_80 | aroonu_14_1d_lt_100 | (roc_9_4h_lt_30))
            # 4h & 1d high, 1d overbought
            & (aroonu_14_4h_lt_80 | aroonu_14_1d_lt_100 | roc_9_1d_lt_50)
            # 4h high, 4h & 1d overbought
            & (aroonu_14_4h_lt_80 | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 1d high, 1h & 4h downtrend
            & ((aroonu_14_1d_lt_85) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_50))
            # 1d high, 1h & 1d overbought
            & ((aroonu_14_1d_lt_85) | (roc_9_1h_lt_20) | (roc_9_1d_lt_100))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_90) | (roc_9_4h_lt_30) | (roc_9_1d_lt_60))
            # 1h high, 1d overbought
            & ((stochrsi_k_1h_lt_70) | (roc_9_1d_lt_40))
            # 4h high, 1h overbought, 1d downtrend
            & ((stochrsi_k_4h_lt_80) | (roc_9_1h_lt_40) | (roc_9_1d_gt_neg_70))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_1h_lt_20) | (roc_9_4h_lt_50))
            # 1h & 4h overbought
            & ((roc_9_1h_lt_100) | (roc_9_4h_lt_100))
            # 5m red, 1h & 4h down move
            & ((change_pct > -5.0) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_5))
            # big drop in last hough, 4h down move, 1h still not low enough
            & ((close > (close_max_12 * 0.90)) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_30))
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
          )

          # Logic
          long_entry_logic.append(
            (rsi_3_lt_50)
            & (aroonu_14_lt_25)
            & (stochrsi_k_lt_30)
            & (ema_26 > ema_12)
            & ((ema_26 - ema_12) > (open_rate * 0.030))
            & ((ema_26_shift_1 - ema_12_shift_1) > (open_rate / 100.0))
          )

        # Condition #62 - Rebuy mode (Long).
        if long_entry_condition_index == 62:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 4h down move, 1d high
            ((rsi_3_gt_3) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_90))
            # 5m & 1d down move, 15m still high
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_20) | (stochrsi_k_15m_lt_40))
            # 5m & 1h down move, 1d high & overbought
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_5) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_20))
            # 5m & 4h down move, 15m still high
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_50))
            # 5m & 4h down move, 4h still not low enough
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_20))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_20))
            # 15m & 1h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_14_4h_lt_30))
            # 15m & 1h & 4h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_80))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (rsi_14_4h_lt_50))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_40))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_25) | (aroonu_14_4h_lt_50))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_3) | (aroonu_14_4h_lt_20))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_20))
            # 15m & 1h down move, 15m still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (stochrsi_k_15m_lt_20))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_40))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_70))
            # 15m & 4h down move, 15m still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_30))
            # 15m & 4h down move, 1h downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_20))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1d_lt_20))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15) | (rsi_14_4h_lt_40))
            # 15m & 1h & 4h down move, 1h still not low enough, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (rsi_14_1h_lt_30) | (rsi_14_4h_lt_40))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_40))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_15m_lt_70))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_30))
            # 15m & 1h & 4h & 1d down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_40))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_100))
            # 15m & 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (aroonu_14_4h_lt_60))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_10))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_4h_lt_90))
            # 15m & 4h down move, 15m still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_15m_lt_20))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_90))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_30))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_70))
            # 15m & 4h down move, 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (cmf_20_4h_gt_neg_0_30))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_90))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_40) | (roc_9_1d_lt_200))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_75))
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_70) | (roc_9_1d_gt_neg_25))
            # 15m & 1h & 4h & 1d down move, 4h still not low enough
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_4h_lt_30))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_4h_lt_75))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_50) | (stochrsi_k_4h_lt_40))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_90))
            # 15m & 1h & 1d down move, 1h still high, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_90))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_60))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_40))
            # 15m down move, 15m downtrend, 4h high
            & ((rsi_3_15m_gt_15) | (cmf_20_15m_gt_neg_0_30) | (aroonu_14_4h_lt_50))
            # 15m down move, 15m still high, 4h overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_40) | (roc_9_4h_lt_40))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 15m & 4h down move, 1h downtrend, 15m still not low enough
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (cmf_20_1h_gt_neg_0_40) | (stochrsi_k_15m_lt_30))
            # 15m & 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 15m down move, 15m still not low enough, 1d overbought
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_30) | (roc_9_1d_lt_80))
            # 15m & 1h & 4h & 1d down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_60) | (aroonu_14_4h_lt_70))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_15m_lt_70))
            # 15m & 4h down move, 15m stil high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_30) | (stochrsi_k_15m_lt_40))
            # 15m down move, 15m still not low enough, 1d downtrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_25) | (roc_9_1d_gt_neg_50))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_80))
            # 15m & 1h & 4h down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_45) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50))
            # 15m & 1h & 1d down move, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_50) | (rsi_3_1d_gt_50) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_20))
            # 15m & 1h & 1d down move, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_50) | (rsi_3_1d_gt_50) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_10))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_70))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 1h high, 4h high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (stochrsi_k_4h_lt_80))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_40))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_50) | aroonu_14_4h_lt_70)
            # 1h down move, 15m still not low enough
            & ((rsi_3_1h_gt_3) | (stochrsi_k_15m_lt_20))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_3) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_15m_lt_30))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_4h_lt_30))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_20))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (roc_9_4h_gt_neg_30))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_20) | (rsi_14_4h_lt_30))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_40))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_15))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_60))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_30))
            # 1h & 4h down move, 1h downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_20))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_1d_lt_10))
            # 1h & 4h & 1d down move, 4h still high, 1d still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30) | (rsi_14_4h_lt_40) | (stochrsi_k_1d_lt_50))
            # 1h & 4h & 1d down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30) | (roc_9_4h_gt_neg_15) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_40))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_30))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_100))
            # 1h& 1d down move, 1h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_40))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_80))
            # 1h & 4h & 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_35) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_10))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_14_1d_lt_60))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_70))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_40))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_90))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_80))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_45) | (roc_9_1d_gt_neg_40))
            # 1h & 1d down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_15) | (stochrsi_k_4h_lt_80))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_100))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_20))
            # 1h & 4h down move, 4h & 1d still not low enough, 15m still not low enough
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_14_4h_lt_30) | (rsi_14_1d < 30.0) | (stochrsi_k_15m_lt_30))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (stochrsi_k_1d_lt_70))
            # 1h & 4h & 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_85) | (roc_2_1d > -30.0))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_70))
            # 1h & 4h down move, 4h overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (roc_9_4h_lt_10))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_45) | (aroonu_14_1d_lt_100))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_80))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_85))
            # 1h down move, 1h still not low enough, 4h stil high
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_20) | (aroonu_14_4h_lt_40))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_40))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1d_lt_80) | (roc_9_4h_gt_neg_20))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_80))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_1h_lt_20))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | roc_9_1d_lt_50)
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_60))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_60) | aroonu_14_1d_lt_100)
            # 1h down move, 4h high, 4h downtrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_70) | (cmf_20_4h_gt_neg_0_50))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 15m still high, 1d overbought
            & ((rsi_3_1h_gt_25) | (stochrsi_k_15m_lt_50) | (roc_9_1d_lt_30))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_100))
            # 1h & dh down move, 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_85))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_30) | (roc_9_4h_gt_neg_25) | (roc_9_1d_gt_neg_60))
            # 1h down move, 4h & 1h overbought
            & ((rsi_3_1h_gt_30) | (roc_9_4h_lt_30) | (roc_9_1d_lt_40))
            # 1h down move, 4h high, 4h downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70) | (cmf_20_4h_gt_neg_0_40))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_4h_gt_neg_30))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_80))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_20))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (roc_9_4h_lt_10) | (roc_9_1d_lt_30))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1d_lt_90) | (roc_9_4h_lt_40))
            # 1h & 4h down move, 1h & 4h high
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_45) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_80))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_30))
            # 1h & 1d down move, 4h & 1d high, 4h overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_1d_gt_55) | (stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_100))
            # 1h down move, 1h overbought
            & ((rsi_3_1h_gt_50) | (roc_9_1h_lt_40))
            # 1h & 4h & 1d down move, 1d high & overbought
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_50))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_60) | (roc_9_4h_lt_30) | (roc_9_1d_lt_100))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_3) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_40))
            # 4h & 1d down move, 4h still not low enough
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_30) | (aroonu_14_4h_lt_20))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_70))
            # 4h down move, 1h high, 4h downtrend
            & ((rsi_3_4h_gt_5) | (aroonu_14_1h_lt_70) | (roc_9_4h_gt_neg_20))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_5) | (aroonu_14_4h_lt_60))
            # 4h & 1d down move, 1d still not low enough
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_30))
            # 4h & 1d down move, 1h & 4h & 1d downtrend
            & (
              (rsi_3_4h_gt_10) | (rsi_3_1d_gt_30) | (roc_9_1h_gt_neg_10) | (roc_9_4h_gt_neg_15) | (roc_9_1d_gt_neg_25)
            )
            # 4h down move, 15m still high
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_40))
            # 4h down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (rsi_14_1d_lt_40) | (roc_9_1d_gt_neg_15))
            # 4h down move, 1h downtrend, 1d downtrend
            & ((rsi_3_4h_gt_15) | (cmf_20_1h_gt_neg_0_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 15m high, 1d overbought
            & ((rsi_3_4h_gt_15) | (aroonu_14_15m_lt_70) | (roc_9_1d_lt_100))
            # 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 4h down move, 15m still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_30) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_45) | (roc_9_1d_lt_40))
            # 4h down move, 15m high, 4h downtrend
            & ((rsi_3_4h_gt_20) | (aroonu_14_15m_lt_70) | (roc_9_4h_gt_neg_30))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_30))
            # 4h & 1d down move, 4h & 1d high
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (roc_9_1d_lt_10))
            # 4h down move, 15m high, 4h high
            & ((rsi_3_4h_gt_25) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_80))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_50) | (cmf_20_4h_gt_neg_0_40))
            # 4h down move, 4h high, 1d high
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_70) | (stochrsi_k_1d_lt_80))
            # 4h down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_30) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 4h down move, 4h still not low enough, 1d overbought
            & ((rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_20) | (roc_9_1d_lt_40))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_35) | (aroonu_14_1h_lt_70))
            # 4h down move, 1d high, 1d overbought, 4h downtrend
            & ((rsi_3_4h_gt_40) | (rsi_14_1d_lt_70) | (roc_9_1d_lt_200) | (roc_9_4h_gt_neg_10))
            # 4h down move, 4h still high, 1d high & overbought
            & ((rsi_3_4h_gt_40) | (rsi_14_4h_lt_50) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_150))
            # 4h down move, 15m & 4h still high
            & ((rsi_3_4h_gt_40) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_50))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_40) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_200))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_40) | (aroonu_14_4h_lt_100))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (rsi_14_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h overbought
            & ((rsi_3_4h_gt_55) | (roc_9_4h_lt_30))
            # 4h down move, 4h overbought
            & ((rsi_3_4h_gt_60) | (roc_9_4h_lt_40))
            # 1d down move, 4h high, 1d downtrend
            & ((rsi_3_1d_gt_10) | (stochrsi_k_4h_lt_90) | (roc_9_1d_gt_neg_50))
            # 1d down move, 4h & 1d downtrend
            & ((rsi_3_1d_gt_10) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_30))
            # 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1d_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_20))
            # 1d down move, 4h & 1d downtrend
            & ((rsi_3_1d_gt_15) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_40))
            # 1d down move, 15m still high, 1h high
            & ((rsi_3_1d_gt_40) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_90))
            # 4h & 1d downtrend, 1d high
            & ((cmf_20_4h_gt_neg_0_50) | (cmf_20_1d_gt_neg_0_50) | (aroonu_14_1d_lt_85))
            # 4h still not low enough, 4h & 1d downtrend
            & ((aroonu_14_4h_lt_30) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_25))
            # 4h & 1d high, 4h overbought
            & (aroonu_14_4h_lt_70 | aroonu_14_1d_lt_100 | (roc_9_4h_lt_30))
            # 4h & 1d high, 1d overbought
            & (aroonu_14_4h_lt_70 | aroonu_14_1d_lt_100 | (roc_9_1d_lt_80))
            # 4h high, 1h & 4h overbought
            & (aroonu_14_4h_lt_80 | (roc_9_1h_lt_40) | (roc_9_4h_lt_40))
            # 1d high, 4h downtrend, 1d overbought
            & ((aroonu_14_1d_lt_85) | (roc_9_4h_gt_neg_20) | (roc_9_1d_lt_200))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_90) | (roc_9_4h_lt_30) | (roc_9_1d_lt_60))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_70) | (roc_9_1h_lt_40) | (roc_9_4h_lt_40))
            # 4h high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_80) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 1d green, 4h down move, 4h still high
            & ((change_pct_1d_lt_40) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_40))
          )

          # Logic
          long_entry_logic.append(
            (rsi_3_lt_40)
            & (aroonu_14_lt_30)
            & (stochrsi_k_lt_20)
            & (stochrsi_k_15m_lt_70)
            & (willr_84_1h < -70.0)
            & (stochrsi_k_1h_lt_30)
            & (bbb_20_2_0_1h > 12.0)
            & (close_max_48 >= (close * 1.10))
          )

        # Condition #63 - Rebuy mode (Long).
        if long_entry_condition_index == 63:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            (rsi_3_15m_gt_5)
            # 5m & 1h down move, 1h still not low enough
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_30))
            # 5m & 1d down move, 1d downtrend
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_15) | (cmf_20_1d_gt_neg_0_25))
            # 5m down move, 1h high, 4h overbought
            & ((rsi_3_gt_3) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_20))
            # 5m down move, 1d high & overbought
            & ((rsi_3_gt_3) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_30))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_70))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_50))
            # 15m & 1h & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 15m & 1h down move 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (aroonu_14_15m_lt_50))
            # 15m & 1h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_50))
            # 15m & 1h down move 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (roc_9_4h_lt_10))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_50) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_90))
            # 15m & 1d down move, 1h high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_30))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_80))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_30))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_50))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_80))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_10) | (aroonu_14_1d_lt_70))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_75))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_50) | aroonu_14_4h_lt_80)
            # 15m down move, 1h still high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_50) | (roc_9_1d_lt_60))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_60) | (roc_9_1d_lt_60))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 15m down move, 1d high, 4h overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1d_lt_90) | (roc_9_4h_lt_10))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_50) | (stochrsi_k_4h_lt_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70))
            # 15m & 4h & 1h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_35) | (stochrsi_k_1d_lt_80))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_15m_lt_40))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (stochrsi_k_1d_lt_90))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (aroonu_14_15m_lt_60))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_60))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_100))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_50) | (stochrsi_k_4h_lt_80))
            # 15m down move, 4h high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_60) | (roc_9_4h_gt_neg_20))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_75) | (aroonu_14_1d_lt_100))
            # 15m down move, 15m still not low enough, 1h still high
            & ((rsi_3_15m_gt_15) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_50))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_15) | (roc_9_4h_lt_20) | (roc_9_1d_lt_60))
            # 15m & 1h & 4h & 1d down move, 15m downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (cmf_20_15m_gt_neg_0_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_70))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_85))
            # 15m down move, 1h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_75))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_80))
            # 15m down move, 15m high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_70) | (roc_9_1d_gt_neg_25))
            # 15m down move, 15m high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_60) | (roc_9_4h_gt_neg_50))
            # 15m down move, 4h overbought
            & ((rsi_3_15m_gt_20) | (roc_9_4h_lt_40))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (rsi_14_4h_lt_40))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_60))
            # 15m & 1h & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 15m still not low enough, 1h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_50))
            # 15m & 1h & 4h down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_70))
            # 15m & 1h & 4h down move, 1h & 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_40) | (roc_9_1d_lt_80))
            # 15m & 1h & 4h down move, 15m high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (stochrsi_k_15m_lt_80))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_60))
            # 15m down move, 1d high, 4h overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_1d_lt_80) | (roc_9_4h_lt_10))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_25) | (roc_9_4h_lt_10) | (roc_9_1d_lt_50))
            # 15m & 1h down move, 4h & 1d high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100))
            # 15m & 1h & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_80))
            # 15m down move, 15m downtrend, 4h high
            & ((rsi_3_15m_gt_30) | (cmf_20_15m_gt_neg_0_30) | (aroonu_14_4h_lt_100))
            # 15m down move, 15m still high, 1d high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_50) | (stochrsi_k_1d_lt_70))
            # 15m down move, 15m high, 4h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_60) | (stochrsi_k_4h_lt_70))
            # 15m down move, 4h high, 1h downtrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_4h_lt_85) | (roc_9_1h_gt_neg_40))
            # 15m down move, 4h high
            & ((rsi_3_15m_gt_30) | (stochrsi_k_4h_lt_90))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_45) | (aroonu_14_15m_lt_70))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_80))
            # 15m down move, 15m still high, 4h overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_40) | (roc_9_4h_lt_20))
            # 15m down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_40) | (roc_9_1d_lt_30))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_4h_lt_60) | (roc_9_4h_lt_20))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_35) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_20))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_40) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10))
            # 15m still high, 4h high
            & ((rsi_3_15m < 40.0) | (aroonu_14_4h_lt_85))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h > 2.0) | (rsi_3_4h_gt_15) | (rsi_14_4h_lt_30))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_3) | (stochrsi_k_15m_lt_30))
            # 1h & 4h down move, 15m downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_3) | (roc_9_15m > -30.0))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_40))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_40))
            # 1h & 4h down move, 4h stil high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_20) | (rsi_14_4h_lt_40))
            # 1h ^ 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (roc_9_1d_gt_neg_50))
            # 1h & 4h & 1d down mnove, 15m still high, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_15m_lt_40) | (stochrsi_k_1d_lt_50))
            # 1h & 1d down move, 4h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_1d_gt_10) | (stochrsi_k_4h_lt_40))
            # 1h & 1d down move, 1h downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_1d_gt_15) | (roc_9_1h_gt_neg_40))
            # 1h down move, 15m downtrend, 1h still high
            & ((rsi_3_1h_gt_3) | (cmf_20_15m_gt_neg_0_40) | (aroonu_14_1h_lt_40))
            # 1h down move, 15m still not low enough, 4h still high
            & ((rsi_3_1h_gt_3) | (aroonu_14_15m_lt_30) | (stochrsi_k_4h_lt_40))
            # 1h down move, 1h still not low enough
            & ((rsi_3_1h_gt_3) | (stochrsi_k_1h_lt_30))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_3) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_3) | (stochrsi_k_4h_lt_70))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_1d_lt_60))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_20))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_20))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_30))
            # 1h & 4h & 1d down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (rsi_14_4h_lt_30) | (roc_9_1d_gt_neg_30))
            # 1g & 4h & 1d down move, 1h still not low enough, 1d still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30) | (stochrsi_k_1h_lt_30) | (stochrsi_k_1d_lt_50))
            # 15m & 4h down move, 4h still not low enough, 15m still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_20) | (stochrsi_k_15m_lt_20))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_35) | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_40) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_10))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_60) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 1h down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_5) | (aroonu_14_1h_lt_40) | (stochrsi_k_1d_lt_90))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_30))
            # 1h down move, 4h downtrend
            & ((rsi_3_1h_gt_5) | (roc_9_4h_gt_neg_20))
            # 1h, 1d downtrend
            & ((rsi_3_1h_gt_5) | (roc_9_1d_gt_neg_50))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (rsi_14_4h_lt_30))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_30))
            # 1h & 4h down move, 15m still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_50))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_15m_lt_30))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_20))
            # & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (stochrsi_k_15m_lt_50))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_35) | (roc_9_1d_lt_70))
            # 1h & 4h & 1d down move, 1d still high, 1d overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_50) | (roc_9_1d_lt_40))
            # 1h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_40))
            # 1h & 1d down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_4h_lt_70))
            # 1h & 1d downtrend, 1d overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_45) | (roc_9_1d_lt_10))
            # 1h down move, 1h downtrend, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (cmf_20_1h_gt_neg_0_20) | (aroonu_14_1h_lt_30))
            # 1h down move, 1h downtrend, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (cmf_20_1h_gt_neg_0_20) | (stochrsi_k_1h_lt_30))
            # 1h down move, 1h downtrend
            & ((rsi_3_1h_gt_10) | (cmf_20_1h_gt_neg_0_30))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_50))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_20))
            # 1h & 4h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_70) | (roc_9_1d_lt_10))
            # 1h down move, 1d overbought
            & ((rsi_3_1h_gt_10) | (roc_9_1d_lt_100))
            # 1h & 4h & 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_35) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_10))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_30))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_15m < 90.0))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down mov, 1d overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_100))
            # 1h & 4h & 1d down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_40))
            # 1h & 4h & 1d down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_35) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_25))
            # 1h down move, 1d downtrend, 1d high
            & ((rsi_3_1h_gt_15) | (cmf_20_1d_gt_neg_0_30) | (stochrsi_k_1d_lt_80))
            # 1h down move, 1h still high
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_30))
            # 1h down move, 1h still high
            & ((rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_40))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_80))
            # 1h & 4h & 1d down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_1d_lt_70))
            # 1h & 4h & 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_85) | (roc_2_1d > -30.0))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_45) | (aroonu_14_1h_lt_60))
            # 1h & 1d down move, 1h & 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_70))
            # 1h & 1d down move, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_55) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_100))
            # 1h down move, 4h still high
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_40))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_25))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_10))
            # 1h & 4h down move, 1d high, 4h downtrend, 1d overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_20) | (roc_9_1d_lt_20))
            # 1h & 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_1h_lt_50) | (roc_9_1d_gt_neg_30))
            # 1h & 4h & 1d down move, 1d downtrend, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_45) | (cmf_20_1d_gt_neg_0_30) | (aroonu_14_1d_lt_70))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_85))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_50) | (roc_9_1d_lt_100))
            # 1h & 1d down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h still not low enough, 4h still high
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_30) | (stochrsi_k_4h_lt_50))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_40))
            # 1h down move, 1h still high, 1h downtrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_40) | (roc_9_1h_gt_neg_50))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_20))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_40))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_70))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_60))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50))
            # 1h & 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | aroonu_14_1h_lt_70)
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_90))
            # 1h down move, 1h still high, 1h & 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_40) | (roc_9_1h_gt_neg_10) | (roc_9_1d_gt_neg_50))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_100))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_30))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_80))
            # 1h down move, 4h & 1d high, 4h overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_30))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_20))
            # 1h down move, 1d high, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_200))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_90) | (roc_9_4h_gt_neg_40))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_80))
            # 1h down move, 1h & 4h still high
            & ((rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_50))
            # 1h down move, 1h highm 1d overbought
            & ((rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_60) | (roc_9_1d_lt_30))
            # 1h down move, 4h overbought
            & ((rsi_3_1h_gt_30) | (roc_9_4h_lt_50))
            # 1h & 4h & 1d down move, 1h & 4h still high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_50))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_40))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (roc_9_1d_gt_neg_25))
            # 1h down move, 1h still high, 4h & 1d downtrend
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_50) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_70))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_85) | (roc_9_4h_lt_100))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_100))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_200))
            # 1h & 1d down move, 1d high & overbought
            & ((rsi_3_1h_gt_40) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_30))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_40) | (rsi_14_1d_lt_80) | (roc_9_1d_lt_150))
            # 1h down move, 15m high, 1h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_70))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_80))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 1h & 4h overbought
            & ((rsi_3_1h_gt_40) | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (roc_9_1d_lt_200))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_70) | (roc_9_1h_lt_10))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_40))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_90) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_100))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_60) | (roc_9_1d_gt_neg_60))
            # 1h down move, 15m high, 1h high
            & ((rsi_3_1h_gt_55) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_80))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_90) | (roc_9_1h_lt_10))
            # 4h & 1d down move, 4h still not low enough
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_15) | (aroonu_14_4h_lt_20))
            # 4h down move, 1h still not low enough, 4h downtrend
            & ((rsi_3_4h_gt_3) | (stochrsi_k_1h_lt_20) | (roc_9_4h_gt_neg_30))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_3) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h & 1d down move, 1h downtrend
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_20) | (roc_9_1h_gt_neg_50))
            # 4h & 1d down move, 1d still high, 4h downtrend
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_40) | (roc_9_4h_gt_neg_10))
            # 4h down move, 1d high, 4h downtrend
            & ((rsi_3_4h_gt_5) | (aroonu_14_1d_lt_80) | (roc_9_4h_gt_neg_10))
            # 4h down move, 1h still high
            & ((rsi_3_4h_gt_5) | (stochrsi_k_1h_lt_50))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_4h_gt_neg_15) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_40) | (stochrsi_k_4h_lt_40))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_45) | (roc_9_1d_lt_10))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_80))
            # 4h down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1d high, 4h downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_85) | (roc_9_4h_gt_neg_20))
            # 4h down move, 15m high, 15m downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_60) | (roc_9_15m > -10.0))
            # 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_70))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h downtrend, 1d overbought
            & ((rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_30) | (roc_9_1d_lt_40))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_60))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_80))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_15) | (aroonu_14_1h_lt_50))
            # 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_50) | (roc_9_1d > -30.0))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 4h & 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_10))
            # 4h down move, 15m still high
            & ((rsi_3_4h_gt_20) | (aroonu_14_15m < 45.0))
            # 4h down move, 1h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_20) | (aroonu_14_1h_lt_30) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_100))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_80))
            # 4h down move, 15m still high, 4h high
            & ((rsi_3_4h_gt_25) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_70))
            # 4h down move, 1h & 4h still high
            & ((rsi_3_4h_gt_25) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_40))
            # 4h dowqn move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_30) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_50))
            # 4h down move, 1h high, 4h downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_4h_gt_neg_10))
            # 4h down move, 1d downtrend
            & ((rsi_3_4h_gt_30) | (roc_9_1d_gt_neg_50))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_40) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_80))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_40) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_40) | (roc_9_4h_lt_10) | (roc_9_1d_lt_50))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (rsi_14_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_40))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1h high, 1d overbought
            & ((rsi_3_4h_gt_60) | (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_30))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_20))
            # 1d down move, 1h & 4h still not low enough
            & ((rsi_3_1d_gt_5) | (stochrsi_k_1h_lt_20) | (stochrsi_k_4h_lt_20))
            # 1d down move, 1h & 1d high, 1d downtrend
            & ((rsi_3_1d_gt_15) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_10))
            # 15m down move, 1h high, 4h & 1d downtrend
            & ((rsi_3_1d_gt_15) | (aroonu_14_1h_lt_70) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_50))
            # 1d down move, 4h still high, 4h downtrend
            & ((rsi_3_1d_gt_15) | (stochrsi_k_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 1d down move, 1h still low, 4h high, 4h downtrend
            & ((rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_70) | (roc_9_4h_gt_neg_10))
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_70) | (roc_9_1d_gt_neg_60))
            # 1d down move, 1h & 4h high, 1d downtrend
            & ((rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_30))
            # 1d down move, 4h high, 1d downtrend
            & ((rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_60))
            # 1d down move, 1h high, 1h overbought, 1d downtrend
            & ((rsi_3_1d_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_1h_lt_10) | (roc_9_1d_gt_neg_40))
            # 1d down move, 1h high & overbought
            & ((rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10))
            # 1d down move, 1h high & overbought
            & ((rsi_3_1d_gt_40) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_80))
            # 1d down move, 4h high & overbought
            & ((rsi_3_1d_gt_45) | aroonu_14_4h_lt_80 | (roc_9_4h_lt_30))
            # 1h downtrend, 1h high
            & ((cmf_20_1h_gt_neg_0_20) | aroonu_14_1h_lt_80)
            # 4h & 1d downtrend, 1d high
            & ((cmf_20_4h_gt_neg_0_30) | (cmf_20_1d_gt_neg_0_30) | (stochrsi_k_1d_lt_60))
            # 1d downtrend, 1d high & overbought
            & ((cmf_20_1d_gt_neg_0_30) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_100))
            # 1d downtrend, 1d high & overbought
            & ((cmf_20_1d_gt_neg_0_40) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_20))
            # 15m still high, 1h overbought
            & ((aroonu_14_15m_lt_40) | (roc_9_1h_lt_40))
            # 15m still high, 4h overbought
            & ((aroonu_14_15m_lt_40) | (roc_9_4h_lt_80))
            # 15m still high, 1h high
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_85))
            # 15m still high, 4h high & overbought
            & ((aroonu_14_15m_lt_50) | aroonu_14_4h_lt_70 | (roc_9_4h_lt_30))
            # 15m still high, 4h downtrend, 1d overbought
            & ((aroonu_14_15m_lt_50) | (roc_9_4h_gt_neg_20) | (roc_9_1d_lt_40))
            # 1h still high, 4h & 1d downtrend
            & ((aroonu_14_1h_lt_40) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_40))
            # 1h high, 4h high, 1h overbought
            & (aroonu_14_1h_lt_70 | aroonu_14_4h_lt_100 | (roc_9_1h_lt_20))
            # 1h & 4h high, 4h overbought
            & (aroonu_14_1h_lt_70 | aroonu_14_4h_lt_100 | (roc_9_4h_lt_40))
            # 1h & 1d high, 1h overbought
            & (aroonu_14_1h_lt_70 | (aroonu_14_1d_lt_70) | (roc_9_1h_lt_20))
            # 1h high, 1h & 4h overbought
            & (aroonu_14_1h_lt_70 | (roc_9_1h_lt_10) | (roc_9_4h_lt_40))
            # 1h high, 1d downtrend
            & (aroonu_14_1h_lt_80 | (roc_9_1d_gt_neg_40))
            # 4h still not low enough, 4h & 1d downtrend
            & ((aroonu_14_4h_lt_30) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_25))
            # 4h still high, 1d high, 4h downtrend
            & ((aroonu_14_4h_lt_50) | aroonu_14_1d_lt_100 | (roc_9_4h_gt_neg_30))
            # 4h high, 1h & 1d downtrend
            & (aroonu_14_4h_lt_70 | (roc_9_1h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h & 1d high, 1d overbought
            & (aroonu_14_4h_lt_80 | aroonu_14_1d_lt_100 | roc_9_1d_lt_50)
            # 4h & 1d high, 4h overbought
            & (aroonu_14_4h_lt_100 | aroonu_14_1d_lt_100 | (roc_9_4h_lt_10))
            # 4h high, 1h & 4h overbought
            & (aroonu_14_4h_lt_100 | (roc_9_1h_lt_10) | (roc_9_4h_lt_40))
            # 1d high, 4h & 1d downtrend
            & ((aroonu_14_1d_lt_80) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 1d high, 1h & 4h downtrend
            & ((aroonu_14_1d_lt_85) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_50))
            # 1d high, 1h & 1d overbought
            & ((aroonu_14_1d_lt_85) | (roc_9_1h_lt_20) | (roc_9_1d_lt_100))
            # 1d high, 1h & 4h down move
            & (aroonu_14_1d_lt_100 | (roc_9_1h_lt_25) | (roc_9_4h_lt_60))
            # 1d high, 4h & 1d overbought
            & (aroonu_14_1d_lt_100 | (roc_9_4h_lt_20) | (roc_9_1d_lt_30))
            # 1h high, 4h & 1d overbought
            & ((stochrsi_k_1h_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_lt_100))
            # 4h still high, 4h & 1d downtrend
            & ((stochrsi_k_4h_lt_40) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_40))
            # 4h high, 1h & 1d downtrend
            & ((stochrsi_k_4h_lt_70) | (roc_9_1h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_70) | (roc_9_4h_lt_20) | (roc_9_1d_lt_30))
            # 4h high, 1h overbought, 1d downtrend
            & ((stochrsi_k_4h_lt_80) | (roc_9_1h_lt_40) | (roc_9_1d_gt_neg_70))
            # 4h high, 4h overbought
            & ((stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_1h_lt_20) | (roc_9_4h_lt_50))
            # 1d high, 4h & 1d overbought
            & ((stochrsi_k_1d_lt_90) | (roc_9_4h_lt_40) | (roc_9_1d_lt_100))
            # 1h & 4h overbought
            & ((roc_9_1h_lt_30) | (roc_9_4h_lt_80))
            # 1d green with top wick, 4h high
            & ((change_pct_1d_lt_30) | (top_wick_pct_1d_lt_20) | aroonu_14_4h_lt_80)
            # 1d top wick, 4h down move, 1d overbought
            & ((top_wick_pct_1d_lt_50) | (rsi_3_4h_gt_35) | (roc_9_1d_lt_60))
            # big drop in last hough, 4h down move, 1h still not low enough
            & ((close > (close_max_12 * 0.90)) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_30))
            # drop in last 20 days, 4h high
            & ((close > (high_max_20_1d * 0.10)) | (stochrsi_k_4h_lt_90))
            # drop in last 20 days, 1h high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | aroonu_14_1h_lt_70 | (roc_9_1d_gt_neg_70))
            # drop in last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
          )

          # Logic
          long_entry_logic.append(
            (rsi_3 > 0.0)
            & (rsi_3_lt_50)
            & (aroonu_14_lt_25)
            & (ema_26 > ema_12)
            & ((ema_26 - ema_12) > (open_rate * 0.022))
            & ((ema_26_shift_1 - ema_12_shift_1) > (open_rate / 100.0))
          )

        # Condition #64 - Trend Pullback mode (Long).
        if long_entry_condition_index == 64:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # Trend confirmation (higher TF must be bullish)
            (ema_12_4h > ema_200_4h)
            # 15m & 1h down move, 1h still high, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_50) | (roc_9_4h_lt_50))
            # 15m & 1h down move, 1h & 4h high, 1d overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_65) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_20))
            # 15m & 4h down move, 4h high, 1d high, 4h overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 15m down move, 1h & 4h high & overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 15m down move, 4h & 1d high, 4h overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 15m down move. 1d high, 4h overbought
            & ((rsi_3_15m_gt_25) | (stochrsi_k_1d_lt_90) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_50))
            # 15m & 1h down move, 4h high, 1h & 4h overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_70) | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 15m & 1h & 1d down move, 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_4h_lt_100))
            # 15m & 1h & 1d down move, 4h & 1d high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_45) | (rsi_3_1d_gt_65) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100))
            # 15m & 1h down move, 1h still high, 4h & 1d overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_40) | (roc_9_4h_lt_50) | (roc_9_1d_lt_50))
            # 15m & 1h down move, 4h high, 1h & 1d overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_55) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_20) | (roc_9_1d_lt_40))
            # 15m & 1d down move, 1h & 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_90))
            # 15m down move, 15m still not low enough, 4h high, 1d overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_20))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 15m down move, 4h high, 1d high, 4h overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_80))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_30) | (stochrsi_k_1h_lt_70) | (stochrsi_k_4h_lt_80))
            # 15m & 1h & 4h down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_70) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 4h & 1d high
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_40) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 15m & 1h down move, 1h still high, 4h high
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_70))
            # 15m & 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 1d high & overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_45) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_80))
            # 15m & 1h down move, 1d downtrend, 1d overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_50) | (cmf_20_1d_gt_neg_0_10) | (roc_9_1d_lt_50))
            # 15m & 1h & 1d down move, 15m still high, 1d high
            & (
              (rsi_3_15m_gt_35) | (rsi_3_1h_gt_55) | (rsi_3_1d_gt_65) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1d_lt_80)
            )
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_55) | (aroonu_14_1h_lt_75) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 1h & 4h high, 1h overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_75) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_10))
            # 15m & 1h down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_70) | (roc_9_1d_lt_100))
            # 15m & 1h down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_65) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_65) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_100))
            # 15m & 4h down move, 1h & 4h high
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_65) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_10))
            # 15m & 1d down move, 1d still high, 4h high, 1h overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_1d_gt_35) | (rsi_14_1d_lt_50) | (aroonu_14_4h_lt_80) | (roc_9_1h_lt_10))
            # 15m & 4h down move, 15m still high, 4h high, 1d overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_65) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_20))
            # 15m down move, 4h high, 1d high & overbought
            & ((rsi_3_15m_gt_35) | (stochrsi_k_4h_lt_70) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_30))
            # 15m down move, 1h & 1d overbought
            & ((rsi_3_15m_gt_40) | (roc_9_1h_lt_20) | (roc_9_1d_lt_100))
            # 15m & 1h & 4h down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_70) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 1d high, 4h & 1d overbought
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_40) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_30) | (roc_9_1d_lt_40))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_50) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_50) | (aroonu_14_1h_lt_70) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 1h high, 4h high, 1d overbought
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_55) | (aroonu_14_1h_lt_70) | (stochrsi_k_4h_lt_70) | (roc_9_1d_lt_80))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_60) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 1h still high, 1d high & overbought
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_65) | (rsi_14_1h_lt_50) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 1d high, 4h & 1d overbought
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_65) | (stochrsi_k_1d_lt_80) | (roc_9_4h_lt_50) | (roc_9_1d_lt_50))
            # 15m & 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_15m_gt_40) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_30))
            # 15m down move, 4h downtrend, 4h high & overbought
            & ((rsi_3_15m_gt_40) | (cmf_20_4h_gt_neg_0_10) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_20))
            # 15m down move, 15m still high
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_50))
            # 15m down move, 1h high
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_lt_80) | (stochrsi_k_1h_lt_80))
            # 15m down move, 1h & 4h high, 4h overbought
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_20))
            # 15m down move, 1h & 4h high, 1d overbought
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_10))
            # 15m down move, 4h & 1d high, 4h overbought
            & ((rsi_3_15m_gt_40) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_50))
            # 15m down move, 4h & 1d high, 4h overbought
            & ((rsi_3_15m_gt_40) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 15m down move, 4h high, 1h & 4h overbought
            & ((rsi_3_15m_gt_40) | (rsi_14_4h_lt_70) | (roc_9_1h_lt_20) | (roc_9_4h_lt_20))
            # 15m down move, 1h high, 1d high & overbought
            & ((rsi_3_15m_gt_40) | (stochrsi_k_1h_lt_60) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_10))
            # 15m down move, 1h & 4h & 1d high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_1h_lt_70) | (stochrsi_k_4h_lt_70) | (stochrsi_k_1d_lt_70))
            # 15m down move, 4h high, 1h & 4h overbought
            & ((rsi_3_15m_gt_40) | (stochrsi_k_4h_lt_90) | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 15m down move, 1d high & overbought\
            & ((rsi_3_15m_gt_40) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_80))
            # 15m & 1h & 4h down move, 15m & 4h high
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_55) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_80))
            # 15m & 1h & 1d down move, 15m high, 1h high
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_45) | (rsi_3_1d_gt_50) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_90))
            # 15m & 1h down move, 1d high, 4h overbought
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_45) | (aroonu_14_15m_lt_60) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 15m & 1h down move, 15m & 4h high, 1d overbought
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_45) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 15m still high, 4h high & overbought
            & (
              (rsi_3_15m_gt_45) | (rsi_3_1h_gt_45) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_10)
            )
            # 15m & 1h down move, 15m high, 4h high
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_55) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 1h high, 4h high, 4h overbought
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_55) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_10))
            # 15m & 1h & 1d down move, 15m high, 1h high
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_60) | (rsi_3_1d_gt_60) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_90))
            # 15m & 1h down move, 1h high, 4h high & overbought
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_40))
            # 15m & 1h down move, 15m & 1h still high
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_60) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_70) | (stochrsi_k_4h_lt_90))
            # 15m & 1h down move, 1h & 4h & 1d overbought
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_65) | (roc_9_1h_lt_20) | (roc_9_4h_lt_30) | (roc_9_1d_lt_50))
            # 15m & 4h down move, 15m & 4h high
            & ((rsi_3_15m_gt_45) | (rsi_3_4h_gt_60) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_70))
            # 15m & 1d down move, 15m & 4h high
            & ((rsi_3_15m_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_90))
            # 15m & 1d down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_45) | (rsi_3_1d_gt_50) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_20))
            # 15m & 1d down move, 15m still high, 1d high
            & ((rsi_3_15m_gt_45) | (rsi_3_1d_gt_65) | (aroonu_14_15m_lt_40) | (aroonu_14_1d_lt_100))
            # 15m down move, 15m high, 1h high
            & ((rsi_3_15m_gt_45) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_100))
            # 15m down move, 15m high, 4h high & overbought
            & ((rsi_3_15m_gt_45) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_25))
            # 15m down move, 15m & 4h high, 1d high
            & ((rsi_3_15m_gt_45) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_100) | (stochrsi_k_1d_lt_90))
            # 15m down move, 15m & 1h & 4h high
            & ((rsi_3_15m_gt_45) | (aroonu_14_15m_lt_80) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 15m down move, 15m high, 4h high & overbought
            & ((rsi_3_15m_gt_45) | (aroonu_14_15m_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 15m down move, 15m high, 1d high & overbought
            & ((rsi_3_15m_gt_45) | (aroonu_14_15m_lt_80) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 15m down move, 1h & 4h high, 1d overbought
            & ((rsi_3_15m_gt_45) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_20))
            # 15m down move, 4h & 1d high, 4h overbought
            & ((rsi_3_15m_gt_45) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 15m down move, 1h still high, 4h high, 4h overbought
            & ((rsi_3_15m_gt_45) | (stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_20))
            # 15m down move, 1h & 4h high, 1d overbought
            & ((rsi_3_15m_gt_45) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_30))
            # 15m down move, 1h still high, 4h high, 1h & 1d overbought
            & ((rsi_3_15m_gt_45) | (stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_70) | (roc_9_1h_lt_10) | (roc_9_1d_lt_30))
            # 15m down move, 4h & 1d high, 4h & 1d overbought
            & ((rsi_3_15m_gt_45) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20) | (roc_9_1d_lt_30))
            # 15m down move, 1d high, 1h & 4h & 1d overbought
            & ((rsi_3_15m_gt_45) | (aroonu_14_1d_lt_100) | (roc_9_1h_lt_10) | (roc_9_4h_lt_40) | (roc_9_1d_lt_40))
            # 15m down move, 4h high, 4h & 1d overbought
            & ((rsi_3_15m_gt_45) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_50) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_80))
            # 15m & 1h & 4h down move, 15m high, 1h high
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_55) | (rsi_3_4h_gt_60) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_80))
            # 15m & 1h & 4h & qd down move, 1d overbought
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (rsi_3_1d_gt_60) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_65) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_90))
            # 15m & 1h down move, 4h high, 1h overbought
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_80) | (roc_9_1h_lt_10))
            # 15m & 4h down move, 15m & 1h high, 1d overbought
            & ((rsi_3_15m_gt_50) | (rsi_3_4h_gt_50) | (aroonu_14_15m_lt_80) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_10))
            # 15m & 4h down move, 1h & 4h high, 1d overbought
            & ((rsi_3_15m_gt_50) | (rsi_3_4h_gt_65) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_10))
            # 15m down move, 15m high, 4h high, 1d overbought
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_40))
            # 15m down move, 15m & 4h & 1d high
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_75) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 15m down move, 15m still high, 4h high, 1d overbought
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_30))
            # 15m down move, 15m still high, 4h & 1d overbought
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_50) | (roc_9_4h_lt_20) | (roc_9_1d_lt_80))
            # 15m down move, 1h & 4h high, 1d overbought
            & ((rsi_3_15m_gt_50) | (stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 1h still high, 4h high
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_gt_55) | (rsi_14_1h_lt_50) | (stochrsi_k_4h_lt_90))
            # 15m & 1d down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_55) | (rsi_3_1d_gt_55) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_lt_90))
            # 15m down move, 15m high, 4h high, 1d overbought
            & ((rsi_3_15m_gt_55) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_30))
            # 15m down move, 1d high, 15m still high, 1d high
            & ((rsi_3_15m_gt_55) | (aroonu_14_1d_lt_100) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1d_lt_90))
            # 15m down move, 4h high, 1h & 4h overbought
            & ((rsi_3_15m_gt_55) | (stochrsi_k_4h_lt_90) | (roc_9_1h_lt_20) | (roc_9_4h_lt_20))
            # 15m down move, 4h high, 4h & 1d overbought
            & ((rsi_3_15m_gt_55) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_30) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 15m & 4h high
            & ((rsi_3_15m > 60.0) | (rsi_3_1h_gt_60) | (stochrsi_k_15m_lt_70) | (stochrsi_k_4h_lt_90))
            # 15m down move, 15m still high, 1h high, 4h high
            & ((rsi_3_15m > 60.0) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_60) | (stochrsi_k_4h_lt_80))
            # 1h down move, 15m still high, 1h still high, 4h high
            & ((rsi_3_1h_gt_25) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90))
            # 1h & 4h down move, 4h & 1d high, 4h overbought
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20))
            # 1h down move, 4h & 1d high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 1h & 1d down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90))
            # 1h & 1d down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_35) | (rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_80))
            # 1h down move, 15m high, 1h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_80))
            # 1h & 1d down move, 1d high & overbought
            & ((rsi_3_1h_gt_40) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_50))
            # 1h down move, 15m high, 4h high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_15m_lt_60) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_10))
            # 1h down move, 1h high, 1d still high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_50) | (roc_9_1d_lt_20))
            # 1h down move, 4h high, 4h & 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10) | (roc_9_1d_lt_15))
            # 1h down move, 4h & 1d high, 4h overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 4h high, 15m high, 4h high
            & ((rsi_3_1h_gt_45) | (rsi_14_4h_lt_70) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_90))
            # 1h down move, 4h high, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (rsi_14_4h_lt_70) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_30))
            # 15m & 1h down move, 1h & 4h & 1d high
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_45) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_50))
            # 1h & 1d down move, 1d high & overbought
            & ((rsi_3_1h_gt_50) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_20))
            # 1h down move, 15m high, 1h high, 1d overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_20))
            # 1h down move, 1h high, 1d high, 4h overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20))
            # 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_70) | (roc_9_1d_lt_10))
            # 1h down move, 4h high, 1h & 4h overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_80) | (roc_9_1h_lt_20) | (roc_9_4h_lt_30))
            # 1h down move, 4h & 1d high, 4h & 1d overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_30) | (roc_9_1d_lt_40))
            # 1h down move, 1h high, 4h & 1d overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_30) | (roc_9_1d_lt_80))
            # 1h & 4h down move, 1h & 4h high
            & ((rsi_3_1h_gt_55) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h still high, 4h high & overbought
            & ((rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_70) | (roc_9_4h_lt_60))
            # 1h & 4h down move, 1d high, 1d overbought
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_50))
            # 1h & 4h down move, 15m & 4h high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_65) | (stochrsi_k_15m_lt_70) | (stochrsi_k_4h_lt_80))
            # 1h & 4h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_10))
            # 1h down move, 15m & 1h & 4h high
            & ((rsi_3_1h_gt_60) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 4h high & overbought
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_60) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_80))
            # 1h down move, 1d downtrend, 1h high, 4h high
            & ((rsi_3_1h_gt_65) | (cmf_20_1d_gt_neg_0_10) | (aroonu_14_1h_lt_90) | (stochrsi_k_4h_lt_90))
            # 1h down move, 1d downtrend, 1h high, 4h high
            & ((rsi_3_1h_gt_65) | (cmf_20_1d_gt_neg_0_20) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h & 4h high, 1d overbought
            & ((rsi_3_1h_gt_65) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_30))
            # 1h down move, 1h high, 4h high
            & ((rsi_3_1h_gt_65) | (aroonu_14_1h_lt_100) | (stochrsi_k_4h_lt_90))
            # 1h down move, 4h high, 1d high & overbought
            & ((rsi_3_1h_gt_65) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_200))
            # 1h down move, 1h & 1d high & overbought
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_80) | (stochrsi_k_1d_lt_90) | (roc_9_1h_lt_10) | (roc_9_1d_lt_20))
            # 1h down move, 1h & 4h overbought
            & ((rsi_3_1h_gt_65) | (roc_9_1h_lt_80) | (roc_9_4h_lt_80))
            # 4h down move, 1h & 4h & 1d down move
            & ((rsi_3_4h_gt_55) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 4h & 1d down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_60) | (rsi_3_1d_gt_60) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_30))
            # 1h down move, 15m still high, 1h & 4h & 1d overbought
            & ((rsi_3_1h_gt_65) | (aroonu_14_15m_lt_50) | (roc_9_1h_lt_20) | (roc_9_4h_lt_30) | (roc_9_1d_lt_50))
            # 4h down move, 15m high, 4h high & overbought
            & ((rsi_3_4h_gt_65) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_30))
            # 4h down move, 1h high, 1h & 4h & 1d overbought
            & ((rsi_3_4h_gt_65) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10) | (roc_9_4h_lt_30) | (roc_9_1d_lt_50))
            # 4h down move, 4h & 1d high, 1d overbought
            & ((rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_10))
            # 4h up move, 4h high & overbought
            & ((rsi_3_4h_lt_90) | (rsi_14_4h_lt_70) | (aroonu_14_4h_lt_100) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_10))
            # 1d down move, 1h & 4h high, 1d overbought
            & ((rsi_3_1d_gt_40) | (stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_20))
            # 1d down move, 4h high, 1h & 4h overbought
            & ((rsi_3_1d_gt_40) | (stochrsi_k_4h_lt_80) | (roc_9_1h_lt_20) | (roc_9_4h_lt_20))
            # 1d down move, 1h high, 1h & 4h & 1d overbought
            & ((rsi_3_1d_gt_60) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_20) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 4h high, 1h & 4h downtrend, 4h high
            & ((rsi_14_4h_lt_70) | (cmf_20_1h_gt_neg_0_20) | (cmf_20_4h_gt_neg_0_30) | (stochrsi_k_4h_lt_70))
            # 4h high, 4h & 1d high, 4h high
            & ((rsi_14_4h_lt_70) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (stochrsi_k_4h_lt_90))
            # 4h high & overbought
            & ((rsi_14_4h_lt_80) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_10))
            # 1h & 4h downtrend, 4h high, 1d high
            & ((cmf_20_1h_gt_neg_0_20) | (cmf_20_4h_gt_neg_0_30) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 15m & 1h & 4h high
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100))
            # 15m & 4h & 1d high, 4h overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_50))
            # 15m & 4h & 1d high, 4h overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 15m high, 4h high, 1d overbought
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_50))
            # 15m high, 4h high, 4h & 1d overbought
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_lt_30))
            # 15m & 1h high, 4h overbought
            & ((aroonu_14_15m_lt_80) | (aroonu_14_1h_lt_100) | (roc_9_4h_lt_10))
            # 15m & 4h high, 1d overbought
            & ((aroonu_14_15m_lt_80) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_10))
            # 1h & 4h & 1d high, 4h overbought
            & ((aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20))
            # 1h & 4h & 1d high, 4h overbought
            & ((aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20))
            # 1h & 4h & 1d high, 1d overbought
            & ((aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_40))
            # 1h & 4h & 1d high, 1d overbought
            & ((aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 1h & 4h high, 1h & 4h & 1d overbought
            & ((aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_20) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 1h & 4h & 1d high, 1d overbought
            & ((aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 1h & 4h & 1d high
            & ((aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100))
            # 1h & 4h high, 1d overbought
            & ((aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_20))
            # 4h uptrend active
            & (aroonu_14_4h_gt_50)
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_80))
            # 4h & 1d high & overbought
            & ((aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10) | (roc_9_1d_lt_10))
            # 4h & 1d high, 4h overbought
            & ((aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_80))
            # 1d high, 1h & 4h & 1d overbought
            & ((aroonu_14_1d_lt_100) | (roc_9_1h_lt_10) | (roc_9_4h_lt_40) | (roc_9_1d_lt_100))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_100) | (roc_9_4h_lt_80) | (roc_9_1d_lt_80))
            # 15m still high, 1h & 4h high, 1d overbought
            & ((stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_70) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_20))
            # 1h still high, 1d high, 4h & 1d overbought
            & ((stochrsi_k_1h_lt_50) | (stochrsi_k_1d_lt_90) | (roc_9_4h_lt_30) | (roc_9_1d_lt_150))
            # 1h & 4h & 1d high, 1h overbought
            & ((stochrsi_k_1h_lt_70) | (stochrsi_k_4h_lt_70) | (stochrsi_k_1d_lt_70) | (roc_9_1h_lt_10))
            # 1h & 4h high, 1d overbought
            & ((stochrsi_k_1h_lt_90) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_20))
            # 1h & 1d high
            & ((stochrsi_k_1h_lt_90) | (stochrsi_k_1d_lt_90))
            # 4h & 1d high, 1d overbought
            & ((stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_50))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_1h_lt_20) | (roc_9_4h_lt_20))
            # 4h high, 1d overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_1d_lt_80))
            # Daily not crashing
            & (roc_9_1d > -5.0)
          )

          # Logic — Pullback in uptrend
          long_entry_logic.append(
            (rsi_3_gt_10)
            & (rsi_3_15m_gt_20)
            # & (rsi_3_1h_gt_20)
            & (rsi_14 < 45.0)
            & (willr_14 < -70.0)
            & (stochrsi_k_lt_30)
            & (aroonu_14_15m_lt_90)
            & (stochrsi_k_15m_lt_80)
            & (close < ema_12)
            & (close > ema_200)
            & (close > (bbl_20_2_0 * 1.01))
          )

        # Condition #65 - Breakout mode (Long).
        if long_entry_condition_index == 65:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # Trend confirmation
            (ema_12_4h > ema_200_4h)
            # 4h momentum mid-range
            & (rsi_14_4h_gt_50)
            & (rsi_14_4h_lt_68)
            # 1d up move, 1d not oversold
            & (roc_9_1d_gt_0)
            & (rsi_14_1d_gt_45)
            # 4h overbought, 1d up move, 4h money outflow
            & ((stochrsi_k_4h_lt_90) | (roc_9_1d_lt_20) | (cmf_20_4h_gt_neg_0_0))
            # 4h overbought & up move, 1d low
            & ((rsi_3_4h_lt_70) | (roc_9_4h_lt_5) | (stochrsi_k_1d_gt_70))
            # 15m up move, 4h low
            & ((rsi_3_15m_lt_90) | (stochrsi_k_4h_gt_30))
            # 1d overbought & up move
            & ((rsi_14_1d_lt_75) | (roc_9_1d_lt_30))
            # 1d high, 4h money outflow, 1h up
            & ((aroonu_14_1d_lt_100) | (cmf_20_4h_gt_neg_0_10) | (rsi_14_1h_lt_50))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_60))
            # 4h money outflow & up move
            & ((cmf_20_4h_gt_neg_0_10) | (roc_9_4h_lt_20))
            # 15m high, 1h down move, 1d up move
            & ((roc_9_1d_lt_40) | (rsi_3_1h_gt_60) | (stochrsi_k_15m_lt_50))
            # 1h high, 4h high & down move
            & ((aroonu_14_4h_lt_70) | (rsi_3_4h_gt_65) | (stochrsi_k_1h_lt_50))
            # 5m rollover, 1d low, 4h inflow, 1h narrow bands
            & ((rsi_14_change_pct_gt_0) | (rsi_14_1d_gt_60) | (cmf_20_4h_lt_0_15) | (bbb_20_2_0_1h_gt_20))
            # 1d down move, 1d high & overbought
            & (
              (rsi_3_1d_gt_65)
              | (rsi_3_change_pct_1d_gt_neg_20)
              | (stochrsi_k_1d_lt_70)
              | (rsi_14_1d_lt_60)
              | (roc_9_1d_gt_30)
            )
            # 1h low, 1d low
            & ((rsi_14_1h_gt_65) | (stochrsi_k_1d_gt_40) | (roc_9_1d_gt_25))
            # 15m volume spike, 1d low
            & ((stochrsi_k_1d_gt_70) | (obv_change_pct_15m_lt_50))
            # 15m high, 1d & 4h down move
            & ((aroonu_14_15m_lt_60) | (rsi_3_1d_gt_65) | (rsi_3_4h_gt_55))
            ####################################################################
            # 15m up move, 15m high, 4h high & overbought
            & ((rsi_3_15m_lt_85) | (stochrsi_k_15m_lt_70) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30))
            # 15m up move, 15m high, 1h high
            & ((rsi_3_15m_lt_90) | (aroonu_14_15m_lt_100) | (aroonu_14_1h_lt_100))
            # 15m up move, 1d high, 1h & 1d overbought
            & ((rsi_3_15m_lt_90) | (aroonu_14_1d_lt_100) | (roc_9_1h_lt_10) | (roc_9_1d_lt_20))
            # 15m up move, 15m high, 4h high
            & ((rsi_3_15m_lt_95) | (aroonu_14_15m_lt_90) | (stochrsi_k_4h_lt_80))
            # 15m up move, 15m high, 4h high
            & ((rsi_3_15m_lt_95) | (stochrsi_k_15m_lt_80) | (stochrsi_k_4h_lt_90))
            # 1h & 4h down move, 1d high, 4h & 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_80) | (roc_9_4h_lt_20) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_80))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_30))
            # 1h & 4h down move, 1h & 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_90))
            # 1h down move, 15m high, 4h overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_15m_lt_100) | (roc_9_4h_lt_40))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 1h down move, 4h high, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_40) | (roc_9_1d_lt_50))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_30))
            # 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_80))
            # 1h & 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_10))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_80))
            # 1h & 4h & 1d down move, 15m high
            & ((rsi_3_1h_gt_50) | (rsi_3_4h_gt_60) | (rsi_3_1d_gt_60) | (aroonu_14_15m_lt_80) | (stochrsi_k_15m_lt_80))
            # 1h & 4h down move, 15m high, 1d overbought
            & ((rsi_3_1h_gt_55) | (rsi_3_4h_gt_55) | (stochrsi_k_15m_lt_70) | (roc_9_1d_lt_20))
            # 1h down move, 4h high, 4h & 1d overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_15) | (roc_9_1d_lt_40))
            # 1h down move, 1h & 4h high & overbought
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_90) | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 1h down move, 1h & 4h high, 1d overbought
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_70) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_80))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_100))
            # 1h up move, 15m high, 1d overbought
            & ((rsi_3_1h_lt_90) | (aroonu_14_15m_lt_90) | (roc_9_1d_lt_50))
            # 1h up move, 4h downtrend, 15m & 1h high
            & ((rsi_3_1h_lt_95) | (cmf_20_4h_gt_neg_0_10) | (aroonu_14_15m_lt_100) | (aroonu_14_1h_lt_100))
            # 1h up move, 1d high, 1h & 4h overbought
            & ((rsi_3_1h_lt_95) | (stochrsi_k_1d_lt_90) | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_40))
            # 4h down move, 15m & 1d high, 4h & 1d overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 4h down move, 15m high, 1d overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_15m_lt_100) | (roc_9_1d_lt_60))
            # 4h down move, 15m & 4h high, 4h overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_20))
            # 4h down move, 1h high, 15m high
            & ((rsi_3_4h_gt_50) | (aroonu_14_1h_lt_100) | (stochrsi_k_15m_lt_80))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_50) | (roc_9_4h_lt_10) | (roc_9_1d_lt_200))
            # 4h down move, 15m high, 1d overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_15m_lt_90) | (roc_9_1d_lt_100))
            # 4h down move, 15m high, 4h overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_15m_lt_100) | (stochrsi_k_15m_lt_80) | (roc_9_4h_lt_40))
            # 4h down move, 1h high, 1d overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_1h_lt_100) | (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_60))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_4h_lt_60) | (roc_9_4h_lt_30))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_4h_lt_100) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_60) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_100))
            # 4h down move, 15m high, 4h overbought
            & ((rsi_3_4h_gt_60) | (stochrsi_k_15m_lt_70) | (roc_9_4h_lt_30))
            # 1d down move, 15m high, 1h high, 1d overbought
            & ((rsi_3_1d_gt_35) | (aroonu_14_15m_lt_90) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_20))
            # 1d down move, 1h & 4h high, 1h overbought
            & ((rsi_3_1d_gt_35) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_10))
            # 1d down move, 1h & 4h high, 1d overbought
            & ((rsi_3_1d_gt_40) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_70))
            # 1d down move, 15m high, 1d high
            & ((rsi_3_1d_gt_40) | (aroonu_14_15m_lt_100) | (aroonu_14_1d_lt_100))
            # 1d down move, 1h high & overbought
            & ((rsi_3_1d_gt_40) | (aroonu_14_1h_lt_100) | (roc_9_1h_lt_20))
            # 1d down move, 15m & 1h & 4h high
            & ((rsi_3_1d_gt_45) | (aroonu_14_15m_lt_90) | (aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100))
            # 1d down move, 1h high, 1d high & overbought
            & ((rsi_3_1d_gt_50) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_40))
            # 1d down move, 15m high, 1h high & overbought
            & ((rsi_3_1d_gt_55) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_100) | (roc_9_1h_lt_30))
            # 1d down move, 15m & 4h high, 1d overbought
            & ((rsi_3_1d_gt_55) | (aroonu_14_15m_lt_100) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_10))
            # 1d down move, 15m high, 1d high & overbought
            & ((rsi_3_1d_gt_60) | (aroonu_14_15m_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_40))
            # 1d down move, 15m high, 1h overbought
            & ((rsi_3_1d_gt_60) | (stochrsi_k_15m_lt_80) | (roc_9_1h_lt_10))
            # 1h & 4h downtrend, 15m & 1h high
            & ((cmf_20_1h_gt_neg_0_40) | (cmf_20_4h_gt_neg_0_40) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 1d downtrend, 1h high, 1d overbought
            & ((cmf_20_1d_gt_neg_0_20) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_20))
            # 15m & 1h high, 15m overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100) | (roc_9_15m_lt_20))
            # 15m & 1h high, 1h & 1d overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100) | (roc_9_1h_lt_20) | (roc_9_1d_lt_60))
            # 15m high, 1h high, 4h overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100) | (roc_9_4h_lt_100))
            # 15m high, 1d high, 4h overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_100))
            # 15m high, 1h high, 15m high, 1d high
            & ((aroonu_14_15m_lt_80) | (aroonu_14_1h_lt_100) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1d_lt_90))
            # 15m high, 1h high, 1d high, 1h overbought
            & ((aroonu_14_15m_lt_80) | (aroonu_14_1h_lt_100) | (stochrsi_k_1d_lt_80) | (roc_9_1h_lt_15))
            # 15m high, 1h high & overbought
            & ((aroonu_14_15m_lt_80) | (aroonu_14_1h_lt_100) | (roc_9_1h_lt_40))
            # 15m high, 1h high, 1d high & overbought
            & ((aroonu_14_15m_lt_90) | (aroonu_14_1h_lt_100) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_30))
            # 15m & 4h high, 1d overbought
            & ((aroonu_14_15m_lt_90) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_60))
            # 15m & 1h & 4h high
            & ((aroonu_14_15m_lt_100) | (aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100))
            # 15m & 1h & 1d high
            & ((aroonu_14_15m_lt_100) | (aroonu_14_1h_lt_100) | (aroonu_14_1d_lt_100))
            # 15m & 1h high, 1d overbought
            & ((aroonu_14_15m_lt_100) | (aroonu_14_1h_lt_100) | (stochrsi_k_15m_lt_70) | (roc_9_1d_lt_30))
            # 15m high, 1h high, 15m high
            & ((aroonu_14_15m_lt_100) | (aroonu_14_1h_lt_100) | (stochrsi_k_15m_lt_80))
            # 15m & 1h high, 1h overbought
            & ((aroonu_14_15m_lt_100) | (aroonu_14_1h_lt_100) | (roc_9_1h_lt_30))
            # 15m & 1h high, 1d overbought
            & ((aroonu_14_15m_lt_100) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_30))
            # 15m & 4h & 1d high
            & ((aroonu_14_15m_lt_100) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100))
            # 15m high, 4h high & overbought
            & ((aroonu_14_15m_lt_100) | (aroonu_14_4h_lt_100) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30))
            # 15m & 1d high, 4h overbought
            & ((aroonu_14_15m_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10))
            # 15m high, 1h high
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_80))
            # 15m high, 4h high
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_15m_lt_80) | (stochrsi_k_4h_lt_80))
            # 15m high, 1d high
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1d_lt_90))
            # 15m high, 4h & 1d overbought
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_15m_lt_80) | (roc_9_4h_lt_30) | (roc_9_1d_lt_50))
            # 15m high, 1d overbought
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_15m_lt_80) | (roc_9_1d_lt_60))
            # 15m high, 1h & 1d high
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_1h_lt_80) | (stochrsi_k_1d_lt_80))
            # 15m high, 1d overbought
            & ((aroonu_14_15m_lt_100) | (roc_9_1d_lt_100))
            # 1h & 1d high & overbought
            & ((aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_80) | (roc_9_1h_lt_30) | (roc_9_1d_lt_60))
            # 1h high, 1h & 1d overbought
            & ((aroonu_14_1h_lt_70) | (roc_9_1h_lt_30) | (roc_9_1d_lt_200))
            # 1h & 4h high, 1h & 4h overbought
            & ((aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 1h & 4h high, 1d overbought
            & ((aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_100))
            # 1h & 4h high, 15m high, 1d overbought
            & ((aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100) | (stochrsi_k_15m_lt_80) | (roc_9_1d_lt_40))
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_200))
            # 15m & 1h high, 1d high & overbought
            & ((stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_70) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 15m high, 1h high & overbought
            & ((stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_40))
          )

          # Logic — Breakout above BB upper with momentum
          long_entry_logic.append(
            (rsi_3 > 70.0)
            & (rsi_14 > 60.0)
            & (rsi_14 < 78.0)
            & (mfi_14 > 50.0)
            & (bbb_20_2_0 > 10.0)
            & (obv_change_pct_15m > 0.0)
            & (close > bbu_20_2_0)
            & (ema_12 > ema_26)
          )

        # Condition #68 - Triple Oversold Flush + Volume Accumulation (Long).
        if long_entry_condition_index == 68:
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(global_protections_long_pump == True)
          long_entry_logic.append(global_protections_long_dump == True)
          long_entry_logic.append(rsi_14_1d > 25.0)
          long_entry_logic.append(rsi_14_4h > 20.0)
          long_entry_logic.append(roc_9_1d > -25.0)
          long_entry_logic.append(
            ((rsi_3 > 2.0) | (rsi_3_15m > 5.0) | (rsi_3_1h > 10.0))
            & ((rsi_3_15m > 3.0) | (rsi_3_1h > 10.0) | (aroonu_14_4h < 90.0))
            & ((rsi_3_1h > 5.0) | (rsi_3_4h > 15.0) | (stochrsi_k_4h < 50.0))
            & ((rsi_3_15m > 5.0) | (rsi_3_4h > 20.0) | (roc_9_1d > -15.0))
            & ((rsi_3_1h > 10.0) | (roc_9_4h > -15.0) | (cmf_20_4h > -0.20))
          )
          long_entry_logic.append((rsi_14_1h > 25.0) | (rsi_14_4h > 25.0) | (rsi_3_1d > 15.0))
          # Daily selling pressure with a strong recent 4h rebound.
          long_entry_logic.append(aroonu_14_4h_lt_80 | (roc_9_1d > -10.0) | cmf_20_1d_gt_neg_0_0)
          # Hourly momentum weakened while daily fast momentum remains elevated.
          long_entry_logic.append((rsi_14_1h > 45.0) | (rsi_3_1d < 75.0))
          long_entry_logic.append(rsi_3 < 5.0)
          long_entry_logic.append(rsi_14 < 28.0)
          long_entry_logic.append(stochrsi_k < 3.0)
          long_entry_logic.append(willr_14 < -97.0)
          long_entry_logic.append(cmf_20 > 0.05)
          long_entry_logic.append(mfi_14 > 25.0)
          long_entry_logic.append(close < bbl_20_2_0)
          long_entry_logic.append(rsi_14_1h > 35.0)

        # Condition #101 - Rapid mode (Long).
        if long_entry_condition_index == 101:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(rsi_14_1h_lt_80)
          long_entry_logic.append(rsi_14_4h_lt_80)
          long_entry_logic.append(rsi_14_1d_lt_80)
          # big drop in the last hour
          long_entry_logic.append(
            (close > (close_max_12 * 0.50))
            # 5m & 4h down move, 1d downtrend
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 5m & 4h down move, 15m still high
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_50))
            # 5 & 15m down move, 1h high
            & ((rsi_3_gt_10) | (rsi_3_15m_gt_40) | (stochrsi_k_1h_lt_90))
            # 5m down move, 1h & 4h high
            & ((rsi_3_gt_10) | (aroonu_14_1h_lt_85) | (aroonu_14_4h_lt_90))
            # 15m & 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_50) | (rsi_14_1d_lt_40))
            # 15m & 1h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (stochrsi_k_4h_lt_30))
            # 15m & 1h down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (aroonu_14_1d_lt_40))
            # 15m & 1h & 4h down move, 4h still not low enough, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_20) | (rsi_14_1d_lt_50))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (rsi_14_4h_lt_40))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_75))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_30))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_20))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_30))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_30))
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_3) | (aroonu_14_15m_lt_20) | (stochrsi_k_1h_lt_60))
            # 15m down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_3) | (aroonu_14_15m_lt_30) | (stochrsi_k_4h_lt_70))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_3) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_30))
            # 15m & 1h & 1d down move
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (rsi_3_1d_gt_20))
            # 15m down move, 1h still not low enough, 1d high
            & ((rsi_3_15m_gt_5) | (stochrsi_k_1h_lt_30) | (aroonu_14_1d_lt_90))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_55) | (rsi_3_1d_gt_55) | (aroonu_14_1d_lt_80))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_30))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_80))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_50) | (stochrsi_k_1h_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_90))
            # 15m & 4h down move, 1d still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_1d_lt_40))
            # 15m & 4h & 1d down move, 4h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_40) | (aroonu_14_4h_lt_30))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_50))
            # 15m & 1d down move
            & ((rsi_3_15m_gt_5) | (rsi_3_1d_gt_5))
            # 15m & 1d down move, 4h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_30))
            # 15m down move, 1h still high, 4h high
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_50) | (stochrsi_k_4h_lt_90))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_80) | (roc_9_1h_lt_10))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_5) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_60) | (aroonu_14_4h_lt_40))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_70))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_50))
            # 15m & 1h & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_1d_lt_70))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_25))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_50))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_50) | aroonu_14_1h_lt_80)
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 15m still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_15m < 10.0))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_40))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (roc_9_1d_gt_neg_25))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_85))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_50))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_70))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_50))
            # 15m down move, 15m still not low enough, 1h still high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_lt_50))
            # 15m down move, 1h still high, 4h high
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_50) | (aroonu_14_4h_lt_85))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_70) | (stochrsi_k_4h < 75.0))
            # 15m & 1h down move, 15m still not low enough
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (stochrsi_k_15m_lt_30))
            # 15m & 1h & 4h & 1d down move, 4h still not low enough
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_30))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_90))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_55) | (aroonu_14_4h_lt_60) | (roc_9_4h_lt_30))
            # 15m & 4h & 1d down move
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_15))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_15) | rsi_3_4h_gt_20 | (stochrsi_k_1h_lt_50))
            # 15m & 4h down move, 15m still not low enough
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_15m_lt_30))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_50))
            # 1h & 1d down move, 1d overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_35) | (roc_9_1d_lt_10))
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_25) | (stochrsi_k_1h_lt_80))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_40))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_70) | (aroonu_14_4h_lt_85))
            # 15m & 1h & 4h down move, 5h & 1d downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_90))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_70))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_20))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_85))
            # 15m down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_25) | (aroonu_14_4h_lt_60))
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_25) | (stochrsi_k_15m_lt_30) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_70))
            # 15m & 1h & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (roc_9_1d_lt_150))
            # 15m & 1d down move, 1h & 1d high
            & ((rsi_3_15m_gt_30) | (rsi_3_1d_gt_30) | (stochrsi_k_1h_lt_70) | (stochrsi_k_1d_lt_80))
            # 1h & 4h down move, 15m downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_3) | (roc_9_15m > -30.0))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_25))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_50) | aroonu_14_4h_lt_70)
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (roc_9_4h_gt_neg_20))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (roc_9_4h_gt_neg_30))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | rsi_3_4h_gt_20 | (stochrsi_k_4h_lt_20))
            # 1h & 4h down move, 1d low
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (cmf_20_1d_gt_neg_0_20))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_20))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_30))
            # 1h & 1d down move, 5m moving down
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_15) | (roc_2 > -0.0))
            # 1h down move, 4h downtrend
            & ((rsi_3_1h_gt_10) | (roc_9_4h_gt_neg_30))
            # 1h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (roc_9_1d_gt_neg_30))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_15) | rsi_3_4h_gt_20 | (rsi_3_1d_gt_30))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_40))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (stochrsi_k_1h_lt_30))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_10) | (aroonu_14_1h_lt_40))
            # 1h down move, 1d high & overbought
            & (rsi_3_1h_gt_20 | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_30))
            # 1h down move, 1h still not low enough, 4h high
            & (rsi_3_1h_gt_20 | (stochrsi_k_1h_lt_20) | aroonu_14_4h_lt_80)
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_1h_lt_50))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_80))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (stochrsi_k_1h_lt_50))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_40))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100))
            # 1h down move, 1d high, 1h & 4h downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_90) | (roc_9_1h_gt_neg_25) | (roc_9_4h_gt_neg_35))
            # 1h down move, 15m high
            & ((rsi_3_1h_gt_35) | (stochrsi_k_15m_lt_80))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_20))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_60) | (stochrsi_k_1d_lt_70) | (roc_9_1d_lt_40))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_60) | (aroonu_14_4h_lt_90))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_3) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h down move, 15m still high
            & ((rsi_3_4h_gt_5) | (stochrsi_k_15m_lt_40))
            # 4h down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 4h down move, 15m 4h still high
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_40) | (aroonu_14_4h_lt_50))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | aroonu_14_4h_lt_70)
            # 4h down move, 1h still high
            & ((rsi_3_4h_gt_15) | (aroonu_14_1h_lt_50))
            # 4h down move, 4h still high
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_15) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_15))
            # 4h down move, 4h & 1d downtrend
            & (rsi_3_4h_gt_20 | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_30))
            # 4h dowqn move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_35) | aroonu_14_4h_lt_80 | aroonu_14_1d_lt_100)
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_40) | (rsi_3_1d_gt_10) | (stochrsi_k_4h_lt_50))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_60))
            # 4h down move, 4h still high
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_40))
            # 4h down move, 4h overbought
            & ((rsi_3_4h_gt_60) | (roc_9_4h_lt_20))
            # 4h up move, 1d downtrend, 4h high
            & ((rsi_3_4h_lt_90) | (cmf_20_1d_gt_neg_0_25) | (aroonu_14_4h_lt_100))
            # 1d down move, 1h still high, 4h high
            & ((rsi_3_1d_gt_20) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_85))
            # 1d down move, 1h high & overbought
            & ((rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10))
            # 1d down move, 4h high, 1d overbought
            & ((rsi_3_1d_gt_45) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_10))
            # 4h still high, 4h moving lower, 4h overbought
            & ((aroonu_14_4h_lt_50) | (aroonu_14_4h > aroonu_14_4h_shift_48) | (roc_9_4h_lt_40))
            # 1h high, 1d downtrend
            & ((aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_30))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_85) | (roc_9_4h_lt_60) | (roc_9_1d_lt_60))
            # 1d high, 4h & 1d overbought
            & (aroonu_14_1d_lt_100 | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 1h high, 4h downtrend
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_gt_neg_20))
            # 1h high, 4h overbought
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_lt_80))
            # 4h high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30) | (roc_9_1d_lt_30))
            # 1d high, 4h & 1d overbought
            & ((stochrsi_k_1d_lt_80) | (roc_9_4h_lt_60) | (roc_9_1d_lt_60))
            # 1d red, 4h down move, 1h still high
            & ((change_pct_1d_gt_neg_30) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_50))
            # pump, drop but not yet near the previous lows
            & (
              (((high_max_24_4h - low_min_24_4h) / low_min_24_4h) < 2.0)
              | (close > (high_max_6_4h * 0.75))
              | (close < (low_min_24_4h * 1.25))
            )
            # 4h high, drop but not yet near the previous lows
            & (aroonu_14_4h_lt_70 | (close > (high_max_6_4h * 0.80)) | (close < (low_min_24_4h * 1.25)))
            # 4h high, drop but not yet near the previous lows
            & (aroonu_14_4h_lt_80 | (close > (high_max_6_4h * 0.85)) | (close < (low_min_24_4h * 1.25)))
            # 1h down move, drop but not yet near the previous lows
            & ((rsi_3_1h_gt_30) | (close > (high_max_12_4h * 0.50)) | (close < (low_min_24_4h * 1.25)))
            # 1d overbought, drop but not yet near the previous lows
            & ((roc_9_1d_lt_50) | (close > (high_max_6_1d * 0.70)) | (close < (low_min_12_1d * 1.25)))
            # big drop in last hough, 4h down move, 1h still not low enough
            & ((close > (close_max_12 * 0.90)) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_30))
            # big drop in last 6 hours, 1d overbought
            & ((close > (high_max_6_1h * 0.65)) | roc_9_1d_lt_50)
            # big drop in last 4 hours, 4h still not low enough
            & ((close > (high_max_24_4h * 0.50)) | (stochrsi_k_4h_lt_30))
            # big drop in the last 4 days, 4h down move
            & ((close > (high_max_24_4h * 0.20)) | rsi_3_4h_gt_20)
            # big drop in the last 6 days, 1d down move
            & ((close > (high_max_6_1d * 0.30)) | (rsi_3_1d_gt_15))
            # big drop in the last 12 days, 4h high
            & ((close > (high_max_12_1d * 0.50)) | (stochrsi_k_4h_lt_90))
            # big drop in the last 30 days, 4h down move
            & ((close > (high_max_20_1d * 0.10)) | (rsi_3_4h_gt_30))
            # big drop in the last 20 days, 1h still high
            & ((close > (high_max_20_1d * 0.05)) | (aroonu_14_1h_lt_50))
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
            # big drop in the last 30 days, 1h down move
            & ((close > (high_max_30_1d * 0.25)) | (rsi_3_1h_gt_15))
          )

          # Logic
          long_entry_logic.append(
            (rsi_3_gt_3)
            & (rsi_14 < 36.0)
            & (aroonu_14_lt_25)
            & (stochrsi_k_lt_20)
            & (close < (sma_16 * 0.946))
            & (aroonu_14_15m_lt_50)
          )

        # Condition #102 - Rapid mode (Long).
        if long_entry_condition_index == 102:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(rsi_3_lt_46)
          long_entry_logic.append(rsi_3_15m_gt_5)
          long_entry_logic.append(rsi_3_1h_gt_10)
          long_entry_logic.append(rsi_3_4h_gt_10)
          # 5m & 15m down move, 4h still high
          long_entry_logic.append(
            ((rsi_3_gt_3) | (rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_50))
            # 5m & 15m down move, 15m still high
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_20) | (aroonu_14_15m_lt_40))
            # 5m & 15m down move, 1h still high
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_25) | (stochrsi_k_1h_lt_40))
            # 5m & 1h down move, 4h still high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_25) | (aroonu_14_4h_lt_50))
            # 5m & 4h & 1d down move
            & ((rsi_3_gt_3) | rsi_3_4h_gt_20 | (rsi_3_1d_gt_20))
            # 5m & 1d down move, 15m still high
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_10) | (stochrsi_k_15m_lt_40))
            # 5m down move, 15m high
            & ((rsi_3_gt_3) | (aroonu_14_15m_lt_70))
            # 5m down move, 15m & 1h still high
            & ((rsi_3_gt_3) | (stochrsi_k_15m_lt_40) | (aroonu_14_1h_lt_40))
            # 5m down move, 1h high
            & ((rsi_3_gt_3) | aroonu_14_1h_lt_70 | (stochrsi_k_1h_lt_50))
            # 5m & 1h down move, 1h high
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_60))
            # 5m & 4h down move, 4h high
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_50) | aroonu_14_4h_lt_70)
            # 5m down move, 15m still high, 1h high
            & ((rsi_3_gt_5) | (rsi_14_15m_lt_40) | aroonu_14_1h_lt_80)
            # 5m down move, 15m still high, 1h high
            & ((rsi_3_gt_5) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_50))
            # 5m down move, 15m & 4h high
            & ((rsi_3_gt_5) | (stochrsi_k_15m_lt_70) | (stochrsi_k_4h_lt_90))
            # 5m & 15m down move, 4h high
            & ((rsi_3_gt_10) | (rsi_3_15m_gt_20) | (aroonu_14_4h_lt_90))
            # 5m & 15m down move, 1d high
            & ((rsi_3_gt_10) | (rsi_3_15m_gt_20) | (stochrsi_k_1d_lt_80))
            # 5m & 15m down move, 1h high
            & ((rsi_3_gt_10) | (rsi_3_15m_gt_25) | (stochrsi_k_1h_lt_90))
            # 5m & 1h down move, 4h still high
            & ((rsi_3_gt_10) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_50))
            # 5m down move, 1h & 4h high
            & ((rsi_3_gt_10) | (aroonu_14_1h_lt_85) | (aroonu_14_4h_lt_90))
            # 5m down move, 4h high, 1d high
            & ((rsi_3_gt_10) | (aroonu_14_4h_lt_60) | (stochrsi_k_1d_lt_90))
            # 5m down move, 15m still high, 1h high
            & ((rsi_3_gt_15) | (rsi_14_15m_lt_40) | (stochrsi_k_1h_lt_90))
            # 5m down move, 15m still high, 4h high
            & ((rsi_3_gt_15) | (rsi_14_15m_lt_40) | (stochrsi_k_4h_lt_90))
            # 15m down move, 15m still not low enough, 1h high
            & (rsi_3_15m_gt_3 | (aroonu_14_15m_lt_20) | (stochrsi_k_1h_lt_60))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_10) | rsi_3_1h_gt_20 | (aroonu_14_1d_lt_70))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_10) | rsi_3_1h_gt_20 | (stochrsi_k_1h_lt_20))
            # 15m & 1h & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_1d_lt_70))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_30))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (stochrsi_k_4h_lt_40))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | aroonu_14_4h_lt_70)
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_30))
            # 15m& 4h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_40))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_10) | rsi_3_4h_gt_20 | (aroonu_14_15m_lt_50))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | rsi_3_4h_gt_20 | (stochrsi_k_4h_lt_30))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_50))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_40))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_10) | rsi_3_4h_gt_20 | (stochrsi_k_1h_lt_40))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_85))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_50))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | aroonu_14_4h_lt_70)
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_50))
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_lt_80))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_10) | aroonu_14_1h_lt_70 | (roc_9_4h_lt_50))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_40))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_50) | (stochrsi_k_1d_lt_70))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_45) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 15m still not low enough
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_45) | (stochrsi_k_15m_lt_50))
            # 15m & 4h & 1d down move
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_15))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_15) | rsi_3_4h_gt_20 | (aroonu_14_4h_lt_50))
            # 15m & 4h down move, 15m still not low enough
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_30) | (stochrsi_k_15m < 25.0))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_60))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_70))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_50))
            # 15m down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_14_15m_lt_35) | (stochrsi_k_4h_lt_90))
            # 15m down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_30) | (stochrsi_k_4h_lt_90))
            # 15m down move, 15m & 4h still high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_50))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_15) | (stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_70))
            # 15m down move, 1h still high, 4h high
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_60))
            # 15m down move, 4h still high 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_50) | roc_9_1d_lt_50)
            # 15m & 1h & 4h & 1d down move, 1h still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_40))
            # 15m & 1h down move, 15m still not low enough
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (aroonu_14_15m_lt_30))
            # 15m & 1h & 4h & 1d down move, 1h still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_90))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_40) | (aroonu_14_15m_lt_60))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_60))
            # 15m & 4h & 1d down move, 4h still high, 1d still high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_50) | (rsi_14_4h_lt_40) | (rsi_14_1d_lt_50))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_90))
            # 15m down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_14_15m_lt_35) | (rsi_14_4h < 85.0))
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_lt_80))
            # 15m down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_30) | (stochrsi_k_4h_lt_70))
            # 15m down move, 15m still high, 4d downtrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_40) | (roc_9_4h_gt_neg_20))
            # 15m down move, 15m still not low enough, 1h still high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_30) | (aroonu_14_1h_lt_50))
            # 15m down move, 15m & 1h still high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_lt_40))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_90))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_40) | (stochrsi_k_1d_lt_90))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_85))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_40) | (aroonu_14_15m_lt_50))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_4h_lt_70))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_30) | (stochrsi_k_1h_lt_80))
            # 15m down move, 15m & 1h still high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_lt_50))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_50) | (stochrsi_k_4h_lt_70))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_70) | (roc_9_1d_lt_100))
            # 15m down move, 15m high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_85))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_25) | aroonu_14_1h_lt_80 | (aroonu_14_4h_lt_90))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_25) | (stochrsi_k_1h_lt_70) | (aroonu_14_4h_lt_90))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_50))
            # 15m & 1h & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_60))
            # 15m & 1d down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_80))
            # 15m down move, 15m high, 4h still high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_50))
            # 15m down move, 15m still not low enough, 1h high
            & ((rsi_3_15m_gt_30) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_80))
            # 15m down move, 15m still high, 1d high, 1d downtrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_50) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
            # 15m down move, 1h still high, 4h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90))
            # 15m down move, 1d high, 4h & 1d overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_4h_lt_10) | (roc_9_1d_lt_80))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_70) | (stochrsi_k_1h_lt_70))
            # 15m down move, 15m & 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_70))
            # 15m down move, 15m high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_80))
            # 15m down move, 4h still high, 4h overbought
            & ((rsi_3_15m_gt_35) | (stochrsi_k_4h_lt_50) | (roc_9_4h_lt_20))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_40) | (rsi_14_15m_lt_50) | aroonu_14_1h_lt_80)
            # 15m down move, 15m high, 1h high
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_90))
            # 15m down move, 15m high
            & ((rsi_3_15m_gt_45) | (aroonu_14_15m_lt_90))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | rsi_3_4h_gt_20 | (rsi_14_4h_lt_40))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_50))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_40))
            # 1h & 1d down move, 4h downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_35) | (cmf_20_4h_gt_neg_0_40))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_30))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_70))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_70))
            # 1h down move, 1h still not low enough, 4h high
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_30) | (stochrsi_k_4h_lt_70))
            # 1h down move, 1d still high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1d_lt_50) | (roc_9_1d_gt_neg_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70) | roc_9_1d_gt_neg_50)
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_40))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (roc_9_4h_lt_10) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_55) | (stochrsi_k_4h_lt_80))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_20))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_40) | (rsi_14_4h_lt_75) | (roc_9_1d_lt_100))
            # 1h down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_85))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50) | (roc_9_1d_lt_20))
            # 1h down move 1h high & overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_90) | (roc_9_1h_lt_10))
            # 1h & 4h & 1d down move, 1h & 1d still high
            & ((rsi_3_1h_gt_50) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_50) | (stochrsi_k_1h_lt_40) | (stochrsi_k_1d_lt_40))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10))
            # 1h down move, 1d high, 1h overbought
            & ((rsi_3_1h_gt_60) | (aroonu_14_1d_lt_90) | (roc_9_1h_lt_10))
            # 4h & 1d down move, 1d still not low enough, 4h downtrend
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_30) | (roc_9_4h_gt_neg_20))
            # 4h down move, 4h still not low enough, 1d overbought
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_30) | (roc_9_1d_lt_100))
            # 4h down move, 1d high, 4h downtrend, 1d overbought
            & ((rsi_3_4h_gt_15) | (aroonu_14_1d_lt_100) | (roc_9_4h_gt_neg_20) | (roc_9_1d_lt_30))
            # 4h down move, 15m still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_50) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 15m still not low enough
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_15m_lt_30))
            # 4h down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_30) | (roc_9_1d_gt_neg_20))
            # 4h down move, 15m still high, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1d high, 4h downtrend
            & ((rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_90) | (roc_9_4h_gt_neg_20))
            # 4h & 1d down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (stochrsi_k_4h_lt_50) | (aroonu_14_1d_lt_60))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_30))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_40) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_100))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_20))
            # 4h down move, 15m high, 4h overbought
            & ((rsi_3_4h_gt_60) | (stochrsi_k_15m_lt_80) | (roc_9_4h_lt_20))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_60) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 1d down move, 1h & 4h still not low enough
            & ((rsi_3_1d_gt_5) | (stochrsi_k_1h_lt_20) | (stochrsi_k_4h_lt_20))
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_10) | (aroonu_14_1h_lt_85) | (roc_9_1d_gt_neg_30))
            # 1d down move, 15m still not low enough, 1h still high
            & ((rsi_3_1d_gt_15) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_lt_50))
            # 15m still not low enough, 1h high, 1d overbought
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_100))
            # 15m still high, 4h high & overbought
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30))
            # 15m & 1h & 4h high
            & ((aroonu_14_15m_lt_70) | aroonu_14_1h_lt_80 | (aroonu_14_4h_lt_90))
            # 15m & 1h high, 4h overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_90) | (roc_9_4h_lt_20))
            # 15m & 1d high, 1d overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_100))
            # 15m high
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_15m_lt_60))
            # 15m & 4h high
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_4h_lt_70))
            # 15m high, 1d overbought
            & ((aroonu_14_15m_lt_80) | roc_9_1d_lt_50)
            # 15m & 4h high
            & ((aroonu_14_15m_lt_90) | aroonu_14_4h_lt_70)
            # 15m & 1h high
            & ((aroonu_14_15m_lt_90) | (aroonu_14_1h_lt_90))
            # 1h still high, 4h high & overbought
            & ((aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_80))
            # 1h & 4h high, 1h overbought
            & (aroonu_14_1h_lt_80 | aroonu_14_4h_lt_100 | (roc_9_1h_lt_40))
            # 1h & 1d high, 1d overbought
            & (aroonu_14_1h_lt_80 | aroonu_14_1d_lt_100 | (roc_9_1d_lt_30))
            # 1h high, 4h & 1d overbought
            & ((aroonu_14_1h_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_lt_40))
            # 4h & 1d high, 4h overbought
            & (aroonu_14_4h_lt_80 | aroonu_14_1d_lt_100 | (roc_9_4h_lt_30))
            # 4h & 1d high, 1d overbought
            & (aroonu_14_4h_lt_70 | aroonu_14_1d_lt_100 | (roc_9_1d_lt_10))
            # 4h high & overbought
            & ((aroonu_14_4h_lt_90) | (stochrsi_k_4h < 85.0) | (roc_9_4h_lt_50))
            # 1d high, 4h & 1d overbought
            & (aroonu_14_1d_lt_100 | (roc_9_4h_lt_10) | roc_9_1d_lt_50)
            # 1d high, 4h & 1d overbought
            & (aroonu_14_1d_lt_100 | (roc_9_4h_lt_20) | (roc_9_1d_lt_40))
            # 4h high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_70) | (roc_9_4h_lt_30) | (roc_9_1d_lt_30))
            # 5m red, 1h still high
            & ((change_pct > -5.0) | (stochrsi_k_1h_lt_50))
            # 1d top wick, 4h down move, 4h still high
            & ((top_wick_pct_1d_lt_30) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_50))
            # pump, drop but not yet near the previous lows
            & (
              (((high_max_24_4h - low_min_24_4h) / low_min_24_4h) < 2.0)
              | (close > (high_max_6_4h * 0.75))
              | (close < (low_min_24_4h * 1.25))
            )
            # 4h high, drop but not yet near the previous lows
            & ((stochrsi_k_4h_lt_90) | (close > (close_max_48 * 0.85)) | (close < (low_min_24_1h * 1.25)))
            # 4h high, drop but not yet near the previous lows
            & (aroonu_14_4h_lt_70 | (close > (high_max_6_4h * 0.80)) | (close < (low_min_24_4h * 1.25)))
            # 1d overbought, drop but not yet near the previous lows
            & (roc_9_1d_lt_50 | (close > (high_max_6_1d * 0.70)) | (close < (low_min_12_1d * 1.25)))
            # big drop in the last 4 days, 4h down move
            & ((close > (high_max_24_4h * 0.20)) | rsi_3_4h_gt_20)
            # big drop in the last 12 days, 1h high
            & ((close > (high_max_12_1d * 0.30)) | (stochrsi_k_1h_lt_90))
            # big drop in the last 20 days, 1d down move
            & ((close > (high_max_20_1d * 0.40)) | (rsi_3_1d_gt_30))
            # big drop in the last 30 days, 4h down move, 4h still high
            & ((close > (high_max_30_1d * 0.25)) | (rsi_3_4h_gt_45) | (rsi_14_4h_lt_40))
            # big drop in the last 30 days, 1h high
            & ((close > (high_max_30_1d * 0.20)) | (stochrsi_k_1h_lt_80))
          )

          # Logic
          long_entry_logic.append(
            (willr_14 < -95.0) & (stochrsi_k < 10.0) & (close < (bbl_20_2_0 * 0.999)) & (close < (ema_20 * 0.960))
          )

        # Condition #103 - Rapid mode (Long).
        if long_entry_condition_index == 103:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(roc_2 > -0.0)
          long_entry_logic.append(
            # 15m & 1h & 4h down move, 15m still high
            ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (stochrsi_k_15m_lt_50))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_4h_lt_70) | (roc_9_1d_lt_80))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_80))
            # 15m & 1h & 1d down move, 1h & 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_60) | (rsi_3_1d_gt_60) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_80))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_20))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_10) | rsi_3_4h_gt_20 | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_30))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (aroonu_14_15m_lt_70))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_50))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_14_15m_lt_40) | (stochrsi_k_1h_lt_70))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_14_15m_lt_40) | (aroonu_14_4h_lt_90))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_90))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_70))
            # 15m down move, 15m high, 4h still high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_50))
            # 15m down move, 15m & 1h still high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_50))
            # 15m down move, 4h overbought
            & ((rsi_3_15m_gt_20) | (roc_9_4h_lt_70))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_80))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_90) | (stochrsi_k_1d_lt_90))
            # 15m down move, 1h & 1d high
            & ((rsi_3_15m_gt_25) | (stochrsi_k_1h_lt_80) | (stochrsi_k_1d_lt_90))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_25) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_20))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (aroonu_14_15m_lt_70))
            # 15m & 1h & 4h down move, 15m high, 4h overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_50) | (aroonu_14_15m_lt_70) | (roc_9_4h_lt_20))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_80))
            # 15m & 4h & 1d down move, 4h & 1d high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_55) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_90))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_30) | (stochrsi_k_1h_lt_70) | (aroonu_14_4h_lt_90))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_80))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_80))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_70) | (stochrsi_k_1h_lt_80))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_1h_lt_85) | (roc_9_4h_lt_80))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_40))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_20))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_50) | (stochrsi_k_15m_lt_80))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_10))
            # 1h & 4h & 1d down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_15) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_40))
            # 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_40))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_40))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_100))
            # 1h down move, 4h still high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_4h_gt_neg_20))
            # 1h & 4h down move, 1h high, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_90))
            # 1h & 1d down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_lt_60) | (roc_9_1d_lt_20))
            # 1h down move, 15m still not low enough, 4h high
            & ((rsi_3_1h_gt_20) | (aroonu_14_15m_lt_25) | (aroonu_14_4h_lt_80))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70) | (stochrsi_k_1d_lt_80))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_40))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (roc_9_4h_lt_10) | (roc_9_1d_lt_40))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_30) | (roc_9_4h_lt_30) | (roc_9_1d_lt_40))
            # 1h down move, 15m & 1h still high
            & ((rsi_3_1h_gt_40) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_lt_50))
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_30))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_50))
            # 1h down move, 1h overbought
            & ((rsi_3_1h_gt_40) | (roc_9_1h_lt_30))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 1h down move, 15m & 1h still high
            & ((rsi_3_1h_gt_50) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_85))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_20))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h down move, 1d high, 1d overbought, 4h downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_50) | (roc_9_4h_gt_neg_30))
            # 4h & 1d down move, 15m high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_15m_lt_60) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_10))
            # 4h & 1d down move, 15m downtrend, 4h still high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_50) | (cmf_20_15m_gt_neg_0_35) | (aroonu_14_4h_lt_50))
            # 4h down move, 15m & 1d high, 1h downtrend
            & ((rsi_3_4h_gt_20) | (aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1h_gt_neg_20))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 1h down move, 15m & 1h still high
            & ((rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_50))
            # 4h down move, 15m still high, 4h high
            & ((rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_50) | (aroonu_14_4h_lt_70))
            # 4h & 1d down move, 1h high & overbought
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_10))
            # 4h & 1d down move, 1d high & overbought
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_100))
            # 4h down move, 1h high, 4h downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_4h_gt_neg_10))
            # 4h down move, 1h high, 4h & 1d downtrend
            & ((rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_90) | (roc_9_4h_gt_neg_40) | (roc_9_1d_gt_neg_40))
            # 4h down move, 1d high, 1d overbought, 4h downtrend
            & ((rsi_3_4h_gt_40) | (rsi_14_1d_lt_70) | (roc_9_1d_lt_200) | (roc_9_4h_gt_neg_10))
            # 4h down move, 15m still not low enough, 4h high
            & ((rsi_3_4h_gt_35) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_70))
            # 1d down move, 4h & 1d high
            & ((rsi_3_1d_gt_55) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (rsi_14_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 15m still high, 1h high
            & ((rsi_3_4h_gt_60) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_90))
            # 4h down move, 1h high, 1d overbought
            & ((rsi_3_4h_gt_60) | (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_30))
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_10) | (aroonu_14_1h_lt_80) | (roc_9_1d_gt_neg_10))
            # 1d down move, 4h high
            & ((rsi_3_1d_gt_10) | (stochrsi_k_4h_lt_80))
            # 1d down move, 15m still high, 1h high
            & ((rsi_3_1d_gt_15) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_85))
            # 1d down move, 1h & 1d overbought
            & ((rsi_3_1d_gt_45) | (roc_9_1h_lt_80) | (roc_9_1d_lt_80))
            # 15m still high, 1h & 4h high
            & ((rsi_14_15m_lt_40) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_90))
            # 15m & 1h still high, 4h high
            & ((rsi_14_15m < 45.0) | (aroonu_14_1h_lt_40) | (stochrsi_k_4h_lt_70))
            # 15m still high, 4h high & overbought
            & ((rsi_14_15m_lt_50) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_80))
            # 15m still high, 1h high, 4h still high
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_90) | (stochrsi_k_4h_lt_50))
            # 15m still high, 1d high
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_1d_lt_90))
            # 15m & 1h
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_90))
            # 15m & 1h & 4h high
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_1h_lt_70) | (aroonu_14_4h_lt_90))
            # 1h & 1d high, 4h downtrend
            & ((aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h & 4h high, 4h overbought
            & (aroonu_14_1h_lt_70 | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_10))
            # 1h high, 1h & 1d overbought
            & ((aroonu_14_1h_lt_90) | (roc_9_1h_lt_10) | (roc_9_1d_lt_30))
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_10))
            # 4h high, 1h & 4h & 1d overbought
            & ((aroonu_14_4h_lt_80) | (roc_9_1h_lt_10) | (roc_9_4h_lt_20) | (roc_9_1d_lt_50))
            # 4h high, 4h & 1d overbought
            & ((aroonu_14_4h_lt_80) | (roc_9_4h_lt_80) | (roc_9_1d_lt_100))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_100) | (roc_9_4h_lt_10) | roc_9_1d_lt_50)
            # 15m still high, 1h high
            & ((stochrsi_k_15m_lt_40) | (aroonu_14_1h_lt_90) | (stochrsi_k_1h_lt_90))
            # 15m still high, 1d high
            & ((stochrsi_k_15m_lt_50) | (stochrsi_k_1d_lt_90))
            # 4h high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_80) | (roc_9_4h_lt_40) | (roc_9_1d_lt_100))
            # 1d green, 4h down move, 4h still high
            & ((change_pct_1d_lt_40) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_40))
            # 1d top wick, 4h high
            & ((top_wick_pct_1d_lt_30) | (aroonu_14_4h_lt_90))
            # pump, 4h overbought
            & ((((high_max_6_1h - low_min_6_1h) / low_min_6_1h) < 0.5) | (roc_9_4h_lt_50))
            # pump, drop but not yet near the previous lows
            & (
              (((high_max_24_4h - low_min_24_4h) / low_min_24_4h) < 2.0)
              | (close > (high_max_6_4h * 0.85))
              | (close < (low_min_24_4h * 1.25))
            )
            # pump, 1h high
            & ((((high_max_24_4h - low_min_24_4h) / low_min_24_4h) < 4.0) | (stochrsi_k_1h_lt_90))
            # big drop in the last 2 days, 1d down move
            & ((close > (high_max_12_4h * 0.30)) | (rsi_3_1d_gt_30))
            # big drop in the last 12 days, 1h still high
            & ((close > (high_max_12_1d * 0.25)) | (aroonu_14_1h_lt_50))
            # big drop in the last 12 days, 1h still not low enough
            & ((close > (high_max_12_1d * 0.10)) | (stochrsi_k_1h_lt_30))
            # big drop in the last 12 days, 15m still high
            & ((close > (high_max_12_1d * 0.20)) | (aroonu_14_15m_lt_50))
            # big drop in the last 20 days, 4h down move
            & ((close > (high_max_20_1d * 0.10)) | rsi_3_4h_gt_20)
          )

          # Logic
          long_entry_logic.append(
            (rsi_4 < 45.0) & (rsi_14 > 35.0) & (rsi_20 < rsi_20_shift_1) & (aroonu_14_lt_25) & (close < sma_16 * 0.960)
          )

        # Condition #104 - Rapid mode (Long).
        if long_entry_condition_index == 104:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          # 5m & 4h & 1d down move
          long_entry_logic.append(
            ((rsi_3_gt_3) | rsi_3_4h_gt_20 | (rsi_3_1d_gt_20))
            # 5m & 4h down move, 1d downtrend
            & ((rsi_3_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 5m & 1h down move, 1h still high
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_50))
            # 15m & 4h & 1d down move
            & (rsi_3_15m_gt_3 | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_15))
            # 15m & 1h down move
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_3))
            # 15m & 1h down move, 4h still not low enough
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_5) | (rsi_14_4h < 35.0))
            # 15m & 1h down move, 1d still high
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_50))
            # 15m & 1h down move, 1h still not low enough
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_30))
            # 15m & 4h down move, 4h still high
            & (rsi_3_15m_gt_3 | (rsi_3_4h_gt_30) | (rsi_14_4h_lt_40))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15))
            # 15m & 1h & 4h down move, 15m downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (cmf_20_15m_gt_neg_0_20))
            # 15m & 1h down move, 4h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_20))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_50))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50))
            # 15m & 1h down move, 15m & 1h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (cmf_20_15m_gt_neg_0_40) | (cmf_20_1h_gt_neg_0_40))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_20))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 15m & 1h & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_50))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_50))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (stochrsi_k_1h_lt_80))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_40) | (roc_9_4h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_80))
            # 15m & 4h & 1d down move, 1h still not low enough, 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_30) | (roc_9_4h_gt_neg_20))
            # 15m & 4h down move, 1h & 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (cmf_20_1h_gt_neg_0_20) | (cmf_20_4h_gt_neg_0_20))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_30))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_40))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_90))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_70))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_40))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (roc_9_1d_gt_neg_25))
            # 15m & 4h down move, 15m still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_20))
            # 15m & 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_40) | (roc_9_4h_gt_neg_10))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80))
            # 15m & 1d down move, 1h high, 4h downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_90) | (roc_9_4h_gt_neg_20))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_40))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_60))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_40))
            # 15m down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 15m down move, 1d high, 4h overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_50))
            # 15m & 1h & 4h & 1d down move, 15m downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (cmf_20_15m_gt_neg_0_40))
            # 15m & 3h down move, 15m still not low enough
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_20))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_45) | (stochrsi_k_1h_lt_80))
            # 15m & 1h & 4h down move, 4h downtrend
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (roc_9_4h_gt_neg_40))
            # 15m & 1d down move, 1d high, 1h downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_80) | (roc_9_1h_gt_neg_20))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_14_1h_lt_40))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_70))
            # 15m down move, 15m still not low enough, 1d overbought
            & ((rsi_3_15m_gt_25) | (stochrsi_k_15m_lt_20) | (roc_9_1d_lt_80))
            # 1h & 4h down move
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_30))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70))
            # 1h & 4h down move
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50))
            # 1h down move, 1h still high
            & ((rsi_3_1h_gt_5) | (aroonu_14_1h_lt_50))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_5) | (aroonu_14_4h_lt_85))
            # 1h & 4h down move
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_30))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_50))
            # 1h & 4h down move, 4h still high, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_40) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 1h & 1d down move, 1h still moving lower
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_15) | (cci_20_change_pct_1h_gt_neg_0))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_85) | (roc_9_4h_gt_neg_10))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_50))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_20))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_30))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (aroonu_14_1h_lt_80))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_70))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_70))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_50))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (stochrsi_k_1h_lt_50))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_70))
            # 4h & 1d down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_80))
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_70))
            # 1h down move, 4h high
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_90))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_25) | aroonu_14_1h_lt_70 | (aroonu_14_1d_lt_90))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_45) | aroonu_14_4h_lt_80)
            # 1h & dh down move, 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_85))
            # 1h down move, 4h still not low enough, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_30) | roc_9_1d_lt_50)
            # 1h down move, 1h still not low enough, 4h downtrend
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_30) | (roc_9_4h_gt_neg_20))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_40) | (roc_9_4h_lt_10) | roc_9_1d_lt_50)
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_20))
            # 4h down move, 15m not low enough, 1h still high
            & ((rsi_3_4h_gt_3) | (stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_40))
            # 4h & 1d down move, 4h downtrend
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_20) | (roc_9_4h_gt_neg_20))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_70))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_5) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1d still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_5) | (stochrsi_k_1d_lt_30) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d high & overbought
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 4h down move, 1h downtrend, 1h still not low enough
            & ((rsi_3_4h_gt_10) | (cmf_20_1h_gt_neg_0_25) | (aroonu_14_1h_lt_30))
            # 4h down move, 1h & 1d downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_45) | (stochrsi_k_4h_lt_40))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_60))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_50))
            # 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_50) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_80))
            # 4h down move, 1d high, 1h downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_70) | (roc_9_1h_gt_neg_10))
            # 4h down move, 4h still high, 1d overbought
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_40) | (roc_9_1d_lt_100))
            # 4h down move, 4h high, 1h downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_80) | (roc_9_1h_gt_neg_30))
            # 4h down move, 4h still high, 1d overbought
            & ((rsi_3_4h_gt_35) | (aroonu_14_4h_lt_50) | (roc_9_1d_lt_40))
            # 4h down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_40) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_100))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_40) | (roc_9_4h_lt_10) | (roc_9_1d_lt_50))
            # 1d down move, 1h still not low enough
            & ((rsi_3_1d_gt_5) | (stochrsi_k_1h_lt_20))
            # 1h & 4h high, 4h overbought
            & ((aroonu_14_1h_lt_60) | aroonu_14_4h_lt_100 | (roc_9_4h_lt_30))
            # 4h & 1d high, 4h overbought
            & ((aroonu_14_4h_lt_60) | aroonu_14_1d_lt_100 | (roc_9_4h_lt_40))
            # 4h & 1d high,1d overbought
            & (aroonu_14_4h_lt_70 | aroonu_14_1d_lt_100 | roc_9_1d_lt_50)
            # 1d red, 4h down move, 1h still high
            & ((change_pct_1d_gt_neg_30) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_50))
            # 1d top wick, 4h down move, 1d high
            & ((top_wick_pct_1d_lt_20) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100))
            # pump, drop but not yet near the previous lows
            & (
              (((high_max_24_4h - low_min_24_4h) / low_min_24_4h) < 2.0)
              | (close > (high_max_12_4h * 0.60))
              | (close < (low_min_24_4h * 1.10))
            )
            # pump, drop but not yet near the previous lows
            & (
              (((high_max_12_1d - low_min_12_1d) / low_min_12_1d) < 5.0)
              | (close > (high_max_6_1d * 0.30))
              | (close < (low_min_12_1d * 1.25))
            )
            # big drop in the last hour
            & (close > (close_max_12 * 0.50))
            # big drop in the last 12 days, 15m & 4h down move
            & ((close > (high_max_12_1d * 0.40)) | (rsi_3_15m_gt_10) | (rsi_3_4h_gt_10))
            # big drop in the last 20 days, 15m & 1h down move
            & ((close > (high_max_20_1d * 0.40)) | (rsi_14_15m < 10.0) | (rsi_14_1h < 10.0))
            # big drop in the last 20 days, 1d down move
            & ((close > (high_max_20_1d * 0.25)) | (rsi_3_1d_gt_30))
            # big drop in the last 20 days, 4h still not low enough
            & ((close > (high_max_20_1d * 0.10)) | (rsi_14_4h_lt_30))
            # big drop in the last 30 days, 4h down move
            & ((close > (high_max_30_1d * 0.25)) | rsi_3_4h_gt_20)
          )

          # Logic
          long_entry_logic.append(
            (rsi_3_lt_40)
            & (aroonu_14_lt_25)
            & (stochrsi_k_lt_20)
            & (aroonu_14_15m_lt_25)
            & (stochrsi_k_15m_lt_30)
            & (close < ema_16 * 0.975)
            & (((ema_50 - ema_200) / close * 100.0) < -5.5)
          )

        # Condition #105 - Williams %R snapback (Long, experimental — Goodwin mean-reversion port).
        if long_entry_condition_index == 105:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            # 5m down move, 15m high
            ((rsi_3_gt_10) | (aroonu_14_15m_lt_75))
            # 5m down move, 4h overbought, 1d still high
            & ((rsi_3_gt_10) | (roc_9_4h_lt_5) | (stochrsi_k_1d_lt_50))
            # 5m down move, 4h & 1d high
            & ((rsi_3_gt_10) | (stochrsi_k_4h_lt_70) | (aroonu_14_1d_lt_75))
            # 5m down move, 1d high
            & ((rsi_3_gt_15) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d_lt_80))
            # 5m & 1h & 1d down move
            & ((rsi_3_gt_15) | (rsi_3_1h_gt_20) | (rsi_3_1d_gt_60))
            # 5m & 4h down move, 4h high
            & ((rsi_3_gt_15) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_70))
            # 5m down move, 15m still not low enough, 4h overbought
            & ((rsi_3_gt_15) | (stochrsi_k_15m_lt_20) | (roc_9_4h_lt_5))
            # 5m down move, 4h & 1d high
            & ((rsi_3_gt_15) | (stochrsi_k_4h_lt_70) | (stochrsi_k_1d_lt_60))
            # 5m still not low enough, 15m downtrend
            & ((aroonu_14_lt_25) | (roc_9_15m > -7.0))
            # 5m still not low enough, 15m down move, 4h overbought
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_20) | (roc_9_4h_lt_5))
            # 5m still not low enough, 1h down move, 4h high
            & ((aroonu_14_lt_25) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_70))
            # 5m still not low enough, 4h down move, 1d high
            & ((aroonu_14_lt_25) | (rsi_3_4h_gt_45) | (aroonu_14_1d_lt_75))
            # 5m still not low enough, 4h high, 1d still high
            & ((aroonu_14_lt_25) | (stochrsi_k_4h_lt_70) | (stochrsi_k_1d_lt_40))
            # 5m & 15m still not low enough
            & ((aroonu_14_lt_25) | (stochrsi_k_lt_30) | (aroonu_14_15m_lt_30))
            # 5m still not low enough, 15m still high
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_40))
            # 5m still not low enough, 4h down move & high
            & ((aroonu_14_lt_30) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_60))
            # 5m & 1h still not low enough
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_lt_20))
            # 5m still not low enough, 4h high, 1d still high
            & ((aroonu_14_lt_30) | (stochrsi_k_4h_lt_60) | (stochrsi_k_1d_lt_40))
            # 5m still not low enough, 4h still high
            & ((aroonu_14_lt_30) | (stochrsi_k_lt_30) | (aroonu_14_4h_lt_50))
            # 5m still not low enough, 4h overbought, 1d still high
            & ((stochrsi_k_lt_20) | (roc_9_4h_lt_5) | (stochrsi_k_1d_lt_50))
            # 5m & 1h still not low enough, 15m down move
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_15) | (aroonu_14_1h_lt_20))
            # 5m still not low enough, 15m down move, 1d overbought
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_20) | (roc_9_1d_lt_40))
            # 5m still not low enough, 15m down move, 1d downtrend
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_30) | (roc_9_1d_gt_neg_10))
            # 5m & 15m still not low enough, 15m down move
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_30) | (stochrsi_k_15m_lt_20))
            # 5m & 1h still not low enough, 1h down move
            & ((stochrsi_k_lt_20) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_20))
            # 5m & 4h still not low enough, 1d high
            & ((stochrsi_k_lt_20) | (stochrsi_k_4h_lt_30) | (stochrsi_k_1d_lt_60))
            # 5m & 15m & 1d still not low enough
            & ((stochrsi_k_lt_30) | (aroonu_14_15m_lt_20) | (aroonu_14_1d_lt_30))
            # 5m & 15m still not low enough, 4h high
            & ((stochrsi_k_lt_30) | (aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_80))
            # 5m & 15m still not low enough
            & ((stochrsi_k_lt_30) | (aroonu_14_15m_lt_25) | (stochrsi_k_15m_lt_20))
            # 5m & 15m still not low enough, 4h high
            & ((stochrsi_k_lt_30) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_70))
            # 5m still not low enough, 1h still high, 4h down move
            & ((stochrsi_k_lt_30) | (aroonu_14_1h_lt_40) | (rsi_3_4h_gt_25))
            # 5m still not low enough, 1h & 4h still high
            & ((stochrsi_k_lt_30) | (aroonu_14_1h_lt_50) | (stochrsi_k_4h_lt_40))
            # 5m still not low enough, 4h high, 1d still high
            & ((stochrsi_k_lt_30) | (aroonu_14_4h_lt_80) | (stochrsi_k_1d_lt_40))
            # 5m & 1d still not low enough, 4h high
            & ((stochrsi_k_lt_30) | (aroonu_14_4h_lt_90) | (stochrsi_k_1d_lt_30))
            # 5m still not low enough, 4h high
            & ((stochrsi_k_lt_30) | (aroonu_14_4h_lt_90) | (stochrsi_k_4h_lt_80))
            # 5m still not low enough, 15m & 1h down move
            & ((stochrsi_k_lt_30) | (rsi_3_15m_gt_20) | (rsi_3_1h_gt_10))
            # 5m still not low enough, 1h down move, 4h high
            & ((stochrsi_k_lt_30) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_80))
            # 5m still not low enough, 4h & 1d down move
            & ((stochrsi_k_lt_30) | (rsi_3_4h_gt_55) | (rsi_3_1d_gt_55))
            # 5m still not low enough, 4h still high, 1d high
            & ((stochrsi_k_lt_30) | (stochrsi_k_4h_lt_40) | (aroonu_14_1d_lt_80))
            # 5m overbought, 15m still not low enough
            & ((roc_9 < 0.5) | (aroonu_14_15m_lt_20))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_60) | (stochrsi_k_4h_lt_70))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_80))
            # 15m down move, 4h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_90) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (roc_9_1d_lt_60))
            # 15m & 4h down move, 1d still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_30))
            # 15m down move & still not low enough, 1d overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_15m_lt_20) | (roc_9_1d_lt_20))
            # 15m down move, 4h high, 1d still high
            & ((rsi_3_15m_gt_10) | (stochrsi_k_4h_lt_80) | (aroonu_14_1d_lt_40))
            # 15m & 1d down move
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_45))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_60))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_70))
            # 15m down move, 4h high, 1d still high
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_70) | (stochrsi_k_1d_lt_40))
            # 15m down move, 4h & 1d low
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_gt_20) | (stochrsi_k_1d_gt_30))
            # 15m down move, 4h high, 1d still high
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_80) | (stochrsi_k_1d_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_80))
            # 15m & 4h down move, 15m still not low enough
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_20) | (rsi_3_4h_gt_35))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_20) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_0))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_80) | (stochrsi_k_1d_lt_80))
            # 15m down move & still not low enough, 4h high
            & ((rsi_3_15m_gt_25) | (stochrsi_k_15m_lt_20) | (aroonu_14_4h_lt_80))
            # 15m down move & still not low enough, 4h still high
            & ((rsi_3_15m_gt_25) | (stochrsi_k_15m_lt_30) | (stochrsi_k_4h_lt_50))
            # 15m down move, 1h still not low enough, 1d high
            & ((rsi_3_15m_gt_25) | (stochrsi_k_1h_lt_20) | (aroonu_14_1d_lt_80))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_30) | (rsi_3_1d_gt_60) | (stochrsi_k_1d_lt_70))
            # 15m & 4h & 1d down move
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_50))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_30) | (stochrsi_k_4h_lt_80) | (rsi_3_1d_gt_55))
            # 15m down move, 1d still not low enough & downtrend
            & ((rsi_3_15m_gt_35) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_10))
            # 15m down move, 1h still high, 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_1h_lt_40) | (stochrsi_k_4h_lt_80))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_35) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_75))
            # 15m down move & still not low enough, 1h still high
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_50))
            # 15m down move & still not low enough
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_30))
            # 15m down move, 4h high
            & ((rsi_3_15m_gt_5) | (stochrsi_k_4h_lt_60))
            # 15m up move, 4h aroon-up floored
            & ((rsi_3_15m_lt_50) | (aroonu_14_4h_gt_20))
            # 15m still not low enough, 4h still high, 1d high
            & ((aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_40) | (aroonu_14_1d_lt_75))
            # 15m still not low enough, 4h aroon-up parked mid-range
            & ((aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_60) | (aroonu_14_4h_gt_70))
            # 15m still not low enough, 1d down move & overbought
            & ((aroonu_14_15m_lt_20) | (rsi_3_1d_gt_65) | (roc_9_1d_lt_0))
            # 15m still not low enough, 1h down move & still high
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_40))
            # 15m & 1d still not low enough, 1h down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_20) | (aroonu_14_1d_lt_30))
            # 15m still not low enough, 4h down move & high
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_80))
            # 15m still not low enough, 1h down move
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_lt_20) | (rsi_3_1h_gt_10))
            # 15m still not low enough, 4h high, 1d still high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_4h_lt_90) | (stochrsi_k_1d_lt_40))
            # 15m & 1h still not low enough, 4h down move
            & ((aroonu_14_15m_lt_25) | (aroonu_14_1h_lt_30) | (rsi_3_4h_gt_35))
            # 15m still not low enough & still high, 4h down move
            & ((aroonu_14_15m_lt_25) | (stochrsi_k_15m_lt_50) | (rsi_3_4h_gt_45))
            # 15m still not low enough, 1h still high, 1d high
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_50) | (stochrsi_k_1d_lt_60))
            # 15m still not low enough, 4h & 1d high
            & ((aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_60) | (stochrsi_k_1d_lt_60))
            # 15m still not low enough, 1h down move, 4h high
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_90))
            # 15m still not low enough, 1d high
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_15m_lt_30) | (aroonu_14_1d_lt_80))
            # 15m & 1h still not low enough
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_1h_lt_20))
            # 15m still high, 1h still not low enough, 4h down move
            & ((aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_40))
            # 15m still high, 1d down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1d_gt_50))
            # 15m still high, 4h high, 1d downtrend
            & ((aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_80) | (roc_9_1d_gt_neg_10))
            # 15m still high, 4h down move & high
            & ((aroonu_14_15m_lt_50) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_80))
            # 15m high, 1h still not low enough
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_30))
            # 15m high, 1d down move
            & ((aroonu_14_15m_lt_60) | (rsi_3_1d_gt_65))
            # 15m & 4h high, 1d still high
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_4h_lt_70) | (stochrsi_k_1d_lt_40))
            # 15m & 1d still not low enough, 1d downtrend
            & ((stochrsi_k_15m_lt_20) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_10))
            # 15m still not low enough, 1h still high, 1d downtrend
            & ((stochrsi_k_15m_lt_20) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_0))
            # 15m still not low enough, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_20) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_80))
            # 15m still not low enough, 4h down move & high
            & ((stochrsi_k_15m_lt_20) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_70))
            # 15m still not low enough, 4h & 1d down move
            & ((stochrsi_k_15m_lt_20) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_65))
            # 15m still not low enough, 4h & 1d high
            & ((stochrsi_k_15m_lt_20) | (stochrsi_k_4h_lt_60) | (aroonu_14_1d_lt_80))
            # 15m still not low enough, 4h & 1d high
            & ((stochrsi_k_15m_lt_20) | (stochrsi_k_4h_lt_70) | (stochrsi_k_1d_lt_60))
            # 15m still not low enough, 4h downtrend
            & ((stochrsi_k_15m_lt_30) | (roc_9_4h > 0.0))
            # 15m still not low enough, 1d down move
            & ((stochrsi_k_15m_lt_30) | (rsi_3_1d_gt_45))
            # 15m still not low enough, 1d down move & high
            & ((stochrsi_k_15m_lt_30) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_60))
            # 15m still high, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_70))
            # 15m & 4h still high, 4h down move
            & ((stochrsi_k_15m_lt_50) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_40))
            # 15m & 4h high
            & ((stochrsi_k_15m_lt_60) | (stochrsi_k_4h_lt_70))
            # 15m downtrend, 4h overbought
            & ((roc_9_15m > -3.0) | (roc_9_4h_lt_50))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_40))
            # 1h down move, 4h high, 1d still not low enough
            & ((rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_60) | (stochrsi_k_1d_lt_30))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_5))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_60) | (stochrsi_k_1d_lt_80))
            # 1h low, 4h down move, 1d up move
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_gt_30) | (rsi_3_1d_lt_80))
            # 1h at a new low while the 4h is hot
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_lt_70))
            # 1h & 1d still not low enough, 4h down move
            & ((aroonu_14_1h_lt_20) | (rsi_3_4h_gt_35) | (aroonu_14_1d_lt_30))
            # 1h still not low enough, 4h down move, 1d high
            & ((aroonu_14_1h_lt_20) | (rsi_3_4h_gt_40) | (stochrsi_k_1d_lt_80))
            # 1h still not low enough, 4h & 1d down move
            & ((aroonu_14_1h_lt_30) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_60))
            # 1h still high, 4h overbought, 1d high
            & ((aroonu_14_1h_lt_40) | (roc_9_4h_lt_10) | (stochrsi_k_1d_lt_60))
            # 1h still high, 1d overbought and its aroon-up floored
            & ((aroonu_14_1h_lt_50) | (roc_9_1d_lt_10) | (aroonu_14_1d_gt_0))
            # 1h high, 1d overbought
            & ((aroonu_14_1h_lt_60) | (roc_9_1d_lt_25))
            # 1h high, 4h downtrend
            & ((aroonu_14_1h_lt_60) | (roc_9_4h > -3.0))
            # 1h high, 1d down move
            & ((aroonu_14_1h_lt_60) | (rsi_3_1d_gt_40))
            # 1h high, 1d down move & overbought
            & ((aroonu_14_1h_lt_60) | (rsi_3_1d_gt_65) | (roc_9_1d_lt_0))
            # 1h & 4h high, 1d overbought
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_10))
            # 1h & 4h & 1d high
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_60))
            # 1h still not low enough, 1d high & still high
            & ((stochrsi_k_1h_lt_20) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d_lt_40))
            # 1h still not low enough, 4h still high, 1d high
            & ((stochrsi_k_1h_lt_30) | (stochrsi_k_4h_lt_50) | (stochrsi_k_1d_lt_60))
            # 4h down move, 1d high & still not low enough
            & ((rsi_3_4h_gt_35) | (aroonu_14_1d_lt_75) | (stochrsi_k_1d_lt_30))
            # 4h down move & high, 1d still high
            & ((rsi_3_4h_gt_40) | (aroonu_14_4h_lt_70) | (stochrsi_k_1d_lt_40))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80) | (rsi_3_1d_gt_55))
            # a new daily high made while 4h money flow sits at the floor
            & ((mfi_14_4h > 45.0) | (cmf_20_4h_gt_neg_0_0) | (aroonu_14_1d_lt_100))
            # 4h high, 1d down move & overbought
            & ((aroonu_14_4h_lt_80) | (rsi_3_1d_gt_65) | (roc_9_1d_lt_0))
            # 4h washed out, 1h at a new low, 1d already run
            & ((stochrsi_k_4h_gt_20) | (aroonu_14_1h_gt_0) | (roc_9_1d_lt_15))
            # 4h & 1d high
            & ((stochrsi_k_4h_lt_60) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d_lt_60))
            # 4h high, 1d down move & overbought
            & ((stochrsi_k_4h_lt_60) | (rsi_3_1d_gt_60) | (roc_9_1d_lt_0))
            # 4h & 1d high
            & ((stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_90))
            # 4h at the ceiling, 1d washed out, 1h at a new low
            & ((stochrsi_k_4h_lt_90) | (stochrsi_k_1d_gt_20) | (aroonu_14_1h_gt_0))
            # 1d down move & high
            & ((rsi_3_1d_gt_55) | (stochrsi_k_1d_lt_70))
            # 1d downtrend with an overbought daily stochastic
            & ((aroonu_14_1d_gt_20) | (stochrsi_k_1d_lt_80))
            # 1h low, 4h high, 1d downtrend
            & ((roc_9_1d_gt_neg_10) | (aroonu_14_1h_gt_30) | (aroonu_14_4h_lt_80))
            # 15m rsi_3 already jumped, 4h aroon-up floored
            & ((rsi_3_change_pct_15m < 50.0) | (aroonu_14_4h_gt_20))
          )

          # Logic
          long_entry_logic.append(
            # money still flowing in on the hour and a healthy 4h — no dip-buying a bleed
            (cmf_20_1h > -0.02)
            & (rsi_14_4h > 45.0)
            # 1h close crosses INTO the oversold extreme (source strategy runs on 30m/1h scale)
            & (willr_14_1h < -90.0)
            & (np_shift(willr_14_1h, 12) >= -90.0)
            # mean-revert WITH the daily trend: only long when the day is up
            & (change_pct_1d > 0.0)
            # only above the daily 200 EMA: in a bear market the snapback does not come
            & (close > ema_200_1d)
          )

        # Condition #120 - Grind mode (Long).
        if long_entry_condition_index == 120:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(num_open_long_grind_mode < self.grind_mode_max_slots)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(is_pair_long_grind_mode)
          long_entry_logic.append(rsi_3 <= 50.0)
          long_entry_logic.append(rsi_3_15m >= 20.0)
          long_entry_logic.append(rsi_3_1h >= 20.0)
          long_entry_logic.append(rsi_3_4h >= 20.0)
          long_entry_logic.append(rsi_14_1h_lt_80)
          long_entry_logic.append(rsi_14_4h_lt_80)
          long_entry_logic.append(rsi_14_1d_lt_80)
          long_entry_logic.append(aroonu_14_15m_lt_70)
          long_entry_logic.append(aroonu_14_1h_lt_100)
          long_entry_logic.append(aroonu_14_4h_lt_100)
          long_entry_logic.append(aroonu_14_1d_lt_100)
          long_entry_logic.append(stochrsi_k_15m_lt_50)
          long_entry_logic.append(stochrsi_k_1h_lt_70)
          long_entry_logic.append(stochrsi_k_4h_lt_70)
          long_entry_logic.append(stochrsi_k_1d_lt_90)

          # Logic
          long_entry_logic.append(
            (stochrsi_k_lt_20) & (willr_14 < -80.0) & (aroonu_14_lt_25) & (close < (ema_20 * 0.978))
          )

        # Condition #141 - Top Coins mode (Long).
        if long_entry_condition_index == 141:
          # Protections
          long_entry_logic.append(is_pair_long_top_coins_mode)
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 15m down move, 15m high
            ((rsi_3_gt_3) | (rsi_3_15m_gt_15) | (aroonu_14_15m_lt_70))
            # 5m & 15m down move, 4h still high
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_50))
            # 5m & 15m down move, 15m high
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_20) | (aroonu_14_15m_lt_70))
            # 5m & 1h down move, 15m still high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_15) | (aroonu_14_15m_lt_40))
            # 5m & 1h down move, 1h high
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_80))
            # 5m & 4h down move, 15m still high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_5) | (aroonu_14_15m_lt_40))
            # 5m & 4h down move, 15m still high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_5) | (stochrsi_k_15m_lt_40))
            # 5m & 4h down move, 15m still high
            & ((rsi_3_gt_3) | rsi_3_4h_gt_20 | (stochrsi_k_15m_lt_50))
            # 5m & 4h down move, 1h high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_45) | (stochrsi_k_1h_lt_80))
            # 5m & 1d down move, 15m high
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_10) | (aroonu_14_15m_lt_70))
            # 5m & 1d down move, 15m stil high
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_10) | (stochrsi_k_15m_lt_40))
            # 5m & 1d down move, 4h still high
            & ((rsi_3_gt_3) | (rsi_3_1d_gt_10) | (stochrsi_k_4h_lt_40))
            # 5m down move, 1h high
            & ((rsi_3_gt_3) | (stochrsi_k_1h_lt_90))
            # 5m down move, 15m & 1d high
            & ((rsi_3_gt_5) | (aroonu_14_15m_lt_60) | (aroonu_14_1d_lt_100))
            # 5m down move, 1h & 1d high
            & ((rsi_3_gt_10) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_100))
            # 15m & 1h & 4h & 1d down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_15))
            # 15m & 1h & 4h & 1d down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_40))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (roc_9_1d_lt_100))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_20))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (roc_9_1d_lt_60))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_90))
            # 15m & 1h down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (stochrsi_k_1d_lt_50))
            # 15m & 1h & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_25) | (rsi_14_4h_lt_40) | (roc_9_1d_gt_neg_10))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (aroonu_14_15m_lt_50))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (aroonu_14_1d_lt_80))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_85))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_80))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_45) | (stochrsi_k_1d_lt_80))
            # 15m & 4h down move, 15m downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_3) | (cmf_20_15m_gt_neg_0_30))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_40))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_3) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_10))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_3) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_50))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_50))
            # 15m & 1h & 4h down move, 15m still not low enough, 1h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_lt_30))
            # 15m & 1h & 4h down move, 4h high & overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_80))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_40) | (aroonu_14_15m_lt_60))
            # 15m & 1h down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_50) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_70))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80))
            # 15m & 1d down move, 1d still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1d_gt_10) | (aroonu_14_1d_lt_40))
            # 15m down move, 15m downtrend, 1d high
            & ((rsi_3_15m_gt_5) | (cmf_20_15m_gt_neg_0_40) | (aroonu_14_1d_lt_100))
            # 15m down move, 4h high, 1h overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_10))
            # 15m & 1h & 4h & 1d down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (roc_9_1d_gt_neg_10))
            # 15m & 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_20) | (rsi_14_1d_lt_40))
            # 15m & 1h & 4h down move, 4h still high, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (rsi_14_4h_lt_40) | (rsi_14_1d_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_85))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_85))
            # 15m & 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (rsi_14_1d_lt_50))
            # 15m & 1h & 4h & 1d down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_50) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (stochrsi_k_15m_lt_50))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (stochrsi_k_1d_lt_50))
            # 15m & 1h & 4h & 1d down move, 1h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_40) | (stochrsi_k_1h_lt_30))
            # 15m & 1h & 4h & 1d down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_45) | (aroonu_14_4h_lt_60))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_15m_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_80))
            # 15m & 1h & 4h down move, 15m & 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_40))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_45) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (roc_9_1d_lt_60))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_15m_lt_40))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (roc_9_1d_lt_20))
            # 15m & 4h & 1d down move, 15m still high, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_40) | (aroonu_14_15m_lt_40) | (aroonu_14_1d_lt_70))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (rsi_14_1d_lt_70))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_15m_lt_60))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_70))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_80))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_50))
            # 15m & 4h & 1d down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_55) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_60))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_30))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_15m_lt_70))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_70))
            # 15m down move, 1h high
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_90))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_50))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_60))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_100))
            # 15m down move, 15m & 4h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_60) | (aroonu_14_4h_lt_70))
            # 15m down move, 15m high, 1h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_70) | (stochrsi_k_1h_lt_80))
            # 15m down move, 1h & 4h high, 4h overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_100))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_20))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_40))
            # 15m & 1h & 4h down move, 1h & 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_50))
            # 15m & 1h & 4h & 1d down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (stochrsi_k_1h_lt_50))
            # 15m & 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_4h_lt_80))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_80))
            # 15m & 1h & 1d down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_90))
            # 15m & 1h down move, 4h & 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_45) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 15m & 1h & 4h down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_55) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_90))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_15m_lt_50))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_70))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_15m_lt_70))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_60))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_40))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_90))
            # 15m & 4h down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_45) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_90))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_15) | (stochrsi_k_1h_lt_30))
            # 15m down move, 15m downtrend, 1h high
            & ((rsi_3_15m_gt_15) | (cmf_20_15m_gt_neg_0_40) | (aroonu_14_1h_lt_60))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_50) | (stochrsi_k_4h_lt_80))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_70) | (roc_9_1d_lt_20))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100))
            # 15m down move, 4h high, 4h overbought, 1d downtrend
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_10) | (roc_9_1d_gt_neg_20))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_15) | (roc_9_4h_lt_20) | (roc_9_1d_lt_80))
            # 15m & 1h & 1d down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 15m & 1h down move, 4h high, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 15m & 1h down move, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_40) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_30))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_45) | (stochrsi_k_1h_lt_80))
            # 15m & 1h & 4h down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 4h & 1d down move
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 15m & 1h down move, 1d high, 4h & 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10) | (roc_9_1d_lt_10))
            # 15m & 4h & 1d down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_55) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_50))
            # 15m & 4h down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_40) | (stochrsi_k_1h_lt_70) | (roc_9_1d_gt_neg_40))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_10))
            # 15m down move, 4h & 1d high & overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_20))
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_30))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_30) | (stochrsi_k_15m_lt_70))
            # 15m & 1h down move, 15m high, 4h high & overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_45) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 15m & 4h down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_10))
            # 15m & 4h down mve, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_80))
            # 15m & 1d down move, 1d high & overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_10))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_90))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_90) | (roc_9_1d_gt_neg_10))
            # 15m down move, 15m high, 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_80))
            # 15m down move, 15m & 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_90))
            # 15m & 4h down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_40) | (rsi_3_4h_gt_40) | (stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_90))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_10))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_40))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (roc_9_1d_lt_10))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_40))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_15m_lt_20))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_10))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_60))
            # 1h & 4h & 1d down move, 4h still not low enough, 1d still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_50) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_40))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_50))
            # 1h & 4h down move, 15m still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_70))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_30))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | rsi_3_4h_gt_20 | (aroonu_14_4h_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_60))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | aroonu_14_4h_lt_70)
            # 1h & 1d down move, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_15) | (aroonu_14_1h_lt_20))
            # 1h & 1d down move, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_20) | (aroonu_14_1h_lt_30))
            # 1h down move, 15m downtrend, 1d high
            & ((rsi_3_1h_gt_10) | (cmf_20_15m_gt_neg_0_40) | (aroonu_14_1d_lt_70))
            # 1h down move, 1h high, 4h high
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_70) | (stochrsi_k_4h_lt_80))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_40))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_50))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_30))
            # 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (rsi_14_1d_lt_50))
            # 1h & 1d down move, 4h downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_15) | (roc_9_4h_gt_neg_30))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_50))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_35) | (aroonu_14_1d_lt_70))
            # 1h down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50) | (stochrsi_k_1d_lt_80))
            # 1h down move, 1h still high, 4h overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50) | (roc_9_4h_lt_10))
            # 1h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50) | (roc_9_1d > -30.0))
            # 1h down move, 4h still high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_1d_lt_40))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_100))
            # 1h & 4h & 1d down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | aroonu_14_1h_lt_70)
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | aroonu_14_4h_lt_100)
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_25) | (roc_9_1d_gt_neg_30))
            # 1h down move, 15m still high, 1d high
            & ((rsi_3_1h_gt_20) | (aroonu_14_15m_lt_40) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_60) | (roc_9_1d_lt_10))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_70))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | aroonu_14_1h_lt_80)
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (rsi_14_1d_lt_80))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_40))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_30) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_20))
            # 1h down move, 15m still high, 1h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_85))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (stochrsi_k_1h_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_80))
            # 1h down move, 1h high , 1d overbought
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_30))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_60) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_40))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_80))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_75) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_60) | (stochrsi_k_1d_lt_70) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 4h, 1d high & overbought
            & ((rsi_3_1h_gt_50) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_25))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_60) | (rsi_3_1d_gt_60) | (aroonu_14_1h_lt_70))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_20) | (rsi_14_1d_lt_40))
            # 4h down move, 1h still not low enough, 4h downtrend
            & ((rsi_3_4h_gt_3) | (aroonu_14_1h_lt_20) | (roc_9_4h_gt_neg_10))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_40))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_5) | (stochrsi_k_1h_lt_90))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_10))
            # 4h & 1d down move, 1h high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_60))
            # 4h & 1d down move, 4h downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (roc_9_4h_gt_neg_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_40))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (roc_9_1d > -30.0))
            # 4h & 1d down move, 1h high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_30) | (aroonu_14_1h_lt_100))
            # 4h down move, 15m still high, 1h still high
            & ((rsi_3_4h_gt_10) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_50))
            # 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_80))
            # 4h down move, 1h still not low enough, 4h downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_20) | (roc_9_4h_gt_neg_20))
            # 4h & 1d down move, 15m still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_15) | (stochrsi_k_15m_lt_50))
            # 4h & 1d down move, 1h still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_15) | (stochrsi_k_1h_lt_40))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_60))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | aroonu_14_4h_lt_70)
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_50))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_70))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d > 50.0) | (stochrsi_k_4h_lt_40))
            # 4h down move, 1d still high, 4h still not low enough
            & ((rsi_3_4h_gt_15) | (rsi_14_1d_lt_40) | (stochrsi_k_4h_lt_30))
            # 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 4h down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_20) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1h downtrend, 1d overbought
            & ((rsi_3_4h_gt_15) | (roc_9_1h_gt_neg_10) | (roc_9_1d_lt_200))
            # 4h down move, 4h high, 4h downtrend
            & (rsi_3_4h_gt_20 | (aroonu_14_4h_lt_60) | (roc_9_4h_gt_neg_20))
            # 4h down move, 1d high & overbought
            & (rsi_3_4h_gt_20 | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_70))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_25) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_10))
            # 1h down move, 4h still not low enough, 1d downtrend
            & (rsi_3_4h_gt_20 | (stochrsi_k_4h_lt_30) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1h high
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_80))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_25) | (stochrsi_k_1h_lt_70))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_30))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_50))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_90))
            # 4h down move, 15m high, 1h high
            & ((rsi_3_4h_gt_30) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_80))
            # 4h down move, 15m & 4h high
            & ((rsi_3_4h_gt_30) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_70))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_30) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_35) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_20))
            # 4h down move, 15m still high, 1h high
            & ((rsi_3_4h_gt_35) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_100))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_40) | (aroonu_14_1h_lt_80))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_20))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_55) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_80))
            # 1d down move, 1d high, 4h downtrend
            & ((rsi_3_1d_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_4h_gt_neg_40))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_30) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1d down move, 1h high, 1d overbought
            & ((rsi_3_1d_gt_45) | (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_10))
            # 1d down move, 4h high, 1d overbought
            & ((rsi_3_1d_gt_45) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_10))
            # 1d down move, 1d high & overbought
            & ((rsi_3_1d_gt_55) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_10))
            # 1d down move, 1d overbought
            & ((rsi_3_1d_gt_60) | (roc_9_1d_lt_200))
            # 15m & 1h high, 4h overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100) | (roc_9_4h_lt_15))
            # 15m & 1h high, 1d overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_100))
            # 15m & 1h high, 1d downtrend
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100) | (roc_9_1d_gt_neg_10))
            # 15m high, 1d high & overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_30))
            # 15m high, 1d high & overbought
            & ((aroonu_14_15m_lt_70) | aroonu_14_1d_lt_100 | (roc_9_1d_lt_20))
            # 15m high, 1h high, 1d downtrend
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_20))
            # 1h & 4h high, 4h overbought
            & ((aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_10))
            # 1h & 4h high, 1d overbought
            & ((aroonu_14_1h_lt_90) | aroonu_14_4h_lt_100 | roc_9_1d_lt_50)
            # 1h & 1d high, 1d overbought
            & ((aroonu_14_1h_lt_100) | aroonu_14_1d_lt_100 | (roc_9_1d_lt_40))
            # 4h & 1d high, 4h overbought
            & (aroonu_14_4h_lt_100 | aroonu_14_1d_lt_100 | (roc_9_4h_lt_50))
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_90) | aroonu_14_1d_lt_100 | roc_9_1d_lt_50)
            # 1h high, 1h & 4h overbought
            & ((stochrsi_k_1h_lt_80) | (roc_9_1h_lt_20) | (roc_9_4h_lt_20))
            # 4h & 1d overbought
            & ((roc_9_4h_lt_100) | (roc_9_1d_lt_200))
          )

          # Logic
          long_entry_logic.append(
            (rsi_20 < rsi_20_shift_1) & (rsi_3 < 30.0) & (aroonu_14_lt_25) & (close < sma_16 * 0.960)
          )

        # Condition #142 - Top Coins mode (Long).
        if long_entry_condition_index == 142:
          # Protections
          long_entry_logic.append(is_pair_long_top_coins_mode)
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 4h down move, 15m high
            ((rsi_3_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_15m_lt_40))
            # 5m & 1d down move, 15m high
            & ((rsi_3_gt_10) | (rsi_3_1d_gt_30) | (aroonu_14_15m_lt_80))
            # 5m down move, 15m & 1h high
            & ((rsi_3_gt_10) | (aroonu_14_15m_lt_85) | (aroonu_14_1h_lt_100))
            # 5m down move, 1h & 1d high
            & ((rsi_3_gt_10) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_100))
            # 15m & 1h & 4h down move
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_3) | (rsi_3_4h_gt_15))
            # 15m & 1h & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_20))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_70))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (roc_9_1d_lt_60))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_90))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (aroonu_14_15m_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_75))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_40))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_3) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_10))
            # 15m down move, 4h high
            & ((rsi_3_15m_gt_3) | (aroonu_14_4h_lt_90))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_3) | (stochrsi_k_1h_lt_60) | (roc_9_1d_lt_20))
            # 15m down move, 4h high
            & ((rsi_3_15m_gt_3) | (stochrsi_k_4h_lt_80))
            # 15m & 1d down move, 1d still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (aroonu_14_1d_lt_40))
            # 15m & 1h down move, 15m still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (stochrsi_k_15m_lt_30))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_50))
            # 15m & 1h & 4h & 1d down move, 1h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_30))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_70))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_20) | (aroonu_14_15m_lt_60))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_15) | (aroonu_14_4h_lt_85))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_60))
            # 15m & 1h & 4h down move, 15m still not low enough, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_lt_40))
            # 15m & 1h & 4h down move, 4h high & overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_40) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_70))
            # 15m & 1h down move, 4h high, 4h overbought, 1d downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_50) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80))
            # 15m down move, 4h high, 1h overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_10))
            # 15m & 1h & 4h down move, 4h still high, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (rsi_14_4h_lt_40) | (rsi_14_1d_lt_50))
            # 15m & 1h & 4h & 1d down mode, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (roc_9_1d_gt_neg_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_85))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_60))
            # 15m & 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (rsi_14_1d_lt_50))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_50))
            # 15m & 1h & 4h & 1d down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_45) | (aroonu_14_4h_lt_60))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_15m_lt_60))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (aroonu_14_15m_lt_40))
            # 15m & 1h & 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_1h_lt_50) | (roc_9_1d_gt_neg_30))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (roc_9_1d_lt_60))
            # 15m & 1h & 4h down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_55) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_20))
            # 15m & 4h down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_50))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_15m_lt_50))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_80))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (roc_9_1d_lt_20))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (rsi_14_1d_lt_70))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50))
            # 14m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_70))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_80))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | roc_9_1d_lt_50)
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_70))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_30))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_90))
            # 15m & 4h down move, 4h overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_35) | (roc_9_4h_lt_10))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_15m_lt_70))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_50))
            # 15m down move, 15m high, 1h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_70) | (stochrsi_k_1h_lt_80))
            # 15m down move, 1h & 4h high, 4h overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_100))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_20))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_40))
            # 15m & 1h & 4h & 1d down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (stochrsi_k_1h_lt_50))
            # 15m & 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_70))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_80))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (aroonu_14_4h_lt_100))
            # 15m & 1h & 4h down move, 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_90))
            # 15m & 1h down move, 4h & 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_45) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 15m & 4h & 1d down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_1h_lt_50))
            # 15m & 4h & 1d down move, 1d stil high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (rsi_14_1d_lt_50) | (roc_9_4h_gt_neg_20))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_15m_lt_70))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_50))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_90))
            # 15m & 4h down move, 4h overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_45) | (roc_9_4h_lt_20))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_80))
            # 15m down move, 15m downtrend, 1h high
            & ((rsi_3_15m_gt_15) | (cmf_20_15m_gt_neg_0_40) | (aroonu_14_1h_lt_60))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_50) | (stochrsi_k_4h_lt_80))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_70) | (roc_9_1d_lt_10))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_60))
            # 15m & 1h & 1d down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 15m & 1h & 4h & 1d down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_40) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_30))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_45) | (stochrsi_k_1h_lt_80))
            # 15m & 1h & 4h down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 4h high, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_50) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_40))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_50))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_25) | (aroonu_14_15m_lt_70))
            # 15m & 4h & 1d down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_55) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_50))
            # 15m down move, 15m still high, 1h high, 4h & 1d overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_20) | (roc_9_1d_lt_50))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 15m down move, 15m high, 1d high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_90) | aroonu_14_1d_lt_100)
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_20))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_10))
            # 15m & 1h & 4h & 1d down move, 15m high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_15m_lt_70))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_35) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_60))
            # 15m & 4h down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_10))
            # 15m & 4h down mve, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_80))
            # 15m & 1d down move, 15m & 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 15m & 1d down move, 1d high & overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_10))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_90) | (roc_9_1d_gt_neg_10))
            # 15m down move, 15m high, 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_80))
            # 15m down move, 15m & 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_90))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_80) | (roc_9_1d_lt_50))
            # 15m & 4h down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_40) | (rsi_3_4h_gt_40) | (stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_90))
            # 15m down move, 1d high, 1h overbought
            & ((rsi_3_15m_gt_40) | (stochrsi_k_1d_lt_80) | (roc_9_1h_lt_20))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_50))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (roc_9_1d_lt_10))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_40))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_60))
            # 1h & 4h & 1d down move, 4h still not low enough, 1d still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_50) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_40))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_15))
            # 1h & 4h down move, 1d still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_20))
            # 1h & 4h down move, 15m still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_50))
            # 1h & 4h & 1d down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_30))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_30))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h high & overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_10))
            # 1h & 1d downtrend, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_70))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1h_lt_20))
            # 1h & 4h down move. 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_50))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_30))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_30))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_40))
            # 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (rsi_14_1d_lt_50))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_lt_40))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_35) | (aroonu_14_1d_lt_70))
            # 1h down move, 15m & 1d high
            & ((rsi_3_1h_gt_15) | (aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_100))
            # 1h down move, 1h still high, 4h overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50) | (roc_9_4h_lt_10))
            # 1h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_15) | (roc_9_4h_lt_30) | (roc_9_1d_lt_50))
            # 1h & 4h & 1d down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_80))
            # 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (rsi_14_1d_lt_40))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_50))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_70))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_100))
            # 1h down move, 1d high, 4h & 1d overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_4h_lt_10) | (roc_9_1d_lt_40))
            # 1h down move, 4h high & overbought, 1d downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_70))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 4h & 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_60) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_40))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_25) | (roc_9_4h_lt_30) | (roc_9_1d_lt_60))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_50))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_60))
            # 1h & 4g down move, 4h still high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_50))
            # 1h down move, 15m still high, 1h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_85))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_100))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100))
            # 1h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_50) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 1h down move, 4h & 1d high & overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_60) | (roc_9_1d_lt_60))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_60) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_40))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_80))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_75) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_60) | (stochrsi_k_1d_lt_70) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_50) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_90) | (roc_9_1d_lt_200))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_25))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_10) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_20) | (rsi_14_1d_lt_40))
            # 4h & 1d down move, 15m still high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_20) | (stochrsi_k_15m_lt_50))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_70))
            # 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_5) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_10))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_5) | (stochrsi_k_1h_lt_90))
            # 4h & 1d down move, 1h still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_50))
            # 4h & 1d down move, 15m downtrend, 1d still not low enough
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (cmf_20_15m_gt_neg_0_30) | (aroonu_14_1d_lt_30))
            # 4h & 1d down move, 1h still high, 15m high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_20) | (aroonu_14_1h_lt_50) | (stochrsi_k_15m_lt_60))
            # 4h & 1d down move, 1h high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_1h_lt_70))
            # 4h down move, 15m still high, 1h still high
            & ((rsi_3_4h_gt_10) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_50))
            # 4h down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_80))
            # 4h down move, 15m still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1h high, 4h downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_70) | (roc_9_4h_gt_neg_20))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_15) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_50))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_20) | (aroonu_14_4h_lt_40))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_70))
            # 4h & 1d down move, 1d still high, 4h & 1d downtrend
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (rsi_14_1d_lt_40) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 15m high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (stochrsi_k_15m_lt_80))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_50) | (stochrsi_k_4h_lt_40))
            # 4h down move, 1d still high, 4h still not low enough
            & ((rsi_3_4h_gt_15) | (rsi_14_1d_lt_40) | (stochrsi_k_4h_lt_30))
            # 4h down move, 15m still not low enough, 1d high
            & ((rsi_3_4h_gt_15) | (aroonu_14_15m_lt_30) | (aroonu_14_1d_lt_70))
            # 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 4h down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_20) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_70))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_80))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_70))
            # 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_50) | (roc_9_4h_gt_neg_20))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1d overbought
            & ((rsi_3_4h_gt_20) | (roc_9_1d_lt_80))
            # 4h & 1d down move, 4h overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (roc_9_4h_lt_5))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (roc_9_1d_lt_10))
            # 4h down move, 15m still not low enough, 4h still high
            & ((rsi_3_4h_gt_25) | (aroonu_14_15m_lt_30) | (stochrsi_k_4h_lt_40))
            # 4h down move, 1d high, 4h overbought
            & ((rsi_3_4h_gt_25) | (aroonu_14_1d_lt_80) | (roc_9_4h_lt_5))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_50))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_90))
            # 4h down move, 15m high, 1h high
            & ((rsi_3_4h_gt_30) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_80))
            # 4h down move, 4h high, 1d high
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_70) | (stochrsi_k_1d_lt_80))
            # 4h down move, 1d stil high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_40))
            # 4h & 1d down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (stochrsi_k_4h_lt_50) | (aroonu_14_1d_lt_60))
            # 4h down move, 15m still high, 1h high
            & ((rsi_3_4h_gt_35) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_100))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_35) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_20))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_40) | (aroonu_14_1h_lt_80))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_20))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_25))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_200))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_10))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_50) | (roc_9_4h_lt_10) | roc_9_1d_lt_50)
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_55) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_80))
            # 1d down move, 1d high, 4h downtrend
            & ((rsi_3_1d_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_4h_gt_neg_40))
            # 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1d_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_20))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_30) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 15m & 1h high, 4h overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100) | (roc_9_4h_lt_15))
            # 15m & 1h high, 1d overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_100))
            # 15m & 1h high, 1d downtrend
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100) | (roc_9_1d_gt_neg_10))
            # 15m & 4h & 1d high
            & ((aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_90) | aroonu_14_1d_lt_100)
            # 15m high, 1d high & overbought
            & ((aroonu_14_15m_lt_70) | aroonu_14_1d_lt_100 | (roc_9_1d_lt_20))
            # 15m high, 1h & 4h overbought
            & ((aroonu_14_15m_lt_70) | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 15m high, 4h overbought, 1d downtrend
            & ((aroonu_14_15m_lt_80) | (roc_9_4h_lt_20) | (roc_9_1d_gt_neg_30))
            # 15m & 1h high
            & ((aroonu_14_15m_lt_90) | (aroonu_14_1h_lt_100))
            # 15m & 4h high
            & ((aroonu_14_15m_lt_90) | aroonu_14_4h_lt_100)
            # 1h & 1d high, 1d overbought
            & ((aroonu_14_1h_lt_100) | aroonu_14_1d_lt_100 | (roc_9_1d_lt_10))
            # 1h & 4h high, 1h overbought
            & ((aroonu_14_1h_lt_100) | aroonu_14_4h_lt_100 | (roc_9_1h_lt_10))
            # 1h & 4h high, 4h overbought
            & ((aroonu_14_1h_lt_100) | aroonu_14_4h_lt_100 | (roc_9_4h_lt_10))
            # 4h & 1d high, 4h overbought
            & (aroonu_14_4h_lt_100 | aroonu_14_1d_lt_100 | (roc_9_4h_lt_20))
            # 4h & 1d high, 1d overbought
            & (aroonu_14_4h_lt_100 | aroonu_14_1d_lt_100 | (roc_9_1d_lt_30))
            # 4h high, 1h & 4h overbought
            & (aroonu_14_4h_lt_100 | (roc_9_1h_lt_20) | (roc_9_4h_lt_40))
            # 1d high, 4h & 1d downtrend
            & ((aroonu_14_1d_lt_60) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_30))
            # 1d high, 4h & 1d overbought
            & (aroonu_14_1d_lt_100 | (roc_9_4h_lt_60) | (roc_9_1d_lt_100))
            # 15m high, 4h & 1d overbought
            & ((stochrsi_k_15m_lt_70) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 1h high, 1h & 1d overbought
            & ((stochrsi_k_1h_lt_80) | (roc_9_1h_lt_20) | (roc_9_1d_lt_100))
            # 4h high, 4h overbought, 1d downtrend
            & ((stochrsi_k_4h_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_gt_neg_20))
            # 1d high, 1h & 4h overbought
            & ((stochrsi_k_1d_lt_80) | (roc_9_1h_lt_20) | (roc_9_4h_lt_20))
          )

          # Logic
          long_entry_logic.append(
            (rsi_3_gt_5)
            & (rsi_4 < 46.0)
            # & (stochrsi_k < 20.0)
            & (rsi_20 < rsi_20_shift_1)
            & (close < sma_16 * 0.960)
          )

        # Condition #143 - Top Coins mode (Long).
        if long_entry_condition_index == 143:
          # Protections
          long_entry_logic.append(is_pair_long_top_coins_mode)
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 4h & 1d down move
            ((rsi_3_gt_3) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_10))
            # 5m & 4h down move, 4h still high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_4h_lt_50))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_70))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (aroonu_14_1h_lt_25))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_10))
            # 15m & 1h & 4h down move, 15m still not low enough, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_20))
            # 15m & 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (stochrsi_k_1d_lt_50))
            # 15m & 1h & 4h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_35) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (aroonu_14_15m_lt_40))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_90))
            # 15m & 1h & 4h & 1d down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (aroonu_14_4h_lt_50))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_30) | (aroonu_14_15m_lt_70))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_35) | (roc_9_1d_gt_neg_30))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_85))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_50))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_3) | (rsi_3_4h_gt_20) | (aroonu_14_15m_lt_50))
            # 15m & 1d down move, 4h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_50))
            # 15m & 1h & 4h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_50))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (rsi_14_4h_lt_40))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_15) | (aroonu_14_1d_lt_100))
            # 15m & 1h & 4h down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (rsi_3_1h_gt_50) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_60))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_40) | (aroonu_14_15m_lt_60))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_90))
            # 15m & 4h down move, 1d still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_5) | (rsi_14_1d_lt_40))
            # 15m & 4h down move, 15m still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (aroonu_14_15m_lt_30))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_80))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_40))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_90))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_1d_gt_10) | (aroonu_14_1h_lt_50))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_50))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_3) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_10))
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_3) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_20))
            # 15m & 1h & 4h & 1d down move, 1d overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (roc_9_1d_lt_10))
            # 15m down move, 15m still high, 1d downtrend
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_50) | (roc_9_1d_gt_neg_20))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_5) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_40))
            # 15m & 1h & 4h & 1d down mode, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (roc_9_1d_gt_neg_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_60))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_60))
            # 15m & 1h down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_90))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_35) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_80))
            # 15m & 1h & 1d down move, 15m downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_1d_gt_25) | (cmf_20_15m_gt_neg_0_40))
            # 15m & 1h & 4h & 1d down move, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (roc_9_1d_gt_neg_40))
            # 15m & 1h & 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_30))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_80))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80))
            # 15m & 1h & 4h down move, 1h still high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_50) | (roc_9_1d_gt_neg_10))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_70))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_50))
            # 15m & 4h down move, 4h still high, 1d high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_10))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_lt_70))
            # 15m & 4h down move, 4h & 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_70) | (stochrsi_k_1d_lt_80))
            # 15m & 4h down move, 4h overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_35) | (roc_9_4h_lt_10))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_70))
            # 15m & 1d down move, 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_4h_lt_40))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_15m_lt_70))
            # 15m down move, 15m high, 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_60) | (aroonu_14_1d_lt_100))
            # 15m down move, 1h & 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_90) | (aroonu_14_1d_lt_100))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_100))
            # 15m down move, 1h still high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_50) | (roc_9_1d_gt_neg_20))
            # 15m & 1h & 4h down move, 15m still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_50))
            # 15m & 1h down move, 1h high, 1d high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_10))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_70))
            # 15m & 1h & 4h down move, 15m still high, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 4h & 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_45) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_90))
            # 15m down move, 4h high, 4h overbought, 1d downtrend
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 1h & 1d down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 15m & 4h down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_10))
            # 15m & 1h down move, 4h high, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_10))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_45) | (stochrsi_k_1h_lt_80))
            # 15m & 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 15m & 1h & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (roc_9_1d_lt_150))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_200))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_40))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_50))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_20))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_30))
            # 1h & 4h & 1d down move, 1h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1h_lt_30))
            # 1h down move, 4h & 1d downtrend
            & ((rsi_3_1h_gt_5) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1d still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_20))
            # 1h & 4h & 1d down move, 4h & 1d still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_30) | (stochrsi_k_1d_lt_30))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_3) | (stochrsi_k_15m_lt_30))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 1h still high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_40) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1h still not low enough, 1d overbought
            & ((rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_30) | (roc_9_1d_lt_50))
            # 1h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_40))
            # 15m & 1h & 4h & 1d down move, 1h still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_40))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1h_lt_70))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_70))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_100))
            # 1h & 1d down move, 1d overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_30))
            # 1h down move, 1d high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1d high, 4h & 1d overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_4h_lt_10) | (roc_9_1d_lt_40))
            # 1h down move, 4h high & overbought, 1d downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10) | (roc_9_1d_gt_neg_20))
            # 1h & 4h & 1d down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_4h_lt_30) | (roc_9_1d_gt_neg_40))
            # 1h & 4h & 1d down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_25) | (roc_9_4h_lt_20) | (roc_9_1d_lt_30))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_60))
            # 1h down move, 15m still high, 1h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_85))
            # 1h down move, 4h & 1d high & overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_40) | (roc_9_1d_lt_80))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_200))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_80))
            # 1h down move, 4h & 1d high & overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_100) | (roc_9_1d_lt_100))
            # 4h & 1d down move, 15m still not low enough
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_15) | (aroonu_14_15m_lt_20))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_70))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_5) | (roc_9_1d_gt_neg_30))
            # 4h & 1d down move, 1h still high
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_50))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_5) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_70))
            # 4h & 1d down move, 15m still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_20) | (stochrsi_k_15m_lt_40))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_10))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_40))
            # 4h & 1d down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_4h_gt_neg_10))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_60))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_60))
            # 4h down move, 1d still high, 4h still not low enough
            & ((rsi_3_4h_gt_15) | (rsi_14_1d_lt_40) | (stochrsi_k_4h_lt_30))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_60) | (roc_9_1d_lt_100))
            # 1h down move, 1h still high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_15) | aroonu_14_4h_lt_70 | (aroonu_14_1d_lt_70))
            # 4h down move, 1h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_20) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_15) | (stochrsi_k_1h_lt_80))
            # 4h down move, 1h downtrend, 1d overbought
            & ((rsi_3_4h_gt_15) | (roc_9_1h_gt_neg_10) | (roc_9_1d_lt_200))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_50))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_70))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_70))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_60) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_30))
            # 4h & 1d down move, 1d high & overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_40))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_25) | (stochrsi_k_1h_lt_60) | (roc_9_1d_gt_neg_20))
            # 4h down move, 15m still high, 1h high
            & ((rsi_3_4h_gt_35) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_100))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_40) | (aroonu_14_1h_lt_80))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1d high, 4h & 1d overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_100) | (roc_9_1d_lt_100))
            # 1h high, 4h & 1d overbought
            & ((aroonu_14_1h_lt_70) | (roc_9_4h_lt_40) | (roc_9_1d_lt_80))
            # 1h & 4h high, 1d overbought
            & ((aroonu_14_1h_lt_85) | (aroonu_14_4h_lt_100) | (roc_9_1d_lt_40))
            # 1h & 4h & 1d high
            & ((aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100))
            # 1d high, 4h & 1d downtrend
            & ((aroonu_14_1d_lt_60) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_30))
            # 4h high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
          )

          # Logic
          long_entry_logic.append(
            (rsi_3_lt_40)
            & (stochrsi_k_lt_20)
            & (ema_26 > ema_12)
            & ((ema_26 - ema_12) > (open_rate * 0.020))
            & ((ema_26_shift_1 - ema_12_shift_1) > (open_rate / 100.0))
          )

        # Condition #144 - Top Coins mode (Long).
        if long_entry_condition_index == 144:
          # Protections
          long_entry_logic.append(is_pair_long_top_coins_mode)
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 1h down move, 1h still not low enough
            ((rsi_3_gt_3) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_30))
            # 5m & 4h down move, 15m still high
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_5) | (aroonu_14_15m_lt_40))
            # 5m & 4h & 1d down move
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_10))
            # 5m & 4h down move, 1d downtrend
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_10))
            # 5m & 4h down move, 15m high
            & ((rsi_3_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_15m_lt_40))
            # 15m & 1h down move, 1h still not low enough
            & (rsi_3_15m_gt_3 | (rsi_3_1h_gt_3) | (aroonu_14_1h_lt_25))
            # 15m & 1h & 4h down move, 15m still not low enough, 4h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_20))
            # 15m & 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_40))
            # 15m & 1h & 1d down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_5) | (aroonu_14_1d_lt_70))
            # 15m & 1h & 4h & 1d down move, 1h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1h_lt_30))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_100))
            # 15m & 1h & 4h down move, 15m still not low enough, 1h still not low enough
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_lt_30))
            # 15m  & 1h & 4h down move, 4h high & overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (roc_9_1d_lt_30))
            # 15m & 4h down move, 4h downtrend
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_5) | (roc_9_4h_gt_neg_20))
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_40))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_5) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_40))
            # 15m & 1h & 4h down move, 4h still high, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (rsi_14_4h_lt_40) | (rsi_14_1d_lt_50))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (rsi_14_4h < 20.0))
            # 15m & 4h & 1d down move, 15m high, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_55) | (aroonu_14_15m_lt_60) | (aroonu_14_1d_lt_70))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_70))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_50))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (stochrsi_k_15m_lt_50))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_30))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (roc_9_1d_lt_30))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_80))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 4h & 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_45) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_15m_lt_40))
            # 15m down move, 4h high, 4h overbought, 1d downtrend
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_70) | (roc_9_4h_lt_10) | (roc_9_1d_gt_neg_20))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_15) | (roc_9_4h_lt_20) | (roc_9_1d_lt_200))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_40))
            # 15m & 1h & 4h down move, 1h still high, 15m still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_50) | (stochrsi_k_15m_lt_50))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_100))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_100))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_90))
            # 15m down move, 4h & 1d high, 4h overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_30))
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_25) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_30))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 15m & 1h & 4h down move, 1d high & overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_200))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_45) | (stochrsi_k_15m_lt_70))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_100))
            # 15m & 4h & 1d down move, 1d stil high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (rsi_14_1d_lt_50) | (roc_9_4h_gt_neg_20))
            # 15m & 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_20))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_80))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_30))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_50) | aroonu_14_4h_lt_80)
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_25) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_25) | (stochrsi_k_4h_lt_90) | (roc_9_1d_gt_neg_30))
            # 15m down move, 1h & 4h overbought
            & ((rsi_3_15m_gt_25) | (roc_9_1h_lt_10) | (roc_9_4h_lt_30))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 4h high, 1d high & overbought
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_50) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 15m down move, 15m & 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_90))
            # 1h & 4h down move, 1h downtrend
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (cmf_20_1h_gt_neg_0_20))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_lt_40))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_40))
            # 1h & 4h down move, 15m still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_30) | (stochrsi_k_15m_lt_50))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_5) | (stochrsi_k_15m_lt_20))
            # 1h & 4h down move, 1d still high
            & ((rsi_3_1h_gt_5) | rsi_3_4h_gt_20 | (aroonu_14_1d_lt_50))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_30))
            # 1h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_5) | (rsi_3_1d_gt_5) | (aroonu_14_1h_lt_40))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_5) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 1h & 4h & 1d down move, 4h downtrend, 1d still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (rsi_14_4h_gt_30) | (aroonu_14_1d_lt_40))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_30))
            # 1h & 4h down move, 15m still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_50))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_50))
            # 1h & 4h & 1d down move, 15m high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (stochrsi_k_15m_lt_60))
            # 1h & 4h down move, 4h high & overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_10))
            # 1h & 1d down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_10) | (stochrsi_k_4h_lt_70))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_70))
            # 1h down move, 1d high, 1h downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_70) | (roc_9_1h_gt_neg_10))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_3) | (stochrsi_k_15m_lt_30))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_1h_lt_70))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_70))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_45) | (roc_9_1d_gt_neg_40))
            # 1h & 1d down move, 15m & 1h still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_15) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_30))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_80))
            # 1h down move, 4h still high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_50) | (roc_9_1d_lt_40))
            # 1h down move, 4h high, 4h overbought, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_10) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1d high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_10))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (stochrsi_k_4h_lt_80) | (roc_9_1d_gt_neg_30))
            # 1h & 4h & 1d down move, 1d still high, 1h still not low enough
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30) | (rsi_14_1d_lt_50) | (stochrsi_k_1h_lt_20))
            # 1h & 4h & 1d down move, 1h still not low enough, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_45) | (aroonu_14_1h_lt_30) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_40))
            # 1h & 4h & 1d down move, 1h stil high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_100))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_80))
            # 1h & 4h down move, 4h overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (roc_9_4h_lt_10))
            # 1h & 4h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_100))
            # 1h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_50))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_70))
            # 1h down move, 1h high, 1h still not low enough
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_80) | (stochrsi_k_1h_lt_20))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 1h down move, 4h still high, 1d downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_40))
            # 1h down move, 4h high & overbought, 1d downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10) | (roc_9_1d_gt_neg_20))
            # 1h & 4h & 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_70) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1h high, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_100))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_lt_70))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_30))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (roc_9_1d_lt_100))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_60))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_70))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (rsi_14_1d_lt_80))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 4h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_80) | (stochrsi_k_4h_lt_80))
            # 1h down move, 4h high, 1h overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_80) | (roc_9_1h_lt_10))
            # 1h & 4h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_10))
            # 1h & 4h down move, 4h high & overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 1h & 4h down move, 4h & 1d high
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100))
            # 1h down move, 1h high, 15m high
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_70) | (stochrsi_k_15m_lt_70))
            # 4h & 1d down move, 15m still not low enough
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_15) | (aroonu_14_15m_lt_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_lt_40))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_3) | (rsi_3_1d_gt_25) | (aroonu_14_1d_lt_70))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_3) | (stochrsi_k_15m_lt_60))
            # 4h & 1d down move, 1d still high, 1h still low enough
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_35) | (rsi_14_1d_lt_40) | (stochrsi_k_1h_lt_20))
            # 4h down move, 15m still high, 4h still not low enough
            & ((rsi_3_4h_gt_5) | (stochrsi_k_15m_lt_50) | (aroonu_14_4h_lt_30))
            # 4h & 1d down move, 15m still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_15) | (stochrsi_k_15m_lt_40))
            # 4h down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_4h_lt_20) | (roc_9_1d_gt_neg_10))
            # 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 4h down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_40) | (roc_9_1d > -30.0))
            # 4h down move, 1d high, 15m high
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_80) | (stochrsi_k_15m_lt_60))
            # 4h down move, 1d high, 4h downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_100) | (roc_9_4h_gt_neg_10))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_50))
            # 4h & 1d down move, 1d still high, 4h & 1d downtrend
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (rsi_14_1d_lt_40) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_lt_50))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_45) | (stochrsi_k_4h_lt_40))
            # 4h down move, 4h still not low enough, 1d high
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_70))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_15) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_70))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (roc_9_1d_gt_neg_30))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_70))
            # 4h & 1d down move, 4h overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (roc_9_4h_lt_5))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (roc_9_1d_lt_10))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_30) | (rsi_3_1d > 70.0) | (roc_9_1d_lt_20))
            # 4h down move, 4h high, 1d high
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_70) | (stochrsi_k_1d_lt_80))
            # 4h down move, 1d stil high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h still high, 4h downtrend
            & ((rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_40) | (roc_9_4h_gt_neg_15))
            # 4h & 1d down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (stochrsi_k_4h_lt_50) | (aroonu_14_1d_lt_60))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h & 1d high & overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_55) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_100))
            # 1d down move, 4h still not low enough, 4h downtrend
            & ((rsi_3_1d_gt_10) | (stochrsi_k_4h_lt_30) | (roc_9_4h_gt_neg_15))
            # 1d down move, 4h & 1d downtrend
            & ((rsi_3_1d_gt_10) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 1d down move, 1d high, 4h downtrend
            & ((rsi_3_1d_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_4h_gt_neg_20))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_25) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_30) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1h high, 4h & 1d overbought
            & ((aroonu_14_1h_lt_70) | (roc_9_4h_lt_40) | (roc_9_1d_lt_80))
            # 4h & 1d high & overbought
            & ((aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_40) | (roc_9_1d_lt_60))
            # 4h & 1d high, 1h overbought
            & ((aroonu_14_4h_lt_85) | (aroonu_14_1d_lt_100) | (roc_9_1h_lt_10))
            # 4h high, 4h & 1d overbought
            & ((aroonu_14_4h_lt_90) | (roc_9_4h_lt_30) | (roc_9_1d_lt_60))
            # 15m high, 4h & 1d overbought
            & ((stochrsi_k_15m_lt_80) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 15m still high, 4h & 1d overbought
            & ((stochrsi_k_15m_lt_50) | (roc_9_4h_lt_40) | (roc_9_1d_lt_100))
            # 4h high, 4h & 1d overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_4h_lt_30) | (roc_9_1d_lt_60))
            # 1d high, 4h & 1d overbought
            & ((stochrsi_k_1d_lt_90) | (roc_9_4h_lt_30) | (roc_9_1d_lt_100))
            # 4h & 1d overbought
            & ((roc_9_4h_lt_100) | (roc_9_1d_lt_200))
            # 1d P&D, 4h overbought
            & ((change_pct_1d_gt_neg_10) | (change_pct_1d_shift_288 < 50.0) | (roc_9_4h_lt_30))
          )

          # Logic
          long_entry_logic.append(
            (willr_14 < -50.0)
            & (stochrsi_k_lt_30)
            # & (df["STOCHRSIk_14_14_3_3_15m"] < 40.0)
            & (stochrsi_k_1h_lt_40)
            & (bbb_20_2_0_1h > 12.0)
            & (close_max_48 >= (close * 1.10))
          )

        # Condition #145 - Top Coins mode (Long).
        if long_entry_condition_index == 145:
          # Protections
          long_entry_logic.append(is_pair_long_top_coins_mode)
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append(
            # 5m & 4h down move, 1d downtrend
            ((rsi_3_gt_3) | (rsi_3_4h_gt_3) | (roc_9_1d_gt_neg_20))
            # 5m down move, 15m & 1h high
            & ((rsi_3_gt_10) | (aroonu_14_15m_lt_85) | (aroonu_14_1h_lt_100))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (rsi_3_4h_gt_5))
            # 15m & 1h down move, 1h downtrend
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_3) | (roc_9_1h_gt_neg_20))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_20))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_3) | (rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_70))
            # 15m & 1h & 4h down move, 4h high & overbought
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 1d high, 4h downtrend, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (stochrsi_k_1d_lt_80) | (roc_9_4h_gt_neg_10) | (roc_9_1d_lt_20))
            # 15m & 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (rsi_14_1d_lt_50))
            # 15m & 1h & 4h & 1d down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_55) | (rsi_3_1d_gt_55) | (aroonu_14_1d_lt_80))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_30))
            # 15m & 4h down move, 15m & 4h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_70))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_70))
            # 15m & 4h down move, 15m & 4h, 1d overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_15m_lt_60) | (aroonu_14_4h_lt_60) | (roc_9_1d_lt_20))
            # 15m & 1h & 4h & 1d down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (stochrsi_k_1h_lt_50))
            # 15m & 1h & 1d down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_4h_lt_100))
            # 15m & 4h & 1d down move, 15m still high, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_45) | (aroonu_14_15m_lt_50) | (aroonu_14_1d_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_90))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_90))
            # 15m & 4h & 1d down move, 15m high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_55) | (aroonu_14_15m_lt_90))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_90))
            # 15m down move, 15m downtrend, 1h high
            & ((rsi_3_15m_gt_15) | (cmf_20_15m_gt_neg_0_40) | (aroonu_14_1h_lt_60))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_40) | (stochrsi_k_4h_lt_60))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_90) | (roc_9_1d_gt_neg_30))
            # 15m & 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (roc_9_1d_gt_neg_30))
            # 15m & 1h & 4h down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 4h high, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_50) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_40))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 15m & 4h & 1d down move, 4h still high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_50))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_100))
            # 15m & 1h & 4h down move, 1d still high, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_45) | (rsi_14_1d_lt_50) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_35) | (stochrsi_k_15m_lt_50))
            # 15m down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_25) | (stochrsi_k_15m_lt_50) | (roc_9_1d_lt_30))
            # 15h & 1h & 4h down move, 15m high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (stochrsi_k_15m_lt_70))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_lt_70))
            # 15m down move, 15m & 4h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_70) | aroonu_14_4h_lt_70)
            # 15m down move, 15m high, 1h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_70) | (stochrsi_k_1h_lt_70))
            # 15m down move, 15m high, 4h high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_80))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_20))
            # 15m down move, 4h & 1d high, 4h & 1d overbought
            & ((rsi_3_15m_gt_35) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_20) | (roc_9_1d_lt_40))
            # 15m down move, 4h & 1d overbought
            & ((rsi_3_15m_gt_35) | (roc_9_4h_lt_30) | (roc_9_1d_lt_80))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_3) | rsi_3_4h_gt_20 | (aroonu_14_4h_lt_40))
            # 1h down move, 4h still high, 1d high
            & ((rsi_3_1h_gt_3) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_90))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_5) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_40))
            # 1h & 1d down move, 1h still not low enough
            & ((rsi_3_1h_gt_5) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_20))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_15))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_40))
            # 1h & 4h down move, 4h downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_10))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (roc_9_4h_gt_neg_30))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_50))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (stochrsi_k_15m_lt_80))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_25) | (roc_9_1d_gt_neg_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_90))
            # 1h & 4h down move, 4h high, 1d high & overbought
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_45) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_20))
            # 1h & 1d down move, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_20) | (aroonu_14_1h_lt_30))
            # 1h down move, 15m downtrend, 1d high
            & ((rsi_3_1h_gt_10) | (cmf_20_15m_gt_neg_0_40) | (aroonu_14_1d_lt_70))
            # 1h down move, 4h still high, 1d overbought
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_40) | (roc_9_1d_lt_40))
            # 1h down move, 1d still high, 1d downtrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_20))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_20))
            # 1h & 4h down move, 15m still not low enough
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_lt_30))
            # 1h & 4h down move, 15m still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_15m_lt_50))
            # 1h & 4h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (rsi_14_1d_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (roc_9_1d_gt_neg_40))
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_60))
            # 1h down move, 1h still high, 4h overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_50) | (roc_9_4h_lt_10))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_60) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_15) | (roc_9_4h_lt_30) | (roc_9_1d_lt_50))
            # 1h & 4h & 1d down move, 1d still high, 4h downtrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_35) | (stochrsi_k_1d_lt_40) | (roc_9_4h_gt_neg_10))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_70))
            # 1h & 4h down move, 1d high & overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_80))
            # 1h & 4h down move, 4h high & overbought
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_30))
            # 1h & 1d down move, 4h still high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_50))
            # 1h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_50))
            # 1h down move, 15m still high, 1h high
            & ((rsi_3_1h_gt_20) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_80))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_80) | (roc_9_4h_lt_60))
            # 1h down move, 1h still not low enough, 1d downtrend
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_30) | (roc_9_1d_gt_neg_30))
            # 1h & 4h & 1d down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_10))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_70))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (roc_9_1d_lt_20))
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_85))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_30))
            # 1h down move, 1h still high, 4h downtrend
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_50) | (roc_9_4h_gt_neg_20))
            # 1h down move, 1d overbought
            & ((rsi_3_1h_gt_25) | (roc_9_1d_lt_80))
            # 1h down move, 1h still high, 4h high & overbought
            & ((rsi_3_1h_gt_30) | (rsi_14_1h_lt_40) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_20))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_70) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_80))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_35) | (rsi_3_1d_gt_40) | (aroonu_14_1h_lt_70))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_40) | (roc_9_1d_lt_40))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_60))
            # 1h down move, 4h high, 1d downtrend
            & ((rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_90) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (roc_9_1d_gt_neg_30))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_70) | (roc_9_1d_gt_neg_30))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_80) | (roc_9_4h_lt_10))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_25))
            # 1h down move, 4h high, 1h & 4h overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_10) | (roc_9_4h_lt_10))
            # 4h down move, 4h & 1d downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_4h_gt_neg_15) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_50))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_10) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_lt_70))
            # 4h down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_30))
            # 4h down move, 15m & 1h still not low enough
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_30))
            # 4h down move, 15m stil high, 4h downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_50) | (roc_9_4h_gt_neg_20))
            # 4h & 1d down move, 1d downtrend
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (roc_9_1d > -30.0))
            # 4h & 1d down move, 1h still high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (stochrsi_k_1h_lt_50))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_35) | (stochrsi_k_4h_lt_70))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_60))
            # 4h & 1d down move, 15m still high, 4h downtrend
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_30) | (stochrsi_k_15m_lt_50) | (roc_9_4h_gt_neg_20))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_70))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_20) | (stochrsi_k_15m < 90.0))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_30))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_10))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (aroonu_14_1d_lt_80))
            # 4h down move, 15m high, 1d overbought
            & ((rsi_3_4h_gt_30) | (stochrsi_k_15m < 90.0) | (roc_9_1d_lt_10))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_4h_lt_60) | (roc_9_1d_lt_40))
            # 4h & 1d down move, 1h high
            & ((rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (stochrsi_k_1h_lt_70))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_55) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_80))
            # 1d down move, 1d high, 1d downtrend
            & ((rsi_3_1d_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_20))
            # 1d down move, 1h high
            & ((rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_70))
            # 1d down move, 1h high, 1d downtrend
            & ((rsi_3_1d_gt_25) | (stochrsi_k_1h_lt_60) | (roc_9_1d_gt_neg_30))
            # 1d down move, 1d high, 4h downtrend
            & ((rsi_3_1d_gt_35) | (aroonu_14_1d_lt_70) | (roc_9_4h_gt_neg_10))
            # 1d down move, 4h high, 1d overbought
            & ((rsi_3_1d_gt_60) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_40))
            # 15m high, 1d high & overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_100))
            # 15m high, 4h overbought, 1d downtrend
            & ((aroonu_14_15m_lt_80) | (roc_9_4h_lt_20) | (roc_9_1d_gt_neg_30))
            # 1h & 4h high, 4h overbought
            & ((aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10))
            # 1h high, 1d overbought
            & ((aroonu_14_1h_lt_85) | (roc_9_1d_lt_80))
            # 1h high, 4h & 1d downtrend
            & ((aroonu_14_1h_lt_100) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_25))
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_100) | aroonu_14_1d_lt_100 | (roc_9_1d_lt_60))
            # 1h high, 4h & 1d downtrend
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_25))
            # 1h & 4h high, 4h overbought
            & ((stochrsi_k_1h_lt_90) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_10))
          )

          # Logic
          long_entry_logic.append(
            (rsi_14 < 36.0)
            & (bbd_40_2_0 > close * 0.020)
            & (close_delta > close * 0.02)
            & (bbt_40_2_0 < bbd_40_2_0 * 0.3)
            & (close < bbl_40_2_0_shift_1)
            & (close <= close_shift_1)
          )

        # Condition #146 - Top Coins mode (Long).
        if long_entry_condition_index == 146:
          # Protections
          long_entry_logic.append(is_pair_long_top_coins_mode)
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          # Logic
          long_entry_logic.append(
            # 5m momentum already turning up
            (rsi_20 < rsi_20_shift_1)
            # 5m oversold
            & (rsi_3 < 30.0)
            # 5m freshness has not been bought yet
            & (aroonu_14_lt_25)
            # price still below a stretched 5m mean
            & (close < sma_16 * 0.960)
            # tape not falling on the entry bar
            & (btc_roc_1_5m > -1.2)
            # 1h momentum has turned
            & (cci_20_change_pct_1h > -34.7)
            # 1h range still compressed
            & (bbb_20_2_0_1h > 5.15)
            # 4h still oversold
            & (willr_14_4h < -6.7)
            # 4h trend pointing down
            & (aroond_14_4h > 7.1429)
            # tape not cascading over four hours
            & (btc_roc_1_4h > -2.2)
          )

        # Condition #161 - Scalp mode (Long).
        if long_entry_condition_index == 161:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          # 5m down move, 15m high
          long_entry_logic.append(
            ((rsi_3_gt_15) | (aroonu_14_15m_lt_80))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_35) | aroonu_14_4h_lt_70)
            # 15m & 4h down move, 4h still high
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_50))
            # 15m down move, 15m high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_80))
            # 15m down move, 4h still high, 1d high
            & ((rsi_3_15m_gt_25) | (stochrsi_k_4h_lt_50) | (aroonu_14_1d_lt_90))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_60) | (aroonu_14_15m_lt_50))
            # 15m & 4h & 1d down move, 15m high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_60) | (aroonu_14_15m_lt_70))
            # 15m down move, 15m & 4h still high
            & ((rsi_3_15m_gt_30) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_50))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_60) | aroonu_14_4h_lt_80)
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_40) | aroonu_14_1h_lt_70)
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_60) | aroonu_14_4h_lt_80)
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_40) | (rsi_3_4h_gt_40) | (stochrsi_k_15m_lt_50))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_40) | (rsi_3_4h_gt_60) | (stochrsi_k_15m_lt_70))
            # 15m down move, 15m & 1h still high
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_lt_50))
            # 15m down move, 15m & 1h still high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_50))
            # 15m down move, 4h still high, 1d overbought
            & ((rsi_3_15m_gt_40) | (aroonu_14_4h_lt_50) | (roc_9_1d_lt_100))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_45) | (rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_40))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_45) | (aroonu_14_15m_lt_60) | roc_9_1d_lt_50)
            # 15m down move, 15m high, 4h still high
            & ((rsi_3_15m_gt_45) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_50))
            # 15m down move, 15m still not low enough, 4h still high
            & ((rsi_3_15m_gt_45) | (stochrsi_k_15m_lt_30) | (stochrsi_k_4h_lt_50))
            # 15m down move, 15m & 1h still high
            & ((rsi_3_15m_gt_45) | (stochrsi_k_15m < 45.0) | (stochrsi_k_1h_lt_40))
            # 15m & 1h down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_60) | (stochrsi_k_4h_lt_70) | (roc_9_1d_lt_20))
            # 15m down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_30) | (stochrsi_k_4h_lt_90))
            # 15m down move, 15m still high, 1d overbought
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_50))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_70))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_50) | (aroonu_14_4h_lt_85))
            # 15m down move, 15m & 1h still high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_50))
            # 1h down move, 4h still high, 1d high
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_50) | (stochrsi_k_1d_lt_90))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_65) | (aroonu_14_1h_lt_50))
            # 1h down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_40) | (stochrsi_k_1d_lt_90))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_55) | (stochrsi_k_4h_lt_50))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80))
            # 1h down move, 15m & 1h still high
            & ((rsi_3_1h_gt_40) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_50))
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_70))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_60))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_85) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90))
            # 1h down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_45) | (stochrsi_k_1h_lt_60))
            # 1h & 4h down move, 4h still high, 1d high & overbought
            & ((rsi_3_1h_gt_50) | (rsi_3_4h_gt_55) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_60) | (roc_9_1d_lt_50))
            # 1h & 4h down move, 15m high
            & ((rsi_3_1h_gt_50) | (rsi_3_4h_gt_60) | (aroonu_14_15m_lt_70))
            # 1h down move, 15m still high, 4h high
            & ((rsi_3_1h_gt_50) | (aroonu_14_15m_lt_50) | aroonu_14_4h_lt_80)
            # 1h down move, 15m high, 1h still high
            & ((rsi_3_1h_gt_50) | (aroonu_14_15m_lt_70) | (stochrsi_k_1h_lt_40))
            # 1h down move, 15m still high, 4h high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_80))
            # 1h down move, 15m & 1h high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_15m_lt_60) | (aroonu_14_1h_lt_60))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_70) | (stochrsi_k_1d_lt_80))
            # 1h down move, 4h still high, 1d high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_50) | (stochrsi_k_1d_lt_90))
            # 1h down move, 1h still high, 1d high
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_90))
            # 1h down move, 4h overbought
            & ((rsi_3_1h_gt_50) | (roc_9_4h_lt_40))
            # 1h & 4h down move, 1h & 4h high
            & ((rsi_3_1h_gt_55) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_70))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100))
            # 1h down move, 5m up move, 1h still high
            & ((rsi_3_1h_gt_60) | (rsi_3 < 60.0) | (stochrsi_k_1h_lt_50))
            # 1h & 4h down move, 1h stil high, 1d high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_lt_90))
            # 1h down move, 15m still not low enough, 4h high
            & ((rsi_3_1h_gt_60) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_90))
            # 1h down move, 15m still not low enough, 1h high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_15m_lt_30) | aroonu_14_1h_lt_70)
            # 1h down move, 15m still not low enough, 1h high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_60))
            # 1h down move, 15m & 4h still high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_50))
            # 1h down move, 15m & 1h high
            & ((rsi_3_1h_gt_60) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_90))
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_50) | (stochrsi_k_4h_lt_90))
            # 1h down move, 1h high, 4h still high
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_40))
            # 1h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_40) | aroonu_14_4h_lt_70)
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_70) | (aroonu_14_1d_lt_90))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_60) | (rsi_14_4h_lt_70) | (rsi_14_1d_lt_80))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_65) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_85))
            # 4h down move, 15m high
            & (rsi_3_4h_gt_20 | (aroonu_14_15m_lt_80))
            # 4h down move, 1h high
            & ((rsi_3_4h_gt_25) | (stochrsi_k_1h_lt_80))
            # 4h down move, 15m & 4h still high
            & ((rsi_3_4h_gt_30) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_50))
            # 4h down move, 15m still high, 1d overbought
            & ((rsi_3_4h_gt_30) | (stochrsi_k_15m_lt_50) | (roc_9_1d_lt_10))
            # 4h down move, 1h & 4h still high
            & ((rsi_3_4h_gt_35) | (stochrsi_k_1h_lt_50) | (aroonu_14_4h_lt_50))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_35) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_40))
            # 4h down move, 15m & 1h high
            & ((rsi_3_4h_gt_40) | (aroonu_14_15m_lt_80) | (stochrsi_k_1h_lt_70))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_20))
            # 4h down move, 15m still high, 1h high
            & ((rsi_3_4h_gt_40) | (stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_80))
            # 4h down move, 1h & 4h still high
            & ((rsi_3_4h_gt_40) | (stochrsi_k_1h_lt_50) | (rsi_14_4h_lt_50))
            # 4h down move, 1h still high, 4h still moving down
            & ((rsi_3_4h_gt_40) | (stochrsi_k_1h_lt_50) | (cci_20_change_pct_4h > -0.0))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_40) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_10))
            # 4h & 1d down move, 15m high, 1h high
            & ((rsi_3_4h_gt_45) | (rsi_3_1d_gt_55) | (aroonu_14_15m_lt_70) | (stochrsi_k_1h_lt_80))
            # 4h down move, 1h high, 4h still high
            & ((rsi_3_4h_gt_45) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_50))
            # 4h down move, 4h still high, 1d high & overbought
            & ((rsi_3_4h_gt_50) | (rsi_14_4h_lt_50) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_30))
            # 4h down move, 15m high, 4h still high
            & ((rsi_3_4h_gt_50) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_40))
            # 4h down move, 15m still high, 1h high
            & ((rsi_3_4h_gt_50) | (stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_70))
            # 4h down move, 15m & 4h still high
            & ((rsi_3_4h_gt_50) | (stochrsi_k_15m_lt_50) | (aroonu_14_4h_lt_50))
            # 4h down move, 15m high, 1h high, 1d overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_20))
            # 4h down move, 15m high, 4h still not low enough
            & ((rsi_3_4h_gt_50) | (stochrsi_k_15m_lt_70) | (stochrsi_k_4h_lt_30))
            # 4h down move, 1h still high, 4h high
            & ((rsi_3_4h_gt_50) | (stochrsi_k_1h_lt_50) | aroonu_14_4h_lt_70)
            # 4h down move, 15m & 1d high
            & ((rsi_3_4h_gt_50) | (aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_90))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_50) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 4h down move, 15m & 4h high
            & ((rsi_3_4h_gt_60) | (aroonu_14_15m_lt_70) | aroonu_14_4h_lt_70)
            # 4h down move, 15m high, 4h still high
            & ((rsi_3_4h_gt_60) | (aroonu_14_15m_lt_80) | (aroonu_14_4h_lt_40))
            # 4h down move, 15m still high, 1h high
            & ((rsi_3_4h_gt_60) | (stochrsi_k_15m_lt_50) | aroonu_14_1h_lt_70)
            # 4h down move, 15m still high, 4h high
            & ((rsi_3_4h_gt_60) | (stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_70))
            # 4h down move, 15m & 4h high
            & ((rsi_3_4h_gt_60) | (stochrsi_k_15m_lt_70) | (stochrsi_k_4h_lt_60))
            # 4h down move, 1h & 4h high
            & ((rsi_3_4h_gt_60) | (stochrsi_k_1h_lt_70) | aroonu_14_4h_lt_70)
            # 4h down move, 4h still high, 1d high
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_50) | (stochrsi_k_1d_lt_80))
            # 15m still high, 1d high & overbought
            & ((aroonu_14_15m_lt_50) | aroonu_14_1d_lt_100 | (roc_9_1d_lt_100))
            # 15m high, 4h high
            & ((aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_85))
            # 15m & 1d high, 1d overbought
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 15m & 1d high, 4h overbought
            & ((aroonu_14_15m_lt_70) | aroonu_14_1d_lt_100 | (roc_9_4h_lt_10))
            # 15m high, 4h still high
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_4h_lt_50))
            # 4h & 1d high, 1d overbought
            & (aroonu_14_4h_lt_100 | aroonu_14_1d_lt_100 | (roc_9_1d_lt_20))
            # 4h high, 4h overbought
            & (aroonu_14_4h_lt_70 | (roc_9_4h_lt_40))
            # 4h high, 1d overbought
            & (aroonu_14_4h_lt_70 | (roc_9_1d_lt_40))
            # 1d high, 4h overbought
            & ((aroonu_14_1d_lt_90) | (roc_9_4h_lt_40))
            # 1d high & overbought
            & (aroonu_14_1d_lt_100 | (roc_9_1d_lt_200))
            # 15m high, 1h still high
            & ((stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_40))
            # 15m & 4h high
            & ((stochrsi_k_15m_lt_70) | aroonu_14_4h_lt_70)
            # 15m high, 1d overbought
            & ((stochrsi_k_15m_lt_70) | (roc_9_1d_lt_10))
            # 15m high, 1h still not low enough
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_30))
            # 1d high, 4h overbought
            & ((stochrsi_k_1d_lt_80) | (roc_9_4h_lt_40))
            # 1d high & overbought
            & ((stochrsi_k_1d_lt_90) | (roc_9_1d_lt_30))
            # 4h & 1d overbought
            & ((roc_9_4h_lt_40) | (roc_9_1d_lt_40))
            # 1d green with top wick, 1d overbought
            & ((change_pct_1d_lt_25) | (top_wick_pct_1d_lt_25) | roc_9_1d_lt_50)
          )

          # Logic
          long_entry_logic.append(
            (rsi_14 < 50.0)
            & aroonu_14_15m_lt_90
            & (stochrsi_k_15m < 90.0)
            & (sma_21_shift_1 < sma_200_shift_1)
            & ~np.isnan(sma_200_shift_1)
            & (sma_21 > sma_200)
            & ~np.isnan(sma_200)
            & (close > ema_200_1h)
            & ~np.isnan(ema_200_1h)
            & (close > ema_200_4h)
            & ~np.isnan(ema_200_4h)
            & (bbb_20_2_0 > 1.5)
            & (bbb_20_2_0_1h > 6.0)
          )

        # Condition #162 - Scalp mode (Long).
        if long_entry_condition_index == 162:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append((rsi_3_gt_5) & (rsi_3_15m_gt_5) & (roc_9_15m > -10.0) & (roc_9_1d_lt_200))

          long_entry_logic.append(
            # 15m & 1h down move, 4h high
            ((rsi_3_15m_gt_10) | rsi_3_1h_gt_20 | (stochrsi_k_4h_lt_70))
            # 15m & 1d down move, 1h high & overbought
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_40) | (rsi_14_1h_lt_50))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_20) | (aroonu_14_4h_lt_90))
            # 15m down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_50) | aroonu_14_1h_lt_80)
            # 15m down move, 15m high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_70))
            # 15m down move, 1h & 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_90) | aroonu_14_1d_lt_100)
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_75) | aroonu_14_1d_lt_100)
            # 15m down move, 1d high, 1d downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_1d_lt_85) | (cmf_20_1d_gt_neg_0_40))
            # 15m & 1h down move, 15m still not low enough
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (stochrsi_k_15m_lt_30))
            # 15m & 1h down nove, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_50))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_100))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_90))
            # 15m & 1d down move, 15m high, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_50) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_100))
            # 15m down move, 4h high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_60) | (roc_9_4h_gt_neg_20))
            # 15m down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_15) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_40))
            # 15m & 1h & 4h & 1d down move, 15m downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (cmf_20_15m_gt_neg_0_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_70))
            # 15m & 1h down move, 1d high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_50) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_100))
            # 15m & 4h down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (roc_9_4h_gt_neg_40) | (roc_9_1d_gt_neg_50))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_70) | (roc_9_4h_lt_20))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_90))
            # 15m & 1h & 4h down move, 15m high, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_50) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_100))
            # 15m down move, 15m high, 1d overbought
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_60) | (roc_9_1d_lt_150))
            # 15m down move, 15m still high, 1d high, 1d downtrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_50) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
            # 15m & 1h & 4h down move, 1d high, 4h still not low enough
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100) | (stochrsi_k_4h_lt_30))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_1h_lt_80) | (rsi_14_4h_lt_80))
            # 1h & 4h down move, 15m stil high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_10) | (stochrsi_k_15m_lt_50))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_25) | (aroonu_14_1h_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_5) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_90))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_5) | (aroonu_14_4h_lt_60) | (roc_9_1d_lt_10))
            # 1h & 4h down move, 4h still not low enough, 1h downtrend
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_20) | (roc_9_1h_gt_neg_10))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_50))
            # 1h & 3h down move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_70))
            # 1h down move, 1h downtrend, 1d overbought
            & ((rsi_3_1h_gt_15) | (roc_9_1h_gt_neg_30) | (roc_9_1d_lt_80))
            # 1h & 4h down move, 1d downtrend
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (roc_9_1d_gt_neg_30))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_lt_85))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_60) | (roc_9_1d_lt_50))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_15) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_40))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | aroonu_14_4h_lt_70)
            # 4h down move, 1h & 4h still high, 1h downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_40) | (roc_9_1h_gt_neg_25))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_60) | (roc_9_1d_lt_100))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_90))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_70))
            # 1h & 4h down move, 15m & 4h high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_70))
            # 1h & 4h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_80) | (roc_9_1d_gt_neg_50))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_60) | (roc_9_4h_lt_50))
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_80))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_100))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_30))
            # 1h down move, 1h high, 4h downtrend
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_80) | (roc_9_4h_gt_neg_20))
            # 1h down move, 15m still high, 1d overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_50))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_45) | (roc_9_4h_lt_10) | (roc_9_1d_lt_50))
            # 1h down move,  4h high, 1d overbought
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_150))
            # 1h down move, 1h high & overbought
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_70) | (roc_9_1h_lt_20))
            # 4h down move, 1d high
            & ((rsi_3_4h_gt_3) | (aroonu_14_1d_lt_90))
            # 4h down move, 15m still high
            & ((rsi_3_4h_gt_3) | (stochrsi_k_15m_lt_50))
            # 4h down move, 1d high
            & ((rsi_3_4h_gt_3) | (stochrsi_k_1d_lt_90))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_3) | (roc_9_1h_gt_neg_30) | (roc_9_4h_gt_neg_30))
            # 4h down move, 1d overbought
            & ((rsi_3_4h_gt_3) | (roc_9_1d_lt_40))
            # 4h & 1d down move
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_10))
            # 4h & 1d down move, 1d high & overbought
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_50))
            # 4h down move, 1d high, 1h downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_85) | (roc_9_1h_gt_neg_30))
            # 4h down move, 1h & 4h downtrend
            & ((rsi_3_4h_gt_10) | (roc_9_1h_gt_neg_40) | (roc_9_4h_gt_neg_40))
            # 4h & 1d down move, 4h still not low enough
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_30))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_40))
            # 4h down move, 15m still high, 1d overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_50))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_40) | (roc_9_4h_lt_10) | (roc_9_1d_lt_50))
            # 1d down move, 1h high
            & ((rsi_3_1d_gt_3) | (stochrsi_k_1h_lt_70))
            # 1d down move, 15m still high
            & ((rsi_3_1d_gt_3) | (aroonu_14_15m_lt_50))
            # 1d down move, 15m still high, 1h high
            & ((rsi_3_1d_gt_10) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_lt_70))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_10) | aroonu_14_1h_lt_70 | (aroonu_14_4h_lt_90))
            # 1d down move, 4h high
            & ((rsi_3_1d_gt_20) | (rsi_14_4h_lt_80))
            # 1d downtrend, 1d high & overbought
            & ((cmf_20_1d_gt_neg_0_30) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_100))
            # 1h & 4h high, 1d overbought
            & (aroonu_14_1h_lt_70 | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_30))
            # 1h & 4h high & overbought
            & ((aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_30) | (roc_9_4h_lt_30))
            # 1h & 4h high, 1d overbought
            & ((aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_20))
            # 1h & 4h high
            & ((aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100))
            # 4h & 1d high, 4h overbought
            & (aroonu_14_4h_lt_80 | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_30))
            # 4h high, 4h & 1d overbought
            & (aroonu_14_4h_lt_80 | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 1d still high, 1h & 4h downtrend
            & ((aroonu_14_1d_lt_50) | (roc_9_1h_gt_neg_20) | (roc_9_4h_gt_neg_20))
            # 1h high, 1h overbought
            & ((stochrsi_k_1h_lt_80) | (roc_9_1h_lt_50))
            # 1h high, 1d downtrend
            & ((stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_60))
            # 4h high, 1h overbought, 1d downtrend
            & ((stochrsi_k_4h_lt_80) | (roc_9_1h_lt_10) | (roc_9_1d_gt_neg_70))
            # 4h high, 1h & 4h overbought
            & ((stochrsi_k_4h_lt_90) | (roc_9_1h_lt_20) | (roc_9_4h_lt_50))
            # 1h & 4h overbought
            & ((roc_9_1h_lt_100) | (roc_9_4h_lt_100))
            # 1h P&D, 1h down move
            & ((change_pct_1h > -10.0) | (change_pct_1h_shift_12 < 10.0) | (rsi_3_1h_gt_50))
            # 4h P&D, 4h high
            & ((change_pct_4h > -15.0) | (change_pct_4h_shift_48 < 30.0) | (aroonu_14_4h_lt_90))
            # 4h green, 15m & 1h down move
            & ((change_pct_4h < 10.0) | (rsi_3_15m_gt_10) | (rsi_3_1h_gt_35))
            # 4h green, 1h down move
            & ((change_pct_4h < 40.0) | (rsi_3_1h_gt_50))
            # 4h green with top wick
            & ((change_pct_4h < 50.0) | (change_pct_4h < 50.0))
            # 1d green with top wick, 15m still high
            & ((change_pct_1d_lt_10) | (top_wick_pct_1d_lt_8) | (aroonu_14_15m_lt_50))
            # 1d green, 4h down move, 4h still high
            & ((change_pct_1d_lt_40) | (rsi_3_4h_gt_35) | (aroonu_14_4h_lt_50))
            # 1d green with top wick, 4h down move
            & ((change_pct_1d_lt_40) | (top_wick_pct_1d_lt_8) | (rsi_3_4h_gt_55))
            # 1d top wick, 1h & 4h down move, 1d high
            & ((top_wick_pct_1d_lt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_100))
            # 1d top wick, 4h still high
            & ((top_wick_pct_1d_lt_50) | (aroonu_14_4h_lt_50))
            # big drop in last 4 days, 1d down move
            & ((close > (high_max_24_4h * 0.20)) | (rsi_3_1d_gt_20))
            # big drop in the last 20 days, 4h down move
            & ((close > (high_max_20_1d * 0.15)) | rsi_3_4h_gt_20)
            # big drop in the last 20 days, 1d down move
            & ((close > (high_max_20_1d * 0.05)) | (rsi_3_1d_gt_20))
            # big drop in the last 20 days, 1h still high
            & ((close > (high_max_20_1d * 0.05)) | (stochrsi_k_1h < 45.0))
            # big drop in the last 20 days, 4h high
            & ((close > (high_max_20_1d * 0.05)) | (stochrsi_k_4h_lt_70))
          )

          # Logic
          long_entry_logic.append(
            (aroonu_14_lt_25)
            & (aroond_14_gt_75)
            & (stochrsi_k_lt_30)
            & (ema_26 > ema_12)
            & ((ema_26 - ema_12) > (open_rate * 0.030))
            & ((ema_26_shift_1 - ema_12_shift_1) > (open_rate / 100.0))
            & (close < sma_9)
          )

        # Condition #163 - Scalp mode (Long).
        if long_entry_condition_index == 163:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append((rsi_3_gt_10) & (rsi_3_15m_gt_10) & rsi_3_1h_gt_20)

          long_entry_logic.append(
            # 5m & 15m & 4h down mnove, 4h high
            ((rsi_3_gt_15) | (rsi_3_15m_gt_20) | (rsi_3_4h_gt_40) | aroonu_14_4h_lt_80)
            # 5m & 15m & 1d down move, 1h high
            & ((rsi_3_gt_15) | (rsi_3_15m_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_lt_90))
            # 5m & 1h down move, 15m still high, 4h high
            & ((rsi_3 > 20.0) | (rsi_3_1h_gt_40) | (rsi_14_15m_lt_40) | aroonu_14_4h_lt_100)
            # 5m & 1h & 15m down move, 1h still not low enough
            & ((rsi_3_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_1d_gt_15) | (aroonu_14_1h_lt_30))
            # 15m & 4h down move, 4h high
            & ((rsi_3_gt_15) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_70))
            # 5m & 4h down move, 15m high
            & ((rsi_3_gt_15) | (rsi_3_4h_gt_45) | (aroonu_14_15m_lt_60))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m > 12.0) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_100))
            # 15m & 1h & 4h & 1d down move
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_75) | (aroonu_14_4h_lt_100))
            # 15m & 1h & 4h down move, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (roc_9_1d_lt_40))
            # 15m & 1h & 4h down move, 1h downtrend, 4h high
            & (
              (rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_55) | (cmf_20_1h_gt_neg_0_10) | (aroonu_14_4h_lt_80)
            )
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (aroonu_14_15m_lt_60))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_14_4h < 85.0))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (aroonu_14_15m_lt_40))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | aroonu_14_1h_lt_70)
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_70))
            # 15m & 1h down move, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (roc_9_1d_lt_30))
            # 15m & 1h & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_65) | (mfi_14_4h < 85.0))
            # 15m & 1h & 1d down move, 15m high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (rsi_3_1d_gt_40) | (aroonu_14_15m_lt_60))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (aroonu_14_15m_lt_70))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (stochrsi_k_1h < 85.0))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_80))
            # 15m & 1h & 4h down move, 1h & 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_50) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_lt_100))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_45) | (rsi_14_4h_lt_70) | (roc_9_4h_lt_50))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_90))
            # 15m & 1h & 1d down move, 1h & 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_55) | (rsi_3_4h_gt_65) | (stochrsi_k_1h_lt_70) | (stochrsi_k_4h_lt_70))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_30) | (aroonu_14_15m_lt_60))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_30) | aroonu_14_4h_lt_80)
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_40) | (aroonu_14_1h_lt_40))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (stochrsi_k_1d_lt_90))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (stochrsi_k_1h_lt_60))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_50) | (stochrsi_k_1h_lt_80))
            # 15m down move, 4h & 1d up move, 1d downtrend
            & ((rsi_3_15m_gt_15) | (rsi_3_4h < 90.0) | (rsi_3_1d_lt_80) | (cmf_20_1d_gt_neg_0_20))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_10) | (stochrsi_k_4h_lt_70))
            # 15m & 1h down move, 1h & 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_50))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_1h_lt_100))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_80))
            # 15m & 1d down move, 1d overbought
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_40) | roc_9_1d_lt_50)
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_70))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_60) | (stochrsi_k_1d_lt_80))
            # 15m down move, 4h still high, 15m high, 1h high
            & ((rsi_3_15m_gt_15) | (rsi_14_4h_lt_50) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_100))
            # 15m down move, 4h high
            & ((rsi_3_15m_gt_15) | (rsi_14_4h_lt_70) | (stochrsi_k_4h_lt_90) | (ema_9 < (ema_26 * 0.972)))
            # 15m down move, 4h high and downtrend
            & ((rsi_3_15m_gt_15) | (cmf_20_4h_gt_neg_0_20) | (aroonu_14_4h_lt_80))
            # 15m down move, 15m & 1h & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_80))
            # 15m down move, 15m & 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_80))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_75) | (aroonu_14_1h_lt_100))
            # 15m down move, 1h high, 4h overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_90) | (roc_9_4h_lt_20))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_90) | (roc_9_1d_lt_80))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_40))
            # 15m down move, 4h still high, 4h downtrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_20))
            # 15m down move, 1d high & overbought
            & ((rsi_3_15m_gt_15) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_100))
            # 15m down move, 15m still not low enough, 4h high
            & ((rsi_3_15m_gt_15) | (stochrsi_k_15m_lt_30) | (stochrsi_k_4h_lt_50))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_15) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_50))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_30))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_150))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_20))
            # 15m down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_100))
            # 15m down move, 4h high, 1d overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_25))
            # 15m down move, 4h high & overbought
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_25))
            # 15m down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_15) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_20))
            # 15m & 1h & 4h down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_60) | (roc_9_4h_lt_10))
            # 16m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_40))
            # 15m & 1h & 4h & 1d down move, 15m still high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_60) | (rsi_3_1d_gt_60) | (aroonu_14_15m_lt_50))
            # 15m & 1h down move, 15m still high, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_35) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_85))
            # 15m & 1h down move, 4h high & overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (rsi_14_4h_lt_70) | (roc_9_4h_lt_50))
            # 15m & 1h down move, 1h high, 1d overbought
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_90) | (roc_9_1d_lt_40))
            # 15m & 4h down move, 4h & 1d downtrend
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_50))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_25) | (aroonu_14_15m_lt_60))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_35) | (aroonu_14_1h_lt_100))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_70))
            # 15m down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_14_15m_lt_40) | (rsi_14_4h_lt_75) | (aroonu_14_4h_lt_100))
            # 15m down move, 4h downtrend, 4h overbought
            & ((rsi_3_15m_gt_20) | (cmf_20_4h_gt_neg_0_0) | (roc_9_4h_lt_40))
            # 15m down move, 1h & 4h high, 1f overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_85) | (rsi_14_4h_lt_70) | (roc_9_1d_lt_80))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_100))
            # 15m down move, 1d high, 4h overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_1d_lt_100) | (roc_9_4h_lt_30))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_10))
            # 15m & 1h down move, 1h still high, 4h high & overbought
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_10))
            # 15m & 1h down move, 15m still high, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_45) | (rsi_14_15m_lt_40) | (aroonu_14_4h_lt_100))
            # 15m & 1h & 4h down move, 1h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_60) | (aroonu_14_1h_lt_100))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_80))
            # 15m down move, 4h high, 1d downtrend
            & ((rsi_3_15m_gt_25) | (stochrsi_k_4h_lt_90) | (roc_9_1d_gt_neg_30))
            # 15m & 1h & 1d down move, 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_35) | (rsi_3_1d_gt_35) | (stochrsi_k_4h_lt_70))
            # 15m & 1h down move, 1h & 4h high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_45) | (rsi_14_4h_lt_70) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_100))
            # 15m & 4h down move, 4h overbought
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_60) | (roc_9_4h_lt_60))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_lt_80))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (stochrsi_k_1d_lt_80))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_40) | aroonu_14_4h_lt_70)
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_80))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_65) | aroonu_14_1d_lt_100)
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_70))
            # 1h down move, 15m downtrend, 4h still high
            & ((rsi_3_1h_gt_25) | (cmf_20_15m_gt_neg_0_40) | (aroonu_14_4h_lt_50))
            # 1h down move, 4h downtrend, 4h high
            & ((rsi_3_1h_gt_25) | (cmf_20_4h_gt_neg_0_25) | aroonu_14_4h_lt_70)
            # 1h down move, 15m still high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_15m_lt_40) | (roc_9_1d_gt_neg_20))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_60) | aroonu_14_4h_lt_100)
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_90) | (cmf_20_1d_gt_neg_0_20))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_25) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_20))
            # 1h down move, 1h still not low enough, 1d downtrend
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_30) | (roc_9_1d_gt_neg_40))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_25))
            # 1h & 4h & 1d down move, 1d high & overbought
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_55) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_20))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_1h_lt_40))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_40))
            # 1h down move, 15m & 4h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_15m_lt_60) | (stochrsi_k_4h < 95.0))
            # 1h down move, 15m & 4h high
            & ((rsi_3_1h_gt_30) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_90))
            # 1h down move, 1h high
            & ((rsi_3_1h_gt_30) | (mfi_14_1h < 80.0) | (aroonu_14_1h_lt_90))
            # 1h down move, 1h still high, 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_50) | (roc_9_1d_lt_40))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_30) | aroonu_14_1h_lt_80 | aroonu_14_4h_lt_100)
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_90) | (cmf_20_1d_gt_neg_0_20))
            # 1h down move, 1h highm 1d overbought
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_90) | (roc_9_1d_lt_40))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_30) | aroonu_14_4h_lt_100 | (roc_9_4h_lt_30))
            # 1h down move, 1d high, 4h overbought
            & ((rsi_3_1h_gt_30) | aroonu_14_1d_lt_100 | (roc_9_4h_lt_20))
            # 1h & 4h down move, 1h still high, 4h high
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_60) | (rsi_14_1h_lt_50) | (rsi_14_4h_lt_70))
            # 1h down move, 1d downtrend, 15m still high, 1d high
            & ((rsi_3_1h_gt_35) | (cmf_20_1d_gt_neg_0_0) | (aroonu_14_15m_lt_50) | (aroonu_14_1d_lt_90))
            # 1h down move, 15m still not low enough, 1h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_15m_lt_30) | aroonu_14_1h_lt_80)
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_60) | aroonu_14_1d_lt_100)
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_25))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_90))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_lt_90) | (aroonu_14_1d_lt_90))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_35) | (stochrsi_k_1h_lt_60) | (roc_9_4h_lt_10))
            # 1h down move, 4h & 1d overbought
            & ((rsi_3_1h_gt_35) | (roc_9_4h_lt_20) | (roc_9_1d_lt_80))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_40) | (rsi_3_1d_gt_55) | (aroonu_14_1d_lt_100))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_70) | (roc_9_4h_lt_40))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_80) | aroonu_14_4h_lt_80)
            # 1h down move, 1h high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_85) | (roc_9_1d_lt_80))
            # 1h down move, 1h high, 15m downtrend
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_90) | (roc_9_15m > -10.0))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_65) | (roc_9_1d_lt_200))
            # 1h & 1d down move, 4h high
            & ((rsi_3_1h_gt_45) | (rsi_3_1d_gt_50) | (stochrsi_k_4h_lt_90))
            # 1h down move, 1h high, 4h overbought
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_100) | (roc_9_4h_lt_10))
            # 1h & 4h & 1d down move, 4h still high, 1h high
            & ((rsi_3_1h_gt_50) | (rsi_3_4h_gt_55) | (rsi_3_1d_gt_55) | (rsi_14_4h_lt_40) | (aroonu_14_1h_lt_70))
            # 1h & 4h down move, 1h & 4h high
            & ((rsi_3_1h_gt_50) | (rsi_3_4h_gt_65) | (aroonu_14_1h_lt_85) | (aroonu_14_4h_lt_100))
            # 1h down move, 15m & 1h high
            & ((rsi_3_1h_gt_50) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_80))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_90))
            # 1h down move, 4h overbought
            & ((rsi_3_1h_gt_50) | (roc_9_4h_lt_100))
            # 1h down move, 4h high, 1h overbought
            & ((rsi_3_1h_gt_55) | (aroonu_14_4h_lt_100) | (roc_9_1h_lt_20))
            # 1h down move, 15m & 1h high, 1d downtrend
            & ((rsi_3_1h_gt_60) | (aroonu_14_15m < 65.0) | (stochrsi_k_1h_lt_80) | (cmf_20_1d_gt_neg_0_0))
            # 1h down move, 1h high, 1d downtrend
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_90) | (roc_9_1d_gt_neg_20))
            # 4h down move, 15m high
            & ((rsi_3_4h_gt_3) | (aroonu_14_15m_lt_50))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d > 50.0) | (aroonu_14_1d_lt_90))
            # 4h down move, 15m still not low enough, 4h downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_15m_lt_30) | (cmf_20_4h_gt_neg_0_30))
            # 4h down move, 15m & 1h still not low enough
            & ((rsi_3_4h_gt_10) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h < 25.0))
            # 4h down move, 4h still high
            & ((rsi_3_4h_gt_10) | (aroonu_14_4h_lt_40))
            # 4h down move, 1h still high, 4h downtrend
            & ((rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_50) | (cmf_20_4h_gt_neg_0_30))
            # 4h down move, 1d still high, 1d downtrend
            & ((rsi_3_4h_gt_15) | (rsi_14_1d_lt_40) | (roc_9_1d_gt_neg_10))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_60))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_15) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20))
            # 4h down move, 15m still high, 1d overbought
            & ((rsi_3_4h_gt_20) | (aroonu_14_15m_lt_40) | (roc_9_1d_lt_20))
            # 4h & 1d down move, 1h & 4h low
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (cmf_20_1h_gt_neg_0_30) | (cmf_20_4h_gt_neg_0_40))
            # 4h down move, 4h still high 1d downtrend
            & ((rsi_3_4h_gt_25) | (aroonu_14_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_25) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_25))
            # 4h down move, 4h high, 1d downtrend
            & ((rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_60))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_35) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_100))
            # 4h down move, 15m still high, 1d overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_50))
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_40) | (aroonu_14_4h_lt_80) | (roc_9_1d_lt_20))
            # 4h down move, 1h high, 1d downtrend
            & ((rsi_3_4h_gt_40) | (stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_20))
            # 4h down move, 4h & 1d overbought
            & ((rsi_3_4h_gt_40) | (roc_9_4h_lt_10) | roc_9_1d_lt_50)
            # 4h down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_45) | aroonu_14_4h_lt_70 | (roc_9_1d_lt_20))
            # 4h down move, 1d high, 4h overbought
            & ((rsi_3_4h_gt_45) | (aroonu_14_1d_lt_90) | (roc_9_4h_lt_10))
            # 4h down move, 4h still high, 1d downtrend
            & ((rsi_3_4h_gt_50) | (rsi_14_4h_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h high & overbought
            & ((rsi_3_4h_gt_50) | aroonu_14_4h_lt_70 | (roc_9_4h_lt_10))
            # 4h down move, 15m still high, 1d overbought
            & ((rsi_3_4h_gt_55) | (aroonu_14_15m_lt_40) | (roc_9_1d_lt_100))
            # 4h & 1d down move, 4h high, 1d overbought
            & ((rsi_3_4h_gt_60) | (rsi_3_1d_gt_60) | (aroonu_14_4h_lt_75) | (roc_9_1d_lt_40))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h > 70.0) | (aroonu_14_4h_lt_90) | aroonu_14_1d_lt_100)
            # 4h up move, 1d downtrend, 4h high
            & ((rsi_3_4h_lt_90) | (cmf_20_1d_gt_neg_0_25) | (aroonu_14_4h_lt_100))
            # 1d down move, 4h high
            & ((rsi_3_1d_gt_3) | (stochrsi_k_4h_lt_60))
            # 1d down move, 1h high
            & ((rsi_3_1d_gt_5) | (stochrsi_k_1h_lt_80))
            # 1d down move, 15m & 1h still high
            & ((rsi_3_1d_gt_10) | (rsi_14_15m_lt_40) | (stochrsi_k_1h_lt_50))
            # 1d down move, 1h & 4h high
            & ((rsi_3_1d_gt_10) | aroonu_14_1h_lt_80 | (aroonu_14_4h_lt_90))
            # 1d down move, 1h & 4h still high
            & ((rsi_3_1d_gt_10) | (stochrsi_k_1h_lt_40) | (aroonu_14_4h_lt_40))
            # 1d down move, 1h high & overbought
            & ((rsi_3_1d_gt_20) | (stochrsi_k_1h_lt_80) | (roc_9_1h_lt_20))
            # 1d down move, 1d high & overbought
            & ((rsi_3_1d_gt_40) | (aroonu_14_1d_lt_70) | (roc_9_1d_lt_20))
            # 1d down move, 4h high & overbought
            & ((rsi_3_1d_gt_45) | aroonu_14_4h_lt_80 | (roc_9_4h_lt_30))
            # 1d down move, 1h high, 1d overbought
            & ((rsi_3_1d_gt_60) | aroonu_14_1h_lt_80 | (roc_9_1d_lt_80))
            # 1d down move, 15m still high, 1d overbought
            & ((rsi_3_1d_gt_65) | (aroonu_14_15m_lt_40) | (roc_9_1d_lt_100))
            # 1d down move, 4h & 1d high
            & ((rsi_3_1d_gt_65) | (roc_9_4h_lt_10) | (roc_9_1d_lt_10))
            # 5m still high, 1h down move, 15m still high, 1h high
            & ((rsi_3_lt_40) | (rsi_3_1h_gt_30) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_90))
            # 5m still high, 15m high
            & ((rsi_3 < 45.0) | (aroonu_14_15m_lt_70))
            # 5m still high, 1h down move, 4h high
            & ((rsi_3_lt_50) | (rsi_3_1h_gt_30) | aroonu_14_4h_lt_100)
            # 15m down move, 1h high
            & ((rsi_14_15m > 25.0) | (stochrsi_k_1h_lt_80))
            # 15m down move, 4h & 1d high
            & ((rsi_14_15m > 30.0) | (stochrsi_k_4h_lt_90) | (stochrsi_k_1d_lt_70))
            # 1h downtrend, 4h high, 1d downtrend
            & ((cmf_20_1h_gt_neg_0_20) | (stochrsi_k_4h_lt_90) | (cmf_20_1d_gt_neg_0_25))
            # 15m & 1h high, 1d overbought
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_100) | (roc_9_1d_lt_20))
            # 4h high, 4h & 1d overbought
            & ((aroonu_14_4h_lt_80) | (roc_9_4h_lt_20) | (roc_9_1d_lt_20))
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_85) | (aroonu_14_1d_lt_85) | (roc_9_1d_lt_60))
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_100) | (aroonu_14_1d_lt_100) | (roc_9_1d_lt_30))
            # 1d still high, 4h & 1d downtrend
            & ((aroonu_14_1d_lt_50) | (roc_9_4h_gt_neg_20) | (roc_9_1d_gt_neg_30))
            # 1d high, 4h & 1d overbought
            & ((aroonu_14_1d_lt_100) | (roc_9_4h_lt_100) | (roc_9_1d_lt_200))
            # 1h & 4h & 1d overbought
            & ((roc_9_1h_lt_20) | (roc_9_4h_lt_100) | (roc_9_1d_lt_200))
            # 4h top wick, 15m & 1h down move
            & ((top_wick_pct_4h < 10.0) | (rsi_3_15m_gt_15) | (rsi_3_1h_gt_40))
            # 4h top wick, 1h down move, 1h high
            & ((top_wick_pct_4h < 10.0) | (rsi_3_1h_gt_30) | aroonu_14_1h_lt_70)
            # 1d red, 1h down move, 1h still high
            & ((change_pct_1d_gt_neg_15) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_50))
            # 1d P&D, 1h high
            & ((change_pct_1d_gt_neg_15) | (change_pct_1d_shift_288 < 15.0) | (stochrsi_k_1h_lt_80))
            # 1d P&D, 1d downtrend
            & ((change_pct_1d_gt_neg_5) | (change_pct_1d_shift_288 < 30.0) | (cmf_20_1d_gt_neg_0_10))
            # 1d P&D, 15m high
            & ((change_pct_1d_gt_neg_10) | (change_pct_1d_shift_288 < 40.0) | (aroonu_14_15m_lt_50))
            # 1d P&D, 1h high
            & ((change_pct_1d_gt_neg_10) | (change_pct_1d_shift_288 < 40.0) | (stochrsi_k_1h_lt_70))
            # 1d red with top wick, 1h high
            & ((change_pct_1d_gt_neg_10) | (top_wick_pct_1d_lt_10) | aroonu_14_1h_lt_80)
            # 1d green, 4m down move, 4h high
            & ((change_pct_1d_lt_25) | (rsi_3_4h_gt_55) | (aroonu_14_4h_lt_50))
            # 1d green with top wick, 1d low
            & ((change_pct_1d_lt_25) | (top_wick_pct_1d_lt_10) | (cmf_20_1d_gt_neg_0_20))
            # 1d top wick, 1h still high
            & ((top_wick_pct_1d_lt_25) | (aroonu_14_1h_lt_50))
            # 1d top wick, 4h still high
            & ((top_wick_pct_1d_lt_30) | (stochrsi_k_4h_lt_50))
            # 1d top wick, 1h down move
            & ((top_wick_pct_1d_lt_50) | (rsi_3_1h_gt_30))
            # big drop in last hough, 4h down move, 1h still not low enough
            & ((close > (close_max_12 * 0.90)) | (rsi_3_4h_gt_10) | (stochrsi_k_1h_lt_30))
            # big drop in the last 12 days, 1h down move, 1h high
            & ((close > (high_max_12_1d * 0.35)) | (rsi_3_1h_gt_35) | aroonu_14_1h_lt_70)
            # big drop in the last 20 days, 1h down move, 1h high
            & ((close > (high_max_20_1d * 0.30)) | (rsi_3_1h_gt_30) | (stochrsi_k_1h < 75.0))
            # big drop in the last 20 days, 1d high, 1d downtrend
            & ((close > (high_max_20_1d * 0.20)) | (stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_15))
          )

          # Logic
          long_entry_logic.append(
            (rsi_14 < 30.0)
            & (aroonu_14_lt_25)
            & (aroond_14_gt_75)
            & (stochrsi_k_lt_20)
            & (ema_9 < (ema_26 * 0.982))
            & (close < sma_9)
          )

        # Condition #164 - 4h opening-range fakeout (Long, experimental).
        if long_entry_condition_index == 164:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          # Logic
          long_entry_logic.append(
            # only fade a downside break into an already-deeply-sold 4h (a flush into oversold = spring)
            ((willr_14_4h < -70.0) | (stoch_k_4h < 40.0))
            # prev 5m candle CLOSED below the day's first-4h range low; current closes back INSIDE
            & (np_shift(close, 1) < orange_l)
            & (close > orange_l)
            & (close < orange_h)
          )

        # Condition #165 - Fib golden-pocket continuation (Long, experimental, RAW — The Moving Average port).
        if long_entry_condition_index == 165:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          long_entry_logic.append((sqz_cnt_24 > 14) | (mfi_14_1d < 45.0) | (willr_14_4h < -50.0))

          # Logic
          # retrace depth of the 48-candle impulse (0 = at the high, 1 = at the low)
          _fib_rng_165 = close_max_48 - close_min_48
          _fib_retr_165 = (close_max_48 - close) / _fib_rng_165
          long_entry_logic.append(
            # trend filter (video: "only clear trends") + impulse quality (never draw fibs in chop)
            (ema_12_4h > ema_200_4h)
            # R1 (eyeball): only a CLEAN ACTIVE uptrend — whipsaw chop (RIVER) has rsi_4h ~50 and stale 4h highs
            & (rsi_14_4h > 55.0)
            & (aroonu_14_4h > 70.0)
            # R1: anti-blow-off — don't buy the retrace of a parabolic final leg (ARIA top)
            & (roc_9_1d < 30.0)
            & ((close_max_48 - close_min_48) > (close_min_48 * 0.04))
            # golden pocket: FIRST entry into the 0.5-0.618 retrace band of the 48-candle impulse (from above)
            & (np_shift(_fib_retr_165, 1) < 0.5)
            & (_fib_retr_165 >= 0.5)
            & (_fib_retr_165 <= 0.618)
          )

        # Condition #166 - Squeeze Momentum release (Long, experimental, RAW — LazyBear port).
        if long_entry_condition_index == 166:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            # 5m down move & washed out, 15m uptrend, 1h still high, 1d up move
            ((rsi_3 > 85.0) | (aroonu_14_15m_lt_90) | (roc_9_1d_lt_15) | (stochrsi_k > 90.0) | (stochrsi_k_1h < 15.0))
            # 5m down move, 15m still high, 1h down move, 4h downtrend & still high
            & (
              (rsi_3 > 85.0)
              | (stochrsi_k_15m_lt_60)
              | (aroonu_14_4h > 65.0)
              | (stochrsi_k_4h_lt_20)
              | (rsi_3_1h_gt_55)
            )
            # 5m down move, 15m downtrend, 4h down move & downtrend & still high
            & (
              (rsi_3 > 90.0) | (rsi_3_4h_gt_40) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h < 25.0) | (aroonu_14_15m_gt_60)
            )
            # 5m & 1h down move
            & ((rsi_3 > 70) | (rsi_3_1h_gt_60))
            # 5m down move, 1d overbought
            & ((rsi_3 > 85) | (roc_9_1d_lt_60))
            # 5m down move & washed out, 15m up move, 1h uptrend, 1d washed out
            & (
              (rsi_3 > 85.0) | (aroonu_14_1h_lt_60) | (stochrsi_k_1d_gt_50) | (stochrsi_k > 85.0) | (rsi_3_15m < 45.0)
            )
            # 5m down move, 15m down move, 4h down move & uptrend & washed out
            & ((rsi_3 > 85.0) | (rsi_3_4h_gt_55) | (rsi_3_15m > 70.0) | (aroonu_14_4h_lt_75) | (stochrsi_k_4h > 25.0))
            # 5m down move, 15m overbought, 1h low
            & ((rsi_3 > 90) | (roc_9_15m < 1.5) | (aroonu_14_1h_gt_10))
            # 5m down move, 1h down move & still high, 1d downtrend & down move
            & ((rsi_3 > 90.0) | (rsi_3_1h_gt_45) | (aroonu_14_1d > 65.0) | (stochrsi_k_1h < 10.0) | (rsi_3_1d > 70.0))
            # 5m down move, 15m downtrend, 1h down move & downtrend, 1d down move
            & ((rsi_3 > 95.0) | (rsi_3_1h_gt_45) | (rsi_3_1d > 75.0) | (aroonu_14_15m > 25.0) | (aroonu_14_1h > 65.0))
            # 5m not oversold, 15m up move
            & ((rsi_14 > 60.0) | (rsi_3_15m > 65.0))
            # 5m overbought, 15m overbought & down move, 1h uptrend, 1d uptrend
            & (
              (stochrsi_k < 80.0)
              | (aroonu_14_1h_lt_25)
              | (stochrsi_k_15m < 95.0)
              | (aroonu_14_1d < 95.0)
              | (rsi_3_15m > 90.0)
            )
            # 5m overbought, 15m overbought, 1h up move & washed out, 4h uptrend
            & (
              (stochrsi_k < 90.0)
              | (aroonu_14_4h_lt_60)
              | (stochrsi_k_15m < 85.0)
              | (rsi_3_1h_lt_60)
              | (stochrsi_k_1h > 55.0)
            )
            # 5m overbought, 1h up move & washed out, 4h uptrend & washed out
            & (
              (stochrsi_k < 90.0)
              | (aroonu_14_4h_lt_75)
              | (stochrsi_k_4h_gt_40)
              | (rsi_3_1h_lt_60)
              | (stochrsi_k_1h > 35.0)
            )
            # 5m overbought, 15m overbought, 1h up move & downtrend, 1d up move
            & (
              (stochrsi_k < 90.0)
              | (roc_9_1d_lt_10)
              | (stochrsi_k_15m < 85.0)
              | (rsi_3_1h_lt_60)
              | (aroonu_14_1h_gt_60)
            )
            # 5m overbought & down move, 1h still high, 1d down move & downtrend
            & (
              (stochrsi_k < 90.0) | (rsi_3_1d_gt_55) | (aroonu_14_1d > 80.0) | (stochrsi_k_1h < 25.0) | (rsi_3 > 95.0)
            )
            # 5m overbought, 15m still high, 4h washed out & up move & down move
            & (
              (stochrsi_k < 90.0)
              | (stochrsi_k_15m_lt_50)
              | (stochrsi_k_4h > 25.0)
              | (rsi_3_4h < 45.0)
              | (roc_9_4h > 5.0)
            )
            # 5m high, 15m down move
            & ((stochrsi_k < 85) | (rsi_3_15m_gt_55))
            # 5m overbought, 1h up move, 4h down move & washed out, 1d up move
            & ((stochrsi_k < 90.0) | (roc_9_1d_lt_15) | (rsi_3_1h_lt_60) | (roc_9_4h > 5.0) | (stochrsi_k_4h > 55.0))
            # 15m down move, 1d downtrend
            & ((rsi_3_15m_gt_40) | (roc_9_1d > 20))
            # 15m down move, 1d extended
            & ((rsi_3_15m_gt_40) | (roc_9_1d_lt_100))
            # 15m down move & still not low enough, 1h high
            & ((rsi_3_15m_gt_55) | (aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_80))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_55) | (aroonu_14_15m_lt_75) | (rsi_3_4h_gt_50))
            # 15m down move, 4h overbought, 1d high
            & ((rsi_3_15m_gt_55) | (roc_9_4h_lt_20) | (stochrsi_k_1d_lt_80))
            # 15m & 1h down move
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_gt_35))
            # 15m & 4h down move, 15m high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_70) | (rsi_3_4h_gt_20))
            # 15m up move, 1d on the floor & up move
            & ((rsi_3_15m_lt_75) | (stochrsi_k_1d_gt_10) | (rsi_3_1d < 50.0))
            # 5m washed out, 15m up move, 1h money coming in
            & ((rsi_3_15m_lt_90) | (mfi_14_1h < 80.0) | (stochrsi_k > 85.0))
            # 5m down move, 15m uptrend & washed out, 1h uptrend & up move
            & (
              (aroonu_14_15m_lt_25) | (aroonu_14_1h_lt_90) | (rsi_3 > 85.0) | (rsi_3_1h_lt_75) | (stochrsi_k_15m_gt_70)
            )
            # 15m uptrend, 1h downtrend & still high, 1d down move
            & (
              (aroonu_14_15m_lt_40)
              | (rsi_3_1d_gt_55)
              | (aroonu_14_1h > 80.0)
              | (roc_9_1d > 20.0)
              | (stochrsi_k_1h < 25.0)
            )
            # 5m down move, 15m uptrend, 4h overbought, 1d washed out & up move
            & (
              (aroonu_14_15m_lt_40)
              | (stochrsi_k_4h_lt_80)
              | (stochrsi_k_1d > 35.0)
              | (roc_9_1d_lt_15)
              | (rsi_3 > 90.0)
            )
            # 5m down move, 15m uptrend, 1h down move & downtrend, 1d washed out
            & (
              (aroonu_14_15m_lt_90)
              | (rsi_3_1h_gt_55)
              | (rsi_3 > 85.0)
              | (stochrsi_k_1d > 85.0)
              | (aroonu_14_1h > 25.0)
            )
            # 15m still not low enough, 1h down move, 1d still high
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_65) | (stochrsi_k_1d_lt_50))
            # 15m still not low enough, 1h down move & high
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_80))
            # 15m still not low enough, 4h & 1d down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_40))
            # 15m still not low enough, 1h still high, 4h high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_80))
            # 15m & 1h still not low enough, 4h down move
            & ((aroonu_14_15m_lt_25) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_50))
            # 15m still not low enough, 1h high, 1d overbought
            & ((aroonu_14_15m_lt_25) | (aroonu_14_1h_lt_80) | (roc_9_1d_lt_30))
            # 15m still not low enough, 1h overbought, 1d down move
            & ((aroonu_14_15m_lt_25) | (roc_9_1h_lt_10) | (rsi_3_1d_gt_60))
            # 15m still not low enough, 1h overbought
            & ((aroonu_14_15m_lt_25) | (roc_9_1h_lt_50))
            # 15m still not low enough, 1h down move, 4h high
            & ((aroonu_14_15m_lt_25) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_80))
            # 15m still not low enough, 1h & 1d down move
            & ((aroonu_14_15m_lt_25) | (rsi_3_1h_gt_40) | (rsi_3_1d_gt_40))
            # 15m still not low enough, 1h down move, 4h high
            & ((aroonu_14_15m_lt_25) | (rsi_3_1h_gt_50) | (aroonu_14_4h_lt_70))
            # 15m still not low enough, 1h down move, 1d high
            & ((aroonu_14_15m_lt_25) | (rsi_3_1h_gt_65) | (aroonu_14_1d_lt_90))
            # 15m still not low enough, 1h down move, 1d overbought
            & ((aroonu_14_15m_lt_25) | (rsi_3_1h_gt_65) | (roc_9_1d_lt_10))
            # 15m still not low enough, 15m & 4h high
            & ((aroonu_14_15m_lt_25) | (stochrsi_k_15m_lt_70) | (stochrsi_k_4h_lt_80))
            # 15m still not low enough, 15m & 1d high
            & ((aroonu_14_15m_lt_25) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1d_lt_70))
            # 15m still not low enough, 1h high, 1d overbought
            & ((aroonu_14_15m_lt_25) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_20))
            # 15m still not low enough, 4h still high, 1d high
            & ((aroonu_14_15m_lt_25) | (stochrsi_k_4h_lt_40) | (stochrsi_k_1d_lt_80))
            # 5m overbought, 15m uptrend, 4h up move, 1d washed out
            & ((aroonu_14_15m_lt_40) | (roc_9_4h_lt_15) | (stochrsi_k_1d > 35.0) | (stochrsi_k < 80.0))
            # 15m still high, 1h down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_10))
            # 15m still high, 1h & 1d high
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_80))
            # 15m still high, 4h high, 1d overbought
            & ((aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_50))
            # 15m high, 1h still high, 4h down move
            & ((aroonu_14_15m_lt_75) | (aroonu_14_1h_lt_40) | (rsi_3_4h_gt_65))
            # 15m & 1h high, 1d down move
            & ((aroonu_14_15m_lt_75) | (aroonu_14_1h_lt_80) | (rsi_3_1d_gt_65))
            # 15m uptrend, 1h uptrend & down move, 1d down move
            & ((aroonu_14_15m_lt_75) | (aroonu_14_1h_lt_90) | (roc_9_1d > 5.0) | (rsi_3_1h > 70.0))
            # 15m high, 4h down move
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_lt_80) | (rsi_3_4h_gt_40))
            # 15m & 1h & 4h high
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_1h_lt_60) | (aroonu_14_4h_lt_90))
            # 15m & 1h high, 4h down move
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_1h_lt_80) | (rsi_3_4h_gt_65))
            # 15m high, 1h downtrend
            & ((aroonu_14_15m_lt_80) | (roc_9_1h_gt_neg_25))
            # 15m uptrend & washed out, 1h down move
            & ((aroonu_14_15m_lt_80) | (rsi_3_1h_gt_50) | (stochrsi_k_15m > 35.0))
            # 15m uptrend & overbought, 1d down move
            & ((aroonu_14_15m_lt_90) | (rsi_3_1d_gt_40) | (stochrsi_k_15m < 85.0))
            # 5m still high, 15m still high & down move, 4h down move & still high
            & (
              (stochrsi_k_15m_lt_60)
              | (roc_9_4h > 5.0)
              | (rsi_3_15m > 70.0)
              | (stochrsi_k_4h_lt_20)
              | (stochrsi_k < 70.0)
            )
            # 15m still high, 1h down move, 4h downtrend, 1d washed out & uptrend
            & (
              (stochrsi_k_15m_lt_60)
              | (rsi_3_1h_gt_65)
              | (aroonu_14_4h_gt_30)
              | (stochrsi_k_1d > 75.0)
              | (aroonu_14_1d_lt_60)
            )
            # 15m still high, 1h still high, 4h uptrend, 1d down move & downtrend
            & (
              (stochrsi_k_15m_lt_70)
              | (rsi_3_1d_gt_65)
              | (aroonu_14_1d > 80.0)
              | (stochrsi_k_1h < 25.0)
              | (aroonu_14_4h < 5.0)
            )
            # 5m overbought, 15m overbought, 1h up move, 4h uptrend & washed out
            & (
              (stochrsi_k_15m_lt_80)
              | (aroonu_14_4h_lt_90)
              | (stochrsi_k_4h_gt_60)
              | (rsi_3_1h_lt_65)
              | (stochrsi_k < 85.0)
            )
            # 15m overbought, 1h still high & down move, 1d down move & washed out
            & (
              (stochrsi_k_15m_lt_80)
              | (roc_9_1d > 25.0)
              | (stochrsi_k_1d > 65.0)
              | (stochrsi_k_1h < 15.0)
              | (rsi_3_1h > 75.0)
            )
            # 15m overbought & downtrend, 1h up move, 4h downtrend, 1d still high
            & (
              (stochrsi_k_15m_lt_80)
              | (stochrsi_k_1d_lt_70)
              | (rsi_3_1h_lt_60)
              | (aroonu_14_15m_gt_40)
              | (aroonu_14_4h > 75.0)
            )
            # 15m still not low enough, 1h & 1d high
            & ((stochrsi_k_15m_lt_30) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_80))
            # 15m & 4h still not low enough, 1h down move
            & ((stochrsi_k_15m_lt_30) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_10))
            # 15m & 4h still not low enough, 1h down move
            & ((stochrsi_k_15m_lt_30) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_20))
            # 15m still not low enough, 1h high, 1d down move
            & ((stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_80) | (rsi_3_1d_gt_55))
            # 15m & 1h still high, 1d high
            & ((stochrsi_k_15m_lt_40) | (aroonu_14_1h_lt_50) | (stochrsi_k_1d_lt_90))
            # 15m still high, 4h overbought, 1d downtrend
            & ((stochrsi_k_15m_lt_40) | (roc_9_4h_lt_20) | (roc_9_1d > 35))
            # 15m still high, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_50) | (aroonu_14_4h_lt_90))
            # 15m still high, 1h down move & high
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_60))
            # 15m & 1h still high, 1h down move
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_40))
            # 15m still high, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_60))
            # 15m still high, 1d high & overbought
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_60))
            # 15m & 1h still high, 4h down move
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_40) | (rsi_3_4h_gt_50))
            # 15m & 4h still high, 1d down move
            & ((stochrsi_k_15m_lt_50) | (aroonu_14_4h_lt_40) | (rsi_3_1d_gt_65))
            # 15m still high, 1d down move & high
            & ((stochrsi_k_15m_lt_50) | (rsi_3_1d_gt_50) | (stochrsi_k_1d_lt_80))
            # 15m still high, 1d down move & high
            & ((stochrsi_k_15m_lt_50) | (rsi_3_1d_gt_65) | (aroonu_14_1d_lt_60))
            # 15m still high, 1h down move & overbought
            & ((stochrsi_k_15m_lt_50) | (rsi_3_1h_gt_50) | (roc_9_1h_lt_10))
            # 15m still high, 1h & 1d high
            & ((stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_80) | (aroonu_14_1d_lt_80))
            # 15m still high, 4h high, 1d overbought
            & ((stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_40))
            # 15m & 4h high, 1h still not low enough
            & ((stochrsi_k_15m_lt_60) | (aroonu_14_1h_lt_30) | (stochrsi_k_4h_lt_60))
            # 15m high, 1h down move, 4h still not low enough
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_20))
            # 15m high, 1h down move, 4h overbought
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_50) | (roc_9_4h_lt_5))
            # 15m & 1d high, 4h still high
            & ((stochrsi_k_15m_lt_60) | (stochrsi_k_4h_lt_40) | (stochrsi_k_1d_lt_90))
            # 15m & 4h high, 1d down move
            & ((stochrsi_k_15m_lt_60) | (stochrsi_k_4h_lt_80) | (rsi_3_1d_gt_50))
            # 15m high, 1h still not low enough, 4h downtrend
            & ((stochrsi_k_15m_lt_70) | (aroonu_14_1h_lt_20) | (roc_9_4h_gt_neg_10))
            # 15m high, 1h still not low enough
            & ((stochrsi_k_15m_lt_70) | (aroonu_14_1h_lt_30) | (stochrsi_k_1h_lt_20))
            # 15m & 1h & 4h high
            & ((stochrsi_k_15m_lt_70) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_90))
            # 15m still high, 1h uptrend, 4h washed out, 1d downtrend
            & ((stochrsi_k_15m_lt_70) | (aroonu_14_1h_lt_75) | (stochrsi_k_4h > 25.0) | (aroonu_14_1d > 45.0))
            # 15m high, 1h & 1d down move
            & ((stochrsi_k_15m_lt_70) | (rsi_3_1h_gt_50) | (rsi_3_1d_gt_55))
            # 15m & 1h high, 1h down move
            & ((stochrsi_k_15m_lt_70) | (rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_60))
            # 15m overbought, 1h uptrend, 4h downtrend
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_gt_10))
            # 15m high, 1h down move & still not low enough
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_20))
            # 15m high, 1h down move & still not low enough
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_20))
            # 15m high, 4h down move & overbought
            & ((stochrsi_k_15m_lt_80) | (rsi_3_4h_gt_30) | (roc_9_4h_lt_5))
            # 15m & 4h & 1d high
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_4h_lt_60) | (stochrsi_k_1d_lt_70))
            # 5m up move, 15m up move & still high, 4h down move, 1d down move
            & ((roc_9_15m < 1.5) | (roc_9_1d > 25.0) | (rsi_3_lt_90) | (stochrsi_k_15m_lt_50) | (roc_9_4h > 10.0))
            # 15m downtrend, 1h down move & still high, 4h on the floor, 1d down move
            & (
              (rsi_3_1h_gt_35)
              | (roc_9_1d > 30.0)
              | (stochrsi_k_4h > 5.0)
              | (stochrsi_k_1h < 35.0)
              | (aroonu_14_15m_gt_10)
            )
            # 1h down move & still high & uptrend, 4h down move, 1d washed out
            & (
              (rsi_3_1h_gt_45)
              | (rsi_3_4h_gt_40)
              | (stochrsi_k_1h < 10.0)
              | (stochrsi_k_1d > 75.0)
              | (aroonu_14_1h < 5.0)
            )
            # 5m washed out, 15m still high, 1h down move & still high, 4h still high
            & (
              (rsi_3_1h_gt_65)
              | (stochrsi_k_4h_lt_30)
              | (stochrsi_k > 85.0)
              | (stochrsi_k_1h < 45.0)
              | (stochrsi_k_15m < 25.0)
            )
            # 1h down move, 1d down move
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_30))
            # 1h down move & still not low enough, 4h high
            & ((rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_20) | (aroonu_14_4h_lt_80))
            # 1h & 1d down move, 4h still not low enough
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_20) | (rsi_3_1d_gt_40))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 1h down move & still high, 4h overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_40) | (roc_9_4h_lt_10))
            # 5m washed out, 1h down move & uptrend, 4h down move
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_75) | (roc_9_4h > 0.0) | (stochrsi_k > 95.0))
            # 1h down move & uptrend & still high, 4h downtrend
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_80) | (stochrsi_k_1h < 65.0) | (aroonu_14_4h_gt_0))
            # 1h down move & high, 1d overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_60) | (roc_9_1d_lt_20))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_60))
            # 5m up move, 15m down move, 1h down move, 4h down move & up move
            & ((rsi_3_1h_gt_50) | (roc_9_4h > 2.0) | (rsi_3_4h < 65.0) | (rsi_3_15m > 75.0) | (rsi_3 < 80.0))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_90))
            # 1h down move, 4h high, 1d overbought
            & ((rsi_3_1h_gt_60) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_30))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_60) | (aroonu_14_4h_lt_90) | (stochrsi_k_1d_lt_90))
            # 1h down move & washed out, 4h up move, 1d down move
            & ((rsi_3_1h_gt_60) | (roc_9_1d > 25.0) | (rsi_3_4h_lt_75) | (rsi_3_1d_gt_55) | (stochrsi_k_1h_gt_80))
            # 1h & 1d down move, 1d overbought
            & ((rsi_3_1h_gt_60) | (rsi_3_1d_gt_60) | (roc_9_1d_lt_60))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_40))
            # 1h & 4h down move, 4h overbought
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_65) | (roc_9_4h_lt_5))
            # 1h down move & still not low enough, 1d still high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_20) | (aroonu_14_1d_lt_40))
            # 1h down move & high, 1d still high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_60) | (stochrsi_k_1d_lt_50))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_60))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_65) | (aroonu_14_1h_lt_60) | (stochrsi_k_1d_lt_90))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_65) | (aroonu_14_1h_lt_60) | (stochrsi_k_4h_lt_80))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_65) | (aroonu_14_4h_lt_60) | (stochrsi_k_1d_lt_90))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1d_lt_70) | (roc_9_1d_lt_70))
            # 1h down move & still high, 4h high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_80))
            # 1h down move, 4h still not low enough, 1d high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_20) | (stochrsi_k_1d_lt_80))
            # 5m washed out & down move, 1h down move, 4h still high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_70) | (stochrsi_k > 65.0) | (rsi_3 > 85.0))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_70))
            # 15m uptrend, 1h money coming in & washed out, 1d washed out
            & ((cmf_20_1h < 0.2) | (stochrsi_k_1d_gt_30) | (stochrsi_k_1h > 35.0) | (aroonu_14_15m < 15.0))
            # 5m overbought, 15m overbought, 1h uptrend, 1d down move & downtrend
            & (
              (aroonu_14_1h_lt_30)
              | (rsi_3_1d_gt_55)
              | (stochrsi_k_15m < 85.0)
              | (stochrsi_k < 95.0)
              | (aroonu_14_1d > 80.0)
            )
            # 15m uptrend, 1h uptrend & still high, 1d downtrend & down move
            & (
              (aroonu_14_1h_lt_50)
              | (stochrsi_k_1h_lt_50)
              | (aroonu_14_1d > 90.0)
              | (roc_9_1d > 30.0)
              | (aroonu_14_15m < 15.0)
            )
            # 1h still not low enough, 4h down move & high
            & ((aroonu_14_1h_lt_20) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_60))
            # 1h still high, 1d down move & high
            & ((aroonu_14_1h_lt_40) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_60))
            # 1h still high, 4h down move & overbought
            & ((aroonu_14_1h_lt_40) | (rsi_3_4h_gt_50) | (roc_9_4h_lt_20))
            # 1h still high, 4h down move, 1d high
            & ((aroonu_14_1h_lt_40) | (rsi_3_4h_gt_60) | (stochrsi_k_1d_lt_90))
            # 1h still high, 4h down move
            & ((aroonu_14_1h_lt_50) | (rsi_3_4h_gt_35))
            # 1h uptrend, 4h down move, 1d extended
            & ((aroonu_14_1h_lt_60) | (rsi_3_4h_gt_50) | (roc_9_1d_lt_60))
            # 1h high, 4h down move, 1d overbought
            & ((aroonu_14_1h_lt_60) | (rsi_3_4h_gt_60) | (roc_9_1d_lt_70))
            # 1h & 1d high, 4h down move
            & ((aroonu_14_1h_lt_60) | (rsi_3_4h_gt_65) | (stochrsi_k_1d_lt_60))
            # 1h & 4h & 1d high
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_4h_lt_80) | (aroonu_14_1d_lt_80))
            # 1h high, 1d down move
            & ((aroonu_14_1h_lt_75) | (rsi_3_1d_gt_60))
            # 1h high, 4h & 1d overbought
            & ((aroonu_14_1h_lt_80) | (roc_9_4h_lt_70) | (roc_9_1d_lt_100))
            # 1h uptrend, 1d down move & up move
            & ((aroonu_14_1h_lt_80) | (rsi_3_1d_gt_65) | (roc_9_1d_lt_40))
            # 1h down move, 1h & 4h high
            & ((aroonu_14_1h_lt_80) | (rsi_3_1h_gt_60) | (aroonu_14_4h_lt_80))
            # 1h high, 4h overbought
            & ((aroonu_14_1h_lt_80) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_25))
            # 1h still high & down move, 4h still high & downtrend, 1d down move
            & (
              (stochrsi_k_1h_lt_20)
              | (stochrsi_k_4h_lt_50)
              | (aroonu_14_4h > 45.0)
              | (roc_9_1d > 25.0)
              | (rsi_3_1h > 85.0)
            )
            # 5m washed out, 15m up move, 1h still high & down move, 4h uptrend
            & (
              (stochrsi_k_1h_lt_30)
              | (aroonu_14_4h_lt_60)
              | (stochrsi_k > 70.0)
              | (rsi_3_1h > 80.0)
              | (rsi_3_15m < 35.0)
            )
            # 15m down move & downtrend & still high, 1h still high, 1d overbought
            & (
              (stochrsi_k_1h_lt_40)
              | (stochrsi_k_1d_lt_90)
              | (rsi_3_15m > 70.0)
              | (aroonu_14_15m_gt_40)
              | (stochrsi_k_15m_lt_30)
            )
            # 15m down move, 1h still high & downtrend, 4h up move, 1d down move
            & (
              (stochrsi_k_1h_lt_70) | (rsi_3_1d_gt_55) | (rsi_3_4h_lt_75) | (aroonu_14_1h > 80.0) | (rsi_3_15m > 90.0)
            )
            # 5m washed out, 1h still high, 4h down move, 1d overbought & downtrend
            & (
              (stochrsi_k_1h_lt_70)
              | (stochrsi_k_1d_lt_90)
              | (aroonu_14_1d > 95.0)
              | (stochrsi_k > 95.0)
              | (rsi_3_4h > 85.0)
            )
            # 1h still not low enough, 4h down move & overbought
            & ((stochrsi_k_1h_lt_20) | (rsi_3_4h_gt_60) | (roc_9_4h_lt_10))
            # 1h still not low enough, 4h down move & still high
            & ((stochrsi_k_1h_lt_20) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_40))
            # 1h still not low enough, 4h down move & high
            & ((stochrsi_k_1h_lt_20) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_60))
            # 1h still not low enough, 4h & 1d high
            & ((stochrsi_k_1h_lt_20) | (stochrsi_k_4h_lt_80) | (aroonu_14_1d_lt_80))
            # 1h still high, 4h down move
            & ((stochrsi_k_1h_lt_50) | (rsi_3_4h_gt_35))
            # 1h & 4h high, 4h down move
            & ((stochrsi_k_1h_lt_60) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_60))
            # 1h high, 4h down move, 1d overbought
            & ((stochrsi_k_1h_lt_60) | (rsi_3_4h_gt_60) | (roc_9_1d_lt_10))
            # 1h & 1d high, 4h down move
            & ((stochrsi_k_1h_lt_60) | (rsi_3_4h_gt_65) | (stochrsi_k_1d_lt_80))
            # 1h & 4h & 1d high
            & ((stochrsi_k_1h_lt_60) | (stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_60))
            # 1h & 4h & 1d high
            & ((stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_60) | (aroonu_14_1d_lt_90))
            # 1h & 4h & 1d high
            & ((stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_60) | (stochrsi_k_1d_lt_90))
            # 1h overbought, 4h down move
            & ((roc_9_1h_lt_10) | (rsi_3_4h_gt_60))
            # 15m overbought, 1h up move & downtrend, 4h down move & uptrend
            & (
              (rsi_3_4h_gt_60)
              | (aroonu_14_4h_lt_90)
              | (rsi_3_1h_lt_65)
              | (aroonu_14_1h > 45.0)
              | (stochrsi_k_15m < 90.0)
            )
            # 4h down move & uptrend & still high
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_80) | (stochrsi_k_4h_lt_20))
            # 4h down move & high, 1d overbought
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_60) | (roc_9_1d_lt_20))
            # 4h down move & still not low enough, 1d still high
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_20) | (stochrsi_k_1d_lt_50))
            # 15m downtrend, 1h up move, 4h down move & uptrend, 1d extended
            & ((rsi_3_4h_gt_55) | (roc_9_1d_lt_80) | (rsi_3_1h_lt_60) | (aroonu_14_4h < 55.0) | (aroonu_14_15m_gt_30))
            # 15m up move, 4h down move & up move & still high, 1d down move
            & ((rsi_3_4h_gt_55) | (rsi_3_1d_gt_40) | (roc_9_4h < -5.0) | (stochrsi_k_4h < 15.0) | (rsi_3_15m_lt_70))
            # 4h down move & still not low enough, 1d overbought
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_10) | (roc_9_1d_lt_40))
            # 4h down move, 4h & 1d still high
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_40) | (stochrsi_k_1d_lt_50))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80) | (rsi_3_1d_gt_60))
            # 4h down move & still high, 1d overbought
            & ((rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_40) | (roc_9_1d_lt_30))
            # 15m washed out, 1h washed out, 4h uptrend & washed out, 1d up move
            & (
              (aroonu_14_4h_lt_75)
              | (roc_9_1d_lt_15)
              | (stochrsi_k_4h > 25.0)
              | (stochrsi_k_1h > 45.0)
              | (stochrsi_k_15m_gt_90)
            )
            # 15m down move, 4h uptrend & down move, 1d overbought & down move
            & (
              (aroonu_14_4h_lt_90) | (stochrsi_k_1d_lt_80) | (rsi_3_1d > 75.0) | (rsi_3_4h_gt_65) | (rsi_3_15m > 75.0)
            )
            # 5m downtrend, 4h uptrend, 1d washed out
            & ((aroonu_14_4h_lt_80) | (stochrsi_k_1d_gt_40) | (aroonu_14 > 65.0))
            # 5m downtrend, 4h uptrend, 1d up move & washed out
            & ((aroonu_14_4h_lt_90) | (roc_9_1d_lt_35) | (stochrsi_k_1d > 35.0) | (aroonu_14 > 95.0))
            # 15m uptrend, 4h uptrend, 1d down move & on the floor
            & ((aroonu_14_4h_lt_90) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_gt_10) | (aroonu_14_15m < 10.0))
            # 5m down move & washed out, 4h uptrend, 1d overbought
            & ((aroonu_14_4h_lt_90) | (stochrsi_k_1d_lt_90) | (rsi_3 > 75.0) | (stochrsi_k > 85.0))
            # 1h downtrend, 4h still high & downtrend, 1d down move
            & (
              (stochrsi_k_4h_lt_50)
              | (rsi_3_1d_gt_60)
              | (aroonu_14_4h_gt_50)
              | (aroonu_14_1h > 80.0)
              | (roc_9_1d > 20.0)
            )
            # 5m washed out, 1h still high, 4h still high, 1d still high & down move
            & (
              (stochrsi_k_4h_lt_60)
              | (stochrsi_k_1d_lt_70)
              | (roc_9_1d > 10.0)
              | (stochrsi_k_1h < 65.0)
              | (stochrsi_k > 95.0)
            )
            # 4h & 1d high, 1d down move
            & ((stochrsi_k_4h_lt_60) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_90))
            # 4h & 1d high
            & ((stochrsi_k_4h_lt_80) | (aroonu_14_1d_lt_90) | (stochrsi_k_1d_lt_80))
            # 4h overbought, 1d high & downtrend
            & ((roc_9_4h_lt_30) | (aroonu_14_1d_lt_75) | (roc_9_1d > 35))
            # 4h overbought, 1d down move
            & ((roc_9_4h_lt_5) | (rsi_3_1d_gt_40))
            # 1d down move & up move
            & ((rsi_3_1d_gt_30) | (roc_9_1d_lt_10))
            # 1d down move & high
            & ((rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_80))
            # 5m overbought, 1h up move, 1d down move & downtrend
            & ((rsi_3_1d_gt_50) | (roc_9_1d > 25.0) | (stochrsi_k < 95.0) | (rsi_3_1h < 45.0) | (aroonu_14_1d > 80.0))
            # 1d down move & overbought
            & ((rsi_3_1d_gt_50) | (roc_9_1d_lt_60))
            # 15m downtrend, 1h washed out, 4h up move, 1d uptrend & extended
            & (
              (aroonu_14_1d_lt_90)
              | (roc_9_1d_lt_60)
              | (aroonu_14_15m_gt_30)
              | (stochrsi_k_1h > 45.0)
              | (rsi_3_4h < 45.0)
            )
            # 4h downtrend & up move, 1d still high & down move
            & ((stochrsi_k_1d_lt_60) | (roc_9_1d > 25.0) | (aroonu_14_4h_gt_0) | (rsi_3_1d_gt_55) | (roc_9_4h < 0.0))
            # 5m up move, 1h up move, 1d overbought & down move
            & ((stochrsi_k_1d_lt_80) | (roc_9_1d > 25.0) | (rsi_3_1h_lt_80) | (rsi_3_1d > 70.0) | (rsi_3_lt_90))
            # 1h uptrend, 4h up move, 1d overbought & down move
            & ((stochrsi_k_1d_lt_90) | (roc_9_1d > 30.0) | (rsi_3_1d > 70.0) | (rsi_3_4h_lt_80) | (aroonu_14_1h_lt_75))
          )

          # Logic
          long_entry_logic.append(
            # squeeze RELEASE this candle after a coil (>=12 of the prior 24 candles squeezed)
            (np_shift(sqz_on, 1) > 0.5)
            & (sqz_on < 0.5)
            & (np_shift(sqz_cnt_24, 1) >= 12.0)
            # expansion direction: close breaks through the upper band
            & (close > bbu_20_2_0)
            # the daily is not falling into the release — a coil breaking into a dead daily is a fake one
            & (roc_9_1d > 0.0)
            # and the daily trend itself has to be up: a squeeze release below the daily 200 EMA has
            # nothing to expand into, and it bled -12,025 across the four collapse windows
            & (close > ema_200_1d)
            # the 4h with it: the same release inside a 4h downtrend is a dead-cat break
            & (ema_12_4h > ema_200_4h)
          )

        # Condition #167 - Engulfing continuation (Long, experimental, RAW — TradingLab port).
        if long_entry_condition_index == 167:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            # 5m down move & still high, 15m uptrend & overbought, 4h overbought
            (
              (rsi_3 > 70.0)
              | (aroonu_14_15m_lt_80)
              | (stochrsi_k_15m < 95.0)
              | (stochrsi_k_4h_lt_90)
              | (stochrsi_k < 35.0)
            )
            # 5m down move & downtrend & on the floor, 15m still high & uptrend
            & (
              (rsi_3 > 70.0) | (stochrsi_k_15m_lt_50) | (aroonu_14 > 10.0) | (stochrsi_k > 5.0) | (aroonu_14_15m_lt_75)
            )
            # 5m down move, 15m up move & uptrend, 1h downtrend, 1d overbought
            & (
              (rsi_3 > 70.0)
              | (stochrsi_k_1d_lt_90)
              | (aroonu_14_1h_gt_10)
              | (rsi_3_15m < 65.0)
              | (aroonu_14_15m_lt_60)
            )
            # 5m down move, 15m high
            & ((rsi_3 > 35) | (aroonu_14_15m_lt_90))
            # 5m down move, 1d downtrend
            & ((rsi_3 > 40) | (aroonu_14_1d_gt_10))
            # 5m & 15m down move
            & ((rsi_3 > 45) | (rsi_3_15m_gt_30))
            # 5m down move, 4h high
            & ((rsi_3 > 45) | (stochrsi_k_4h_lt_90))
            # 5m down move & still not low enough
            & ((rsi_3 > 50) | (aroonu_14_lt_25))
            # 5m down move, 15m up move, 1d extended
            & ((rsi_3 > 60.0) | (roc_9_1d_lt_60) | (rsi_3_15m < 65.0))
            # 5m down move & uptrend, 1d extended
            & ((rsi_3 > 60.0) | (roc_9_1d_lt_70) | (aroonu_14 < 80.0))
            # 5m down move, 4h down move, 1d downtrend
            & ((rsi_3 > 60.0) | (rsi_3_4h_gt_50) | (aroonu_14_1d > 80.0))
            # 5m down move, 15m still high, 1d up move
            & ((rsi_3 > 60.0) | (stochrsi_k_15m_lt_70) | (roc_9_1d_lt_30) | (rsi_3_1d_lt_95))
            # 5m down move & uptrend, 15m up move
            & ((rsi_3 > 70.0) | (rsi_3_15m_lt_80) | (aroonu_14 < 80.0))
            # 5m down move & uptrend, 4h down move
            & ((rsi_3 > 70.0) | (rsi_3_4h_gt_60) | (aroonu_14 < 95.0))
            # 5m down move & still high, 15m still high
            & ((rsi_3 > 70.0) | (stochrsi_k_15m_lt_70) | (stochrsi_k < 55.0))
            # 5m down move & uptrend, 15m overbought
            & ((rsi_3 > 70.0) | (stochrsi_k_15m_lt_80) | (aroonu_14 < 80.0))
            # 5m up move, 1h down move
            & ((rsi_3_lt_95) | (rsi_3_1h_gt_60))
            # 5m RSI high & base position low
            & ((rsi_14 < 68) | (ph_base_pos > 3))
            # 5m rsi 20 low & downtrend & down move, 15m down move, 4h -DI low
            & ((rsi_20 > 60.0) | (minus_di_14_4h > 10.0) | (rsi_3_15m_gt_35) | (aroonu_14 > 0.0) | (rsi_3 > 60.0))
            # 5m money leaving, 1h RSI high
            & ((cmf_20 > -0.1) | (rsi_14_1h_lt_80))
            # 5m money leaving, 15m up move
            & ((cmf_20 > -0.1) | (rsi_3_15m_lt_85))
            # 5m money leaving, 15m still high
            & ((mfi_14 > 30) | (stochrsi_k_15m_lt_60))
            # money leaving the base while the 15m cci is stretched high
            & ((mfi_14 > 30.0) | (cci_20_15m < 70.0))
            # 5m money leaving, 1h money leaving
            & ((mfi_14 > 40) | (cmf_20_1h_gt_neg_0_10))
            # 5m uptrend, 1h downtrend, 4h still high, 1d overbought & down move
            & (
              (aroonu_14_lt_30)
              | (stochrsi_k_1d_lt_80)
              | (aroonu_14_1h > 25.0)
              | (stochrsi_k_4h < 45.0)
              | (roc_9_1d > 35.0)
            )
            # 5m uptrend & still high, 1h downtrend & down move, 4h still high
            & (
              (aroonu_14_lt_30) | (stochrsi_k_lt_30) | (aroonu_14_1h > 25.0) | (rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_50)
            )
            # 5m still not low enough, 4h still high, 1d high
            & ((aroonu_14_lt_25) | (stochrsi_k_4h_lt_40) | (aroonu_14_1d_lt_90))
            # 5m still not low enough, 4h still high & high
            & ((aroonu_14_lt_30) | (aroonu_14_4h_lt_40) | (stochrsi_k_4h_lt_70))
            # 5m still not low enough, 15m down move, 1d high
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_55) | (aroonu_14_1d_lt_90))
            # 5m still not low enough, 15m down move, 1h high
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_55) | (aroonu_14_1h_lt_70))
            # 5m still not low enough, 1h down move, 1d high
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_60) | (aroonu_14_1d_lt_100))
            # 5m still not low enough, 4h down move, 1d overbought
            & ((aroonu_14_lt_30) | (rsi_3_4h_gt_60) | (roc_9_1d_lt_150))
            # 5m uptrend, 1d overbought & down move
            & ((aroonu_14_lt_30) | (stochrsi_k_1d_lt_80) | (rsi_3_1d_gt_55))
            # 5m still not low enough, 1h still high, 4h high
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_80))
            # 5m still not low enough, 1h & 1d high
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_lt_70) | (stochrsi_k_1d_lt_80))
            # 5m still not low enough, 15m high
            & ((aroonu_14_lt_30) | (stochrsi_k_lt_20) | (stochrsi_k_15m_lt_70))
            # 5m still not low enough, 1h high
            & ((aroonu_14_lt_30) | (stochrsi_k_lt_30) | (aroonu_14_1h_lt_80))
            # 5m still not low enough, 15m down move
            & ((aroonu_14_lt_30) | (stochrsi_k_lt_30) | (rsi_3_15m_gt_50))
            # 5m AROOND high & 12-bar low high
            & ((aroond_14_lt_25) | (quad_s93_min_12 < 60))
            # 5m still high, 15m overbought, 4h downtrend & still high, 1d overbought
            & (
              (stochrsi_k_lt_30)
              | (stochrsi_k_15m_lt_80)
              | (aroonu_14_4h > 40.0)
              | (stochrsi_k_4h_lt_40)
              | (stochrsi_k_1d < 85.0)
            )
            # 5m still high, 1h downtrend, 4h still high, 1d down move & uptrend
            & (
              (stochrsi_k_lt_30)
              | (stochrsi_k_4h_lt_40)
              | (aroonu_14_1h > 15.0)
              | (rsi_3_1d > 75.0)
              | (aroonu_14_1d_lt_75)
            )
            # 5m still not low enough, 1d high
            & ((stochrsi_k_lt_20) | (aroonu_14_1d_lt_90) | (stochrsi_k_1d_lt_70))
            # 5m still high, 15m down move, 1h up move
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_40) | (roc_9_1h_lt_20))
            # 5m still high, 15m down move, 1d down move
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_40) | (rsi_3_1d_gt_30))
            # 5m still high, 15m down move & still high
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_40))
            # 5m still high, 15m down move, 1h overbought
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_40) | (stochrsi_k_1h_lt_90))
            # 5m still not low enough, 15m down move & high
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_80))
            # 5m still not low enough, 1h & 1d down move
            & ((stochrsi_k_lt_20) | (rsi_3_1h_gt_65) | (rsi_3_1d_gt_60))
            # 5m & 15m still not low enough, 1d high
            & ((stochrsi_k_lt_30) | (aroonu_14_15m_lt_20) | (stochrsi_k_1d_lt_90))
            # 5m still not low enough, 15m high, 1h still high
            & ((stochrsi_k_lt_30) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_40))
            # 5m still not low enough, 1d high & overbought
            & ((stochrsi_k_lt_30) | (aroonu_14_1d_lt_90) | (roc_9_1d_lt_20))
            # 5m still high, 4h up move, 1d down move
            & ((stochrsi_k_lt_30) | (roc_9_1d > 30.0) | (roc_9_4h_lt_40))
            # 5m still not low enough, 15m down move & high
            & ((stochrsi_k_lt_30) | (rsi_3_15m_gt_40) | (aroonu_14_15m_lt_90))
            # 5m still not low enough, 15m & 4h down move
            & ((stochrsi_k_lt_30) | (rsi_3_15m_gt_40) | (rsi_3_4h_gt_50))
            # 5m still not low enough, 15m down move & high
            & ((stochrsi_k_lt_30) | (rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_70))
            # 5m still not low enough, 4h down move & high
            & ((stochrsi_k_lt_30) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_60))
            # 5m still high, 15m still high, 1h down move & uptrend
            & ((stochrsi_k_lt_30) | (stochrsi_k_15m_lt_40) | (roc_9_1h > 0.0) | (aroonu_14_1h_lt_80))
            # 5m still not low enough, 15m & 1h still high
            & ((stochrsi_k_lt_30) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_50))
            # 5m still high & down move, 15m overbought
            & ((stochrsi_k_lt_30) | (stochrsi_k_15m_lt_80) | (rsi_3 > 60.0))
            # 5m still not low enough, 1h & 1d high
            & ((stochrsi_k_lt_30) | (stochrsi_k_1h_lt_70) | (stochrsi_k_1d_lt_70))
            # 5m still not low enough, 4h & 1d high
            & ((stochrsi_k_lt_30) | (stochrsi_k_4h_lt_60) | (aroonu_14_1d_lt_90))
            # 5m stoch 4 4 low & washed out, 4h -DI low & downtrend, 1d down move
            & (
              (stoch_4_4 > 80.0)
              | (minus_di_14_4h > 10.0)
              | (aroonu_14_4h_gt_80)
              | (roc_9_1d > 15.0)
              | (stochrsi_k > 20.0)
            )
            # 5m stoch 9 3 low & up move, 15m up move, 1d downtrend & up move
            & ((stoch_9_3 > 80.0) | (rsi_3_15m_lt_70) | (aroonu_14_1d > 65.0) | (roc_9_1d_lt_30) | (rsi_3 < 70.0))
            # 5m willr 480 high, 15m RSI low
            & ((willr_480 < -5) | (rsi_14_15m > 60))
            # 5m still high & down move, 15m down move, 4h still high, 1d downtrend
            & (
              (rsi_3_15m_gt_55) | (stochrsi_k_4h_lt_70) | (aroonu_14_1d > 60.0) | (stochrsi_k < 45.0) | (rsi_3 > 60.0)
            )
            # the 15m has not moved up and the hour is already topped out
            & ((rsi_3_15m > 30.0) | (stochrsi_k_1h_lt_80))
            # 15m down move & high
            & ((rsi_3_15m_gt_35) | (stochrsi_k_15m_lt_70))
            # 15m down move, 1h overbought
            & ((rsi_3_15m_gt_35) | (stochrsi_k_1h_lt_90))
            # 15m down move, 15m & 1d high
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_90) | (stochrsi_k_1d_lt_90))
            # 15m down move, 4h money leaving
            & ((rsi_3_15m_gt_40) | (mfi_14_4h > 30))
            # 15m down move, 1d down move & extended
            & ((rsi_3_15m_gt_40) | (rsi_3_1d_gt_65) | (roc_9_1d_lt_100))
            # 15m & 4h down move, 4h high
            & ((rsi_3_15m_gt_40) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_90))
            # 15m down move & high, 1h overbought
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_60) | (roc_9_1h_lt_20))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_60) | (stochrsi_k_1h_lt_90))
            # 15m down move & high, 1h still high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_50))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_4h_lt_80) | (rsi_3_1d_gt_65))
            # 15m down move, 1h still high & downtrend, 1d down move
            & ((rsi_3_15m_gt_45) | (stochrsi_k_1h_lt_40) | (roc_9_1d > 10.0) | (aroonu_14_1h_gt_10))
            # 15m down move, 1h WILLR high & downtrend, 1d down move
            & ((rsi_3_15m_gt_45) | (willr_14_1h < -45.0) | (roc_9_1d > 10.0) | (aroonu_14_1h_gt_10))
            # 15m down move & high, 4h still high
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_60) | (stochrsi_k_4h_lt_50))
            # 15m down move, 1d downtrend
            & ((rsi_3_15m_gt_50) | (aroonu_14_1d_gt_10))
            # 5m up move, 15m down move & still high, 1h up move, 1d up move
            & ((rsi_3_15m_gt_50) | (roc_9_1d_lt_30) | (rsi_3 < 75.0) | (stochrsi_k_15m < 45.0) | (rsi_3_1h_lt_80))
            # 5m downtrend, 15m down move & still high, 1h up move, 1d down move
            & ((rsi_3_15m_gt_50) | (roc_9_1h_lt_10) | (roc_9_1d > 35.0) | (aroonu_14 > 10.0) | (stochrsi_k_15m < 45.0))
            # 15m down move, 1h & 1d overbought
            & ((rsi_3_15m_gt_50) | (roc_9_1h_lt_40) | (roc_9_1d_lt_150))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_50) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_70))
            # 5m downtrend, 15m down move & still high, 1h up move
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_lt_95) | (aroonu_14 > 10.0) | (stochrsi_k_15m_lt_40))
            # 15m down move & still high, 1d overbought
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_40) | (roc_9_1d_lt_80))
            # 15m down move & high, 4h overbought
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_70) | (roc_9_4h_lt_50))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_70))
            # 15m down move, 1h overbought, 4h up move, 1d down move
            & ((rsi_3_15m_gt_50) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_5) | (roc_9_1d > 20.0))
            # 15m down move, 4h still high, 1d high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_4h_lt_50) | (stochrsi_k_1d_lt_70))
            # 15m down move, 15m & 1h still high
            & ((rsi_3_15m_gt_55) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_lt_50))
            # 15m down move & high, 1d overbought
            & ((rsi_3_15m_gt_55) | (aroonu_14_15m_lt_80) | (roc_9_1d_lt_40))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_55) | (aroonu_14_15m_lt_80) | (rsi_3_1h_gt_60))
            # 15m down move, 1h & 1d high
            & ((rsi_3_15m_gt_55) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_70))
            # 15m down move, 1h uptrend, 4h down move
            & ((rsi_3_15m_gt_55) | (aroonu_14_1h_lt_90) | (rsi_3_4h_gt_50))
            # 5m up move, 15m down move & up move, 1d down move
            & ((rsi_3_15m_gt_55) | (roc_9_15m < 1.5) | (roc_9_1d > 30.0) | (rsi_3 < 65.0))
            # 15m & 1d down move, 1h overbought
            & ((rsi_3_15m_gt_55) | (roc_9_1h_lt_30) | (rsi_3_1d_gt_65))
            # 15m down move, 1h overbought
            & ((rsi_3_15m_gt_55) | (roc_9_1h_lt_80))
            # 15m down move, 1h RSI high & down move, 1d down move
            & ((rsi_3_15m_gt_55) | (rsi_14_1h < 70.0) | (rsi_3_1h_gt_65) | (rsi_3_1d > 80.0))
            # 15m down move, 1d down move & extended
            & ((rsi_3_15m_gt_55) | (rsi_3_1d_gt_50) | (roc_9_1d_lt_60))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_gt_60) | (aroonu_14_1d_lt_90))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_55) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_80))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_55) | (rsi_3_4h_gt_50) | (stochrsi_k_1d_lt_80))
            # 15m & 1d down move, 15m still not low enough
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_30) | (rsi_3_1d_gt_50))
            # 15m & 1d down move, 15m high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_70) | (rsi_3_1d_gt_65))
            # 15m down move & high, 1d downtrend
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_80) | (roc_9_1d_gt_neg_10))
            # 15m down move & high, 1d overbought
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_80) | (roc_9_1d_lt_100))
            # 15m up move, 4h money leaving
            & ((rsi_3_15m_lt_60) | (cmf_20_4h_gt_neg_0_30))
            # 5m on the floor & up move, 15m up move, 1h roc 2 high
            & ((rsi_3_15m_lt_70) | (roc_2_1h < 5.0) | (stochrsi_k > 5.0) | (rsi_3 < 60.0))
            # 15m up move, 1h money coming in
            & ((rsi_3_15m_lt_85) | (mfi_14_1h < 95))
            # 15m up move, 1d low
            & ((rsi_3_15m_lt_90) | (aroonu_14_1d_gt_10))
            # 15m up move & washed out, 4h washed out
            & ((rsi_3_15m_lt_90) | (stochrsi_k_4h_gt_40) | (stochrsi_k_15m_gt_90))
            # 15m up move, 1d downtrend
            & ((rsi_3_15m_lt_97) | (aroonu_14_1d_gt_20))
            # 15m downtrend, 4h ADX low
            & ((aroonu_14_15m_gt_10) | (adx_14_4h > 20))
            # 15m downtrend, 1d downtrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1d_gt_10))
            # 15m downtrend, 1d daily range low
            & ((aroonu_14_15m_gt_10) | (range_pct_14_1d > 4))
            # 15m downtrend & rising fast
            & ((aroonu_14_15m_gt_10) | (uo_7_14_28_change_pct_15m < 13))
            # 15m downtrend, 1d top wick high
            & ((aroonu_14_15m_gt_20) | (top_wick_pct_1d_lt_10))
            # 15m downtrend, 4h -DI high
            & ((aroonu_14_15m_gt_30) | (minus_di_14_4h < 20))
            # 15m downtrend, 1h overbought
            & ((aroonu_14_15m_gt_40) | (stochrsi_k_1h_lt_90))
            # the 15m making no new high while the hour is already maxed out
            & ((aroonu_14_15m_gt_60) | (rsi_3_1h_lt_90))
            # 15m still high, 4h downtrend
            & ((aroonu_14_15m_lt_50) | (roc_9_4h_gt_neg_10))
            # 15m & 1h & 4h high
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_90) | (stochrsi_k_4h_lt_60))
            # 15m down move & high, 1h still high
            & ((aroonu_14_15m_lt_60) | (rsi_3_15m_gt_45) | (stochrsi_k_1h_lt_40))
            # 15m & 1h high, 15m still high
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_80))
            # 15m & 1h & 4h high
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_70) | (stochrsi_k_4h_lt_80))
            # 15m & 1h high
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_90) | (stochrsi_k_1h_lt_90))
            # 15m high, 1h down move, 1d overbought
            & ((aroonu_14_15m_lt_70) | (rsi_3_1h_gt_65) | (roc_9_1d_lt_150))
            # 15m uptrend, 1h down move, 4h up move
            & ((aroonu_14_15m_lt_70) | (rsi_3_1h_gt_65) | (roc_9_4h_lt_25))
            # 15m & 4h high, 4h down move
            & ((aroonu_14_15m_lt_70) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_60))
            # 15m & 1d high, 4h still high
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_4h_lt_40) | (aroonu_14_1d_lt_90))
            # 15m uptrend, 1d uptrend & down move
            & ((aroonu_14_15m_lt_75) | (aroonu_14_1d_lt_80) | (rsi_3_1d_gt_55))
            # 5m down move & still high, 15m uptrend, 4h down move, 1d uptrend
            & ((aroonu_14_15m_lt_75) | (aroonu_14_1d_lt_90) | (rsi_3 > 60.0) | (stochrsi_k_lt_30) | (roc_9_4h > 5.0))
            # 5m downtrend, 15m uptrend, 1h down move & downtrend
            & ((aroonu_14_15m_lt_75) | (rsi_3_1h_gt_65) | (aroonu_14_1h_gt_10) | (aroonu_14 > 25.0))
            # 15m uptrend, 4h down move
            & ((aroonu_14_15m_lt_75) | (rsi_3_4h_gt_15))
            # 5m on the floor & up move, 15m uptrend, 4h up move
            & ((aroonu_14_15m_lt_80) | (roc_9_4h_lt_20) | (stochrsi_k > 5.0) | (rsi_3 < 60.0))
            # 5m down move, 15m uptrend, 1d AROOND low & downtrend
            & ((aroonu_14_15m_lt_90) | (aroond_14_1d > 5.0) | (aroonu_14_1d_gt_30) | (rsi_3 > 50.0))
            # 5m up move, 15m uptrend, 1h down move, 4h down move & still high
            & ((aroonu_14_15m_lt_90) | (roc_9_4h > 5.0) | (rsi_3_1h_gt_65) | (stochrsi_k_4h < 75.0) | (rsi_3 < 80.0))
            # 15m high, 1d down move
            & ((aroonu_14_15m_lt_90) | (rsi_3_1d_gt_60))
            # 15m uptrend, 1h down move, 4h up move
            & ((aroonu_14_15m_lt_90) | (rsi_3_1h_gt_60) | (roc_9_4h_lt_20))
            # 15m uptrend & washed out, 1h down move
            & ((aroonu_14_15m_lt_90) | (rsi_3_1h_gt_65) | (stochrsi_k_15m > 55.0))
            # 15m & 4h high, 4h down move
            & ((aroonu_14_15m_lt_90) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80))
            # 15m uptrend & washed out, 4h washed out
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_15m_gt_50) | (stochrsi_k_4h > 25.0))
            # 15m & 1h high, 15m still high
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_15m_lt_50) | (aroonu_14_1h_lt_90))
            # 15m high, 4h down move
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_15m_lt_80) | (rsi_3_4h_gt_20))
            # 15m & 4h high
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_15m_lt_80) | (stochrsi_k_4h_lt_60))
            # 15m uptrend, 1d overbought & down move
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_1d_lt_90) | (rsi_3_1d > 85.0))
            # 15m uptrend & washed out, 4h still high
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_4h_lt_70) | (stochrsi_k_15m > 25.0))
            # 15m & 4h & 1d high
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_4h_lt_90) | (stochrsi_k_1d_lt_90))
            # a 15m downtrend already maxed out with no hourly downtrend behind it
            & ((aroond_14_15m < 80.0) | (aroond_14_1h < 25.0))
            # 5m down move, 15m still high & downtrend, 1h uptrend, 4h up move
            & (
              (stochrsi_k_15m_lt_50) | (aroonu_14_1h_lt_90) | (aroonu_14_15m_gt_50) | (rsi_3_4h_lt_90) | (rsi_3 > 80.0)
            )
            # 5m down move, 15m overbought, 1h downtrend & up move, 4h overbought
            & (
              (stochrsi_k_15m_lt_80)
              | (stochrsi_k_4h_lt_90)
              | (aroonu_14_1h > 50.0)
              | (roc_9_1h < 5.0)
              | (rsi_3 > 75.0)
            )
            # 15m on the floor, 4h UO low
            & ((stochrsi_k_15m_gt_10) | (uo_7_14_28_4h > 55))
            # 15m washed out, 1d downtrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1d_gt_10))
            # 15m washed out, 4h down move
            & ((stochrsi_k_15m_gt_30) | (rsi_3_4h_gt_60))
            # 15m still high, 1h down move & downtrend
            & ((stochrsi_k_15m_lt_30) | (rsi_3_1h_gt_60) | (aroonu_14_1h_gt_10))
            # 15m still high & downtrend, 1h down move & downtrend
            & ((stochrsi_k_15m_lt_30) | (rsi_3_1h_gt_65) | (aroonu_14_1h_gt_0) | (aroonu_14_15m > 15.0))
            # 5m downtrend & up move, 15m still high & down move, 1d down move
            & ((stochrsi_k_15m_lt_40) | (roc_9_1d > 25.0) | (aroonu_14 > 0.0) | (rsi_3_15m_gt_35) | (rsi_3_lt_40))
            # 15m still high, 1h & 1d down move
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_65) | (rsi_3_1d_gt_65))
            # 15m still high, 1h & 1d high
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_80) | (aroonu_14_1d_lt_90))
            # 15m still high, 1h high, 1d down move
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_80) | (rsi_3_1d_gt_65))
            # 15m still high, 4h high & overbought
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_4h_lt_90) | (roc_9_4h_lt_5))
            # 15m & 1h still high, 4h high
            & ((stochrsi_k_15m_lt_50) | (aroonu_14_1h_lt_40) | (stochrsi_k_4h_lt_70))
            # 5m downtrend & still high, 15m still high, 4h -DI low
            & ((stochrsi_k_15m_lt_50) | (minus_di_14_4h > 10.0) | (aroonu_14 > 10.0) | (stochrsi_k < 70.0))
            # 15m still high, 4h & 1d high
            & ((stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_90) | (stochrsi_k_1d_lt_90))
            # 15m & 1h high, 1d down move
            & ((stochrsi_k_15m_lt_60) | (aroonu_14_1h_lt_60) | (rsi_3_1d_gt_55))
            # 15m high, 4h overbought, 1d downtrend
            & ((stochrsi_k_15m_lt_60) | (roc_9_4h_lt_5) | (roc_9_1d_gt_neg_10))
            # 15m still high, 1h down move, 4h on the floor
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_65) | (stochrsi_k_4h > 15.0))
            # 15m high, 4h down move & overbought
            & ((stochrsi_k_15m_lt_60) | (rsi_3_4h_gt_55) | (roc_9_4h_lt_15))
            # 5m downtrend, 15m still high, 1d overbought
            & ((stochrsi_k_15m_lt_60) | (stochrsi_k_1d_lt_90) | (aroonu_14 > 0.0))
            # 5m up move, 15m still high, 1h downtrend, 1d down move
            & ((stochrsi_k_15m_lt_70) | (roc_9_1d > 15.0) | (aroonu_14_1h_gt_0) | (rsi_3 < 75.0))
            # 5m overbought, 15m still high, 4h up move
            & ((stochrsi_k_15m_lt_70) | (roc_9_4h_lt_5) | (stochrsi_k < 95.0))
            # 15m & 1d high, 1d down move
            & ((stochrsi_k_15m_lt_70) | (rsi_3_1d_gt_60) | (stochrsi_k_1d_lt_80))
            # 15m high, 1h still high, 1d overbought
            & ((stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_50) | (roc_9_1d_lt_150))
            # 15m & 1h high, 4h overbought
            & ((stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_90) | (roc_9_4h_lt_70))
            # 15m still high & rising fast
            & ((stochrsi_k_15m_lt_70) | (uo_7_14_28_change_pct_15m < 13))
            # 15m overbought, 1h downtrend & still high, 4h money coming in
            & ((stochrsi_k_15m_lt_80) | (mfi_14_4h < 85.0) | (aroonu_14_1h > 50.0) | (stochrsi_k_1h < 15.0))
            # 15m high, 1d overbought
            & ((stochrsi_k_15m_lt_80) | (roc_9_1d_lt_200))
            # 15m overbought, 1h down move, 4h up move
            & ((stochrsi_k_15m_lt_80) | (roc_9_4h_lt_10) | (roc_9_1h > 0.0))
            # 15m high, 4h overbought
            & ((stochrsi_k_15m_lt_80) | (roc_9_4h_lt_100))
            # 15m & 1d high, 4h overbought
            & ((stochrsi_k_15m_lt_80) | (roc_9_4h_lt_50) | (stochrsi_k_1d_lt_90))
            # 15m high, 1d down move
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1d_gt_60))
            # 15m overbought, 1d down move & downtrend
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1d_gt_65) | (aroonu_14_1d_gt_0))
            # 15m high, 4h down move & overbought
            & ((stochrsi_k_15m_lt_80) | (rsi_3_4h_gt_60) | (roc_9_4h_lt_15))
            # 15m & 1d high, 4h down move
            & ((stochrsi_k_15m_lt_80) | (rsi_3_4h_gt_60) | (stochrsi_k_1d_lt_90))
            # 15m high, 1h still high, 4h overbought
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_50) | (roc_9_4h_lt_15))
            # 15m overbought, 1h overbought & downtrend, 1d overbought
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_80) | (stochrsi_k_1d_lt_90) | (aroonu_14_1h > 90.0))
            # 15m & 1h high, 4h still high
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_90) | (stochrsi_k_4h_lt_50))
            # 15m & 4h high, 1d overbought
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_4h_lt_70) | (roc_9_1d_lt_60))
            # 15m stochk 14 3 3 high, 4h -DI high
            & ((stochk_14_3_3_15m < 95) | (minus_di_14_4h < 20))
            # 15m up move, 4h up move & on the floor
            & ((roc_9_15m < 1.5) | (roc_9_4h_lt_5) | (stochrsi_k_4h > 15.0))
            # 15m overbought, 4h downtrend, 1d high
            & ((roc_9_15m < 10) | (roc_9_4h > 15) | (stochrsi_k_1d_lt_90))
            # 15m overbought, 1d downtrend
            & ((roc_9_15m < 15) | (roc_9_1d > 15))
            # 15m & 1d overbought
            & ((roc_9_15m < 30) | (roc_9_1d_lt_200))
            # 15m down move, 1d extended
            & ((roc_9_15m > -1) | (roc_9_1d_lt_150))
            # 15m down move, 4h up move
            & ((roc_9_15m > -1) | (roc_9_4h_lt_40))
            # the 15m cci below its zero band with the daily money flow gone
            & ((cci_20_15m > 15.0) | (mfi_14_1d > 45.0))
            # 1h down move, 4h down move
            & ((rsi_3_1h_gt_60) | (roc_9_4h > 2))
            # 1h down move & still high, 1d up move
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_60) | (roc_9_1d_lt_40))
            # 1h down move & still high, 1d up move
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_30))
            # 1h down move & high, 4h overbought
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_25))
            # 1h down move & overbought
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_90))
            # 1h down move, 4h washed out
            & ((rsi_3_1h_gt_60) | (stochrsi_k_4h_gt_20))
            # 1h & 1d down move, 4h still high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_4h_lt_40) | (rsi_3_1d_gt_65))
            # 1h down move, 1d downtrend
            & ((rsi_3_1h_gt_65) | (aroonu_14_1d_gt_10))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_65) | (aroonu_14_1h_lt_60) | (stochrsi_k_1d_lt_80))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_65) | (aroonu_14_1h_lt_80) | (rsi_3_4h_gt_65))
            # 1h down move, 1d downtrend
            & ((rsi_3_1h_gt_65) | (roc_9_1d_gt_neg_10))
            # 1h down move, 1h & 1d overbought
            & ((rsi_3_1h_gt_65) | (roc_9_1h_lt_30) | (roc_9_1d_lt_40))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_65) | (rsi_3_1d_gt_60) | (stochrsi_k_1d_lt_90))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_65) | (rsi_3_1d_gt_65) | (aroonu_14_1d_lt_90))
            # 1h & 4h down move, 4h still high
            & ((rsi_3_1h_gt_65) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_40))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_50) | (rsi_3_4h_gt_60))
            # 1h down move & high, 1d overbought
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_40))
            # 1h down move & overbought, 4h up move
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_90) | (roc_9_4h_lt_5))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_90) | (stochrsi_k_1d_lt_90))
            # 1h up move & washed out
            & ((rsi_3_1h_lt_75) | (stochrsi_k_1h_gt_20))
            # 1h up move & downtrend
            & ((rsi_3_1h_lt_85) | (aroonu_14_1h_gt_60))
            # 1h money coming in, 4h downtrend
            & ((mfi_14_1h < 80) | (aroonu_14_4h_gt_30))
            # 5m on the floor, 15m up move, 1h uptrend, 1d uptrend & overbought
            & (
              (aroonu_14_1h_lt_90)
              | (aroonu_14_1d_lt_90)
              | (stochrsi_k > 5.0)
              | (stochrsi_k_1d_lt_90)
              | (rsi_3_15m_lt_50)
            )
            # 5m down move, 1h uptrend & washed out, 4h still high & downtrend
            & (
              (aroonu_14_1h_lt_90)
              | (stochrsi_k_4h_lt_60)
              | (aroonu_14_4h_gt_80)
              | (stochrsi_k_1h > 55.0)
              | (rsi_3 > 55.0)
            )
            # 1h downtrend, 4h AROOND high
            & ((aroonu_14_1h_gt_20) | (aroond_14_4h_lt_80))
            # 1h downtrend, 1d downtrend
            & ((aroonu_14_1h_gt_60) | (aroonu_14_1d_gt_50))
            # 1h high, 4h down move & overbought
            & ((aroonu_14_1h_lt_70) | (rsi_3_4h_gt_60) | (roc_9_4h_lt_5))
            # 1h high, 4h overbought, 1d down move
            & ((aroonu_14_1h_lt_80) | (roc_9_4h_lt_15) | (rsi_3_1d_gt_40))
            # 1h high, 1d down move & downtrend
            & ((aroonu_14_1h_lt_90) | (rsi_3_1d_gt_60) | (roc_9_1d_gt_neg_10))
            # 1h uptrend, 1d down move & extended
            & ((aroonu_14_1h_lt_90) | (rsi_3_1d_gt_65) | (roc_9_1d_lt_100))
            # 1h & 4h high, 4h down move
            & ((aroonu_14_1h_lt_90) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_60))
            # 1h high, 4h down move
            & ((aroonu_14_1h_lt_90) | (stochrsi_k_1h_lt_70) | (rsi_3_4h_gt_50))
            # 1h AROOND high & overbought, 4h rising fast
            & ((aroond_14_1h_lt_50) | (stochrsi_k_change_pct_4h < 20.0) | (stochrsi_k_1h_lt_90))
            # 15m washed out, 1h still high, 4h still high & down move
            & (
              (stochrsi_k_1h_lt_60)
              | (stochrsi_k_4h_lt_70)
              | (stochrsi_k_15m_gt_20)
              | (roc_9_4h > 10.0)
              | (rsi_3_4h > 90.0)
            )
            # 1h washed out, 4h extended
            & ((stochrsi_k_1h_gt_30) | (roc_9_4h_lt_80))
            # 1h still high, 4h washed out, 1d down move
            & ((stochrsi_k_1h_lt_20) | (roc_9_1d > 30.0) | (stochrsi_k_4h_gt_30))
            # 1h still high, 4h down move, 1d high
            & ((stochrsi_k_1h_lt_50) | (rsi_3_4h_gt_50) | (stochrsi_k_1d_lt_90))
            # 1h still high, 4h down move & overbought
            & ((stochrsi_k_1h_lt_50) | (rsi_3_4h_gt_65) | (roc_9_4h_lt_10))
            # 1h still high, 4h & 1d high
            & ((stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_90) | (stochrsi_k_1d_lt_90))
            # 1h & 1d high, 4h down move
            & ((stochrsi_k_1h_lt_60) | (rsi_3_4h_gt_65) | (aroonu_14_1d_lt_80))
            # 1h & 4h high, 1d overbought
            & ((stochrsi_k_1h_lt_60) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_100))
            # 1h high, 4h down move & overbought
            & ((stochrsi_k_1h_lt_70) | (rsi_3_4h_gt_65) | (roc_9_4h_lt_5))
            # 1h & 1d high, 1d down move
            & ((stochrsi_k_1h_lt_80) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_90))
            # 15m overbought, 1h overbought, 4h down move
            & ((stochrsi_k_1h_lt_80) | (rsi_3_4h_gt_60) | (stochrsi_k_15m_lt_80))
            # 1h & 1d high, 4h down move
            & ((stochrsi_k_1h_lt_80) | (rsi_3_4h_gt_60) | (stochrsi_k_1d_lt_90))
            # 1h overbought, 4h down move & uptrend
            & ((stochrsi_k_1h_lt_80) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_70))
            # 1h & 4h high, 1d overbought
            & ((stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_60))
            # 15m downtrend, 1h overbought, 4h overbought
            & ((stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_90) | (aroonu_14_15m_gt_50))
            # 15m downtrend, 1h overbought, 1d up move
            & ((stochrsi_k_1h_lt_90) | (roc_9_1d_lt_35) | (aroonu_14_15m_gt_60))
            # 1h overbought, 4h down move
            & ((stochrsi_k_1h_lt_90) | (rsi_3_4h_gt_65))
            # 15m downtrend, 1h overbought, 1d overbought
            & ((stochrsi_k_1h_lt_90) | (stochrsi_k_1d_lt_80) | (aroonu_14_15m_gt_50))
            # 5m down move, 1h overbought, 4h overbought
            & ((stochrsi_k_1h_lt_90) | (stochrsi_k_4h_lt_90) | (rsi_3 > 50.0))
            # 1h overbought, 4h overbought, 1d down move
            & ((stochrsi_k_1h_lt_90) | (stochrsi_k_4h_lt_90) | (rsi_3_1d_gt_65))
            # 1h down move, 4h overbought
            & ((roc_9_1h > -2) | (stochrsi_k_4h_lt_80))
            # 1h up move, 4h downtrend
            & ((roc_9_1h_lt_25) | (aroonu_14_4h_gt_10))
            # 1h overbought, 1d high
            & ((roc_9_1h_lt_80) | (stochrsi_k_1d_lt_80))
            # 4h down move, 1d extended
            & ((rsi_3_4h_gt_35) | (roc_9_1d_lt_150))
            # 5m washed out, 4h down move, 1d down move
            & ((rsi_3_4h_gt_40) | (roc_9_1d > 25.0) | (stochrsi_k > 30.0))
            # 4h down move & still high, 1d down move
            & ((rsi_3_4h_gt_45) | (roc_9_1d > 25.0) | (stochrsi_k_4h < 45.0))
            # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_80) | (rsi_3_1d_gt_65))
            # 1h uptrend, 4h down move, 1d down move
            & ((rsi_3_4h_gt_50) | (roc_9_1d > 30.0) | (aroonu_14_1h < 55.0))
            # 4h down move & still high, 1d high
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_50) | (stochrsi_k_1d_lt_70))
            # 4h down move, 1d still not low enough & downtrend
            & ((rsi_3_4h_gt_60) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_10))
            # 4h down move & uptrend, 1d down move
            & ((rsi_3_4h_gt_60) | (roc_9_1d > 20.0) | (aroonu_14_4h_lt_75))
            # 1h still high, 4h down move & up move
            & ((rsi_3_4h_gt_60) | (roc_9_4h_lt_5) | (stochrsi_k_1h < 65.0))
            # 4h down move & still high, 1d high
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_50) | (stochrsi_k_1d_lt_80))
            # 4h down move, 1d down move
            & ((rsi_3_4h_gt_65) | (rsi_3_1d_gt_60))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_40) | (rsi_3_1d_gt_65))
            # 4h down move & still high, 1d overbought
            & ((rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_60) | (stochrsi_k_1d_lt_80))
            # 4h up move & low
            & ((rsi_3_4h_lt_80) | (aroonu_14_4h_gt_10))
            # 4h up move, 1d downtrend
            & ((rsi_3_4h_lt_90) | (aroonu_14_1d_gt_10))
            # 1h money leaving, 4h RSI low
            & ((cmf_20_1h_gt_neg_0_20) | (rsi_14_4h_gt_60))
            # 4h money coming in & downtrend
            & ((mfi_14_4h < 85) | (aroonu_14_4h_gt_50))
            # 4h downtrend, 1d downtrend
            & ((aroonu_14_4h_gt_10) | (aroonu_14_1d_gt_50))
            # 4h downtrend, 1d money leaving
            & ((aroonu_14_4h_gt_10) | (cmf_20_1d_gt_neg_0_0))
            # 4h low & high
            & ((aroonu_14_4h_gt_10) | (stochrsi_k_4h_lt_60))
            # the 4h is not making new highs and has already run up hard
            & ((aroonu_14_4h_gt_80) | (roc_9_4h_lt_30))
            # 5m overbought, 4h uptrend, 1d down move
            & ((aroonu_14_4h_lt_90) | (rsi_3_1d_gt_55) | (stochrsi_k < 80.0))
            # 5m downtrend, 4h washed out, 1d washed out
            & ((stochrsi_k_4h_gt_90) | (stochrsi_k_1d_gt_60) | (aroonu_14 > 10.0))
            # 4h still high & down move
            & ((stochrsi_k_4h_lt_50) | (roc_9_4h > 2))
            # 4h & 1d high, 1d down move
            & ((stochrsi_k_4h_lt_60) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_80))
            # 4h high, 1d down move
            & ((stochrsi_k_4h_lt_70) | (rsi_3_1d_gt_55))
            # 4h high, 4h & 1d downtrend
            & ((stochrsi_k_4h_lt_80) | (roc_9_4h > 5) | (roc_9_1d > 15))
            # 4h & 1d high, 1d down move
            & ((stochrsi_k_4h_lt_80) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_70))
            # 15m down move, 4h overbought, 1d down move
            & ((stochrsi_k_4h_lt_90) | (roc_9_1d > 25.0) | (rsi_3_15m_gt_40))
            # 4h high, 1d down move
            & ((stochrsi_k_4h_lt_90) | (rsi_3_1d_gt_60))
            # 4h & 1d downtrend
            & ((roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_10))
            # 4h up move, 1d downtrend
            & ((roc_9_4h_lt_15) | (aroonu_14_1d_gt_30))
            # 15m down move, 4h up move, 1d down move
            & ((roc_9_4h_lt_15) | (roc_9_1d > 20.0) | (rsi_3_15m_gt_55))
            # 4h overbought, 1d downtrend
            & ((roc_9_4h_lt_25) | (roc_9_1d_gt_neg_10))
            # 4h overbought, 1d downtrend
            & ((roc_9_4h_lt_50) | (roc_9_1d > 40))
            # 4h UO low, 1d stochk 14 3 3 high
            & ((uo_7_14_28_4h > 50) | (stochk_14_3_3_1d < 90))
            # 4h ADX low, 1d top wick high
            & ((adx_14_4h > 20) | (top_wick_pct_1d_lt_10))
            # 1d down move & extended
            & ((rsi_3_1d_gt_55) | (roc_9_1d_lt_80))
            # 1d downtrend & extended
            & ((aroonu_14_1d_gt_30) | (roc_9_1d_lt_50))
            # 5m down move & uptrend, 4h up move, 1d uptrend & down move
            & ((aroonu_14_1d_lt_90) | (roc_9_1d > 25.0) | (roc_9_4h_lt_20) | (rsi_3 > 60.0) | (aroonu_14 < 15.0))
            # 1d high & downtrend
            & ((stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_10))
            # 1h downtrend, 1d overbought & down move
            & ((stochrsi_k_1d_lt_90) | (roc_9_1d > 15.0) | (aroonu_14_1h > 45.0))
            # 15m washed out, 1d overbought & down move
            & ((stochrsi_k_1d_lt_90) | (roc_9_1d > 20.0) | (stochrsi_k_15m_gt_20))
            # 1h money flowing in, 1d stochk_14_3_3 high
            & ((cmf_20_1h_lt_0_30) | (stochk_14_3_3_1d < 90))
            # 5m base position high, 1h money leaving
            & ((ph_base_pos < 11) | (mfi_14_1h > 50))
            # 5m base position high, 1h willr 84 low
            & ((ph_base_pos < 9) | (willr_84_1h > -30))
            # 5m pre-entry tightness high, 4h downtrend
            & ((ph_pre_tight < 7) | (aroonu_14_4h_gt_10))
            # 5m pre-entry tightness low, 1d downtrend
            & ((ph_pre_tight > 1) | (aroonu_14_1d_gt_10))
            # 5m quad s93 max 12 low, 15m overbought
            & ((quad_s93_max_12 > 90) | (stochrsi_k_15m_lt_80))
            # 5m 12-bar low high, 4h downtrend
            & ((quad_s93_min_12 < 60) | (aroonu_14_4h_gt_10))
            # 5m 12-bar low high, 1h up move
            & ((quad_s93_min_12 < 65) | (roc_9_1h_lt_15))
            # 5m vol rel high, 15m stochk 14 3 3 low
            & ((vol_rel < 4.5) | (stochk_14_3_3_15m > 65))
            # 15m rising fast, 1h downtrend & on the floor
            & ((rsi_14_change_pct_15m < 3.0) | (aroonu_14_1h_gt_10) | (stochrsi_k_1h > 15.0))
            # 15m rising fast, 1h AROOND high
            & ((rsi_3_change_pct_15m < 70) | (aroond_14_1h_lt_70))
            # 15m rising fast, 4h money leaving
            & ((rsi_3_change_pct_15m < 70) | (cmf_20_4h_gt_neg_0_10))
            # 15m rising fast, 1h roc 2 high
            & ((rsi_3_change_pct_15m < 70) | (roc_2_1h < 5))
            # 15m rising fast, 1d daily change high
            & ((uo_7_14_28_change_pct_15m < 13) | (change_pct_1d_lt_40))
            # 5m washed out, 1h rising fast, 1d daily change high
            & ((rsi_3_change_pct_1h < 50.0) | (change_pct_1d_lt_10) | (stochrsi_k > 20.0))
            # 1h rising fast, 1d daily change low
            & ((rsi_3_change_pct_1h < 80) | (change_pct_1d_gt_neg_5))
            # 1h rising fast, 1d money leaving
            & ((rsi_3_change_pct_1h < 80) | (mfi_14_1d > 45))
            # 4h falling fast & down move, 1d daily range low & washed out
            & (
              (stochrsi_k_change_pct_4h > -5.0) | (range_pct_14_1d > 4.0) | (stochrsi_k_1d > 65.0) | (rsi_3_4h > 75.0)
            )
            # 4h rising fast, 1d washed out
            & ((rsi_3_change_pct_4h < 70) | (stochrsi_k_1d_gt_60))
            # 4h money leaving, 1d rising fast
            & ((cmf_20_4h_gt_neg_0_0) | (rsi_3_change_pct_1d < 50))
          )

          # Logic
          long_entry_logic.append(
            # the daily is genuinely up, not merely off its floor
            (stochrsi_k_1d > 50.0)
            # 1h momentum actually up
            & (rsi_3_1h > 55.0)
            # uptrend regime + momentum side + bullish engulfing close
            # the daily has to be in an uptrend too: a continuation signal has nothing to
            # continue inside a collapse, and it fired 524 times in the LUNA window for -9,688
            & (close > ema_200_1d)
            # and the 4h with it: 12 of the remaining losses sit where the 4h has rolled over
            & (ema_12_4h > ema_200_4h)
            & (close > ema_200)
            & (rsi_14 > 50.0)
            & (engulf_bull > 0.5)
          )

        # Condition #168 - Swing-failure pattern (Long, experimental, RAW — liquidity-sweep reclaim).
        if long_entry_condition_index == 168:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)

          # Logic
          # prior 48-candle low swept by the wick, candle closes back above it
          long_entry_logic.append(sfp_bull > 0.5)

        # Condition #169 - 1h inside-bar breakout (Long, experimental, RAW — TradingLab port).
        if long_entry_condition_index == 169:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            # 5m down move, 15m still high, 1h down move, 1d downtrend
            ((rsi_3 > 85.0) | (stochrsi_k_15m_lt_50) | (rsi_3_1h_gt_40) | (aroonu_14_1d_gt_30))
            # 5m overbought, 1h on the floor, 4h down move & downtrend, 1d downtrend
            & (
              (stochrsi_k < 90.0)
              | (roc_9_4h > 10.0)
              | (aroonu_14_4h > 75.0)
              | (stochrsi_k_1h > 15.0)
              | (aroonu_14_1d > 25.0)
            )
            # 5m overbought & down move, 1h down move, 4h downtrend & up move
            & ((stochrsi_k < 90.0) | (rsi_3_1h_gt_60) | (rsi_3 > 85.0) | (aroonu_14_4h_gt_80) | (rsi_3_4h < 65.0))
            # 5m overbought, 15m up move, 4h washed out, 1d up move
            & ((stochrsi_k < 95.0) | (roc_9_1d_lt_10) | (stochrsi_k_4h_gt_60) | (rsi_3_15m_lt_80))
            # 5m up move, 1h overbought, 4h overbought, 1d washed out & up move
            & (
              (roc_9 < 0.5)
              | (stochrsi_k_4h_lt_90)
              | (stochrsi_k_1h < 85.0)
              | (stochrsi_k_1d > 80.0)
              | (rsi_3_1d < 65.0)
            )
            # 15m up move, 1d on the floor & at a 14-day low
            & ((rsi_3_15m > 65.0) | (stochrsi_k_1d > 35.0) | (aroond_14_1d < 70.0))
            # 5m up move, 15m down move, 1h uptrend, 4h down move
            & ((rsi_3_15m > 80.0) | (aroonu_14_1h_lt_90) | (rsi_3_4h > 70.0) | (rsi_3_lt_95))
            # 15m & 4h down move
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_60))
            # 15m down move, 1h still not low enough, 1d overbought
            & ((rsi_3_15m_gt_45) | (stochrsi_k_1h_lt_20) | (roc_9_1d_lt_0))
            # 15m down move & overbought
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_80))
            # 15m down move & still not low enough, 1d overbought
            & ((rsi_3_15m_gt_55) | (aroonu_14_15m_lt_30) | (roc_9_1d_lt_0))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_55) | (aroonu_14_15m_lt_50) | (rsi_3_4h_gt_65))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_55) | (aroonu_14_1h_lt_80) | (rsi_3_1d_gt_65))
            # 15m down move, 1d downtrend
            & ((rsi_3_15m_gt_55) | (roc_9_1d_gt_neg_10))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_40))
            # 15m down move, 1h down move & uptrend
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_40))
            # 15m down move & still high, 1h uptrend
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_40) | (aroonu_14_1h_lt_80))
            # 15m down move, 15m & 1d high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_60) | (stochrsi_k_1d_lt_90))
            # 15m down move & high, 1h still high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_70) | (aroonu_14_1h_lt_40))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_60))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_55) | (stochrsi_k_1h_lt_60) | (roc_9_1d_gt_0))
            # 15m uptrend & down move, 1h uptrend & down move, 1d up move
            & (
              (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_80) | (rsi_3_1d_lt_95) | (rsi_3_15m > 75.0) | (roc_9_1h > 10.0)
            )
            # 5m washed out, 15m uptrend & washed out, 4h uptrend, 1d down move
            & (
              (aroonu_14_15m_lt_60)
              | (aroonu_14_4h_lt_90)
              | (stochrsi_k > 70.0)
              | (roc_9_1d > 5.0)
              | (stochrsi_k_15m > 65.0)
            )
            # 5m washed out, 15m uptrend & up move, 1h down move, 1d uptrend
            & (
              (aroonu_14_15m_lt_90) | (aroonu_14_1d_lt_40) | (stochrsi_k > 70.0) | (rsi_3_15m_lt_80) | (roc_9_1h > 5.0)
            )
            # 15m uptrend, 1h down move, 4h overbought, 1d down move & downtrend
            & (
              (aroonu_14_15m_lt_90)
              | (rsi_3_1d_gt_65)
              | (aroonu_14_1d_gt_10)
              | (stochrsi_k_4h < 85.0)
              | (rsi_3_1h > 75.0)
            )
            # 15m & 1h still not low enough, 1d down move
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_30) | (rsi_3_1d_gt_65))
            # 15m & 1d still not low enough, 4h down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_gt_65) | (aroonu_14_1d_lt_30))
            # 15m still not low enough, 1d high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1d_lt_80))
            # 15m still not low enough, 1h high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_60))
            # 15m still not low enough & still high, 4h high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_lt_40) | (stochrsi_k_4h_lt_80))
            # 15m still not low enough & high, 1h down move
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_60))
            # 15m still not low enough, 1h high, 4h overbought
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_lt_60) | (roc_9_4h_lt_5))
            # 15m still not low enough, 4h high, 1d down move
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_4h_lt_90) | (rsi_3_1d_gt_60))
            # 15m still not low enough, 4h down move, 1d overbought
            & ((aroonu_14_15m_lt_25) | (rsi_3_4h_gt_60) | (roc_9_1d_lt_10))
            # 15m still not low enough, 1d high & overbought
            & ((aroonu_14_15m_lt_25) | (stochrsi_k_1d_lt_70) | (roc_9_1d_lt_25))
            # 15m still not low enough, 1h still high, 1d high
            & ((aroonu_14_15m_lt_25) | (stochrsi_k_1h_lt_40) | (stochrsi_k_1d_lt_80))
            # 15m still not low enough, 1h & 4h high
            & ((aroonu_14_15m_lt_25) | (stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_80))
            # 5m down move, 15m uptrend, 1d up move & down move & downtrend
            & ((aroonu_14_15m_lt_40) | (roc_9_1d_lt_0) | (rsi_3_1d_gt_45) | (aroonu_14_1d_gt_10) | (rsi_3 > 90.0))
            # 15m still high, 4h down move
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_lt_50) | (rsi_3_4h_gt_65))
            # 15m still high, 1h still not low enough
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_30) | (stochrsi_k_1h_lt_20))
            # 15m uptrend, 1h uptrend, 4h down move
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_60) | (rsi_3_4h_gt_65))
            # 15m still high, 1h down move & high
            & ((aroonu_14_15m_lt_50) | (rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_80))
            # 15m still high, 4h down move & overbought
            & ((aroonu_14_15m_lt_50) | (rsi_3_4h_gt_50) | (roc_9_4h_lt_5))
            # 15m still high, 4h down move & high
            & ((aroonu_14_15m_lt_50) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_90))
            # 15m still high & still not low enough, 4h overbought
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_lt_30) | (roc_9_4h_lt_10))
            # 15m still high & high, 1h still not low enough
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_lt_60) | (stochrsi_k_1h_lt_20))
            # 15m still high & high, 1d still not low enough
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_lt_70) | (aroonu_14_1d_lt_30))
            # 15m still high, 15m & 1d high
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1d_lt_70))
            # 15m still high, 1h & 1d high
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_1h_lt_80) | (stochrsi_k_1d_lt_70))
            # 15m high, 1h down move
            & ((aroonu_14_15m_lt_75) | (rsi_3_1h_gt_40))
            # 15m high, 1h & 4h down move
            & ((aroonu_14_15m_lt_75) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_55))
            # 15m uptrend, 1h down move, 4h up move
            & ((aroonu_14_15m_lt_75) | (rsi_3_1h_gt_60) | (roc_9_4h_lt_20))
            # 15m uptrend, 1h down move & uptrend
            & ((aroonu_14_15m_lt_75) | (rsi_3_1h_gt_65) | (aroonu_14_1h_lt_80))
            # 15m uptrend, 4h down move & overbought
            & ((aroonu_14_15m_lt_75) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_80))
            # 15m uptrend, 4h down move & uptrend
            & ((aroonu_14_15m_lt_75) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_90))
            # 15m & 1d high, 4h down move
            & ((aroonu_14_15m_lt_75) | (rsi_3_4h_gt_60) | (stochrsi_k_1d_lt_90))
            # 15m uptrend, 4h down move & up move
            & ((aroonu_14_15m_lt_75) | (rsi_3_4h_gt_65) | (roc_9_4h_lt_5))
            # 15m & 1d high, 15m still high
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1d_lt_70))
            # 15m & 4h high
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_lt_80) | (aroonu_14_4h_lt_100))
            # 15m high, 1d downtrend
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_lt_80) | (roc_9_1d_gt_neg_10))
            # 15m high, 1d still high
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1d_lt_50))
            # 15m & 4h high, 1d overbought
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_30))
            # 15m & 4h high, 1d down move
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_4h_lt_90) | (rsi_3_1d_gt_65))
            # 15m high & still not low enough, 1d still high
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_15m_lt_30) | (aroonu_14_1d_lt_40))
            # 15m still high & down move, 4h down move, 1d uptrend & washed out
            & (
              (stochrsi_k_15m_lt_50)
              | (aroonu_14_1d_lt_90)
              | (stochrsi_k_1d_gt_50)
              | (rsi_3_4h > 80.0)
              | (rsi_3_15m > 80.0)
            )
            # 15m still high & downtrend, 1h up move, 4h down move, 1d up move
            & (
              (stochrsi_k_15m_lt_50) | (roc_9_1d_lt_10) | (aroonu_14_15m_gt_10) | (roc_9_1h < 0.0) | (roc_9_4h > 20.0)
            )
            # 15m still high & downtrend, 4h washed out & up move, 1d up move
            & (
              (stochrsi_k_15m_lt_60)
              | (roc_9_1d_lt_15)
              | (aroonu_14_15m_gt_0)
              | (stochrsi_k_4h > 65.0)
              | (rsi_3_4h_lt_70)
            )
            # 5m down move, 15m washed out, 4h WILLR low
            & ((stochrsi_k_15m_gt_50) | (willr_14_4h > -20.0) | (rsi_3 > 70.0))
            # 15m still not low enough, 4h high, 1d down move
            & ((stochrsi_k_15m_lt_30) | (aroonu_14_4h_lt_100) | (rsi_3_1d_gt_65))
            # 15m still not low enough, 4h overbought, 1d still high
            & ((stochrsi_k_15m_lt_30) | (roc_9_4h_lt_10) | (aroonu_14_1d_lt_50))
            # 15m still not low enough, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_30) | (rsi_3_1h_gt_65) | (aroonu_14_4h_lt_80))
            # 15m still high, 1h & 4h high
            & ((stochrsi_k_15m_lt_40) | (aroonu_14_1h_lt_60) | (stochrsi_k_4h_lt_90))
            # 15m still high, 1h high
            & ((stochrsi_k_15m_lt_40) | (aroonu_14_1h_lt_80) | (stochrsi_k_1h_lt_70))
            # 15m still high, 1h down move & high
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_50) | (aroonu_14_1h_lt_60))
            # 15m still high, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_65) | (aroonu_14_4h_lt_80))
            # 15m still high, 1h down move & high
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_60))
            # 15m & 1h still high, 1d high
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_40) | (stochrsi_k_1d_lt_90))
            # 15m still high, 1h & 1d high
            & ((stochrsi_k_15m_lt_50) | (aroonu_14_1h_lt_70) | (stochrsi_k_1d_lt_90))
            # 15m still high, 4h overbought, 1d high
            & ((stochrsi_k_15m_lt_50) | (roc_9_4h_lt_10) | (stochrsi_k_1d_lt_60))
            # 5m down move & uptrend, 15m still high, 4h up move
            & ((stochrsi_k_15m_lt_50) | (roc_9_4h_lt_5) | (rsi_3 > 60.0) | (aroonu_14 < 80.0))
            # 15m still high, 1h & 4h down move
            & ((stochrsi_k_15m_lt_50) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_40))
            # 15m still high, 1h & 4h down move
            & ((stochrsi_k_15m_lt_50) | (rsi_3_1h_gt_60) | (rsi_3_4h_gt_60))
            # 15m still high, 4h down move & high
            & ((stochrsi_k_15m_lt_50) | (rsi_3_4h_gt_45) | (stochrsi_k_4h_lt_90))
            # 15m still high, 1h still high, 4h overbought, 1d up move
            & ((stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_90) | (rsi_3_1d_lt_95) | (stochrsi_k_1h_lt_70))
            # 15m still high, 4h & 1d high
            & ((stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_90) | (stochrsi_k_1d_lt_90))
            # 15m high, 1d down move & overbought
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1d_gt_55) | (roc_9_1d_lt_0))
            # 15m still high & downtrend, 4h down move
            & ((stochrsi_k_15m_lt_60) | (rsi_3_4h_gt_30) | (aroonu_14_15m_gt_0))
            # 15m high, 1d still not low enough & still high
            & ((stochrsi_k_15m_lt_70) | (aroonu_14_1d_lt_30) | (stochrsi_k_1d_lt_50))
            # 15m & 1h high
            & ((stochrsi_k_15m_lt_70) | (aroonu_14_1h_lt_90) | (stochrsi_k_1h_lt_80))
            # 15m & 4h & 1d high
            & ((stochrsi_k_15m_lt_70) | (aroonu_14_4h_lt_100) | (stochrsi_k_1d_lt_90))
            # 15m high, 1h overbought
            & ((stochrsi_k_15m_lt_70) | (roc_9_1h_lt_10))
            # 15m & 1d high, 4h down move
            & ((stochrsi_k_15m_lt_70) | (rsi_3_4h_gt_65) | (stochrsi_k_1d_lt_80))
            # 15m high, 1h still high, 4h down move
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_40) | (rsi_3_4h_gt_40))
            # 15m & 4h high
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_4h_lt_90) | (stochrsi_k_4h_lt_90))
            # 15m high, 4h overbought, 1d still high
            & ((stochrsi_k_15m_lt_80) | (roc_9_4h_lt_5) | (stochrsi_k_1d_lt_50))
            # 15m overbought, 1d down move & still high
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_70))
            # 15m & 1d high, 1h down move
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_50) | (aroonu_14_1d_lt_75))
            # 15m overbought, 4h down move & up move
            & ((stochrsi_k_15m_lt_80) | (rsi_3_4h_gt_40) | (roc_9_4h_lt_5))
            # 15m & 1d high, 4h down move
            & ((stochrsi_k_15m_lt_80) | (rsi_3_4h_gt_50) | (stochrsi_k_1d_lt_70))
            # 15m overbought, 1h still high, 4h down move
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_20) | (rsi_3_4h_gt_40))
            # 15m & 4h high, 1h still high
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_90))
            # 15m & 1h & 1d high
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_60) | (aroonu_14_1d_lt_75))
            # 15m & 1h high, 4h overbought
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_80) | (roc_9_4h_lt_10))
            # 5m up move, 15m up move, 1h overbought, 1d downtrend & up move
            & ((roc_9_15m < 1.5) | (stochrsi_k_1h_lt_90) | (aroonu_14_1d > 40.0) | (rsi_3_lt_90) | (rsi_3_1d < 45.0))
            # 1h down move, 4h uptrend
            & ((rsi_3_1h_gt_20) | (aroonu_14_4h_lt_100))
            # 1h & 4h down move, 1h still high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50) | (rsi_3_4h_gt_50))
            # 1h down move & uptrend, 4h overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_50) | (stochrsi_k_4h_lt_90))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_60) | (rsi_3_4h_gt_60))
            # 1h down move, 1d downtrend
            & ((rsi_3_1h_gt_40) | (roc_9_1d_gt_neg_10))
            # 1h down move & still not low enough, 1d overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_20) | (roc_9_1d_lt_0))
            # 1h down move, 4h high & overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 1h down move & high, 1d overbought
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_60) | (roc_9_1d_lt_20))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_lt_60) | (stochrsi_k_1d_lt_90))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_80) | (aroonu_14_1d_lt_75))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_70) | (rsi_3_1d_gt_65))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_90))
            # 1h down move & uptrend, 1d down move
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_70) | (rsi_3_1d_gt_60))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_70) | (stochrsi_k_1d_lt_90))
            # 1h down move, 4h overbought, 1d still high
            & ((rsi_3_1h_gt_60) | (roc_9_4h_lt_10) | (aroonu_14_1d_lt_40))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_60))
            # 1h & 4h down move, 4h high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_80))
            # 1h down move, 1h & 4h high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_60) | (aroonu_14_4h_lt_100))
            # 1h down move, 1d high & overbought
            & ((rsi_3_1h_gt_65) | (aroonu_14_1d_lt_75) | (roc_9_1d_lt_0))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_65) | (rsi_3_1d_gt_65) | (aroonu_14_1d_lt_50))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_65) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_60))
            # 1h down move & still high, 1d overbought
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_40) | (roc_9_1d_lt_60))
            # 1h down move & still high, 4h high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_80))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_60) | (rsi_3_1d_gt_40))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_80))
            # 5m overbought, 15m downtrend, 1h uptrend & up move, 4h overbought
            & (
              (aroonu_14_1h_lt_80)
              | (stochrsi_k_4h_lt_90)
              | (aroonu_14_15m > 15.0)
              | (rsi_3_1h_lt_65)
              | (stochrsi_k < 85.0)
            )
            # 5m overbought, 15m washed out, 1h uptrend & down move, 1d down move
            & (
              (aroonu_14_1h_lt_90) | (rsi_3_1d_gt_55) | (stochrsi_k < 95.0) | (roc_9_1h > 5.0) | (stochrsi_k_15m_gt_30)
            )
            # 1h still high, 4h high, 1d downtrend
            & ((aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_80) | (roc_9_1d_gt_0))
            # 1h uptrend, 4h down move, 1d overbought
            & ((aroonu_14_1h_lt_50) | (rsi_3_4h_gt_60) | (stochrsi_k_1d_lt_80))
            # 1h still high, 4h down move, 1d overbought
            & ((aroonu_14_1h_lt_50) | (rsi_3_4h_gt_65) | (roc_9_1d_lt_40))
            # 1h & 4h high, 1h still high
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_90))
            # 1h & 4h & 1d high
            & ((aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_100) | (stochrsi_k_1d_lt_90))
            # 1h high, 1d down move & still not low enough
            & ((aroonu_14_1h_lt_70) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_30))
            # 5m up move, 1h uptrend & down move, 4h overbought & down move
            & ((aroonu_14_1h_lt_75) | (stochrsi_k_4h_lt_90) | (rsi_3_4h > 85.0) | (rsi_3_1h > 75.0) | (rsi_3 < 80.0))
            # 1h high, 1h & 4h overbought
            & ((aroonu_14_1h_lt_80) | (roc_9_1h_lt_15) | (roc_9_4h_lt_15))
            # 1h & 1d high, 1h still not low enough
            & ((aroonu_14_1h_lt_80) | (stochrsi_k_1h_lt_20) | (stochrsi_k_1d_lt_60))
            # 1h high, 1d overbought
            & ((aroonu_14_1h_lt_80) | (stochrsi_k_1h_lt_60) | (roc_9_1d_lt_10))
            # 5m washed out, 15m up move, 1h still high, 4h down move, 1d uptrend
            & (
              (stochrsi_k_1h_lt_40)
              | (aroonu_14_1d_lt_90)
              | (rsi_3_15m_lt_90)
              | (stochrsi_k > 95.0)
              | (rsi_3_4h > 95.0)
            )
            # 15m still high, 1h still high & downtrend, 4h uptrend, 1d up move
            & (
              (stochrsi_k_1h_lt_40)
              | (roc_9_1d_lt_0)
              | (aroonu_14_1h_gt_40)
              | (aroonu_14_4h_lt_90)
              | (stochrsi_k_15m < 65.0)
            )
            # 5m overbought, 1h still high & up move, 4h overbought & down move
            & (
              (stochrsi_k_1h_lt_50)
              | (stochrsi_k_4h_lt_90)
              | (rsi_3_4h > 85.0)
              | (stochrsi_k < 90.0)
              | (rsi_3_1h_lt_60)
            )
            # 15m downtrend, 1h overbought & up move, 1d up move & washed out
            & (
              (stochrsi_k_1h_lt_80)
              | (roc_9_1d_lt_0)
              | (aroonu_14_15m_gt_30)
              | (stochrsi_k_1d > 90.0)
              | (rsi_3_1h_lt_75)
            )
            # 5m up move, 1h overbought, 4h washed out, 1d up move & downtrend
            & (
              (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_0) | (aroonu_14_1d > 40.0) | (rsi_3_lt_90) | (stochrsi_k_4h > 95.0)
            )
            # 1h & 1d still high, 1d down move
            & ((stochrsi_k_1h_lt_40) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_50))
            # 1h still high, 4h down move & high
            & ((stochrsi_k_1h_lt_40) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_80))
            # 1h still high, 4h & 1d high
            & ((stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_90) | (aroonu_14_1d_lt_75))
            # 1h still high, 4h high, 1d downtrend
            & ((stochrsi_k_1h_lt_50) | (aroonu_14_4h_lt_80) | (roc_9_1d_gt_0))
            # 1h high, 1d downtrend
            & ((stochrsi_k_1h_lt_80) | (roc_9_1d_gt_neg_10))
            # 1h overbought, 4h up move, 1d down move
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_lt_10) | (rsi_3_1d_gt_50))
            # 1h high, 4h down move
            & ((stochrsi_k_1h_lt_80) | (rsi_3_4h_gt_65))
            # 1h & 4h high, 1d down move
            & ((stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_90) | (rsi_3_1d_gt_40))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_75))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_50) | (aroonu_14_4h_lt_90) | (stochrsi_k_1d_lt_70))
            # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_60) | (aroonu_14_4h_lt_100) | (stochrsi_k_1d_lt_90))
            # 4h & 1d down move, 1d overbought
            & ((rsi_3_4h_gt_60) | (rsi_3_1d_gt_60) | (roc_9_1d_lt_10))
            # 4h down move & overbought
            & ((rsi_3_4h_gt_65) | (roc_9_4h_lt_15))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_65) | (stochrsi_k_1d_lt_60) | (roc_9_1d_lt_0))
            # 4h high, 1d down move & overbought
            & ((aroonu_14_4h_lt_75) | (rsi_3_1d_gt_65) | (roc_9_1d_lt_0))
            # 4h & 1d high, 1d overbought
            & ((aroonu_14_4h_lt_80) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_0))
            # 15m downtrend, 4h overbought & up move, 1d uptrend & still high
            & (
              (stochrsi_k_4h_lt_90)
              | (aroonu_14_1d_lt_30)
              | (aroonu_14_15m > 15.0)
              | (stochrsi_k_1d_lt_70)
              | (rsi_3_4h_lt_80)
            )
            # 15m downtrend & washed out, 4h overbought, 1d still high & up move
            & (
              (stochrsi_k_4h_lt_90)
              | (stochrsi_k_1d_lt_70)
              | (aroonu_14_15m > 15.0)
              | (rsi_3_1d < 70.0)
              | (stochrsi_k_15m > 55.0)
            )
            # 5m overbought, 15m down move, 4h overbought, 1d overbought & downtrend
            & (
              (stochrsi_k_4h_lt_90)
              | (stochrsi_k_1d_lt_80)
              | (aroonu_14_1d_gt_50)
              | (rsi_3_15m > 70.0)
              | (stochrsi_k < 90.0)
            )
            # 4h & 1d high, 1d down move
            & ((stochrsi_k_4h_lt_80) | (rsi_3_1d_gt_60) | (stochrsi_k_1d_lt_80))
            # 4h overbought, 1d down move & still high
            & ((stochrsi_k_4h_lt_90) | (rsi_3_1d_gt_50) | (stochrsi_k_1d_lt_60))
            # 4h overbought, 1d down move & overbought
            & ((stochrsi_k_4h_lt_90) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_80))
            # 5m overbought, 15m down move & uptrend, 4h down move, 1d uptrend
            & (
              (roc_9_4h > 5.0)
              | (aroonu_14_1d_lt_90)
              | (rsi_3_15m > 65.0)
              | (stochrsi_k < 85.0)
              | (aroonu_14_15m < 45.0)
            )
            # 15m up move, 1h overbought, 4h down move, 1d up move & down move
            & ((roc_9_4h > 10.0) | (roc_9_1d_lt_0) | (rsi_3_1d_gt_45) | (stochrsi_k_1h < 85.0) | (rsi_3_15m_lt_70))
            # 4h down move, 1d uptrend & overbought
            & ((roc_9_4h > 5.0) | (aroonu_14_1d_lt_90) | (rsi_3_4h_gt_55) | (stochrsi_k_1d < 95.0))
            # 5m down move, 15m up move, 1h up move, 4h up move, 1d up move
            & ((roc_9_4h_lt_10) | (roc_9_1d_lt_30) | (rsi_3 > 80.0) | (roc_9_1h_lt_10) | (rsi_3_15m_lt_70))
            # 4h overbought, 1d downtrend
            & ((roc_9_4h_lt_20) | (roc_9_1d_gt_neg_10))
            # 4h overbought, 1d down move
            & ((roc_9_4h_lt_20) | (rsi_3_1d_gt_50))
            # 1d down move & high
            & ((rsi_3_1d_gt_60) | (stochrsi_k_1d_lt_90))
            # 4h washed out & down move, 1d uptrend & overbought & up move
            & (
              (aroonu_14_1d_lt_90)
              | (stochrsi_k_1d_lt_80)
              | (stochrsi_k_4h > 65.0)
              | (roc_9_4h > 10.0)
              | (rsi_3_1d < 85.0)
            )
            # 15m still high, 1h up move, 4h down move, 1d uptrend & overbought
            & (
              (aroonu_14_1d_lt_90)
              | (stochrsi_k_1d_lt_90)
              | (stochrsi_k_15m_lt_60)
              | (rsi_3_1h_lt_65)
              | (rsi_3_4h > 95.0)
            )
            # 1h up move, 4h down move, 1d uptrend & still high & up move
            & ((aroonu_14_1d_lt_90) | (stochrsi_k_1d_lt_70) | (roc_9_4h > 5.0) | (rsi_3_1h_lt_75) | (roc_9_1d_lt_15))
            # 1d high & downtrend
            & ((stochrsi_k_1d_lt_60) | (roc_9_1d_gt_neg_10))
            # 15m up move, 1h up move, 1d overbought & up move
            & ((stochrsi_k_1d_lt_90) | (roc_9_1d_lt_15) | (rsi_3_15m_lt_90) | (rsi_3_1h_lt_65))
            # 5m pre-entry tightness low & down move, 15m washed out, 1h AROOND high, 4h downtrend
            & (
              (ph_pre_tight > 1.0)
              | (aroond_14_1h_lt_25)
              | (aroonu_14_4h > 65.0)
              | (stochrsi_k_15m_gt_30)
              | (rsi_3 > 90.0)
            )
          )

          # Logic
          long_entry_logic.append(
            # trend side (source: trade only WITH the trend)
            (close > ema_200)
            # 4h must participate in the breakout (fresh 4h upswing, not a stale drift)
            & (aroonu_14_4h > 50.0)
            & (stochrsi_k_4h > 55.0)
            # last completed 1h candle was an inside bar; this 5m candle CROSSES above the mother high
            & (ib_ready > 0.5)
            & (np_shift(close, 1) <= ib_mother_h)
            & (close > ib_mother_h)
            # the daily has lifted off its floor — a breakout into a dead daily is a fake one
            & (stochrsi_k_1d > 30.0)
          )

        # Condition #170 - Crash-bounce hunter (Long, experimental — capitulation relief rally).
        if long_entry_condition_index == 170:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            # 5m money still flowing in, 15m momentum snapping up, 1h momentum collapsing and 4h cycle falling
            (
              (cmf_20 < -0.1)
              | (rsi_3_change_pct_15m < 70)
              | (rsi_3_change_pct_1h > -60)
              | (cci_20_change_pct_4h > 0.0)
            )
            # 5m money flowing in, 1h momentum snapping up, 4h cycle falling and daily money drained
            & ((cmf_20 < -0.1) | (rsi_3_change_pct_1h < 80) | (cci_20_change_pct_4h > 0.0) | (mfi_14_1d > 30))
            # 5m still not low enough, 1h still high, 4h high
            & ((aroonu_14_lt_25) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_60))
            # 5m still not low enough, 15m down move, 4h downtrend
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_10) | (roc_9_4h_gt_neg_25))
            # 5m & 15m still not low enough, 1d down move
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_10) | (rsi_3_1d_gt_5))
            # 5m still not low enough, 1h & 1d down move
            & ((stochrsi_k_lt_30) | (rsi_3_1h_gt_5) | (rsi_3_1d_gt_5))
            # 15m down move & still not low enough, 4h downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_20) | (roc_9_4h_gt_neg_20))
            # 15m down move, 1h still not low enough, 4h still high
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_20) | (aroonu_14_4h_lt_50))
            # 15m down move, 1h still not low enough, 1d downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_20) | (roc_9_1d_gt_neg_30))
            # 15m & 4h down move, 1h still not low enough
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_25) | (rsi_3_4h_gt_3))
            # 15m down move, 1h & 1d still not low enough
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_25) | (stochrsi_k_1d_lt_30))
            # 15m down move, 1h still high & downtrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_40) | (roc_9_1h_gt_neg_20))
            # 15m down move, 15m & 1h still not low enough
            & ((rsi_3_15m_gt_10) | (stochrsi_k_15m_lt_20) | (aroonu_14_1h_lt_30))
            # 15m down move, 1h still not low enough, 1d downtrend
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_lt_30) | (roc_9_1d_gt_neg_30))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_40) | (rsi_3_1d_gt_5))
            # 15m down move, 1h still high, 4h still not low enough
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_40) | (stochrsi_k_4h_lt_30))
            # 15m down move, 15m & 1d still not low enough
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_20) | (stochrsi_k_1d_lt_20))
            # 15m down move, 15m & 1h still not low enough
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_30))
            # 15m down move & still high, 1h still not low enough
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_20))
            # 15m down move & still high, 1d downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_50) | (roc_9_1d_gt_neg_40))
            # 15m down move & still high, 4h downtrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_50) | (roc_9_4h_gt_neg_15))
            # 15m & 1d down move, 15m still high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_50) | (rsi_3_1d_gt_10))
            # 15m down move, 1h & 4h still high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_50) | (aroonu_14_4h_lt_40))
            # 15m down move, 1h high, 4h still not low enough
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_60) | (aroonu_14_4h_lt_30))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_40) | (rsi_3_1h_gt_10))
            # 15m down move & still not low enough, 1h down move
            & ((rsi_3_15m_gt_30) | (stochrsi_k_15m_lt_30) | (rsi_3_1h_gt_5))
            # 15m down move & still high, 1d downtrend
            & ((rsi_3_15m_gt_30) | (stochrsi_k_15m_lt_40) | (roc_9_1d_gt_neg_60))
            # 15m down move & still not low enough, 4h downtrend
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_20) | (roc_9_4h_gt_neg_35))
            # 15m down move & still not low enough, 4h high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_30) | (aroonu_14_4h_lt_30))
            # 15m down move & still high, 1h still not low enough
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_40) | (aroonu_14_1h_lt_20))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_40) | (rsi_3_4h_gt_3))
            # 15m money leaving, 1d washed out
            & ((cmf_20_15m < 0.1) | (rsi_14_1d > 25.0))
            # 15m still not low enough & high, 1h still high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_40))
            # 15m & 1h still not low enough, 1d down move
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_lt_30) | (rsi_3_1d_gt_5))
            # 15m still not low enough, 1h still high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_lt_50))
            # 15m & 4h & 1d still not low enough
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_4h_lt_30) | (stochrsi_k_1d_lt_20))
            # 15m still not low enough, 1h down move, 4h still high
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_40))
            # 15m still not low enough, 1h down move, 1d downtrend
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_10) | (roc_9_1d_gt_neg_30))
            # 15m still not low enough & high, 1h down move
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_20))
            # 15m & 4h still not low enough, 1d still high
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_4h_lt_20) | (aroonu_14_1d_lt_40))
            # 15m still high, 1h down move, 1d downtrend
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m still high, 15m & 1h still not low enough
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_30))
            # 15m & 1d high
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_15m_lt_80) | (aroonu_14_1d_lt_60))
            # 15m no recent low, 15m momentum alive and daily no recent low
            & ((aroond_14_15m > 30) | (rsi_3_15m < 5) | (aroond_14_1d > 55))
            # 15m stochastic high, 1h momentum collapsing, 4h a trend established and daily high in its range
            & ((stochrsi_k_15m < 5) | (rsi_3_change_pct_1h > -60) | (adx_14_4h < 40) | (willr_14_1d < -90))
            # 15m & 1h still not low enough, 1d high
            & ((stochrsi_k_15m_lt_20) | (aroonu_14_1h_lt_30) | (aroonu_14_1d_lt_60))
            # 15m still not low enough, 1h still high, 4h high
            & ((stochrsi_k_15m_lt_20) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_60))
            # 15m still not low enough, 4h down move & still high
            & ((stochrsi_k_15m_lt_20) | (rsi_3_4h_gt_3) | (aroonu_14_4h_lt_40))
            # 15m & 1d still not low enough, 1d downtrend
            & ((stochrsi_k_15m_lt_20) | (stochrsi_k_1d_lt_20) | (roc_9_1d_gt_neg_25))
            # 15m & 1h still not low enough, 4h downtrend
            & ((stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_20) | (roc_9_4h_gt_neg_25))
            # 15m & 1h still not low enough, 4h down move
            & ((stochrsi_k_15m_lt_30) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_5))
            # 15m still high, 1h & 4h still not low enough
            & ((stochrsi_k_15m_lt_40) | (aroonu_14_1h_lt_25) | (aroonu_14_4h_lt_30))
            # 15m & 4h still high, 1d downtrend
            & ((stochrsi_k_15m_lt_40) | (aroonu_14_4h_lt_40) | (roc_9_1d_gt_neg_60))
            # 15m still high, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_5) | (stochrsi_k_4h_lt_70))
            # 15m & 1h still high, 1h downtrend
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_1h_lt_50) | (roc_9_1h_gt_neg_10))
            # 15m high, 1h & 4h still not low enough
            & ((stochrsi_k_15m_lt_60) | (aroonu_14_1h_lt_20) | (aroonu_14_4h_lt_20))
            # 15m high, 1h down move, 4h downtrend
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_10) | (roc_9_4h_gt_neg_15))
            # 15m high, 1h down move, 1d still high
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_15) | (aroonu_14_1d_lt_40))
            # 15m high, 1h down move & still not low enough
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_5) | (stochrsi_k_1h_lt_30))
            # 15m still not low enough, 1h down move, 1d not collapsing
            & ((stochrsi_k_15m_lt_70) | (rsi_3_1h_gt_15) | (roc_9_1d_gt_neg_25))
            # 15m high, 1h down move, 4h still not low enough
            & ((stochrsi_k_15m_lt_70) | (rsi_3_1h_gt_5) | (stochrsi_k_4h_lt_30))
            # 15m high, 4h still not low enough, 1d downtrend
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_4h_lt_20) | (roc_9_1d_gt_neg_40))
            # 15m & 1d high, 4h down move
            & ((stochrsi_k_15m_lt_80) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_60))
            # 15m stochastic at the floor, 1h stochastic high, 4h money flowing in and 4h momentum falling
            & ((stochk_14_3_3_15m > 15) | (stochrsi_k_1h < 5) | (mfi_14_4h < 25) | (rsi_14_change_pct_4h > -15))
            # 1h down move, 1h & 1d downtrend
            & ((rsi_3_1h_gt_10) | (roc_9_1h_gt_neg_15) | (roc_9_1d_gt_neg_60))
            # 1h & 1d down move, 1d still high
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_5) | (aroonu_14_1d_lt_40))
            # 1h down move, 1h & 4h still not low enough
            & ((rsi_3_1h_gt_10) | (stochrsi_k_1h_lt_30) | (stochrsi_k_4h_lt_10))
            # 1h down move, 4h still not low enough, 1d downtrend
            & ((rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_10) | (roc_9_1d_gt_neg_40))
            # 1h down move, 1d still not low enough & downtrend
            & ((rsi_3_1h_gt_15) | (stochrsi_k_1d_lt_20) | (roc_9_1d_gt_neg_30))
            # 1h down move & still high, 4h downtrend
            & ((rsi_3_1h_gt_15) | (stochrsi_k_1h_lt_40) | (roc_9_4h_gt_neg_35))
            # 1h & 1d down move, 1h still not low enough
            & ((rsi_3_1h_gt_5) | (aroonu_14_1h_lt_20) | (rsi_3_1d_gt_5))
            # 1h & 1d down move, 4h still not low enough
            & ((rsi_3_1h_gt_5) | (aroonu_14_4h_lt_30) | (rsi_3_1d_gt_5))
            # 1h money leaving, 4h up move, 1d low
            & ((cmf_20_1h > -0.3) | (rsi_3_4h < 5.0) | (stochrsi_k_1d < 25.0))
            # 1h money leaving, 1h money flowing in and 4h falling
            & ((cmf_20_1h > 0.02) | (mfi_14_1h < 40) | (roc_2_4h > -14))
            # 1h still not low enough, 1d down move
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_1h_lt_20) | (rsi_3_1d_gt_5))
            # 1h still not low enough, 1d high
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_1h_lt_30) | (aroonu_14_1d_lt_60))
            # 1h & 4h still not low enough
            & ((aroonu_14_1h_lt_25) | (stochrsi_k_1h_lt_20) | (aroonu_14_4h_lt_20))
            # 1h still high & downtrend, 4h down move
            & ((stochrsi_k_1h_lt_40) | (roc_9_1h_gt_neg_10) | (rsi_3_4h_gt_5))
            # 1h still high, 4h & 1d downtrend
            & ((stochrsi_k_1h_lt_40) | (roc_9_4h_gt_neg_15) | (roc_9_1d_gt_neg_70))
            # 1h still high, 4h down move, 1d high
            & ((stochrsi_k_1h_lt_40) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_70))
            # 4h momentum alive, daily no recent low and daily money drained
            & ((rsi_3_4h < 5) | (aroond_14_1d > 55) | (mfi_14_1d > 45))
            # 4h down move & still high, 1d high
            & ((rsi_3_4h_gt_3) | (aroonu_14_4h_lt_40) | (aroonu_14_1d_lt_60))
            # 4h a new high, 4h momentum falling, 4h momentum alive and daily money drained
            & ((aroonu_14_4h < 5) | (rsi_14_change_pct_4h > -15) | (rsi_3_4h < 5) | (mfi_14_1d > 30))
            # 4h & 1d still not low enough, 4h downtrend
            & ((stochrsi_k_4h_lt_10) | (roc_9_4h_gt_neg_15) | (stochrsi_k_1d_lt_30))
            # 4h & 1d still not low enough, 1d downtrend
            & ((stochrsi_k_4h_lt_10) | (stochrsi_k_1d_lt_20) | (roc_9_1d_gt_neg_30))
            # 4h & 1d still high, 1d downtrend
            & ((stochrsi_k_4h_lt_40) | (aroonu_14_1d_lt_50) | (roc_9_1d_gt_neg_50))
            # 4h a trend established, 4h a new high, 4h money flowing in and daily high in its range
            & ((adx_14_4h < 40) | (aroonu_14_4h < 5) | (mfi_14_4h < 25) | (willr_14_1d < -90))
            # 15m momentum snapping up, 15m stochastic at the floor and 1h money drained
            & ((rsi_3_change_pct_15m < 70) | (stochk_14_3_3_15m > 15) | (mfi_14_1h > 5))
            # 1h momentum collapsing, 4h momentum falling and daily range_pct_14 >= 25.0
            & ((rsi_3_change_pct_1h > -50) | (rsi_14_change_pct_4h > -15) | (range_pct_14_1d < 25))
          )

          # Logic
          long_entry_logic.append(
            # capitulation context: crashed hard over the rolling 24h, daily fully washed
            (roc_288 < -15.0)
            # ...but not a free-fall (deeper than -30 keeps falling)
            & (roc_288 > -30.0)
            & (rsi_3_1d < 15.0)
            # fresh bounce only — 1h still deeply down; a half-recovered 1h means we are late
            # (losses entered the SECOND leg / dead-cat top)
            & (roc_9_1h < -5.0)
            # real buyers on the reclaim candle: ~1.3x+ its 24h average volume
            & (vol_rel > 1.3)
            # still near the bottom (not already rallied away)
            & (close < (close_min_48 * 1.08))
            # the right side of the V: FIRST confirmed green close above the prior candle's high
            & (close > open_rate)
            & (close > np_shift(high_px, 1))
          )

        # Condition #171 - Pump hunter (Long, experimental, RAW — ignition candle rider).
        if long_entry_condition_index == 171:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            # 15m & 1h down move, 15m high
            ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_60) | (rsi_3_1h_gt_30))
            # 15m & 1h down move, 4h still high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_60) | (aroonu_14_4h_lt_50))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_80) | (rsi_3_1h_gt_65))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_80) | (stochrsi_k_1h_lt_80))
            # 15m & 1h down move, 1h still not low enough
            & ((rsi_3_15m_gt_50) | (aroonu_14_1h_lt_20) | (rsi_3_1h_gt_50))
            # 15m & 4h & 1d down move
            & ((rsi_3_15m_gt_50) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_30))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_50) | (rsi_3_1h_gt_30))
            # 15m down move, 15m & 1d high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_60) | (stochrsi_k_1d_lt_80))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_1h_lt_60) | (rsi_3_4h_gt_30))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_gt_40) | (aroonu_14_4h_lt_80))
            # 15m & 1h down move, 15m high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_40))
            # 15m down move & high, 1h still high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_40))
            # 15m still not low enough, 4h still high, 1d down move
            & ((aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_40) | (rsi_3_1d_gt_65))
            # 15m & 4h still not low enough, 1h down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_10))
            # 15m still not low enough, 1h down move & still high
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_65) | (aroonu_14_1h_lt_40))
            # 15m & 4h still not low enough, 4h down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_20))
            # 15m still not low enough & still high, 1h high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_80))
            # 15m still not low enough & high, 1h down move
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_40))
            # 15m still high, 1h & 1d down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_50) | (rsi_3_1d_gt_10))
            # 15m still high, 15m & 4h high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_lt_70) | (stochrsi_k_4h_lt_80))
            # 15m high, 4h & 1d still not low enough
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_4h_lt_30) | (aroonu_14_1d_lt_30))
            # 15m high, 1h still high
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_50))
            # 15m high, 1d still not low enough & downtrend
            & ((aroonu_14_15m_lt_80) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_20))
            # 15m high, 1h still not low enough, 1d down move
            & ((aroonu_14_15m_lt_80) | (aroonu_14_1h_lt_30) | (rsi_3_1d_gt_30))
            # 15m high, 4h downtrend, 1d down move
            & ((aroonu_14_15m_lt_80) | (roc_9_4h_gt_neg_10) | (rsi_3_1d_gt_10))
            # 15m & 1d high, 1d down move
            & ((aroonu_14_15m_lt_80) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_80))
            # 15m high, 1d down move & still high
            & ((aroonu_14_15m_lt_80) | (rsi_3_1d_gt_50) | (stochrsi_k_1d_lt_40))
            # 15m high, 1h & 4h down move
            & ((aroonu_14_15m_lt_80) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_10))
            # 15m high, 1h down move, 4h still high
            & ((aroonu_14_15m_lt_80) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_50))
            # 15m high, 1h down move, 1d downtrend
            & ((aroonu_14_15m_lt_80) | (rsi_3_1h_gt_30) | (roc_9_1d_gt_neg_30))
            # 15m high, 1h down move, 1d overbought
            & ((aroonu_14_15m_lt_80) | (rsi_3_1h_gt_65) | (roc_9_1d_lt_15))
            # 15m high, 1h & 1d down move
            & ((aroonu_14_15m_lt_80) | (rsi_3_1h_gt_65) | (rsi_3_1d_gt_10))
            # 15m & 4h high, 4h down move
            & ((aroonu_14_15m_lt_80) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_70))
            # 15m high, 1h down move
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_60))
            # 15m high, 4h down move
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_15m_lt_80) | (rsi_3_4h_gt_20))
            # 15m high, 1h still high, 4h down move
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_1h_lt_50) | (rsi_3_4h_gt_50))
            # 15m & 1h high, 4h downtrend
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_1h_lt_80) | (roc_9_4h_gt_neg_15))
            # 15m & 1h high, 4h still not low enough
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_1h_lt_90) | (stochrsi_k_4h_lt_10))
            # 15m high, 4h still not low enough & downtrend
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_4h_lt_20) | (roc_9_4h_gt_neg_10))
            # 15m high, 4h still high, 1d down move
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_4h_lt_50) | (rsi_3_1d_gt_20))
            # both the 15m and the 4h pinned at a new high: nothing left above
            & ((aroonu_14_15m_lt_90) | (aroonu_14_4h_lt_90))
            # 15m still high, 1h & 4h down move
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_50))
            # 15m still high, 1h down move, 4h downtrend
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_60) | (roc_9_4h_gt_neg_15))
            # 15m still high, 1d still not low enough & downtrend
            & ((stochrsi_k_15m_lt_50) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_10))
            # 15m still high, 1h & 1d high
            & ((stochrsi_k_15m_lt_50) | (aroonu_14_1h_lt_90) | (stochrsi_k_1d_lt_60))
            # 15m still high, 4h still not low enough, 1d down move
            & ((stochrsi_k_15m_lt_50) | (aroonu_14_4h_lt_30) | (rsi_3_1d_gt_30))
            # 15m still high, 1d down move & high
            & ((stochrsi_k_15m_lt_50) | (rsi_3_1d_gt_60) | (stochrsi_k_1d_lt_60))
            # 15m still high, 1h down move & high
            & ((stochrsi_k_15m_lt_50) | (rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_60))
            # 15m still high, 1h high, 1d down move
            & ((stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_70) | (rsi_3_1d_gt_40))
            # 15m still high, 1h high, 1d overbought
            & ((stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_30))
            # 15m high, 4h still high, 1d down move
            & ((stochrsi_k_15m_lt_60) | (aroonu_14_4h_lt_40) | (rsi_3_1d_gt_50))
            # 15m high, 1d down move & overbought
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1d_gt_50) | (roc_9_1d_lt_20))
            # 15m & 1d high, 1d down move
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_80))
            # 15m high, 1h down move & still not low enough
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_lt_30))
            # 15m high, 1h down move & still high
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_40))
            # 15m high, 1h down move & still not low enough
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_20))
            # 15m & 1h & 1d high
            & ((stochrsi_k_15m_lt_60) | (stochrsi_k_1h_lt_80) | (stochrsi_k_1d_lt_80))
            # 15m & 1h & 1d high
            & ((stochrsi_k_15m_lt_70) | (aroonu_14_1h_lt_70) | (stochrsi_k_1d_lt_60))
            # 15m & 1h high, 4h still not low enough
            & ((stochrsi_k_15m_lt_70) | (aroonu_14_1h_lt_90) | (stochrsi_k_4h_lt_30))
            # 15m high, 1d down move & still not low enough
            & ((stochrsi_k_15m_lt_70) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_30))
            # 15m high, 1h down move, 1d downtrend
            & ((stochrsi_k_15m_lt_70) | (rsi_3_1h_gt_40) | (roc_9_1d_gt_neg_15))
            # 15m & 1h high, 1h down move
            & ((stochrsi_k_15m_lt_70) | (rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_70))
            # 15m high, 4h down move, 1d still not low enough
            & ((stochrsi_k_15m_lt_70) | (rsi_3_4h_gt_40) | (stochrsi_k_1d_lt_20))
            # 15m & 1d high, 1h still not low enough
            & ((stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_30) | (stochrsi_k_1d_lt_60))
            # 15m & 1h high, 4h down move
            & ((stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_70) | (rsi_3_4h_gt_40))
            # 15m & 1h & 1d high
            & ((stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_80) | (aroonu_14_1d_lt_80))
            # 15m high, 1d down move & still high
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_1d_lt_40) | (rsi_3_1d_gt_30))
            # 15m high, 1h still not low enough, 1d overbought
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_20) | (roc_9_1d_lt_15))
            # 15m & 1d high, 1h still not low enough
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_30) | (aroonu_14_1d_lt_80))
            # 15m & 1d high, 1h still high
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_50) | (stochrsi_k_1d_lt_60))
            # 15m high, 4h still not low enough
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_4h_lt_20) | (stochrsi_k_4h_lt_10))
            # 15m high, 1d down move & downtrend
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1d_gt_10) | (roc_9_1d_gt_neg_25))
            # 15m high, 1d down move & still not low enough
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_lt_30))
            # 15m high, 1h down move & still not low enough
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_30))
            # 15m & 1d high, 1h down move
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_60) | (stochrsi_k_1d_lt_80))
            # 15m high, 1h down move, 4h still not low enough
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_30))
            # 15m high, 4h down move & still not low enough
            & ((stochrsi_k_15m_lt_80) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_lt_20))
            # 15m high, 1h & 4h still high
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_40) | (aroonu_14_4h_lt_40))
            # 15m & 1h high, 1d down move
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_60) | (rsi_3_1d_gt_20))
            # 15m & 1h high, 1d overbought
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_70) | (roc_9_1d_lt_0))
            # 15m & 1h high, 4h still not low enough
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_80) | (aroonu_14_4h_lt_30))
            # 15m & 1h high, 4h down move
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_80) | (rsi_3_4h_gt_60))
            # 15m high, 4h still not low enough, 1d overbought
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_4h_lt_10) | (roc_9_1d_lt_40))
            # 15m high, 4h & 1d still not low enough
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_4h_lt_10) | (stochrsi_k_1d_lt_20))
            # 15m high, 4h still not low enough, 1d down move
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_4h_lt_20) | (rsi_3_1d_gt_30))
            # 15m high, 4h still high, 1d down move
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_4h_lt_40) | (rsi_3_1d_gt_60))
            # 1h & 1d down move, 1h still not low enough
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_20) | (rsi_3_1d_gt_60))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_20))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_30) | (rsi_3_1d_gt_60) | (stochrsi_k_1d_lt_80))
            # 1h & 1d down move, 4h still not low enough
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_lt_10) | (rsi_3_1d_gt_30))
            # 1h & 1d down move, 4h downtrend
            & ((rsi_3_1h_gt_40) | (roc_9_4h_gt_neg_15) | (rsi_3_1d_gt_65))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_40) | (rsi_3_1d_gt_50) | (stochrsi_k_1d_lt_60))
            # 1h down move & high, 1d still high
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_60) | (aroonu_14_1d_lt_50))
            # 1h & 1d down move, 4h still not low enough
            & ((rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_30) | (rsi_3_1d_gt_20))
            # 1h down move, 1h & 4h still high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_40))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_60) | (aroonu_14_1d_lt_60))
            # 1h down move, 4h still not low enough, 1d high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_20) | (stochrsi_k_1d_lt_60))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_50) | (stochrsi_k_1d_lt_80))
            # 1h down move & still high, 1d overbought
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_40) | (roc_9_1d_lt_10))
            # 1h down move, 1h & 1d still high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_40) | (stochrsi_k_1d_lt_40))
            # 1h down move & high, 4h still not low enough
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_60) | (stochrsi_k_4h_lt_30))
            # 1h & 1d down move, 1h still not low enough
            & ((rsi_3_1h_gt_65) | (aroonu_14_1h_lt_20) | (rsi_3_1d_gt_30))
            # 1h down move & high, 4h still not low enough
            & ((rsi_3_1h_gt_65) | (aroonu_14_1h_lt_75) | (stochrsi_k_4h_lt_20))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_65) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_10))
            # 1h down move & high, 1d overbought
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_60) | (roc_9_1d_lt_0))
            # 1h down move & high, 1d still high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_80) | (stochrsi_k_1d_lt_40))
            # 1h down move, 4h still not low enough, 1d high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_30) | (stochrsi_k_1d_lt_80))
            # 1h down move, 4h still high, 1d overbought
            & ((rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_40) | (roc_9_1d_lt_0))
            # 1h money inflow
            & (mfi_14_1h < 65.0)
            # 1h still not low enough, 1h & 1d high
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_1h_lt_80) | (stochrsi_k_1d_lt_80))
            # 1h still not low enough, 4h still high, 1d overbought
            & ((aroonu_14_1h_lt_25) | (aroonu_14_4h_lt_50) | (roc_9_1d_lt_70))
            # 1h still not low enough, 1d down move & high
            & ((aroonu_14_1h_lt_25) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_60))
            # 1h still not low enough, 4h & 1d down move
            & ((aroonu_14_1h_lt_25) | (rsi_3_4h_gt_50) | (rsi_3_1d_gt_20))
            # 1h still not low enough & still high, 4h down move
            & ((aroonu_14_1h_lt_25) | (stochrsi_k_1h_lt_40) | (rsi_3_4h_gt_30))
            # 1h still not low enough, 4h still high
            & ((aroonu_14_1h_lt_30) | (stochrsi_k_1h_lt_30) | (aroonu_14_4h_lt_50))
            # 1h & 4h still high, 1h still not low enough
            & ((aroonu_14_1h_lt_40) | (stochrsi_k_1h_lt_30) | (stochrsi_k_4h_lt_50))
            # 1h still high, 4h down move, 1d downtrend
            & ((aroonu_14_1h_lt_50) | (rsi_3_4h_gt_40) | (roc_9_1d_gt_neg_10))
            # 1h still high, 4h down move & still not low enough
            & ((aroonu_14_1h_lt_50) | (rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_30))
            # the hour making new highs while the daily oscillator is already at its ceiling
            & ((aroonu_14_1h_lt_50) | (stochrsi_k_1d_lt_80))
            # the hour making new highs while the daily has not moved up with it
            & ((aroonu_14_1h_lt_60) | (rsi_3_1d_gt_40))
            # 1h & 1d high, 4h still high
            & ((aroonu_14_1h_lt_75) | (aroonu_14_4h_lt_40) | (stochrsi_k_1d_lt_60))
            # 1h high, 1d still not low enough & downtrend
            & ((aroonu_14_1h_lt_75) | (stochrsi_k_1d_lt_20) | (roc_9_1d_gt_neg_10))
            # 1h high, 4h still high
            & ((aroonu_14_1h_lt_75) | (stochrsi_k_1h_lt_60) | (stochrsi_k_4h_lt_40))
            # 1h & 1d high, 1d down move
            & ((aroonu_14_1h_lt_90) | (rsi_3_1d_gt_50) | (stochrsi_k_1d_lt_60))
            # 1h high, 4h & 1d down move
            & ((aroonu_14_1h_lt_90) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_50))
            # 1h high, 4h down move & still not low enough
            & ((aroonu_14_1h_lt_90) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_30))
            # 1h high, 4h still not low enough, 1d still high
            & ((aroonu_14_1h_lt_90) | (stochrsi_k_4h_lt_30) | (aroonu_14_1d_lt_40))
            # 1h & 4h still not low enough, 1d down move
            & ((stochrsi_k_1h_lt_30) | (aroonu_14_4h_lt_20) | (rsi_3_1d_gt_65))
            # 1h still not low enough, 4h still high, 1d overbought
            & ((stochrsi_k_1h_lt_30) | (aroonu_14_4h_lt_50) | (roc_9_1d_lt_0))
            # 1h still not low enough, 4h down move, 1d downtrend
            & ((stochrsi_k_1h_lt_30) | (rsi_3_4h_gt_20) | (roc_9_1d_gt_neg_25))
            # 1h still not low enough, 4h down move & still high
            & ((stochrsi_k_1h_lt_30) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_50))
            # 1h & 4h still high, 4h still not low enough
            & ((stochrsi_k_1h_lt_40) | (aroonu_14_4h_lt_20) | (stochrsi_k_4h_lt_40))
            # 1h still high, 4h still not low enough, 1d high
            & ((stochrsi_k_1h_lt_40) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_75))
            # 1h & 4h still high, 1d high
            & ((stochrsi_k_1h_lt_40) | (aroonu_14_4h_lt_50) | (stochrsi_k_1d_lt_60))
            # 1h still high, 1d high & overbought
            & ((stochrsi_k_1h_lt_40) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_15))
            # 1h still high, 4h still not low enough, 1d overbought
            & ((stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_30) | (roc_9_1d_lt_20))
            # 1h still high, 4h still not low enough
            & ((stochrsi_k_1h_lt_50) | (aroonu_14_4h_lt_20) | (stochrsi_k_4h_lt_10))
            # 1h & 4h & 1d still high
            & ((stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_50) | (stochrsi_k_1d_lt_40))
            # 1h & 1d high, 4h still not low enough
            & ((stochrsi_k_1h_lt_60) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_lt_80))
            # 1h & 1d high, 4h still not low enough
            & ((stochrsi_k_1h_lt_60) | (aroonu_14_4h_lt_30) | (stochrsi_k_1d_lt_60))
            # 1h high, 4h & 1d still high
            & ((stochrsi_k_1h_lt_60) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_50))
            # 1h high, 4h down move, 1d downtrend
            & ((stochrsi_k_1h_lt_60) | (rsi_3_4h_gt_20) | (roc_9_1d_gt_neg_10))
            # 1h high, 4h down move, 1d still not low enough
            & ((stochrsi_k_1h_lt_60) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_lt_20))
            # 1h high, 4h still not low enough, 1d downtrend
            & ((stochrsi_k_1h_lt_60) | (stochrsi_k_4h_lt_20) | (roc_9_1d_gt_neg_10))
            # 1h & 1d high, 4h still not low enough
            & ((stochrsi_k_1h_lt_60) | (stochrsi_k_4h_lt_30) | (aroonu_14_1d_lt_60))
            # 1h high, 4h & 1d still not low enough
            & ((stochrsi_k_1h_lt_70) | (stochrsi_k_4h_lt_10) | (aroonu_14_1d_lt_30))
            # 1h & 1d high, 1d down move
            & ((stochrsi_k_1h_lt_80) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_60))
            # 4h down move, 1d high & downtrend
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_lt_75) | (roc_9_1d_gt_neg_10))
            # 4h down move & still high, 1d high
            & ((rsi_3_4h_gt_10) | (aroonu_14_4h_lt_40) | (stochrsi_k_1d_lt_60))
            # 4h down move & still not low enough, 1d high
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_30) | (stochrsi_k_1d_lt_80))
            # 4h down move & still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_20) | (stochrsi_k_4h_lt_20) | (roc_9_1d_gt_neg_10))
            # 4h down move & still not low enough, 1d downtrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_4h_lt_30) | (roc_9_1d_gt_neg_10))
            # 4h & 1d down move, 4h still not low enough
            & ((rsi_3_4h_gt_40) | (aroonu_14_4h_lt_20) | (rsi_3_1d_gt_60))
            # 4h down move, 1d still high & downtrend
            & ((rsi_3_4h_gt_40) | (stochrsi_k_1d_lt_40) | (roc_9_1d_gt_neg_10))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_40) | (stochrsi_k_4h_lt_50) | (rsi_3_1d_gt_60))
            # 4h & 1d down move, 1d still not low enough
            & ((rsi_3_4h_gt_50) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_20))
            # 4h up move
            & (rsi_3_4h_lt_70)
            # an ignition taken into 4h distribution: money leaving, the stochastic on the floor and no 4h momentum
            & ((cmf_20_4h > -0.2) | (stochrsi_k_4h > 10.0) | (rsi_3_4h > 35.0))
            # 4h still not low enough & high, 1d downtrend
            & ((aroonu_14_4h_lt_20) | (stochrsi_k_4h_lt_60) | (roc_9_1d_gt_neg_10))
            # 4h still high, 1d down move & still not low enough
            & ((aroonu_14_4h_lt_40) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_lt_30))
            # 4h still high, 1d high & overbought
            & ((aroonu_14_4h_lt_50) | (stochrsi_k_1d_lt_80) | (roc_9_1d_lt_40))
            # 4h high
            & (aroonu_14_4h_lt_75)
            # 4h still not low enough, 1d down move & still high
            & ((stochrsi_k_4h_lt_10) | (rsi_3_1d_gt_60) | (stochrsi_k_1d_lt_40))
            # 4h still not low enough, 1d high
            & ((stochrsi_k_4h_lt_20) | (aroonu_14_1d_lt_75) | (stochrsi_k_1d_lt_80))
            # 4h still high
            & (stochrsi_k_4h_lt_60)
          )

          # Logic
          long_entry_logic.append(
            # calm base: not already pumped over the rolling 24h (ride the ignition, don't chase)
            (roc_288 < 8.0)
            # ignition: green candle with a real body, closing in its upper half, CROSSING above
            # the prior 48-candle high (a doji-sized ignition, or one closing back in the lower
            # half of its own range, has no follow-through: -4,693 and -4,587 respectively)
            & (close > (open_rate * 1.002))
            & (close > ((high_px + low_px) / 2.0))
            & (np_shift(close, 1) <= np_shift(close_max_48, 1))
            & (close > np_shift(close_max_48, 1))
            # ...on explosive volume. Unlike the dump hunter, where 3.0 is the sweet spot, the
            # pump side loses in the 3-4x band (-5,767 over 343 trades): the ignition needs real
            # participation, not a routine tick up in volume
            & (vol_rel > 4.0)
          )

        # Condition #172 - Marubozu momentum (Long, experimental — full-body ignition).
        if long_entry_condition_index == 172:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            # 5m down move, 15m still high, 1h washed out, 1d down move & washed out
            (
              (rsi_3 > 75.0)
              | (stochrsi_k_15m_lt_50)
              | (rsi_3_1d > 75.0)
              | (stochrsi_k_1d > 65.0)
              | (stochrsi_k_1h > 95.0)
            )
            # 5m & 1h down move, 15m high
            & ((rsi_3 > 60) | (aroonu_14_15m_lt_90) | (rsi_3_1h_gt_55))
            # 5m down move, 15m down move, 1d downtrend
            & ((rsi_3 > 60.0) | (rsi_3_15m_gt_45) | (aroonu_14_1d_gt_10))
            # 5m down move & uptrend, 1h uptrend & down move, 1d down move
            & ((rsi_3 > 70.0) | (rsi_3_1d_gt_60) | (aroonu_14_1h < 95.0) | (rsi_3_1h > 90.0) | (aroonu_14 < 45.0))
            # 5m down move & uptrend, 15m still high, 1h down move, 1d downtrend
            & ((rsi_3 > 70.0) | (rsi_3_1h_gt_50) | (aroonu_14_1d_gt_10) | (aroonu_14 < 5.0) | (stochrsi_k_15m_lt_30))
            # 5m down move & uptrend, 15m down move, 4h down move
            & ((rsi_3 > 70.0) | (rsi_3_4h_gt_60) | (rsi_3_15m_gt_30) | (aroonu_14 < 40.0))
            # 5m down move, 15m overbought, 4h up move & down move, 1d downtrend
            & ((rsi_3 > 70.0) | (stochrsi_k_15m_lt_80) | (aroonu_14_1d > 75.0) | (rsi_3_4h_lt_80) | (roc_9_4h > 15.0))
            # 5m down move & still high, 1h down move, 4h overbought, 1d washed out
            & ((rsi_3 > 85.0) | (rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_90) | (stochrsi_k_1d_gt_40) | (stochrsi_k < 50.0))
            # 5m up move, 4h washed out & uptrend & down move, 1d uptrend
            & ((rsi_3_lt_90) | (stochrsi_k_4h_gt_20) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_80) | (rsi_3_4h_gt_65))
            # 5m & 1h up move, 1d overbought
            & ((rsi_3_lt_95) | (rsi_3_1h_lt_80) | (roc_9_1d_lt_80))
            # 5m up move, 1h up move, 4h downtrend, 1d washed out & up move
            & ((rsi_3_lt_97) | (stochrsi_k_1d_gt_50) | (roc_9_1d_lt_10) | (rsi_3_1h_lt_70) | (aroonu_14_4h > 95.0))
            # 5m money leaving, 15m oscillator high and 4h money leaving
            & ((cmf_20 > 0.02) | (uo_7_14_28_15m < 55) | (cmf_20_4h_gt_neg_0_0))
            # 5m uptrend, 1h down move & still high, 1d washed out & up move
            & (
              (aroonu_14_lt_30) | (rsi_3_1h_gt_45) | (stochrsi_k_1d > 75.0) | (rsi_3_1d < 60.0) | (stochrsi_k_1h_lt_20)
            )
            # 5m still not high enough, 15m high, 1d overbought
            & ((aroonu_14_gt_75) | (stochrsi_k_15m_lt_70) | (roc_9_1d_lt_150))
            # 5m still not low enough, 15m down move, 1d high
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_55) | (stochrsi_k_1d_lt_90))
            # 5m still not low enough, 1h high, 1d overbought
            & ((aroonu_14_lt_25) | (stochrsi_k_1h_lt_90) | (roc_9_1d_lt_10))
            # 5m still not low enough, 15m still high, 1d high
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_40) | (stochrsi_k_1d_lt_90))
            # 5m still not low enough, 15m & 1h down move
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_50) | (rsi_3_1h_gt_30))
            # 5m still not low enough, 1h & 1d down move
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_40) | (rsi_3_1d_gt_65))
            # 5m still not low enough, 1h & 4h down move
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40))
            # 5m still not low enough, 1h down move, 1d overbought
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_60) | (roc_9_1d_lt_50))
            # 5m still not low enough, 1h down move, 1d high
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_60) | (stochrsi_k_1d_lt_80))
            # 5m still not low enough, 1h down move, 4h high
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_80))
            # 5m still not low enough, 15m down move
            & ((aroonu_14_lt_30) | (stochrsi_k_lt_30) | (rsi_3_15m_gt_50))
            # 5m still high & up move, 15m downtrend & up move, 1d washed out
            & (
              (stochrsi_k_lt_30) | (roc_9 < 0.5) | (aroonu_14_15m > 15.0) | (stochrsi_k_1d > 75.0) | (rsi_3_15m < 40.0)
            )
            # 5m still high & up move, 1h washed out, 4h downtrend, 1d downtrend
            & (
              (stochrsi_k_lt_30)
              | (roc_9 < 0.5)
              | (aroonu_14_1d > 60.0)
              | (stochrsi_k_1h_gt_75)
              | (aroonu_14_4h > 95.0)
            )
            # 5m still high, 15m up move, 4h washed out, 1d washed out & up move
            & (
              (stochrsi_k_lt_30)
              | (roc_9_15m < 1.5)
              | (stochrsi_k_1d_gt_50)
              | (rsi_3_1d < 55.0)
              | (stochrsi_k_4h > 95.0)
            )
            # 5m still high, 1h washed out, 4h up move & downtrend, 1d down move
            & (
              (stochrsi_k_lt_30) | (roc_9_1d > 30.0) | (rsi_3_4h_lt_90) | (aroonu_14_4h > 95.0) | (stochrsi_k_1h_gt_70)
            )
            # 5m still high, 15m uptrend, 4h uptrend, 1d down move & downtrend
            & (
              (stochrsi_k_lt_30)
              | (rsi_3_1d_gt_35)
              | (aroonu_14_1d > 15.0)
              | (aroonu_14_4h < 5.0)
              | (aroonu_14_15m_lt_30)
            )
            # 5m still high, 15m still high, 4h down move, 1d still high & uptrend
            & (
              (stochrsi_k_lt_30)
              | (stochrsi_k_1d_lt_70)
              | (roc_9_4h > 0.0)
              | (stochrsi_k_15m < 55.0)
              | (aroonu_14_1d_lt_90)
            )
            # 5m still not low enough, 15m high, 1h overbought
            & ((stochrsi_k_lt_30) | (aroonu_14_15m_lt_60) | (roc_9_1h_lt_10))
            # 5m still not low enough, 15m & 1h high
            & ((stochrsi_k_lt_30) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_80))
            # 5m still high & down move, 1h uptrend, 4h down move, 1d up move
            & ((stochrsi_k_lt_30) | (aroonu_14_1h_lt_90) | (roc_9_4h > 5.0) | (rsi_3 > 85.0) | (rsi_3_1d < 55.0))
            # 5m still not low enough, 1h & 4h high
            & ((stochrsi_k_lt_30) | (aroonu_14_1h_lt_90) | (stochrsi_k_4h_lt_70))
            # 5m still not low enough, 15m down move & high
            & ((stochrsi_k_lt_30) | (rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_60))
            # 5m still not low enough, 1d down move & high
            & ((stochrsi_k_lt_30) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_60))
            # 5m still not low enough, 1h & 4h down move
            & ((stochrsi_k_lt_30) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_60))
            # 5m & 15m still not low enough, 1h high
            & ((stochrsi_k_lt_30) | (stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_80))
            # 5m still not low enough, 1h high, 1d overbought
            & ((stochrsi_k_lt_30) | (stochrsi_k_1h_lt_60) | (roc_9_1d_lt_20))
            # 5m still not low enough, 1h & 1d high
            & ((stochrsi_k_lt_30) | (stochrsi_k_1h_lt_80) | (stochrsi_k_1d_lt_70))
            # 5m still not low enough, 1h & 4h high
            & ((stochrsi_k_lt_30) | (stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_90))
            # 5m up move, 15m downtrend, 4h uptrend & down move, 1d down move
            & ((roc_9 < 0.5) | (aroonu_14_4h_lt_30) | (rsi_3_1d > 75.0) | (rsi_3_4h > 75.0) | (aroonu_14_15m > 95.0))
            # 5m up move, 1h down move, 4h washed out, 1d downtrend
            & ((roc_9 < 0.5) | (rsi_3_1h_gt_50) | (aroonu_14_1d > 60.0) | (rsi_3 < 85.0) | (stochrsi_k_4h > 85.0))
            # 5m up move, 4h still high & uptrend & down move, 1d down move
            & ((roc_9 < 0.5) | (stochrsi_k_4h_lt_40) | (rsi_3_1d_gt_55) | (aroonu_14_4h_lt_30) | (rsi_3_4h > 75.0))
            # 15m down move, 1h washed out & uptrend, 1d down move & washed out
            & (
              (rsi_3_15m_gt_45)
              | (rsi_3_1d_gt_65)
              | (stochrsi_k_1h_gt_90)
              | (aroonu_14_1h_lt_80)
              | (stochrsi_k_1d_gt_40)
            )
            # 5m downtrend, 15m down move & downtrend & washed out, 1h up move
            & (
              (rsi_3_15m_gt_55)
              | (roc_9_1h_lt_10)
              | (aroonu_14_15m > 15.0)
              | (aroonu_14 > 30.0)
              | (stochrsi_k_15m > 35.0)
            )
            # 15m up move & washed out & uptrend, 1d overbought & up move
            & (
              (rsi_3_15m_lt_60)
              | (stochrsi_k_15m_gt_30)
              | (aroonu_14_15m_lt_80)
              | (stochrsi_k_1d_lt_80)
              | (roc_9_1d_lt_15)
            )
            # 15m down move, 1h high & still high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_80) | (stochrsi_k_1h_lt_40))
            # 15m & 4h down move
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_65))
            # 15m & 1d down move, 15m still high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_40) | (rsi_3_1d_gt_60))
            # 15m down move, 1d downtrend
            & ((rsi_3_15m_gt_30) | (roc_9_1d_gt_neg_10))
            # 15m down move, 1h overbought, 1d high
            & ((rsi_3_15m_gt_30) | (roc_9_1h_lt_20) | (stochrsi_k_1d_lt_90))
            # 15m down move, 4h overbought, 1d high
            & ((rsi_3_15m_gt_30) | (roc_9_4h_lt_30) | (stochrsi_k_1d_lt_80))
            # 15m & 1d down move, 1d high
            & ((rsi_3_15m_gt_30) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_75))
            # 5m down move, 15m down move & still high, 1h down move, 1d downtrend
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_55) | (rsi_3 > 75.0) | (aroonu_14_1d > 90.0) | (stochrsi_k_15m_lt_20))
            # 15m & 1d down move, 15m high
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_80) | (rsi_3_1d_gt_30))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_55))
            # 5m up move, 15m down move, 4h down move & on the floor, 1d washed out
            & ((rsi_3_15m_gt_40) | (rsi_3_4h_gt_60) | (stochrsi_k_4h > 15.0) | (stochrsi_k_1d > 55.0) | (rsi_3 < 60.0))
            # 15m down move & high, 1d overbought
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_80) | (roc_9_1d_lt_50))
            # 15m down move, 1h still not low enough, 4h high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_1h_lt_30) | (stochrsi_k_4h_lt_90))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_1h_lt_40) | (rsi_3_4h_gt_50))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_40) | (rsi_3_1h_gt_60))
            # 15m down move, 15m & 1d high
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_80) | (stochrsi_k_1d_lt_90))
            # 15m & 1h down move, 1h high
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_60) | (aroonu_14_1h_lt_80))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_65) | (stochrsi_k_1d_lt_90))
            # 15m down move & still high, 1d high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_40) | (aroonu_14_1d_lt_80))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_60) | (stochrsi_k_1h_lt_70))
            # 15m down move & high, 1h still not low enough
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_30))
            # 15m down move, 1h & 4h high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_90))
            # 5m up move, 15m down move & uptrend, 4h still high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_4h_lt_70) | (rsi_3_lt_90) | (aroonu_14_15m_lt_60))
            # 15m & 4h down move, 1h high
            & ((rsi_3_15m_gt_55) | (aroonu_14_1h_lt_80) | (rsi_3_4h_gt_60))
            # 15m down move, 4h overbought, 1d low
            & ((rsi_3_15m_gt_55) | (roc_9_4h_lt_15) | (aroonu_14_1d_gt_30))
            # 5m up move, 15m down move & downtrend, 1d down move
            & ((rsi_3_15m_gt_55) | (rsi_3_1d_gt_40) | (aroonu_14_15m > 15.0) | (rsi_3 < 80.0))
            # 15m & 1h down move, 1d high
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_gt_30) | (stochrsi_k_1d_lt_80))
            # 15m & 1h down move, 4h overbought
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_gt_60) | (roc_9_4h_lt_20))
            # 5m uptrend, 15m down move, 4h down move, 1d downtrend
            & ((rsi_3_15m_gt_55) | (rsi_3_4h_gt_50) | (aroonu_14_1d_gt_0) | (aroonu_14 < 15.0))
            # 15m & 4h down move, 4h overbought
            & ((rsi_3_15m_gt_55) | (rsi_3_4h_gt_50) | (roc_9_4h_lt_15))
            # 15m down move, 15m & 1d high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_80) | (stochrsi_k_1d_lt_70))
            # 15m down move, 1h still not low enough, 1d overbought
            & ((rsi_3_15m_gt_55) | (stochrsi_k_1h_lt_30) | (roc_9_1d_lt_60))
            # 15m down move, 4h & 1d high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_4h_lt_70) | (stochrsi_k_1d_lt_80))
            # 15m down move, 1h high & overbought
            & ((rsi_3_15m_lt_60) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_20))
            # 15m up move, 1h low, 4h down move
            & ((rsi_3_15m_lt_85) | (aroonu_14_1h_gt_10) | (rsi_3_4h_lt_60))
            # 5m down move, 15m up move, 1d down move
            & ((rsi_3_15m_lt_85) | (rsi_3_1d_gt_25) | (rsi_3 > 85.0))
            # 15m up move, 1h still high, 1d high
            & ((rsi_3_15m_lt_85) | (stochrsi_k_1h_gt_50) | (stochrsi_k_1d_gt_10))
            # 15m up move, 1h down move, 1d still low
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_gt_65) | (aroonu_14_1d_gt_50))
            # 15m up move, 1h down move, 4h overbought
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_gt_65) | (roc_9_4h_lt_25))
            # 5m up move, 15m up move, 1h washed out & up move, 4h washed out
            & ((rsi_3_15m_lt_90) | (stochrsi_k_4h_gt_40) | (rsi_3_lt_90) | (stochrsi_k_1h_gt_90) | (rsi_3_1h_lt_70))
            # 15m up move, 1h uptrend & down move, 4h uptrend, 1d up move
            & ((rsi_3_15m_lt_95) | (aroonu_14_1h_lt_90) | (roc_9_1h > 5.0) | (aroonu_14_4h < 95.0) | (rsi_3_1d < 70.0))
            # 15m downtrend, 1h up move, 4h still high, 1d washed out & up move
            & (
              (aroonu_14_15m_gt_10)
              | (stochrsi_k_1d_gt_40)
              | (roc_9_1d < -5.0)
              | (stochrsi_k_4h_lt_60)
              | (rsi_3_1h < 45.0)
            )
            # 15m downtrend, 1h up move, 4h overbought & down move, 1d overbought
            & (
              (aroonu_14_15m_gt_20)
              | (stochrsi_k_1d_lt_80)
              | (stochrsi_k_4h_lt_80)
              | (rsi_3_4h > 80.0)
              | (rsi_3_1h_lt_55)
            )
            # 5m up move, 15m uptrend, 1h uptrend & washed out, 1d down move
            & (
              (aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_40) | (rsi_3_lt_95) | (roc_9_1d > 10.0) | (stochrsi_k_1h_gt_70)
            )
            # 5m uptrend, 15m uptrend & washed out, 4h overbought, 1d downtrend
            & (
              (aroonu_14_15m_lt_40)
              | (stochrsi_k_4h_lt_80)
              | (aroonu_14_1d > 60.0)
              | (aroonu_14 < 95.0)
              | (stochrsi_k_15m > 85.0)
            )
            # 5m washed out, 15m uptrend, 1h washed out, 4h down move & downtrend
            & (
              (aroonu_14_15m_lt_60)
              | (rsi_3_4h_gt_45)
              | (aroonu_14_4h > 40.0)
              | (stochrsi_k > 55.0)
              | (stochrsi_k_1h_gt_70)
            )
            # 15m & 1h low, 1d down move
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_30) | (rsi_3_1d_gt_65))
            # 15m low, 1h & 1d high
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_75) | (stochrsi_k_1d_gt_10))
            # 15m low, 4h high, 1d overbought
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_4h_lt_90) | (roc_9_1d_lt_40))
            # 15m still high, 1h high, 4h down move
            & ((aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_80) | (rsi_3_4h_gt_65))
            # 15m still high, 1h & 4h down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_60) | (rsi_3_4h_gt_60))
            # 15m still high, 1h down move, 4h high
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_80))
            # 15m still high, 4h down move, 1d high
            & ((aroonu_14_15m_lt_40) | (rsi_3_4h_gt_65) | (aroonu_14_1d_lt_90))
            # 15m uptrend, 1d uptrend & washed out & up move
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d > 25.0) | (rsi_3_1d < 65.0))
            # 5m downtrend & down move, 15m uptrend, 1h uptrend, 1d down move
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_90) | (aroonu_14 > 10.0) | (roc_9_1d > 25.0) | (rsi_3 > 80.0))
            # 15m & 1d high, 1h down move
            & ((aroonu_14_15m_lt_60) | (rsi_3_1h_gt_40) | (stochrsi_k_1d_lt_90))
            # 15m high, 1h down move, 1d overbought
            & ((aroonu_14_15m_lt_60) | (rsi_3_1h_gt_50) | (roc_9_1d_lt_30))
            # 15m high, 1h & 1d down move
            & ((aroonu_14_15m_lt_60) | (rsi_3_1h_gt_65) | (rsi_3_1d_gt_50))
            # 15m high, 4h down move & overbought
            & ((aroonu_14_15m_lt_60) | (rsi_3_4h_gt_60) | (roc_9_4h_lt_25))
            # 15m high, 1h low
            & ((aroonu_14_15m_lt_75) | (aroonu_14_1h_gt_10))
            # 15m & 1d high, 1d down move
            & ((aroonu_14_15m_lt_75) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_90))
            # 15m high, 1h & 1d down move
            & ((aroonu_14_15m_lt_75) | (rsi_3_1h_gt_55) | (rsi_3_1d_gt_55))
            # 15m high, 4h down move
            & ((aroonu_14_15m_lt_75) | (rsi_3_4h_gt_15))
            # 15m & 1h & 1d high
            & ((aroonu_14_15m_lt_80) | (aroonu_14_1h_lt_70) | (stochrsi_k_1d_lt_90))
            # 15m & 4h high
            & ((aroonu_14_15m_lt_80) | (aroonu_14_4h_lt_80) | (stochrsi_k_4h_lt_90))
            # 15m high, 1d downtrend
            & ((aroonu_14_15m_lt_80) | (roc_9_1d_gt_neg_10))
            # 15m & 4h high, 1h overbought
            & ((aroonu_14_15m_lt_80) | (roc_9_1h_lt_15) | (stochrsi_k_4h_lt_80))
            # 15m high, 4h overbought
            & ((aroonu_14_15m_lt_80) | (roc_9_4h_lt_80))
            # 15m high, 4h down move & overbought
            & ((aroonu_14_15m_lt_80) | (rsi_3_4h_gt_40) | (roc_9_4h_lt_5))
            # 15m & 1h high, 15m still not low enough
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_70))
            # 15m & 1h high, 15m still not low enough
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_90))
            # 15m & 1h high
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_60))
            # 5m overbought, 15m uptrend, 4h up move, 1d downtrend
            & ((aroonu_14_15m_lt_90) | (roc_9_4h_lt_15) | (aroonu_14_1d_gt_30) | (stochrsi_k < 85.0))
            # 15m high, 4h overbought
            & ((aroonu_14_15m_lt_90) | (roc_9_4h_lt_70))
            # 15m high, 1d down move
            & ((aroonu_14_15m_lt_90) | (rsi_3_1d_gt_25))
            # 15m high, 1h down move, 4h low
            & ((aroonu_14_15m_lt_90) | (rsi_3_1h_gt_55) | (aroonu_14_4h_gt_10))
            # 5m uptrend, 15m uptrend, 4h down move, 1d downtrend
            & ((aroonu_14_15m_lt_90) | (rsi_3_4h_gt_50) | (aroonu_14_1d_gt_0) | (aroonu_14 < 65.0))
            # 5m down move, 15m washed out, 1h down move, 4h uptrend, 1d washed out
            & (
              (stochrsi_k_15m_gt_30)
              | (stochrsi_k_1d_gt_40)
              | (aroonu_14_4h < 15.0)
              | (rsi_3 > 90.0)
              | (rsi_3_1h > 80.0)
            )
            # 5m uptrend, 15m still high, 1h overbought, 1d overbought & down move
            & (
              (stochrsi_k_15m_lt_40)
              | (stochrsi_k_1d_lt_90)
              | (stochrsi_k_1h_lt_80)
              | (aroonu_14 < 80.0)
              | (rsi_3_1d > 95.0)
            )
            # 15m still high & downtrend, 1h uptrend & up move, 1d up move
            & (
              (stochrsi_k_15m_lt_50)
              | (aroonu_14_1h_lt_80)
              | (aroonu_14_15m_gt_60)
              | (rsi_3_1d < 75.0)
              | (roc_9_1h < 5.0)
            )
            # 5m overbought, 15m still high, 1h still high & downtrend, 4h down move
            & (
              (stochrsi_k_15m_lt_60)
              | (stochrsi_k_1h_lt_70)
              | (rsi_3_4h_gt_60)
              | (stochrsi_k < 95.0)
              | (aroonu_14_1h > 80.0)
            )
            # 5m uptrend, 15m overbought, 1h washed out, 4h up move, 1d down move
            & (
              (stochrsi_k_15m_lt_80)
              | (roc_9_4h_lt_15)
              | (roc_9_1d > 10.0)
              | (stochrsi_k_1h_gt_70)
              | (aroonu_14 < 45.0)
            )
            # 15m overbought, 1h washed out & up move, 1d down move & uptrend
            & (
              (stochrsi_k_15m_lt_80)
              | (rsi_3_1d_gt_55)
              | (stochrsi_k_1h_gt_70)
              | (rsi_3_1h_lt_65)
              | (aroonu_14_1d_lt_40)
            )
            # 15m overbought & up move, 1h washed out, 4h downtrend, 1d down move
            & (
              (stochrsi_k_15m_lt_80)
              | (rsi_3_1d_gt_65)
              | (stochrsi_k_1h_gt_75)
              | (rsi_3_15m_lt_85)
              | (aroonu_14_4h > 90.0)
            )
            # 15m overbought, 1h still high, 4h uptrend & down move, 1d down move
            & (
              (stochrsi_k_15m_lt_80)
              | (stochrsi_k_1h_lt_70)
              | (aroonu_14_4h_lt_90)
              | (roc_9_4h > 10.0)
              | (roc_9_1d > 20.0)
            )
            # 5m washed out, 15m overbought, 4h overbought, 1d down move & up move
            & (
              (stochrsi_k_15m_lt_80)
              | (stochrsi_k_4h_lt_90)
              | (stochrsi_k > 30.0)
              | (rsi_3_1d > 75.0)
              | (roc_9_1d_lt_10)
            )
            # 5m washed out & up move, 15m washed out & up move
            & ((stochrsi_k_15m_gt_50) | (roc_9_15m < 1.5) | (stochrsi_k > 35.0) | (rsi_3 < 75.0) | (rsi_3_15m < 35.0))
            # 15m still not low enough, 4h down move, 1d high
            & ((stochrsi_k_15m_lt_20) | (rsi_3_4h_gt_65) | (stochrsi_k_1d_lt_90))
            # 15m still not low enough, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_30) | (rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_90))
            # 15m still not low enough, 1h down move & high
            & ((stochrsi_k_15m_lt_30) | (rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_70))
            # 15m still not low enough, 4h & 1d down move
            & ((stochrsi_k_15m_lt_30) | (rsi_3_4h_gt_60) | (rsi_3_1d_gt_45))
            # 15m still not low enough, 1h & 1d high
            & ((stochrsi_k_15m_lt_30) | (stochrsi_k_1h_lt_90) | (stochrsi_k_1d_lt_80))
            # 15m still high, 4h high & overbought
            & ((stochrsi_k_15m_lt_40) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_30))
            # 15m still high, 1h down move
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_15))
            # 15m still high, 1h down move & high
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_65) | (aroonu_14_1h_lt_80))
            # 15m still high, 4h & 1d high
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_4h_lt_80) | (aroonu_14_1d_lt_90))
            # 15m still high, 4h high, 1d overbought
            & ((stochrsi_k_15m_lt_50) | (aroonu_14_4h_lt_90) | (roc_9_1d_lt_50))
            # 15m still high, 1h down move, 4h high
            & ((stochrsi_k_15m_lt_50) | (rsi_3_1h_gt_65) | (stochrsi_k_4h_lt_60))
            # 15m still high, 4h & 1d high
            & ((stochrsi_k_15m_lt_50) | (stochrsi_k_4h_lt_70) | (aroonu_14_1d_lt_80))
            # 15m & 4h high, 4h overbought
            & ((stochrsi_k_15m_lt_60) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_15))
            # 15m & 4h & 1d high
            & ((stochrsi_k_15m_lt_60) | (aroonu_14_4h_lt_90) | (stochrsi_k_1d_lt_80))
            # 15m high, 1h down move, 4h overbought
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_55) | (roc_9_4h_lt_60))
            # 15m & 1h & 1d high
            & ((stochrsi_k_15m_lt_70) | (aroonu_14_1h_lt_80) | (stochrsi_k_1d_lt_90))
            # 15m & 1d high, 4h overbought
            & ((stochrsi_k_15m_lt_70) | (roc_9_4h_lt_5) | (stochrsi_k_1d_lt_90))
            # 15m still high, 1d down move
            & ((stochrsi_k_15m_lt_70) | (rsi_3_1d_gt_25) | (roc_9_1d_gt_neg_15))
            # 15m still high & downtrend, 1h down move, 1d down move
            & ((stochrsi_k_15m_lt_70) | (rsi_3_1h_gt_60) | (roc_9_1d > 0.0) | (aroonu_14_15m_gt_10))
            # 15m & 4h high
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_4h_lt_90) | (stochrsi_k_4h_lt_80))
            # 15m & 1d high, 1d down move
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_90))
            # 15m & 1d high, 1d down move
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1d_gt_60) | (stochrsi_k_1d_lt_70))
            # 15m & 1d high, 1d down move
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_80))
            # 15m & 1d high, 1h down move
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_60) | (stochrsi_k_1d_lt_90))
            # 15m & 1d high, 1h still high
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_40) | (aroonu_14_1d_lt_90))
            # 15m & 4h high, 1h still high
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_60))
            # 15m & 1h & 1d high
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_80) | (stochrsi_k_1d_lt_90))
            # 15m down move & uptrend, 1h still high, 4h up move, 1d downtrend
            & (
              (roc_9_15m > -1.0)
              | (roc_9_4h_lt_10)
              | (aroonu_14_1d > 80.0)
              | (stochrsi_k_1h < 55.0)
              | (aroonu_14_15m < 10.0)
            )
            # 5m uptrend, 15m down move & still high, 1h still high, 4h uptrend
            & (
              (roc_9_15m > -1.0)
              | (stochrsi_k_1h_lt_50)
              | (aroonu_14 < 65.0)
              | (stochrsi_k_15m < 15.0)
              | (aroonu_14_4h_lt_75)
            )
            # 5m uptrend, 15m down move & still high, 1h uptrend, 4h still high
            & (
              (roc_9_15m > -1.0)
              | (stochrsi_k_4h_lt_60)
              | (aroonu_14 < 65.0)
              | (stochrsi_k_15m < 15.0)
              | (aroonu_14_1h < 65.0)
            )
            # 15m overbought, 1h down move, 4h high
            & ((roc_9_15m < 1.5) | (rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_80))
            # 5m still high, 15m up move, 1h washed out, 4h down move, 1d down move
            & ((roc_9_15m < 1.5) | (rsi_3_4h_gt_55) | (rsi_3_1d_gt_65) | (stochrsi_k_1h_gt_75) | (stochrsi_k_lt_30))
            # 15m overbought, 1h low
            & ((roc_9_15m < 10) | (aroonu_14_1h_gt_10))
            # 5m uptrend, 15m down move, 1h down move & uptrend, 4h washed out
            & (
              (rsi_3_1h_gt_50)
              | (aroonu_14_1h_lt_80)
              | (aroonu_14 < 60.0)
              | (stochrsi_k_4h > 85.0)
              | (rsi_3_15m > 75.0)
            )
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_lt_60) | (stochrsi_k_1d_lt_70))
            # 15m up move, 1h down move, 4h overbought
            & ((rsi_3_1h_gt_35) | (stochrsi_k_4h_lt_80) | (rsi_3_15m_lt_80))
            # 1h down move & high, 1d overbought
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_60) | (roc_9_1d_lt_50))
            # 1h & 1d down move, 1d high
            & ((rsi_3_1h_gt_40) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_90))
            # 1h & 4h down move, 4h overbought
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_50) | (roc_9_4h_lt_15))
            # 1h & 4h down move, 1d overbought
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_65) | (roc_9_1d_lt_30))
            # 1h down move & still high, 1d high
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_40) | (stochrsi_k_1d_lt_90))
            # 1h down move & high, 1d overbought
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_lt_60) | (roc_9_1d_lt_40))
            # 5m still high, 1h down move, 4h up move, 1d washed out & down move
            & ((rsi_3_1h_gt_45) | (roc_9_4h_lt_10) | (stochrsi_k_1d_gt_50) | (rsi_3_1d > 85.0) | (stochrsi_k < 75.0))
            # 1h down move, 4h overbought & up move, 1d downtrend
            & ((rsi_3_1h_gt_45) | (stochrsi_k_4h_lt_80) | (aroonu_14_1d > 25.0) | (rsi_3_4h_lt_90))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_50) | (rsi_3_4h_gt_60) | (rsi_3_1d_gt_30))
            # 1h & 4h down move, 1h high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_60) | (rsi_3_4h_gt_65))
            # 1h down move & high, 4h still high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_80) | (aroonu_14_4h_lt_40))
            # 1h down move & overbought, 4h up move, 1d down move
            & ((rsi_3_1h_gt_55) | (stochrsi_k_1h_lt_80) | (rsi_3_4h_lt_90) | (rsi_3_1d_gt_65))
            # 1h down move & uptrend, 1d overbought & down move
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_90) | (stochrsi_k_1d < 95.0) | (rsi_3_1d > 70.0))
            # 5m uptrend, 1h down move, 4h up move, 1d washed out
            & ((rsi_3_1h_gt_60) | (roc_9_4h_lt_20) | (stochrsi_k_1d_gt_20) | (aroonu_14 < 80.0))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_60) | (aroonu_14_1d_lt_80))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_65) | (stochrsi_k_1d_lt_80))
            # 1h down move & still not low enough, 1d high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_30) | (stochrsi_k_1d_lt_90))
            # 1h down move & still not low enough, 4h high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_30) | (stochrsi_k_4h_lt_70))
            # 1h down move & still not low enough, 4h high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_30) | (stochrsi_k_4h_lt_80))
            # 1h down move & still high, 4h high
            & ((rsi_3_1h_gt_60) | (stochrsi_k_1h_lt_50) | (aroonu_14_4h_lt_90))
            # 15m down move, 1h down move, 4h overbought, 1d downtrend
            & ((rsi_3_1h_gt_60) | (stochrsi_k_4h_lt_90) | (aroonu_14_1d > 15.0) | (rsi_3_15m_gt_55))
            # 1h & 1d down move, 1h high
            & ((rsi_3_1h_gt_65) | (aroonu_14_1h_lt_60) | (rsi_3_1d_gt_65))
            # 1h down move & high, 1d overbought
            & ((rsi_3_1h_gt_65) | (aroonu_14_1h_lt_90) | (roc_9_1d_lt_80))
            # 5m down move, 1h down move, 4h uptrend & up move, 1d washed out
            & ((rsi_3_1h_gt_65) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_15) | (stochrsi_k_1d_gt_40) | (rsi_3 > 85.0))
            # 1h down move, 4h overbought
            & ((rsi_3_1h_gt_65) | (roc_9_4h_lt_70))
            # 1h & 1d down move, 1d overbought
            & ((rsi_3_1h_gt_65) | (rsi_3_1d_gt_65) | (roc_9_1d_lt_100))
            # 1h down move & still high, 4h uptrend & down move, 1d down move
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_70) | (aroonu_14_4h_lt_90) | (roc_9_4h > 5.0) | (rsi_3_1d > 75.0))
            # 5m down move, 1h RSI low, 1d uptrend & washed out
            & ((rsi_14_1h > 50.0) | (aroonu_14_1d_lt_90) | (stochrsi_k_1d > 25.0) | (rsi_3 > 85.0))
            # 5m overbought, 15m washed out, 1h uptrend, 4h uptrend & down move
            & (
              (aroonu_14_1h_lt_70)
              | (aroonu_14_4h_lt_75)
              | (stochrsi_k < 85.0)
              | (roc_9_4h > 20.0)
              | (stochrsi_k_15m > 75.0)
            )
            # 1h uptrend & washed out, 4h downtrend, 1d down move
            & (
              (aroonu_14_1h_lt_90)
              | (rsi_3_1d_gt_50)
              | (stochrsi_k_1h > 85.0)
              | (aroonu_14_4h_gt_50)
              | (roc_9_1d > 5.0)
            )
            # 5m uptrend, 15m down move, 1h uptrend & washed out, 1d down move
            & (
              (aroonu_14_1h_lt_90)
              | (rsi_3_1d_gt_55)
              | (stochrsi_k_1h > 95.0)
              | (aroonu_14 < 45.0)
              | (rsi_3_15m > 90.0)
            )
            # 15m washed out, 1h uptrend, 4h down move & uptrend
            & (
              (aroonu_14_1h_lt_90)
              | (rsi_3_4h_gt_55)
              | (stochrsi_k_15m > 85.0)
              | (aroonu_14_4h < 55.0)
              | (roc_9_4h > 5.0)
            )
            # 5m down move, 15m overbought, 1h uptrend & still high, 4h up move
            & (
              (aroonu_14_1h_lt_90)
              | (stochrsi_k_1h_lt_60)
              | (stochrsi_k_15m < 90.0)
              | (rsi_3 > 75.0)
              | (rsi_3_4h_lt_80)
            )
            # 5m down move, 15m downtrend & still high, 1h uptrend & overbought
            & (
              (aroonu_14_1h_lt_90)
              | (stochrsi_k_1h_lt_90)
              | (aroonu_14_15m_gt_50)
              | (stochrsi_k_15m_lt_40)
              | (rsi_3 > 75.0)
            )
            # 1h still high, 4h high, 1d downtrend
            & ((aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_90) | (roc_9_1d_gt_0))
            # 5m up move & downtrend, 1h uptrend & up move, 4h uptrend
            & ((aroonu_14_1h_lt_70) | (aroonu_14_4h_lt_75) | (rsi_3_1h_lt_95) | (rsi_3_lt_90) | (aroonu_14 > 30.0))
            # 1h high, 1d overbought
            & ((aroonu_14_1h_lt_75) | (roc_9_1d_lt_200))
            # 1h & 4h high, 1d down move
            & ((aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_80) | (rsi_3_1d_gt_65))
            # 1h high, 1d overbought
            & ((aroonu_14_1h_lt_80) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_50))
            # 5m down move, 15m up move, 1h uptrend, 1d up move & down move
            & ((aroonu_14_1h_lt_90) | (roc_9_1d_lt_15) | (rsi_3_1d > 70.0) | (rsi_3 > 75.0) | (rsi_3_15m < 45.0))
            # 1h high, 4h down move
            & ((aroonu_14_1h_lt_90) | (rsi_3_4h_gt_15))
            # 1h & 1d high, 4h down move
            & ((aroonu_14_1h_lt_90) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_90))
            # 1h high, 4h down move & overbought
            & ((aroonu_14_1h_lt_90) | (rsi_3_4h_gt_65) | (roc_9_4h_lt_20))
            # 1h & 1d high, 1d overbought
            & ((aroonu_14_1h_lt_90) | (stochrsi_k_1d_lt_90) | (roc_9_1d_lt_80))
            # 15m down move, 1h uptrend & washed out, 1d overbought
            & ((aroonu_14_1h_lt_90) | (stochrsi_k_1d_lt_90) | (stochrsi_k_1h > 25.0) | (rsi_3_15m_gt_30))
            # 1h & 4h & 1d high
            & ((aroonu_14_1h_lt_90) | (stochrsi_k_4h_lt_70) | (aroonu_14_1d_lt_80))
            # 5m on the floor, 1h AROOND high, 1d downtrend
            & ((aroond_14_1h_lt_50) | (aroonu_14_1d_gt_20) | (stochrsi_k > 15.0))
            # 5m uptrend, 1h still high, 4h down move & uptrend & on the floor
            & (
              (stochrsi_k_1h_lt_50)
              | (rsi_3_4h_gt_60)
              | (aroonu_14_4h_lt_60)
              | (stochrsi_k_4h > 15.0)
              | (aroonu_14 < 95.0)
            )
            # 5m down move, 15m downtrend, 1h still high & uptrend, 4h overbought
            & (
              (stochrsi_k_1h_lt_50)
              | (stochrsi_k_4h_lt_80)
              | (aroonu_14_15m > 65.0)
              | (rsi_3 > 85.0)
              | (aroonu_14_1h_lt_80)
            )
            # 1h washed out while the 15m spikes and the 1d is spent
            & ((stochrsi_k_1h_gt_10) | (rsi_3_15m_lt_80) | (rsi_3_1d_lt_90))
            # 1h still not low enough & overbought, 1d still high
            & ((stochrsi_k_1h_gt_75) | (roc_9_1h_lt_15) | (stochrsi_k_1d_gt_40))
            # 1h still not low enough, 4h down move & high
            & ((stochrsi_k_1h_lt_30) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_80))
            # 1h still high, 4h down move & high
            & ((stochrsi_k_1h_lt_40) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_70))
            # 1h still high, 4h high, 1d overbought
            & ((stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_70) | (roc_9_1d_lt_20))
            # 1h high, 4h down move, 1d overbought
            & ((stochrsi_k_1h_lt_60) | (rsi_3_4h_gt_65) | (roc_9_1d_lt_30))
            # 1h & 4h high, 4h down move
            & ((stochrsi_k_1h_lt_70) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_60))
            # 5m up move, 1h overbought & down move, 4h uptrend & down move
            & ((stochrsi_k_1h_lt_80) | (aroonu_14_4h_lt_75) | (rsi_3_4h > 75.0) | (rsi_3 < 85.0) | (roc_9_1h > 10.0))
            # 1h & 4h high, 1d down move
            & ((stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_60) | (rsi_3_1d_gt_65))
            # 15m up move, 1h overbought, 1d uptrend & down move & up move
            & ((stochrsi_k_1h_lt_90) | (aroonu_14_1d_lt_90) | (rsi_3_1d_gt_55) | (roc_9_1d_lt_20) | (rsi_3_15m_lt_60))
            # 1h & 4h high, 1d down move
            & ((stochrsi_k_1h_lt_90) | (aroonu_14_4h_lt_60) | (rsi_3_1d_gt_60))
            # 15m down move, 1h overbought & down move & up move, 1d up move
            & ((stochrsi_k_1h_lt_90) | (roc_9_1d_lt_35) | (roc_9_1h > 10.0) | (rsi_3_15m > 90.0) | (rsi_3_1h_lt_75))
            # 5m up move, 1h overbought, 4h down move, 1d downtrend
            & ((stochrsi_k_1h_lt_90) | (rsi_3_4h_gt_65) | (aroonu_14_1d_gt_0) | (rsi_3 < 75.0))
            # 1h downtrend, 4h still not low enough, 1d low
            & ((roc_9_1h > -2) | (stochrsi_k_4h_gt_75) | (aroonu_14_1d_gt_30))
            # 1h overbought, 1d still low & high
            & ((roc_9_1h_lt_10) | (aroonu_14_1d_gt_50) | (stochrsi_k_1d_lt_70))
            # 1h overbought, 1d low
            & ((roc_9_1h_lt_20) | (aroonu_14_1d_gt_10))
            # 15m down move, 4h up move & washed out, 1d down move & downtrend
            & (
              (rsi_3_4h_lt_90) | (stochrsi_k_4h_gt_60) | (roc_9_1d > 30.0) | (rsi_3_15m > 60.0) | (aroonu_14_1d > 95.0)
            )
            # 5m down move, 1h washed out, 4h down move & uptrend, 1d down move
            & ((rsi_3_4h_gt_45) | (rsi_3_1d_gt_60) | (stochrsi_k_1h_gt_70) | (rsi_3 > 90.0) | (aroonu_14_4h < 15.0))
            # 5m down move & still high, 1h washed out, 4h down move, 1d down move
            & ((rsi_3_4h_gt_45) | (rsi_3_1d_gt_65) | (stochrsi_k_1h_gt_70) | (rsi_3 > 90.0) | (stochrsi_k_lt_30))
            # 4h down move & high & overbought
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_60) | (roc_9_4h_lt_20))
            # 4h down move, 1d high & downtrend
            & ((rsi_3_4h_gt_60) | (aroonu_14_1d_lt_80) | (roc_9_1d_gt_30))
            # 4h down move & high, 1d overbought
            & ((rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_80) | (roc_9_1d_lt_30))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_65) | (aroonu_14_1d_lt_75) | (roc_9_1d_lt_60))
            # 4h down move, 1d high & overbought
            & ((rsi_3_4h_gt_65) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_60))
            # 5m up move, 15m still high, 1h uptrend, 4h down move, 1d up move
            & ((rsi_3_4h_gt_65) | (roc_9_1d_lt_40) | (rsi_3_lt_95) | (stochrsi_k_15m_lt_30) | (aroonu_14_1h < 5.0))
            # 1h still high, 4h uptrend, 1d down move & still high & up move
            & (
              (aroonu_14_4h_lt_40)
              | (rsi_3_1d_gt_40)
              | (stochrsi_k_1d_lt_20)
              | (stochrsi_k_1h_lt_70)
              | (roc_9_1d < -5.0)
            )
            # 15m down move, 1h still high, 4h uptrend, 1d down move & washed out
            & (
              (aroonu_14_4h_lt_90)
              | (rsi_3_1d_gt_55)
              | (stochrsi_k_1h_lt_70)
              | (rsi_3_15m > 60.0)
              | (stochrsi_k_1d_gt_30)
            )
            # 4h still not high enough, 4h & 1d overbought
            & ((aroonu_14_4h_gt_70) | (roc_9_4h_lt_15) | (roc_9_1d_lt_70))
            # 15m up move, 4h uptrend, 1d down move
            & ((aroonu_14_4h_lt_90) | (roc_9_1d_gt_neg_15) | (rsi_3_15m_lt_75))
            # 4h high & still high, 1d overbought
            & ((aroonu_14_4h_lt_90) | (stochrsi_k_4h_gt_30) | (roc_9_1d_lt_70))
            # 1h overbought, 4h still high & down move, 1d overbought & down move
            & (
              (stochrsi_k_4h_lt_40)
              | (stochrsi_k_1d_lt_90)
              | (roc_9_4h > 5.0)
              | (stochrsi_k_1h_lt_80)
              | (roc_9_1d > 20.0)
            )
            # 1h washed out & down move, 4h still high, 1d down move & downtrend
            & (
              (stochrsi_k_4h_lt_60)
              | (rsi_3_1d_gt_55)
              | (aroonu_14_1d_gt_50)
              | (stochrsi_k_1h > 85.0)
              | (roc_9_1h > 5.0)
            )
            # 5m uptrend, 1h down move, 4h still high, 1d still high & down move
            & (
              (stochrsi_k_4h_lt_70)
              | (stochrsi_k_1d_lt_70)
              | (roc_9_1d > 15.0)
              | (rsi_3_1h > 80.0)
              | (aroonu_14 < 55.0)
            )
            # 5m up move, 15m washed out, 1h still high, 4h overbought, 1d down move
            & (
              (stochrsi_k_4h_lt_90)
              | (rsi_3_1d_gt_60)
              | (stochrsi_k_15m > 25.0)
              | (rsi_3 < 75.0)
              | (stochrsi_k_1h < 55.0)
            )
            # 5m down move, 1h washed out & uptrend, 4h overbought, 1d washed out
            & (
              (stochrsi_k_4h_lt_90)
              | (stochrsi_k_1d_gt_30)
              | (rsi_3 > 90.0)
              | (stochrsi_k_1h_gt_90)
              | (aroonu_14_1h < 45.0)
            )
            # 4h stochastic up, or 4h making highs
            & ((stochrsi_k_4h > 50.0) | (aroonu_14_4h > 50.0))
            # 5m up move, 15m down move, 4h washed out, 1d up move & down move
            & ((stochrsi_k_4h_gt_30) | (rsi_3_1d_lt_80) | (rsi_3_lt_90) | (roc_9_1d > 40.0) | (rsi_3_15m > 90.0))
            # 5m up move, 1h washed out, 4h still high & down move, 1d up move
            & ((stochrsi_k_4h_lt_70) | (roc_9_1d_lt_35) | (roc_9_4h > 10.0) | (stochrsi_k_1h > 55.0) | (rsi_3 < 75.0))
            # 15m downtrend & up move, 4h overbought, 1d extended
            & ((stochrsi_k_4h_lt_80) | (roc_9_1d_lt_50) | (aroonu_14_15m_gt_0) | (rsi_3_15m_lt_75))
            # 4h & 1d high, 1d down move
            & ((stochrsi_k_4h_lt_80) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_70))
            # 5m down move, 4h overbought, 1d down move
            & ((stochrsi_k_4h_lt_90) | (rsi_3_1d_gt_30) | (rsi_3 > 70.0))
            # 5m downtrend & still high, 15m up move, 4h overbought, 1d down move
            & ((stochrsi_k_4h_lt_90) | (rsi_3_1d_gt_40) | (rsi_3_15m_lt_50) | (aroonu_14 > 95.0) | (stochrsi_k < 50.0))
            # 5m overbought & down move, 1h overbought, 4h down move, 1d uptrend
            & ((roc_9_4h > 5.0) | (aroonu_14_1d_lt_90) | (stochrsi_k < 95.0) | (stochrsi_k_1h < 95.0) | (rsi_3 > 95.0))
            # 5m up move, 15m washed out, 4h up move, 1d down move
            & ((roc_9_4h_lt_15) | (rsi_3_1d_gt_50) | (stochrsi_k_15m_gt_20) | (rsi_3 < 75.0))
            # 15m down move, 4h up move & uptrend, 1d down move & washed out
            & ((roc_9_4h_lt_5) | (rsi_3_1d_gt_60) | (rsi_3_15m_gt_55) | (aroonu_14_4h < 95.0) | (stochrsi_k_1d > 35.0))
            # 5m uptrend & washed out, 1h washed out, 1d down move & uptrend
            & (
              (rsi_3_1d_gt_55)
              | (aroonu_14_1d_lt_90)
              | (aroonu_14 < 80.0)
              | (stochrsi_k_1h > 95.0)
              | (stochrsi_k > 70.0)
            )
            # 5m downtrend, 15m up move, 1h washed out, 1d down move & uptrend
            & (
              (rsi_3_1d_gt_55) | (aroonu_14_1d_lt_90) | (stochrsi_k_1h_gt_75) | (aroonu_14 > 65.0) | (rsi_3_15m_lt_60)
            )
            # 5m up move, 15m overbought, 1d down move & extended & washed out
            & ((rsi_3_1d_gt_65) | (roc_9_1d_lt_50) | (stochrsi_k_15m < 90.0) | (stochrsi_k_1d > 25.0) | (rsi_3 < 65.0))
            # 5m uptrend, 4h down move, 1d RSI high & washed out & uptrend
            & (
              (rsi_14_1d_lt_60) | (stochrsi_k_1d_gt_60) | (roc_9_4h > 0.0) | (aroonu_14_1d_lt_90) | (aroonu_14 < 95.0)
            )
            # 5m still high, 4h down move & uptrend, 1d uptrend & washed out
            & (
              (aroonu_14_1d_lt_90)
              | (stochrsi_k_1d_gt_50)
              | (rsi_3_4h > 80.0)
              | (stochrsi_k < 60.0)
              | (aroonu_14_4h_lt_40)
            )
            # 15m still high, 4h downtrend, 1d uptrend & overbought & down move
            & (
              (aroonu_14_1d_lt_90)
              | (stochrsi_k_1d_lt_90)
              | (roc_9_1d > 15.0)
              | (aroonu_14_4h > 65.0)
              | (stochrsi_k_15m_lt_60)
            )
            # 5m uptrend & down move, 1d uptrend & washed out
            & ((aroonu_14_1d_lt_90) | (stochrsi_k_1d_gt_30) | (aroonu_14 < 10.0) | (rsi_3 > 90.0))
            # 15m & 1d overbought, 1d uptrend
            & ((aroond_14_1d > 20.0) | (roc_9_15m < 10.0) | (roc_9_1d_lt_60))
            # 5m overbought, 15m downtrend, 1d still high & down move & downtrend
            & (
              (stochrsi_k_1d_lt_40)
              | (roc_9_1d > 15.0)
              | (stochrsi_k < 95.0)
              | (aroonu_14_15m_gt_60)
              | (aroonu_14_1d > 95.0)
            )
            # 4h down move, 1d overbought & extended
            & ((stochrsi_k_1d_lt_90) | (roc_9_1d_lt_80) | (rsi_3_4h_gt_20))
            # 15m momentum snapping up, 4h a new high and 4h momentum snapping up
            & ((rsi_3_change_pct_15m < 70) | (aroonu_14_4h < 5) | (rsi_3_change_pct_4h < 65))
          )

          # Logic
          long_entry_logic.append(
            # trend side + momentum side (the frame proven on the engulfing pair)
            (close > ema_200)
            & (rsi_14 > 50.0)
            # hourly money-flow must support the ignition (no conviction candle in a bleed)
            & (cmf_20_1h > 0.02)
            # 4h trend must agree — conviction candles inside brief above-EMA windows of a
            # chronic downtrend are traps (the SOON cluster, verified on the chart)
            & (ema_12_4h > ema_200_4h)
            # full-body green candle: body >90% of range and a meaningful size
            & (mrb_bull > 0.5)
            # only above the daily 200 EMA: in a bear market the ignition is a rally being sold
            & (close > ema_200_1d)
          )

        # Condition #173 - Hammer pin-bar (Long, experimental, RAW — rejection wick at a dip).
        if long_entry_condition_index == 173:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            # 5m up move & base position high, 15m downtrend, 1h still high
            ((rsi_3 < 35.0) | (ph_base_pos < 14.0) | (aroonu_14_15m_gt_0) | (stochrsi_k_1h_lt_20))
            # 5m down move, 15m still not low enough, 4h high
            & ((rsi_3_gt_10) | (stochrsi_k_15m_lt_20) | (stochrsi_k_4h_lt_80))
            # 5m & 1h down move, 15m still high
            & ((rsi_3_gt_15) | (aroonu_14_15m_lt_40) | (rsi_3_1h_gt_20))
            # 5m down move, 15m & 1d high
            & ((rsi_3_gt_15) | (aroonu_14_15m_lt_80) | (stochrsi_k_1d_lt_80))
            # 5m down move & downtrend, 15m up move, 1h down move
            & ((rsi_3_gt_15) | (rsi_3_1h_gt_45) | (rsi_3_15m < 40.0) | (aroonu_14 > 0.0))
            # 5m down move, 1h still high, 4h overbought
            & ((rsi_3_gt_15) | (stochrsi_k_1h_lt_40) | (roc_9_4h_lt_5))
            # 5m down move, 1h still high, 4h high
            & ((rsi_3_gt_15) | (stochrsi_k_1h_lt_40) | (stochrsi_k_4h_lt_80))
            # 5m down move, 15m high, 1h still not low enough
            & ((rsi_3_gt_5) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_lt_20))
            # 5m money leaving, 15m up move, 4h downtrend, 1d RSI low
            & ((mfi_14 > 25.0) | (rsi_14_1d_gt_60) | (rsi_3_15m < 35.0) | (aroonu_14_4h > 25.0))
            # 5m still not low enough, 15m high, 4h down move
            & ((aroonu_14_lt_25) | (aroonu_14_15m_lt_60) | (rsi_3_4h_gt_40))
            # 5m uptrend & up move, 4h overbought, 1d downtrend
            & ((aroonu_14_lt_25) | (stochrsi_k_4h_lt_90) | (aroonu_14_1d > 15.0) | (rsi_3 < 35.0))
            # 5m uptrend & up move, 15m RSI low, 1d uptrend
            & ((aroonu_14_lt_30) | (rsi_14_15m > 30.0) | (aroonu_14_1d_lt_90) | (rsi_3 < 15.0))
            # 5m uptrend, 15m down move & downtrend, 4h down move
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_10) | (roc_9_4h > 0.0) | (aroonu_14_15m_gt_10))
            # 5m still not low enough, 15m & 4h down move
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_20) | (rsi_3_4h_gt_30))
            # 5m still not low enough, 15m down move, 1h high
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_60))
            # 5m still not low enough, 1h down move, 4h overbought
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_30) | (roc_9_4h_lt_5))
            # 5m still not low enough, 4h down move & high
            & ((aroonu_14_lt_30) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_80))
            # 5m still not low enough, 4h down move & overbought
            & ((aroonu_14_lt_30) | (rsi_3_4h_gt_60) | (roc_9_4h_lt_20))
            # 5m uptrend & down move, 1h washed out, 4h up move, 1d overbought
            & ((aroonu_14_lt_30) | (stochrsi_k_1d_lt_80) | (rsi_3_4h_lt_85) | (stochrsi_k_1h_gt_20) | (rsi_3 > 25.0))
            # 5m still not low enough, 1h & 4h high
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_lt_80) | (aroonu_14_4h_lt_80))
            # 5m uptrend, 15m down move, 1h overbought, 4h still high
            & ((aroonu_14_lt_30) | (stochrsi_k_4h_lt_40) | (stochrsi_k_1h < 95.0) | (rsi_3_15m_gt_40))
            # 5m still not low enough, 15m & 1d down move
            & ((stochrsi_k_lt_20) | (rsi_3_15m_gt_30) | (rsi_3_1d_gt_65))
            # 5m still not low enough, 1h high, 1d down move
            & ((stochrsi_k_lt_20) | (stochrsi_k_1h_lt_60) | (rsi_3_1d_gt_65))
            # 5m still not low enough, 1h high, 1d overbought
            & ((stochrsi_k_lt_30) | (aroonu_14_1h_lt_75) | (roc_9_1d_lt_60))
            # 5m & 1h still not low enough, 15m down move
            & ((stochrsi_k_lt_30) | (rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_20))
            # 5m still not low enough, 1h & 4h down move
            & ((stochrsi_k_lt_30) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20))
            # 5m still not low enough, 4h still high, 1d down move
            & ((stochrsi_k_lt_30) | (stochrsi_k_4h_lt_40) | (rsi_3_1d_gt_60))
            # 15m down move & still not low enough, 1d overbought
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_20) | (roc_9_1d_lt_200))
            # 5m up move, 15m down move, 1d stochk 14 3 3 low
            & ((rsi_3_15m_gt_20) | (stochk_14_3_3_1d > 30.0) | (rsi_3 < 35.0))
            # 15m down move & still not low enough, 1h high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_20) | (stochrsi_k_1h_lt_60))
            # 5m down move, 15m down move & downtrend, 1h overbought, 1d up move
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_80) | (roc_9_1d_lt_20) | (aroonu_14_15m > 25.0) | (rsi_3_gt_15))
            # 15m down move, 4h extended & washed out
            & ((rsi_3_15m_gt_30) | (roc_9_4h_lt_50) | (stochrsi_k_4h > 55.0))
            # 5m up move, 15m down move & up move
            & ((rsi_3_15m_gt_35) | (roc_9_15m < 1.5) | (rsi_3 < 35.0))
            # 15m still not low enough, 4h down move, 1d high
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_90))
            # 15m & 1h still not low enough, 1d downtrend
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_lt_20) | (roc_9_1d_gt_neg_10))
            # 15m still high, 1d down move & high
            & ((aroonu_14_15m_lt_40) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_90))
            # 15m still high, 1h & 1d down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_30) | (rsi_3_1d_gt_30))
            # 15m high, 1h still not low enough, 4h down move
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_25) | (rsi_3_4h_gt_50))
            # 15m uptrend & down move, 1h on the floor, 4h down move
            & ((aroonu_14_15m_lt_60) | (rsi_3_4h_gt_40) | (rsi_3_15m_gt_10) | (stochrsi_k_1h > 15.0))
            # 15m high, 4h down move & overbought
            & ((aroonu_14_15m_lt_60) | (rsi_3_4h_gt_65) | (roc_9_4h_lt_10))
            # 15m & 1h high, 1h down move
            & ((aroonu_14_15m_lt_80) | (rsi_3_1h_gt_65) | (stochrsi_k_1h_lt_80))
            # 15m & 4h high, 4h down move
            & ((aroonu_14_15m_lt_80) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_60))
            # 15m on the floor, 4h downtrend & washed out, 1d RSI low & washed out
            & (
              (stochrsi_k_15m_gt_10)
              | (rsi_14_1d_gt_60)
              | (aroonu_14_4h_gt_10)
              | (stochrsi_k_4h_gt_50)
              | (stochrsi_k_1d > 35.0)
            )
            # 15m still not low enough, 4h high & overbought
            & ((stochrsi_k_15m_lt_20) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_15))
            # 15m still not low enough, 1h & 1d down move
            & ((stochrsi_k_15m_lt_30) | (rsi_3_1h_gt_30) | (rsi_3_1d_gt_60))
            # 15m still high, 1h & 1d down move
            & ((stochrsi_k_15m_lt_40) | (rsi_3_1h_gt_60) | (rsi_3_1d_gt_50))
            # 15m still high, 4h high & overbought
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_4h_lt_80) | (roc_9_4h_lt_10))
            # 15m still high, 1h high, 4h overbought
            & ((stochrsi_k_15m_lt_50) | (aroonu_14_1h_lt_75) | (roc_9_4h_lt_5))
            # 15m & 4h still high, 1h down move
            & ((stochrsi_k_15m_lt_50) | (rsi_3_1h_gt_50) | (stochrsi_k_4h_lt_50))
            # 15m still high, 1h uptrend, 4h downtrend, 1d up move
            & ((stochrsi_k_15m_lt_60) | (roc_9_1d_lt_40) | (aroonu_14_4h > 15.0) | (aroonu_14_1h < 55.0))
            # 15m high, 1h down move, 4h still high
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_50) | (aroonu_14_4h_lt_40))
            # 15m & 1h high, 4h still not low enough
            & ((stochrsi_k_15m_lt_70) | (stochrsi_k_1h_lt_60) | (stochrsi_k_4h_lt_20))
            # 15m high, 1h still not low enough, 4h overbought
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_25) | (roc_9_4h_lt_5))
            # 15m high, 1h still high, 4h down move
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_50) | (rsi_3_4h_gt_60))
            # 5m up move, 15m up move, 1h money coming in
            & ((roc_9_15m < 1.5) | (mfi_14_1h < 80.0) | (rsi_3 < 35.0))
            # 1h & 1d down move, 1h still not low enough
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1h_lt_20) | (rsi_3_1d_gt_60))
            # 1h down move, 1h & 1d high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_1h_lt_60) | (stochrsi_k_1d_lt_80))
            # 5m still high & uptrend, 1h money coming in, 4h UO low & up move
            & ((cmf_20_1h < 0.1) | (uo_7_14_28_4h > 50.0) | (rsi_3_4h_lt_75) | (stochrsi_k < 5.0) | (aroonu_14_lt_25))
            # 1h still not low enough, 4h down move & high
            & ((aroonu_14_1h_lt_20) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_60))
            # 1h high, 4h down move & overbought
            & ((aroonu_14_1h_lt_75) | (rsi_3_4h_gt_65) | (roc_9_4h_lt_10))
            # 1h still not low enough, 4h down move & still high
            & ((stochrsi_k_1h_lt_20) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_40))
            # 1h still not low enough, 4h down move & high
            & ((stochrsi_k_1h_lt_20) | (rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80))
            # 1h still not low enough, 4h down move & high
            & ((stochrsi_k_1h_lt_20) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_60))
            # 1h & 4h still high, 4h down move
            & ((stochrsi_k_1h_lt_50) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_lt_40))
            # 1h still high, 4h overbought & down move, 1d downtrend
            & ((stochrsi_k_1h_lt_50) | (stochrsi_k_4h_lt_90) | (rsi_3_4h > 85.0) | (aroonu_14_1d_gt_0))
            # 1h high, 4h down move & still high
            & ((stochrsi_k_1h_lt_60) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_40))
            # 1h & 4h & 1d high
            & ((stochrsi_k_1h_lt_60) | (stochrsi_k_4h_lt_80) | (stochrsi_k_1d_lt_90))
            # 1h & 4h high, 1d down move
            & ((stochrsi_k_1h_lt_80) | (aroonu_14_4h_lt_60) | (rsi_3_1d_gt_60))
            # 5m still high, 1h overbought, 4h down move
            & ((stochrsi_k_1h_lt_80) | (rsi_3_4h_gt_45) | (stochrsi_k < 15.0))
            # 4h & 1d down move, 4h still high
            & ((rsi_3_4h_gt_50) | (stochrsi_k_4h_lt_40) | (rsi_3_1d_gt_60))
            # 4h & 1d down move, 4h overbought
            & ((rsi_3_4h_gt_65) | (roc_9_4h_lt_5) | (rsi_3_1d_gt_60))
            # 15m up move, 4h still high, 1d down move
            & ((stochrsi_k_4h_lt_40) | (rsi_3_1d_gt_35) | (rsi_3_15m < 35.0))
            # 15m downtrend, 1d down move & up move & downtrend
            & ((rsi_3_1d_gt_65) | (roc_9_1d_lt_20) | (aroonu_14_1d_gt_0) | (aroonu_14_15m_gt_0))
          )

          # Logic
          long_entry_logic.append(
            # dip context: near the 4h low, 5m washed
            (close < (close_min_48 * 1.03))
            & (rsi_3 < 40.0)
            # the fact: long lower rejection wick, tiny upper wick
            & (pb_hammer > 0.5)
            # 4h trend must agree — a rejection inside a 4h downtrend gets broken
            & (ema_12_4h > ema_200_4h)
            # only above the daily 200 EMA: in a bear market the low keeps breaking
            & (close > ema_200_1d)
          )

        # Condition #174 - Closed-hour NR4 breakout, scalp mode (Long).
        if long_entry_condition_index == 174:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          # strict comparisons throughout, so a NaN clause reads as false rather than passing
          long_entry_logic.append(
            # # 15m down move, 1h & 1d high
            ((rsi_3_15m_gt_50) | (stochrsi_k_1h_lt_90) | (stochrsi_k_1d_lt_80))
            # # 15m down move, 1h & 4h overbought
            & ((rsi_3_15m_gt_55) | (roc_9_1h_lt_10) | (roc_9_4h_lt_25))
            # # 15m & 1d down move, 1d still high
            & ((rsi_3_15m_gt_55) | (rsi_3_1d_gt_65) | (stochrsi_k_1d_lt_50))
            # # 15m & 1d down move, 15m high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_70) | (rsi_3_1d_gt_60))
            # # 15m & 1h high, 4h down move
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_1h_lt_90) | (rsi_3_4h_gt_50))
            # # 15m & 4h high, 1d down move
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_4h_lt_70) | (rsi_3_1d_gt_50))
            # # 15m high, 4h down move & downtrend
            & ((stochrsi_k_15m_lt_70) | (rsi_3_4h_gt_60) | (roc_9_4h_gt_neg_10))
            # # 15m high, 1d down move & overbought
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_20))
            # # 15m high, 4h down move & still high
            & ((stochrsi_k_15m_lt_80) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_40))
            # # 15m high, 4h down move, 1d overbought
            & ((stochrsi_k_15m_lt_80) | (rsi_3_4h_gt_45) | (roc_9_1d_lt_30))
            # # 15m & 1h high, 4h overbought
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_70) | (roc_9_4h_lt_70))
            # # 15m & 1h high, 1h overbought
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_1h_lt_90) | (roc_9_1h_lt_40))
            # # 1h high, 4h down move & still not low enough
            & ((stochrsi_k_1h_lt_80) | (rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_30))
            # # 1h high, 4h down move & still high
            & ((stochrsi_k_1h_lt_90) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_40))
            # # 1h & 4h high, 1d down move
            & ((stochrsi_k_1h_lt_90) | (stochrsi_k_4h_lt_80) | (rsi_3_1d_gt_40))
            # # 4h & 1d down move, 4h still not low enough
            & ((rsi_3_4h_gt_65) | (aroonu_14_4h_lt_30) | (rsi_3_1d_gt_50))
            # # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_65) | (rsi_3_1d_gt_50) | (stochrsi_k_1d_lt_80))
            # # 4h down move, 4h & 1d high
            & ((rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_60) | (stochrsi_k_1d_lt_90))
            # # 4h & 1d down move, 4h high
            & ((rsi_3_4h_gt_65) | (stochrsi_k_4h_lt_70) | (rsi_3_1d_gt_60))
            # # 4h high, 1d down move & overbought
            & ((aroonu_14_4h_lt_60) | (rsi_3_1d_gt_55) | (roc_9_1d_lt_0))
            # # 4h high, 1d down move & still high
            & ((aroonu_14_4h_lt_80) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_40))
            # # 4h still high, 1d down move & high
            & ((stochrsi_k_4h_lt_40) | (rsi_3_1d_gt_55) | (stochrsi_k_1d_lt_80))
            # # 4h high, 1d down move & overbought
            & ((stochrsi_k_4h_lt_60) | (rsi_3_1d_gt_50) | (roc_9_1d_lt_20))
            # # 4h & 1d high, 1d down move
            & ((stochrsi_k_4h_lt_70) | (rsi_3_1d_gt_50) | (aroonu_14_1d_lt_80))
            # # 4h & 1d overbought, 1d down move
            & ((roc_9_4h_lt_15) | (rsi_3_1d_gt_60) | (roc_9_1d_lt_40))
            # 1d high & overbought
            & ((stochrsi_k_1d_lt_90) | (roc_9_1d_lt_20) | (rsi_14_15m > 70))
            # 15m high, 1h down move
            & ((stochrsi_k_15m_lt_70) | (rsi_3_1h > 85) | (rsi_3_1d < 90))
            # 5m down move, 1d downtrend
            & ((rsi_3 > 60) | (roc_9_1d > 10) | (aroonu_14 < 90))
            # 4h overbought, 1d high
            & ((roc_9_4h_lt_10) | (stochrsi_k_1d_lt_90) | (rsi_14_15m > 70))
            # 1h downtrend, 1d overbought
            & ((roc_9_1h > 5) | (roc_9_1d_lt_20) | (stochrsi_k_1h < 95))
            # 4h & 1d high
            & ((stochrsi_k_4h_lt_90) | (stochrsi_k_1d_lt_90) | (aroonu_14_1d > 95))
            # 1h down move & high, 4h overbought
            & ((rsi_3_1h > 85) | (stochrsi_k_1h_lt_90) | (roc_9_4h_lt_5))
            # 1d low
            & ((aroonu_14_1d_gt_20) | (stochrsi_k_1d_gt_40) | (rsi_3_1d < 70))
            # 15m & 4h up move
            & ((rsi_3_15m_lt_95) | (rsi_3_4h_lt_95) | (stochrsi_k > 70))
            # 15m high, 4h overbought
            & ((stochrsi_k_15m_lt_70) | (roc_9_4h_lt_25) | (aroonu_14_1d > 30))
            # 1h down move, 4h overbought
            & ((rsi_3_1h > 85) | (roc_9_4h_lt_40) | (rsi_3_15m < 80))
            # 1h down move, 1d up move
            & ((rsi_3_1h > 85) | (rsi_3_1d_lt_95) | (rsi_3 < 70))
            # 1h low, 4h high
            & ((stochrsi_k_1h_gt_30) | (stochrsi_k_4h_lt_90) | (stochrsi_k > 65))
            # 15m low, 1d up move
            & ((stochrsi_k_15m_gt_50) | (rsi_3_1d_lt_95) | (rsi_14_change_pct_15m < 3))
            # 5m down move, 1d overbought
            & ((rsi_3 > 50) | (roc_9_1d_lt_60) | (aroonu_14_4h > 95))
            # 5m high, 1d down move
            & ((aroonu_14 < 95) | (rsi_3_1d_gt_65) | (rsi_14 > 64))
            # 15m up move, 1d low
            & ((rsi_3_15m_lt_85) | (aroonu_14_1d_gt_20) | (rsi_3_1d < 90))
            # 15m up move & low
            & ((rsi_3_15m_lt_90) | (stochrsi_k_15m_gt_40) | (roc_9_1d > 20))
            # 1h up move, 1d low
            & ((rsi_3_1h_lt_95) | (aroonu_14_1d_gt_20) | (stochrsi_k > 55))
            # 1h down move & downtrend
            & ((rsi_3_1h > 80) | (roc_9_1h > 5) | (roc_9_4h < 10))
            # 1h down move & high
            & ((rsi_3_1h > 80) | (stochrsi_k_1h_lt_90) | (stochrsi_k_15m < 85))
            # 1h down move, 4h high
            & ((rsi_3_1h > 85) | (stochrsi_k_4h_lt_90) | (rsi_3_4h > 75))
            # 1d down move & overbought
            & ((rsi_3_1d_gt_55) | (roc_9_1d_lt_20) | (aroonu_14_4h < 55))
            # 1h down move, 1d high
            & ((rsi_3_1h > 80) | (stochrsi_k_1d_lt_90) | (aroonu_14_4h > 45))
            # 5m up move, 4h low
            & ((rsi_3_lt_97) | (aroonu_14_4h_gt_20) | (rsi_14_15m > 70))
            # 15m low, 1h downtrend
            & ((stochrsi_k_15m_gt_70) | (roc_9_1h > 5) | (rsi_3 < 85))
            # 15m overbought, 1h high
            & ((roc_9_15m < 10) | (stochrsi_k_1h_lt_90) | (roc_9_1d > 10))
            # 15m overbought, 4h high
            & ((roc_9_15m < 15) | (stochrsi_k_4h_lt_90) | (rsi_3_1h > 90))
            # 1h down move, 4h downtrend
            & ((rsi_3_1h > 90) | (roc_9_4h > -3) | (rsi_3 < 85))
            # 4h low & high, 1d overbought
            & ((aroonu_14_4h_gt_50) | (stochrsi_k_4h_lt_60) | (roc_9_1d_lt_25))
            # 1h high, 1d downtrend
            & ((stochrsi_k_1h_lt_90) | (roc_9_1d > 10) | (roc_2_1d < 10))
            # 5m up move, 15m low
            & ((rsi_3_lt_90) | (aroonu_14_15m > 95) | (aroonu_14_1d > 30))
            # 1h up move, 4h low, 1d high
            & ((rsi_3_1h_lt_95) | (aroonu_14_4h_gt_30) | (aroonu_14_1d_lt_90))
            # 15m & 4h low, 4h up move
            & ((stochrsi_k_15m_gt_50) | (rsi_3_4h_lt_90) | (stochrsi_k_4h_gt_50))
            # 1h down move, 4h high
            & ((rsi_3_1h > 90) | (stochrsi_k_4h_lt_80) | (stochrsi_k_1h < 95))
            # 5m down move, 1d downtrend
            & ((rsi_3 > 80) | (roc_9_1d > 0) | (stochrsi_k < 90))
            # 4h low & high
            & ((aroonu_14_4h_gt_10) | (stochrsi_k_4h_lt_80))
            # 1h down move & low, 1d high
            & ((rsi_3_1h > 85) | (stochrsi_k_1h_gt_60) | (stochrsi_k_1d_lt_90))
            # 5m down move, 15m overbought
            & ((rsi_3 > 35) | (roc_9_15m < 1.5) | (rsi_14_1h > 65))
            # 4h & 1d high, 1d downtrend
            & ((aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_90) | (roc_9_1d > 5))
            # 4h down move & high
            & ((rsi_3_4h_gt_60) | (aroonu_14_4h_lt_80) | (aroonu_14_1d > 30))
            # 4h up move & downtrend
            & ((rsi_3_4h_lt_85) | (roc_9_4h > 2) | (rsi_3_change_pct_1h < 30))
            # 1d low & overbought
            & ((aroonu_14_1d_gt_20) | (roc_9_1d_lt_10) | (rsi_3 > 75))
            # 5m up move, 1h overbought
            & ((rsi_3_lt_97) | (roc_9_1h_lt_10) | (aroonu_14_1d < 90))
            # 4h downtrend, 1d overbought
            & ((roc_9_4h > 2) | (roc_9_1d_lt_10) | (rsi_3_4h < 85))
            # 1h downtrend, 4h high
            & ((roc_9_1h > 5) | (aroonu_14_4h_lt_90) | (stochrsi_k_4h > 70))
            # 15m & 1h low
            & ((stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_70) | (roc_9_1d < 30))
            # 1h & 1d down move
            & ((rsi_3_1h > 80) | (rsi_3_1d_gt_60) | (rsi_3_15m < 90))
            # 4h downtrend, 1d high
            & ((roc_9_4h > 2) | (stochrsi_k_1d_lt_70) | (rsi_3_4h < 85))
            # 4h high & low
            & ((aroonu_14_4h_lt_90) | (stochrsi_k_4h_gt_40) | (stochrsi_k_15m < 95))
            # 5m down move, 1d high
            & ((rsi_3 > 65) | (stochrsi_k_1d_lt_80) | (aroonu_14_4h > 25))
            # 4h & 1d high
            & ((aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_90) | (rsi_14_1h > 65))
            # 1h & 4h high
            & ((stochrsi_k_1h_lt_90) | (aroonu_14_4h_lt_90) | (rsi_3_change_pct_1h < 30))
            # 5m up move, 1d high
            & ((rsi_3_lt_98) | (stochrsi_k_1d_lt_80) | (rsi_14_4h < 70))
            # 4h & 1d high
            & ((stochrsi_k_4h_lt_60) | (aroonu_14_1d_lt_90) | (rsi_14_1h > 65))
            # 5m down move & high
            & ((rsi_3 > 80) | (aroonu_14 < 95) | (stochrsi_k_1d < 95))
            # 5m down move, 1h high
            & ((rsi_3 > 75) | (stochrsi_k_1h_lt_90) | (rsi_3_change_pct_1h < 30))
            # 1h & 4h high
            & ((stochrsi_k_1h_lt_80) | (aroonu_14_4h_lt_70) | (rsi_3_4h > 75))
            # 15m & 4h up move
            & ((rsi_3_15m_lt_95) | (rsi_3_4h_lt_95) | (roc_9_4h > 10))
            # 1h downtrend, 4h overbought
            & ((roc_9_1h > 5) | (roc_9_4h_lt_5) | (stochrsi_k_4h > 65))
            # 5m & 4h up move
            & ((rsi_3_lt_90) | (rsi_3_4h_lt_95) | (roc_9_4h > 10))
            # 1h high, 1d low
            & ((stochrsi_k_1h_lt_90) | (stochrsi_k_1d_gt_20) | (roc_2 > -0))
            # 15m low, 1h high
            & ((stochrsi_k_15m_gt_30) | (stochrsi_k_1h_lt_90) | (stochrsi_k_4h < 90))
            # 1h up move & downtrend
            & ((rsi_3_1h_lt_95) | (roc_9_1h > 5) | (stochrsi_k < 95))
            # 5m down move, 15m up move
            & ((rsi_3 > 70) | (rsi_3_15m_lt_95) | (rsi_3_1h < 95))
            # 4h still high & downtrend
            & ((stochrsi_k_4h_lt_50) | (roc_9_4h > 2) | (rsi_14_4h < 68))
            # 5m low, 15m up move
            & ((aroonu_14_gt_75) | (rsi_3_15m_lt_80) | (stochrsi_k_15m > 75))
            # 4h low & high
            & ((aroonu_14_4h_gt_70) | (stochrsi_k_4h_lt_60) | (rsi_3_change_pct_4h < 50))
            # 5m & 1d high
            & ((aroonu_14 < 95) | (aroonu_14_1d_lt_90) | (rsi_14 > 64))
            # 1h up move & low
            & ((rsi_3_1h_lt_90) | (stochrsi_k_1h_gt_75) | (aroonu_14_1d > 60))
            # 15m low, 4h down move
            & ((aroonu_14_15m > 95) | (rsi_3_4h_gt_65) | (rsi_3_change_pct_4h < 50))
            # 5m down move, 1d high
            & ((rsi_3 > 55) | (stochrsi_k_1d_lt_70) | (stochrsi_k < 80))
            # 4h downtrend, 1d low
            & ((roc_9_4h > 2) | (stochrsi_k_1d_gt_30) | (rsi_3 < 90))
            # 4h low & high
            & ((aroonu_14_4h_gt_50) | (stochrsi_k_4h_lt_60) | (stochrsi_k > 50))
            # 1d up move & low
            & ((rsi_3_1d_lt_80) | (stochrsi_k_1d_gt_40) | (aroonu_14_1d > 40))
            # 5m down move, 1h overbought
            & ((rsi_3 > 70) | (roc_9_1h_lt_15) | (stochrsi_k < 85))
            # 4h overbought, 1d downtrend
            & ((roc_9_4h_lt_15) | (roc_9_1d > 15) | (rsi_3_1d < 90))
            # 4h high, 1d down move
            & ((stochrsi_k_4h_lt_90) | (rsi_3_1d_gt_60) | (rsi_3 > 55))
          )

          # Logic
          long_entry_logic.append(
            s174_hour_closed
            & (s174_event_1h > 0.5)
            & (ema_12_1h > ema_200_1h)
            & (ema_12_4h > ema_200_4h)
            & np.isfinite(volume)
            & (volume > 0)
            # the 4h also needs a direction to break into. A flat 4h leaves the position sitting
            # until the 14-day abandon rule closes it, and that is the single largest exit among
            # the raw losses (140 of 384 across the 35 measured windows)
            & (adx_14_4h > 15.0)
            # and not a falling knife on the day: the liquidations sit below this
            & (rsi_3_1d > 25.0)
          )

        # Condition #192 - Quad-rotation stochastic pullback (Long, experimental).
        if long_entry_condition_index == 192:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            # 5m & 15m down move, 15m high
            ((rsi_3_gt_10) | (rsi_3_15m_gt_35) | (aroonu_14_15m_lt_70))
            # 5m & 15m down move, 15m still high
            & ((rsi_3_gt_15) | (rsi_3_15m_gt_30) | (stochrsi_k_15m_lt_40))
            # 5m & 1h & 4h still not low enough
            & ((aroonu_14_lt_25) | (aroonu_14_1h_lt_20) | (stochrsi_k_4h_lt_20))
            # 5m & 1h still not low enough, 15m down move
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_55) | (aroonu_14_1h_lt_20))
            # 5m still not low enough, 15m & 4h down move
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_50) | (rsi_3_4h_gt_40))
            # 5m still not low enough, 15m still high, 1h high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_lt_50) | (stochrsi_k_1h_lt_90))
            # 15m down move, 1h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_75) | (stochrsi_k_1h_lt_80))
            # 15m spent while the day is not yet stretched
            & ((rsi_3_15m_gt_30) | (stochrsi_k_1d_lt_90))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_75) | (aroonu_14_1h_lt_75))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_90) | (stochrsi_k_1h_lt_90))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_lt_50) | (rsi_3_4h_gt_60))
            # 15m down move, 1h high, 1d downtrend
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_lt_75) | (roc_9_1d_gt_neg_15))
            # 15m down move & high, 1h still not low enough
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_20))
            # 15m & 1d down move, 4h still not low enough
            & ((rsi_3_15m_gt_45) | (stochrsi_k_4h_lt_20) | (rsi_3_1d_gt_30))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_40) | (stochrsi_k_4h_lt_80))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_50) | (rsi_3_1h_gt_50) | (aroonu_14_1h_lt_50))
            # 15m down move, 15m & 1h high
            & ((rsi_3_15m_gt_55) | (stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_75))
            # 15m high, 4h still not low enough, 1d down move
            & ((aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_20) | (rsi_3_1d_gt_20))
            # 15m & 1d high, 4h down move
            & ((aroonu_14_15m_lt_70) | (rsi_3_4h_gt_40) | (stochrsi_k_1d_lt_80))
            # 15m & 1h high, 1d down move
            & ((aroonu_14_15m_lt_75) | (aroonu_14_1h_lt_75) | (rsi_3_1d_gt_30))
            # 15m & 4h high
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_lt_60) | (stochrsi_k_4h_lt_80))
            # 15m & 1h high
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_lt_80) | (aroonu_14_1h_lt_75))
            # 15m high, 4h & 1d still not low enough
            & ((stochrsi_k_15m_lt_60) | (aroonu_14_4h_lt_20) | (aroonu_14_1d_lt_30))
            # 1h trend intact, day not washed out
            & ((aroonu_14_1h_lt_25) | (rsi_3_1d_gt_10))
            # 1h & 4h high, 1d down move
            & ((aroonu_14_1h_lt_75) | (aroonu_14_4h_lt_75) | (rsi_3_1d_gt_50))
            # 1h high, 1d down move & overbought
            & ((stochrsi_k_1h_lt_80) | (roc_9_1d_lt_0) | (rsi_3_1d_gt_50))
            # 4h & 1d down move, 1d still not low enough
            & ((rsi_3_4h_gt_60) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_lt_20))
          )

          # Logic
          long_entry_logic.append(
            # embedded up-regime + quad-oversold pullback + 5-candle shift kink
            (stoch_60_10 > 80.0)
            & (stoch_9_3 < 20.0)
            & (stoch_14_3 < 20.0)
            & (stoch_4_4 < 20.0)
            & (close < np_shift(close, 5))
            & (stoch_9_3 > np_shift(stoch_9_3, 5))
          )

        # Condition #193 - Quad-rotation TRUE pivot divergence (Long, experimental).
        if long_entry_condition_index == 193:
          # Protections
          long_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          long_entry_logic.append(protections_long_global == True)
          long_entry_logic.append(
            # 15m & 1d down move, 15m high
            ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_80) | (rsi_3_1d_gt_20))
            # 15m down move, 1h still not low enough, 1d still high
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_lt_50))
            # 15m down move & still not low enough, 1h high
            & ((rsi_3_15m_gt_30) | (stochrsi_k_15m_lt_20) | (aroonu_14_1h_lt_75))
            # 15m & 1h down move
            & ((rsi_3_15m_gt_40) | (rsi_3_1h > 80.0))
            # 15m down move & still not low enough, 4h high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_20) | (stochrsi_k_4h_lt_80))
            # 15m down move & still not low enough, 1h downtrend
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_lt_30) | (roc_9_1h_gt_neg_10))
          )

          # Logic
          long_entry_logic.append(
            # embedded up-regime + quad-oversold
            (stoch_60_10 > 80.0)
            & (stoch_9_3 < 20.0)
            & (stoch_14_3 < 20.0)
            & (stoch_4_4 < 20.0)
            # price LOWER-LOW across swing windows while stoch makes a HIGHER-LOW (real divergence)
            & (quad_low_min_12 < np_shift(quad_low_min_12, 12))
            & (quad_s93_min_12 > np_shift(quad_s93_min_12, 12))
          )

        long_entry_logic.append(df["volume"] > 0)
        item_long_entry = _and_entry_conditions(long_entry_logic)
        _append_entry_tag(entry_tags, item_long_entry, f"{long_entry_condition_index} ")
        long_entry_conditions.append(item_long_entry)
        df.loc[:, "enter_long"] = item_long_entry.astype(int)

        ###############################################################################################

        # LONG ENTRY CONDITIONS ENDS HERE

        ###############################################################################################

    if long_entry_conditions:
      df.loc[:, "enter_long"] = _or_entry_conditions(long_entry_conditions).astype(int)

    ###############################################################################################

    # SHORT ENTRY CONDITIONS STARTS HERE

    ###############################################################################################

    #   ______  __    __  ______  _______ ________        ________ __    __ ________ ________ _______
    #  /      \|  \  |  \/      \|       |        \      |        |  \  |  |        |        |       \
    # |  $$$$$$| $$  | $|  $$$$$$| $$$$$$$\$$$$$$$$      | $$$$$$$| $$\ | $$\$$$$$$$| $$$$$$$| $$$$$$$\
    # | $$___\$| $$__| $| $$  | $| $$__| $$ | $$         | $$__   | $$$\| $$  | $$  | $$__   | $$__| $$
    #  \$$    \| $$    $| $$  | $| $$    $$ | $$         | $$  \  | $$$$\ $$  | $$  | $$  \  | $$    $$
    #  _\$$$$$$| $$$$$$$| $$  | $| $$$$$$$\ | $$         | $$$$$  | $$\$$ $$  | $$  | $$$$$  | $$$$$$$\
    # |  \__| $| $$  | $| $$__/ $| $$  | $$ | $$         | $$_____| $$ \$$$$  | $$  | $$_____| $$  | $$
    #  \$$    $| $$  | $$\$$    $| $$  | $$ | $$         | $$     | $$  \$$$  | $$  | $$     | $$  | $$
    #   \$$$$$$ \$$   \$$ \$$$$$$ \$$   \$$  \$$          \$$$$$$$$\$$   \$$   \$$   \$$$$$$$$\$$   \$$
    #

    for enabled_short_entry_signal in short_entry_signal_params:
      short_entry_condition_index = int(enabled_short_entry_signal.rsplit("_", 2)[1])
      if short_entry_signal_params[enabled_short_entry_signal]:
        # Short Entry Conditions Starts Here
        # -----------------------------------------------------------------------------------------
        # IMPORTANT: Short Condition Descriptions are not for shorts. These are for longs but completely mirrored opposite side
        # Please dont change these comment descriptions. With these descriptions we are comparing long/short positions.

        short_entry_logic = []
        short_entry_logic.append(True)

        # Condition #501 - Normal mode (Short).
        if short_entry_condition_index == 501:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(global_protections_short_pump == True)
          short_entry_logic.append(global_protections_short_dump == True)

          short_entry_logic.append(rsi_3_1h >= 5.0)
          short_entry_logic.append(rsi_3_4h >= 20.0)
          short_entry_logic.append(rsi_3_1d >= 20.0)
          short_entry_logic.append(rsi_14_1h_gt_20)
          short_entry_logic.append(rsi_14_4h_gt_20)
          short_entry_logic.append(rsi_14_1d_gt_10)
          short_entry_logic.append(
            # 5m up move, 4h still not high enough
            ((rsi_3_lt_97) | (aroonu_14_4h > 60.0))
            # 5m up move, 4h still low
            & ((rsi_3_lt_97) | (stochrsi_k_4h_gt_50))
            # 5m & 15m strong up move
            & ((rsi_3_lt_95) | (rsi_3_15m_lt_95))
            # 5m & 1h up move, 1d uptrend
            & ((rsi_3_lt_95) | (rsi_3_1h_lt_90) | (roc_9_1d_lt_100))
            # 5m up move, 15m & 1h still not high enough
            & ((rsi_3_lt_95) | (aroond_14_15m_lt_25) | (aroond_14_1h_lt_25))
            # 4m up move, 1h & 4h still low
            & ((rsi_3_lt_95) | (stochrsi_k_1h_gt_70) | (stochrsi_k_4h_gt_70))
            # 4m & 1h up move, 1h still low
            & ((rsi_3_lt_90) | (rsi_3_1h_lt_80) | (stochrsi_k_1h_gt_50))
            # 15m & 1h up move, 4h low
            & ((rsi_3_lt_90) | (rsi_3_1h_lt_80) | (aroonu_14_4h_gt_20))
            # 5m up move, 15m & 1h uptrend
            & ((rsi_3_lt_90) | (cmf_20_15m_lt_0_30) | (cmf_20_1h_lt_0_30))
            # 5m up move, 15m stil low
            & ((rsi_3_lt_90) | (aroonu_14_15m_gt_50))
            # 5m up move, 15m & 1h still not high enough
            & ((rsi_3_lt_90) | (stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_75))
            # 15m up move, 1h low
            & ((rsi_3_15m_lt_97) | (aroonu_14_1h_gt_30))
            # 15m & 1h up move, 4h still going up
            & ((rsi_3_15m_lt_95) | (rsi_3_1h_lt_95) | (cci_20_change_pct_4h_lt_neg_0))
            # 15m & 1h up move, 4h still not high enough
            & ((rsi_3_15m_lt_95) | (rsi_3_1h_lt_90) | (stochrsi_k_4h_gt_80))
            # 15m & 1h up move, 4h still not high enough
            & ((rsi_3_15m_lt_95) | (rsi_3_1h_lt_85) | (stochrsi_k_4h_gt_50))
            # 15m & 1h up move, 1h still low
            & ((rsi_3_15m_lt_95) | (rsi_3_1h_lt_70) | (stochrsi_k_1h_gt_50))
            # 15m & 4h up move, 1h still not high enough
            & ((rsi_3_15m_lt_95) | (rsi_3_4h_lt_95) | (stochrsi_k_1h_gt_75))
            # 15m up move, 1d lost, 1h low
            & ((rsi_3_15m_lt_95) | (rsi_14_1d_gt_40) | (aroonu_14_1h_gt_40))
            # 15m up move, 15m & 4h uptrend
            & ((rsi_3_15m_lt_95) | (aroonu_14_15m_lt_90) | (aroonu_14_4h_lt_90))
            # 15m up move, 15m stil not high enough, 1h low
            & ((rsi_3_15m_lt_95) | (stochrsi_k_15m_gt_70) | (stochrsi_k_1h_gt_10))
            # 15m up move, 1h still not high enough, 4h low
            & ((rsi_3_15m_lt_95) | (stochrsi_k_1h_gt_70) | (aroonu_14_4h_gt_20))
            # 15m up move, 1h & 4h still not high enough
            & ((rsi_3_15m_lt_95) | (stochrsi_k_1h_gt_70) | (stochrsi_k_4h_gt_80))
            # 15m up move, 4h still not high enough
            & ((rsi_3_15m_lt_95) | (aroonu_14_4h_gt_70))
            # 15m up move, 4h & 1d uptrend
            & ((rsi_3_15m_lt_95) | (roc_9_4h_lt_30) | roc_9_1d_lt_50)
            # 15m up move, 1h up move, 1h still not high enough
            & ((rsi_3_15m_lt_95) | (rsi_3_change_pct_1h < 80.0) | (stochrsi_k_1h_gt_50))
            # 15m & 1h up move, 1h still not high enough
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_85) | (stochrsi_k_1h_gt_70))
            # 15m & 1h up move, 1h not high enough
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_90) | (aroond_14_1h_lt_50))
            # 15m & 1h up move, 1d stil not high enough
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_90) | (rsi_14_1h > 80.0))
            # 15m & 1h up move, 1d uptrend
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_80) | (roc_9_1d_lt_40))
            # 15m & 1h up move, 15m still not high enough
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_80) | (stochrsi_k_15m_gt_60))
            # 15m & 4h up move, 1h still not high enough
            & ((rsi_3_15m_lt_90) | (rsi_3_4h_lt_90) | (stochrsi_k_1h_gt_80))
            # 15m & 4h up move, 1h still not high enough
            & ((rsi_3_15m_lt_90) | (rsi_3_4h_lt_90) | (stochrsi_k_1h_gt_90))
            # 15m & 4h up move, 4h not high enough
            & ((rsi_3_15m_lt_90) | (rsi_3_4h_lt_90) | (aroond_14_4h_lt_50))
            # 15m & 4h up move, 1d low
            & ((rsi_3_15m_lt_90) | (rsi_3_4h_lt_85) | (stochrsi_k_1d_gt_30))
            # 15m & 4h up move, 1h low
            & ((rsi_3_15m_lt_90) | (rsi_3_4h_lt_70) | (stochrsi_k_1h_gt_20))
            # 15m & 4h up move, 4h low
            & ((rsi_3_15m_lt_90) | (rsi_3_4h_lt_60) | (aroonu_14_4h_gt_30))
            # 15m up move, 15m high, 1d low, 1d oversold
            & ((rsi_3_15m_lt_90) | (aroonu_14_15m_lt_100) | (stochrsi_k_1d_gt_20) | (roc_9_1d_gt_neg_20))
            # 15m up move, 15m high, 1d oversold
            & ((rsi_3_15m_lt_90) | (aroonu_14_15m_lt_100) | (roc_9_1d_gt_neg_30))
            # 15m up move, 15m high, 1d uptrend
            & ((rsi_3_15m_lt_90) | (aroonu_14_15m_lt_100) | (roc_9_1d_lt_40))
            # 15m up move, 1h & 4h low
            & ((rsi_3_15m_lt_90) | (aroonu_14_1h_gt_40) | (aroonu_14_4h_gt_10))
            # 15m up move, 1h still low, 4h low
            & ((rsi_3_15m_lt_90) | (aroonu_14_1h_gt_60) | (stochrsi_k_4h_gt_30))
            # 15m up move, 1h low, 4h still not high enough
            & ((rsi_3_15m_lt_90) | (stochrsi_k_1h_gt_30) | (stochrsi_k_4h_gt_70))
            # 15m & 4h up move, 1d low
            & ((rsi_3_15m_lt_90) | (rsi_3_4h_lt_70) | (stochrsi_k_1d_gt_20))
            # 15m & 1h up move, 4h low
            & ((rsi_3_15m_lt_85) | (rsi_3_1h_lt_85) | (stochrsi_k_4h_gt_20))
            # 15m & 1h up move, 1d still low
            & ((rsi_3_15m_lt_85) | (rsi_3_1h_lt_85) | (stochrsi_k_1d_gt_60))
            # 15m & 1h up move, 1h low
            & ((rsi_3_15m_lt_85) | (rsi_3_1h_lt_70) | (stochrsi_k_1h_gt_30))
            # 15m & 1h up move, 4h low
            & ((rsi_3_15m_lt_85) | (rsi_3_1h_lt_70) | (stochrsi_k_4h_gt_30))
            # 15m & 4h down move, 4h still not high enough
            & ((rsi_3_15m_lt_85) | (rsi_3_4h_lt_90) | (stochrsi_k_4h_gt_75))
            # 15m & 4h up move, 15m low
            & ((rsi_3_15m_lt_85) | (rsi_3_4h_lt_85) | (stochrsi_k_15m_gt_50))
            # 15m down move, 15m still not high enough, 4h low
            & ((rsi_3_15m_lt_85) | (rsi_14_15m > 70.0) | (stochrsi_k_4h_gt_40))
            # 15m up move, 4h overbought
            & ((rsi_3_15m_lt_85) | (roc_9_4h_lt_50))
            # 15m & 1h up move, 1h still not high enough
            & ((rsi_3_15m_lt_80) | (rsi_3_1h_lt_70) | (aroonu_14_1h_gt_60))
            # 15m & 4h up move, 15m still low
            & ((rsi_3_15m_lt_80) | (rsi_3_4h_lt_80) | (aroonu_14_15m_gt_50))
            # 15m up move, 1h low
            & ((rsi_3_15m_lt_80) | (stochrsi_k_1h_gt_20))
            # 15m & 1h up move, 1h low
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_lt_70) | (aroonu_14_1h_gt_30))
            # 15m up move, 15m still not high enough, 1h still low
            & ((rsi_3_15m_lt_70) | (stochrsi_k_15m_gt_90) | (stochrsi_k_1h_gt_50))
            # 1h & 4h up move, 1h still not high enough
            & ((rsi_3_1h_lt_95) | (rsi_3_4h_lt_95) | (stochrsi_k_1h_gt_70))
            # 1h up move, 4h low
            & ((rsi_3_1h_lt_95) | (stochrsi_k_4h_gt_30))
            # 1h & 4h up move, 4h still not high enough
            & ((rsi_3_1h_lt_95) | (rsi_3_4h_lt_95) | (uo_7_14_28_4h > 60.0))
            # 1h & 4h up move, 4h still low
            & ((rsi_3_1h_lt_95) | (rsi_3_4h_lt_85) | (stochrsi_k_4h_gt_50))
            # 1h & 4h up move, 4h uptrend
            & ((rsi_3_1h_lt_95) | (rsi_3_4h_lt_85) | (roc_9_4h_lt_40))
            # 1h & 1d strong up move
            & ((rsi_3_1h_lt_95) | (rsi_3_1d_lt_95))
            # 1h up move, 4h still low
            & ((rsi_3_1h_lt_95) | (rsi_14_4h_gt_60))
            # 1h up move, 1d still low, 1h uptrend
            & ((rsi_3_1h_lt_95) | (rsi_14_1d_gt_50) | (roc_9_1h_lt_30))
            # 1h & 4h strong up move
            & ((rsi_3_1h_lt_95) | (mfi_14_1h < 95.0) | (rsi_3_4h_lt_95))
            # 1h up move, 1d still low, 1h uptrend
            & ((rsi_3_1h_lt_95) | (stochrsi_k_1d_gt_50) | (roc_9_1h_lt_20))
            # 1h strong up move, 15m still move higher
            & ((rsi_3_1h_lt_95) | (cci_20_change_pct_15m < -0.0))
            # 1h & 4h up move, 1h still low
            & ((rsi_3_1h_lt_90) | (rsi_3_4h_lt_90) | (stochrsi_k_1h_gt_50))
            # 1h & 4h up move, 1d still not high enough
            & ((rsi_3_1h_lt_90) | (rsi_3_4h_lt_90) | (stochrsi_k_1d_gt_70))
            # 1h up move, 4h low, 1d overbought
            & ((rsi_3_1h_lt_90) | (aroonu_14_4h_gt_20) | roc_9_1d_lt_50)
            # 1h up move, 1h still low, 1d uptrend
            & ((rsi_3_1h_lt_90) | (stochrsi_k_1h_gt_60) | roc_9_1d_lt_50)
            # 1h up move, 1h still not high enough, 1d low
            & ((rsi_3_1h_lt_90) | (stochrsi_k_1h_gt_70) | (stochrsi_k_1d_gt_30))
            # 1h up move, 4h low, 1h uptrend
            & ((rsi_3_1h_lt_90) | (stochrsi_k_4h_gt_20) | (roc_9_1h_lt_10))
            # 1h up move, 4h low, 1h overbought
            & ((rsi_3_1h_lt_90) | (stochrsi_k_4h_gt_40) | (roc_9_1h_lt_30))
            # 1h up move, 15m & 1h uptrend
            & ((rsi_3_1h_lt_90) | (roc_9_15m < 15.0) | (roc_9_1h_lt_15))
            # 1h up move, 15m & 4h still low
            & ((rsi_3_1h_lt_85) | (stochrsi_k_15m_gt_50) | (stochrsi_k_4h_gt_50))
            # 1h & 4h up move, 15m still not high enough
            & ((rsi_3_1h_lt_85) | (rsi_3_4h_lt_85) | (aroond_14_15m_lt_50))
            # 1h & 4h up move, 15m still not high enough
            & ((rsi_3_1h_lt_85) | (rsi_3_4h_lt_85) | (stochrsi_k_15m_gt_90))
            # 1h up move, 15m still not high enough, 1h still low
            & ((rsi_3_1h_lt_80) | (stochrsi_k_15m_gt_80) | (stochrsi_k_1h_gt_50))
            # 1h up move, 1h still low
            & ((rsi_3_1h_lt_80) | (stochrsi_k_1h_gt_60))
            # 1h up move, 1d uptrend
            & ((rsi_3_1h_lt_80) | (roc_9_1d_lt_200))
            # 4h & 1d strong up move
            & ((rsi_3_4h_lt_95) | (rsi_3_1d_lt_95))
            # 4h up move, 15m still low, 1h not high enough
            & ((rsi_3_4h_lt_95) | (stochrsi_k_15m_gt_50) | (aroond_14_1h_lt_25))
            # 4h up move, 15m still not high enough, 4h overbought
            & ((rsi_3_4h_lt_95) | (stochrsi_k_15m_gt_70) | (roc_9_4h_lt_60))
            # 4h up move, 15m uptrend
            & ((rsi_3_4h_lt_95) | (roc_9_15m < 20.0))
            # 4h up move, 1h uptrend
            & ((rsi_3_4h_lt_95) | (roc_9_1h_lt_20))
            # 4h up move, 1h & 4h overbought
            & ((rsi_3_4h_lt_95) | (roc_9_1h_lt_30) | (roc_9_4h_lt_60))
            # 4h up move, 1h still low
            & ((rsi_3_4h_lt_90) | (aroonu_14_1h_gt_40))
            # 4h up move, 1d still low, 4h uptrend
            & ((rsi_3_4h_lt_85) | (rsi_14_1d_gt_40) | (roc_9_4h_lt_20))
            # 4h up move, 4h still low
            & ((rsi_3_4h_lt_80) | (stochrsi_k_4h_gt_50))
            # 4h up move, 1h low
            & ((rsi_3_4h_lt_70) | (aroonu_14_1h > 25.0))
            # 4h up move, 1d low
            & ((rsi_3_4h_lt_70) | (aroonu_14_1d > 20.0))
            # 4h up move, 1h low
            & ((rsi_3_4h_lt_70) | (stochrsi_k_1h_gt_20))
            # 4h up move, 1d low
            & ((rsi_3_4h_lt_70) | (stochrsi_k_1d_gt_20))
            # 1d up move, 1h & 4h still not low enough
            & ((rsi_3_1d_lt_90) | (stochrsi_k_1h_gt_80) | (stochrsi_k_4h_gt_50))
            # 4h still not high enough, 4h overbought, 4h uptrend
            & ((rsi_14_4h_gt_80) | (roc_9_4h_lt_40) | (cci_20_change_pct_4h_lt_0))
            # 15m & 1h uptrend, 4h still low
            & ((cmf_20_15m_lt_0_30) | (cmf_20_1h_lt_0_30) | (stochrsi_k_4h_gt_60))
            # 15m & 1h uptrend
            & ((aroonu_14_15m_lt_100) | (aroonu_14_1h_lt_100))
            # 15m uptrend, 1h low
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_1h_gt_20))
            # 15m uptrend, 1d uptrend
            & ((aroonu_14_15m_lt_100) | (roc_9_1d_lt_60))
            # 1h & 4h uptrend
            & ((aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_100))
            # 1h uptrend, 4h uptrend
            & ((aroonu_14_1h_lt_100) | (roc_9_4h_lt_20))
            # 4h uptrend, 1d uptrend
            & (aroonu_14_4h_lt_100 | (aroonu_14_1d_lt_100))
            # 4h uptrend, 15m uptrend
            & (aroonu_14_4h_lt_100 | (roc_9_15m < 10.0))
            # 4h uptrend, 1h uptrend
            & (aroonu_14_4h_lt_100 | (roc_9_1h_lt_20))
            # 1d uptrend, 15m uptrend
            & (aroonu_14_1d_lt_100 | (roc_9_15m < 20.0))
            # 1d uptrend, 1h uptrend
            & (aroonu_14_1d_lt_100 | (roc_9_1h_lt_20))
            # 15m still not high enough, 1h & 4h overbought
            & ((stochrsi_k_15m_gt_70) | (roc_9_1h_lt_30) | (roc_9_4h_lt_60))
            # 1h & 4h overbought, 1h uptrend
            & ((roc_9_1h_lt_10) | (roc_9_4h_lt_40) | (cci_20_change_pct_1h_lt_0))
            # 1h & 4h overbought, 4h uptrend
            & ((roc_9_1h_lt_10) | (roc_9_4h_lt_40) | (cci_20_change_pct_4h_lt_0))
            # 1h & 4h & 1d uptrend
            & ((roc_9_1h_lt_10) | (roc_9_4h_lt_10) | (roc_9_1d_lt_20))
            # 5m green, 15m still not high enough
            & ((change_pct < 5.0) | (aroond_14_15m_lt_50))
            # 5m green, 15m still not high enough
            & ((change_pct < 5.0) | (stochrsi_k_15m_gt_90))
            # pump in the last half hour, 1h low
            & ((close < (close_min_6 * 1.20)) | (aroonu_14_1h_gt_30))
            # pump in the last half hour, 15m still low
            & ((close < (close_min_6 * 1.20)) | (stochrsi_k_15m_gt_40))
            # pump in the last half hour, 1d uptrend
            & ((close < (close_min_6 * 1.20)) | (roc_9_1d_lt_20))
            # big pump in the last 4 hours, 15m still low
            & ((close < (close_min_48 * 1.50)) | (aroonu_14_15m_gt_50))
          )

          # Logic
          short_entry_logic.append(
            (ema_12 > ema_26)
            & ((ema_12 - ema_26) > (open_rate * 0.030))
            & ((ema_12_shift_1 - ema_26_shift_1) > (open_rate / 100.0))
            & (close > (bbu_20_2_0 * 1.004))
          )

        # Condition #502 - Normal mode (Short).
        if short_entry_condition_index == 502:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)

          # 5m & 15m & 1h & 4h up move
          short_entry_logic.append(
            ((rsi_3_lt_97) | (rsi_3_15m_lt_90) | (rsi_3_1h_lt_90) | (rsi_3_4h_lt_80))
            # 5m & 4h up move
            & ((rsi_3_lt_97) | (rsi_3_4h_lt_95))
            # 5m up move, 4h still not high enough
            & ((rsi_3_lt_97) | (stochrsi_k_4h_gt_80))
            # 5m & 15m strong up move
            & ((rsi_3_lt_95) | (rsi_3_15m_lt_95))
            # 5m & 15m up move, 4h low
            & ((rsi_3_lt_95) | (rsi_3_15m_lt_90) | (aroonu_14_4h_gt_30))
            # 5m & 1h & 4h up move
            & ((rsi_3_lt_95) | (rsi_3_1h_lt_90) | (rsi_3_4h_lt_90))
            # 5m & 1h up move, 15m still not high enough
            & ((rsi_3_lt_95) | (rsi_3_1h_lt_85) | (stochrsi_k_15m_gt_70))
            # 5m up move, 15m still low
            & ((rsi_3_lt_95) | (stochrsi_k_15m_gt_50))
            # 5m up move, 4h low
            & ((rsi_3_lt_90) | (aroonu_14_4h_gt_20))
            # 15m & 1h down move, 4h still not high enough
            & ((rsi_3_15m_lt_97) | (rsi_3_1h_lt_85) | (stochrsi_k_4h_gt_80))
            # 15m up move, 1h still low
            & ((rsi_3_15m_lt_97) | (stochrsi_k_1h_gt_60))
            # 15m & 1h & 4h up move
            & ((rsi_3_15m_lt_95) | (rsi_3_1h_lt_90) | (rsi_3_4h_lt_85))
            # 15m & 1h up move, 4h still low
            & ((rsi_3_15m_lt_95) | (rsi_3_1h_lt_85) | (stochrsi_k_4h_gt_60))
            # 15m up move, 1h still low
            & ((rsi_3_15m_lt_95) | (stochrsi_k_1h_gt_40))
            # 15m up move, 4h still not high enough
            & ((rsi_3_15m_lt_95) | (aroonu_14_4h_gt_70))
            # 15m & 1h & 4h up move
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_90) | (rsi_3_4h_lt_90))
            # 15m & 1h up move, 15m still not high enough
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_90) | (stochrsi_k_15m_gt_80))
            # 15m & 1h up move, 1d low
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_90) | (stochrsi_k_1d > 40.0))
            # 15m & 1h up move, 1h still not high enough
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_85) | (stochrsi_k_1h_gt_80))
            # 15m & 1h up move, 4h stil low
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_80) | (aroonu_14_4h_gt_50))
            # 15m & 4h up move, 1d low
            & ((rsi_3_15m_lt_90) | (rsi_3_4h_lt_85) | (rsi_14_1d_gt_40))
            # 15m & 4h up move, 1d low
            & ((rsi_3_15m_lt_90) | (rsi_3_4h_lt_85) | (stochrsi_k_1d_gt_30))
            # 15m up move, 1h still low, 1d low
            & ((rsi_3_15m_lt_90) | (aroonu_14_1h > 50.0) | (aroonu_14_1d_gt_30))
            # 15m up move, 1h high
            & ((rsi_3_15m_lt_90) | (aroonu_14_1h_lt_100))
            # 15m up move, 1h still low
            & ((rsi_3_15m_lt_90) | (stochrsi_k_1h_gt_50))
            # 15m up move, 4h uptrend
            & ((rsi_3_15m_lt_90) | (roc_9_4h_lt_20))
            # 15m & 1h up move, 1h still low
            & ((rsi_3_15m_lt_85) | (rsi_3_1h_lt_65) | (stochrsi_k_1h_gt_60))
            # 15m up move, 1h low
            & ((rsi_3_15m_lt_85) | (stochrsi_k_1h_gt_30))
            # 15m & 1h & 4h up move, 4h uptrend
            & ((rsi_3_15m_lt_80) | (rsi_3_1h_lt_80) | (rsi_3_4h_lt_80) | (aroonu_14_4h_lt_100))
            # 15m & 4h up move, 15m still low
            & ((rsi_3_15m_lt_80) | (rsi_3_4h_lt_75) | (aroonu_14_15m_gt_50))
            # 15m up move, 4h low, 15m uptrend, 4h oversold
            & ((rsi_3_15m_lt_80) | (rsi_14_4h_gt_20) | (aroonu_14_15m_lt_100) | (roc_9_4h_gt_neg_20))
            # 15m up move, 15m high, 4h & 1d oversold
            & ((rsi_3_15m_lt_80) | (aroonu_14_15m_lt_100) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_60))
            # 15m up move, 15m high, 1h & 4h uptrend
            & ((rsi_3_15m_lt_80) | (aroonu_14_15m_lt_100) | (roc_9_1h_lt_20) | (roc_9_4h_lt_30))
            # 15m up move, 1h low
            & ((rsi_3_15m_lt_80) | (aroonu_14_1h_gt_10))
            # 15m up move, 1h low, 1d uptrend
            & ((rsi_3_15m_lt_80) | (aroonu_14_1h_gt_40) | (roc_9_1d_lt_100))
            # 15m up move, 1h still low, 1d oversold
            & ((rsi_3_15m_lt_80) | (stochrsi_k_1h_gt_50) | (roc_9_1d_gt_neg_30))
            # 15m up move, 4h low
            & ((rsi_3_15m_lt_80) | (stochrsi_k_4h_gt_40))
            # 15m up move, 1h uptrend
            & ((rsi_3_15m_lt_75) | (roc_9_1h_lt_40))
            # 1h & 1d strong up move
            & ((rsi_3_1h_lt_95) | (rsi_3_1d_lt_95))
            # 1h up move, 1h still not high enough
            & ((rsi_3_1h_lt_95) | (stochrsi_k_1h_gt_70))
            # 1h up move, 4h still low, 1h moving higher
            & ((rsi_3_1h_lt_95) | (stochrsi_k_4h_gt_60) | (cci_20_change_pct_1h_lt_neg_0))
            # 1h up move, 1d low
            & ((rsi_3_1h_lt_95) | (rsi_14_1d_gt_40))
            # 1h strong up move, 15m still move higher
            & ((rsi_3_1h_lt_95) | (cci_20_change_pct_15m < -0.0))
            # 1h up move, relative stable before the hour
            & ((rsi_3_1h_lt_95) | (close_min_12 > (close_min_48 * 1.10)))
            # 1h up move, 15m uptrend
            & ((rsi_3_1h_lt_90) | (aroonu_14_15m_lt_100))
            # 1h up move, 1d low
            & ((rsi_3_1h_lt_90) | (stochrsi_k_1d_gt_10))
            # 1h up move, 1h & 4h uptrend
            & ((rsi_3_1h_lt_90) | (roc_9_1h_lt_30) | (roc_9_4h_lt_30))
            # 1h up move, 4h uptrend
            & ((rsi_3_1h_lt_90) | (roc_9_4h_lt_20))
            # 1h up move, 4h still low
            & ((rsi_3_1h_lt_85) | (aroonu_14_4h_gt_50))
            # 1h up move, 4h still low
            & ((rsi_3_1h_lt_85) | (stochrsi_k_4h_gt_50))
            # 1h & 4h up move, 1d low
            & ((rsi_3_1h_lt_80) | (rsi_3_4h_lt_80) | (stochrsi_k_1d_gt_30))
            # 1h up move, 15m & 1h high, 1h uptrend
            & ((rsi_3_1h_lt_80) | (aroonu_14_15m_lt_100) | (aroonu_14_1h_lt_100) | (roc_9_1h_lt_20))
            # 1h up move, 1h still not high enough
            & ((rsi_3_1h_lt_80) | (stochrsi_k_1h_gt_70))
            # 1h up move, 4h still low, 1h still moving higher
            & ((rsi_3_1h_lt_80) | (rsi_14_4h_gt_60) | (cci_20_change_pct_1h_lt_neg_0))
            # 1h up move, 4h low
            & ((rsi_3_1h_lt_80) | (stochrsi_k_4h_gt_20))
            # 1h up move, 4h low
            & ((rsi_3_1h_lt_80) | (aroonu_14_4h_gt_10))
            # 1h up move, 1h still low
            & ((rsi_3_1h_lt_75) | (stochrsi_k_1h_gt_50))
            # 1h up move, 4h low
            & ((rsi_3_1h_lt_70) | (rsi_14_4h_gt_40))
            # 1h up move, 4h low
            & ((rsi_3_1h_lt_70) | (stochrsi_k_4h_gt_40))
            # 1h up move, 1h uptrend
            & ((rsi_3_1h_lt_70) | (roc_9_1h_lt_40))
            # 1h up move, 1h low
            & ((rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_20))
            # 4h up move, 1d still low
            & ((rsi_3_4h < 97.0) | (rsi_14_1d_gt_50))
            # 4h up move, 1h still not high enough
            & ((rsi_3_4h_lt_95) | (stochrsi_k_1h_gt_70))
            # 4h up move, 4h still not high enough
            & ((rsi_3_4h_lt_95) | (stochrsi_k_4h_gt_80))
            # 4h up move, 15m still not high enough, 4h moving higher
            & ((rsi_3_4h_lt_90) | (stochrsi_k_15m_gt_80) | (cci_20_change_pct_4h_lt_0))
            # 4h up move, 15m still low
            & ((rsi_3_4h_lt_90) | (stochrsi_k_15m_gt_50))
            # 4h up move, 1h still low
            & ((rsi_3_4h_lt_90) | (aroonu_14_1h_gt_40))
            # 4h up move, 4h still not high enough
            & ((rsi_3_4h_lt_90) | (stochrsi_k_4h_gt_75))
            # 4h up move, 4h still not high enough
            & ((rsi_3_4h_lt_85) | (stochrsi_k_4h_gt_70))
            # 4h up move, 1d still low, 4h uptrend
            & ((rsi_3_4h_lt_85) | (rsi_14_1d_gt_50) | (roc_9_4h_lt_20))
            # 4h up move, 4h high, 4h & 1d uptrend
            & ((rsi_3_4h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_10) | (roc_9_1d_lt_40))
            # 4h up move, 4h uptrend
            & ((rsi_3_4h_lt_80) | (roc_9_4h_lt_20))
            # 4h up move, 1h low
            & ((rsi_3_4h_lt_75) | (stochrsi_k_1h_gt_20))
            # 4h up move, 4h low
            & ((rsi_3_4h_lt_70) | (stochrsi_k_4h_gt_40))
            # 1d up move, 1h still not high enough
            & ((rsi_3_1d_lt_95) | (stochrsi_k_1h_gt_90))
            # 1d up move, 1h still low
            & ((rsi_3_1d_lt_90) | (stochrsi_k_1h_gt_50))
            # 1d up move, 4h still low
            & ((rsi_3_1d_lt_80) | (stochrsi_k_4h_gt_40))
            # 15m low, 1h still low
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_1h_gt_50))
            # 15m low, 4h low
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m still low, 1h low
            & ((aroonu_14_15m_gt_50) | (stochrsi_k_1h_gt_30))
            # 15m still not high enough, 4h low
            & ((stochrsi_k_15m_gt_70) | (aroonu_14_4h_gt_10))
            # 1h & 4h low
            & ((aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_20))
            # 1h & 4h low
            & ((aroonu_14_1h_gt_20) | (stochrsi_k_4h_gt_20))
            # 1h low, 1d low
            & ((aroonu_14_1h_gt_30) | (stochrsi_k_1d_gt_30))
            # 4h low, 1d uptrend
            & ((aroonu_14_4h_gt_30) | (roc_9_1d_lt_80))
            # 4h still not high enough, 4h & 1d uptrend
            & ((aroonu_14_4h_gt_70) | (roc_9_4h_lt_60) | (roc_9_1d_lt_200))
            # 1h & 4h low
            & ((stochrsi_k_1h_gt_20) | (aroonu_14_4h_gt_20))
            # 1d big green, 1d still not high enough
            & ((change_pct_1d_lt_30) | (rsi_14_1d > 65.0))
            # rise in the last hour, relatively stable before the hour
            & ((close < (close_min_12 * 1.10)) | (close_min_12 > (close_min_48 * 1.10)))
            # big pump in the last 6 days, 4h still not high enough
            & ((close < (low_min_6_1d * 4.0)) | (stochrsi_k_4h_gt_80))
            # big pump in the last 20 days, 1h up move
            & ((close < (low_min_20_1d * 6.0)) | (rsi_3_1h_lt_90))
          )

          # Logic
          short_entry_logic.append(
            (aroond_14_lt_25)
            & (stochrsi_k_gt_80)
            & (close > (ema_20 * 1.060))
            & (close > (bbu_20_2_0 * 0.995))
            & (aroond_14_15m_lt_25)
          )

        # Condition #503 - Normal mode (Short).
        if short_entry_condition_index == 503:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)

          short_entry_logic.append(rsi_3_1h >= 5.0)
          short_entry_logic.append(rsi_3_4h >= 20.0)
          short_entry_logic.append(rsi_3_1d >= 20.0)
          short_entry_logic.append(rsi_14_1h_gt_20)
          short_entry_logic.append(rsi_14_4h_gt_20)
          short_entry_logic.append(rsi_14_1d_gt_10)
          # 5m strong down move
          short_entry_logic.append((rsi_3_lt_98) | (roc_9 < 50.0))
          # 5m down move, 4h still high
          short_entry_logic.append((rsi_3_lt_90) | (mfi_14 > 10.0) | (stochrsi_k_4h_gt_30))
          # 5m & 1h down move, 1h still high
          short_entry_logic.append((rsi_3_lt_90) | (rsi_3_1h_lt_90) | (stochrsi_k_1h_gt_70))
          # 5m down move, 4h downtrend, 1h still high
          short_entry_logic.append((rsi_3_lt_95) | (rsi_3_4h_lt_85) | (stochrsi_k_1h_gt_30))
          # 5m & 4h strong down move, 4h still not low enough
          short_entry_logic.append((rsi_3_lt_95) | (rsi_3_1h_lt_95) | (stochrsi_k_4h_gt_60))
          # 5m down move, 1h high, 1d overbought
          short_entry_logic.append((rsi_3_lt_90) | (roc_9_1h_lt_15) | (roc_9_1d_gt_neg_40))
          # 5m down move, 1h & 4h high
          short_entry_logic.append((rsi_3_lt_90) | (uo_7_14_28_1h > 40.0) | (stochrsi_k_4h_gt_30))
          # 5m down move, 1h high, 4h downtrend
          short_entry_logic.append((rsi_3_lt_98) | (stochrsi_k_1h_gt_10) | (roc_9_4h_lt_10))
          # 5m & 1h down move, 4h down
          short_entry_logic.append((rsi_3_lt_90) | (rsi_3_1h_lt_85) | (cmf_20_4h_gt_neg_0_20))
          # 5m down move, 1h high
          short_entry_logic.append((rsi_14_change_pct < 40.0) | (stochrsi_k_1h_gt_30))
          # 5m down move, 1h high
          short_entry_logic.append((rsi_14_change_pct < 40.0) | (stochrsi_k_4h_gt_30))
          # 15m & 1h down move, 4h still high
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_85) | (stochrsi_k_4h_gt_50))
          # 15m down move, 15m still not low enough, 1h & 4h still not low enough
          short_entry_logic.append(
            (rsi_3_15m_lt_95) | (aroond_14_15m_lt_25) | (stochrsi_k_1h_gt_75) | (mfi_14_4h > 50.0)
          )
          # 5m & 1h down move, 1h still high
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_85) | (stochrsi_k_1h_gt_50))
          # 15m & 4h down move, 1h still not low
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_4h_lt_90) | (stochrsi_k_1h_gt_70))
          # 15m & 4h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_4h_lt_80) | (stochrsi_k_4h_gt_60))
          # 15m down move, 1h & 4h still high
          short_entry_logic.append((rsi_3_15m_lt_95) | (stochrsi_k_1h_gt_50) | (rsi_14_4h_gt_50))
          # 15m & 1h & 4h down move
          short_entry_logic.append((rsi_3_15m_lt_90) | (rsi_3_change_pct_1h > -60.0) | (rsi_3_change_pct_4h > -40.0))
          # 15m down move, 1d downtrend, 1h still high
          short_entry_logic.append((rsi_3_15m_lt_90) | (roc_9_1d_gt_neg_25) | (stochrsi_k_1h_gt_30))
          # 15m & 1d down move, 1h still high
          short_entry_logic.append((rsi_3_15m_lt_90) | (rsi_3_1d_lt_90) | (stochrsi_k_1h_gt_30))
          # 15m & 4h down move, 1h still high
          short_entry_logic.append((rsi_3_15m_lt_90) | (rsi_3_4h_lt_95) | (stochrsi_k_1h_gt_50))
          # 15m down move, 15m still not low enough, 4h down move
          short_entry_logic.append((rsi_3_15m_lt_90) | (aroond_14_15m_lt_50) | (rsi_3_4h_lt_85))
          # 15m down move, 1h still high, 1d strong downtrend
          short_entry_logic.append((rsi_3_15m_lt_80) | (aroond_14_1h_lt_25) | (mfi_14_1d < 90.0))
          # 15m down move, 1h still high, 1d downtrend
          short_entry_logic.append((rsi_3_15m_lt_85) | (stochrsi_k_1h_gt_30) | roc_9_1d_lt_50)
          # 15m down move, 4h still high, 1d downtrend
          short_entry_logic.append((rsi_3_15m_lt_85) | (stochrsi_k_4h_gt_30) | roc_9_1d_lt_50)
          # 15m & 4h down move, 1d downtrend
          short_entry_logic.append((rsi_3_15m_lt_85) | (rsi_3_4h_lt_85) | (roc_9_1d_gt_neg_70))
          # 15m down move, 15m not low enough, 1h overbought
          short_entry_logic.append((rsi_14_change_pct_15m > -40.0) | (stochrsi_k_15m_gt_90) | (rsi_14_1h > 30.0))
          # 15m strong down move, 1h still high
          short_entry_logic.append((roc_9_15m < 15.0) | (stochrsi_k_1h_gt_50))
          # 15m downtrend, 1h & 4h still high
          short_entry_logic.append((roc_9_15m < 10.0) | (stochrsi_k_1h_gt_50) | (stochrsi_k_4h_gt_50))
          # 15m & 1h & 4h down move
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_95) | (cci_20_change_pct_4h_lt_0))
          # 15m strong down move
          short_entry_logic.append((rsi_3_15m_lt_90) | (mfi_14_15m < 85.0) | (aroond_14_15m_lt_25))
          # 14m down move, 4h still high
          short_entry_logic.append((rsi_3_15m_lt_80) | (aroond_14_15m_lt_50) | (uo_7_14_28_4h > 50.0))
          # 15m down move, 1h stil high, 1d overbought
          short_entry_logic.append((rsi_3_15m_lt_85) | (aroond_14_1h_lt_25) | (roc_9_1d_gt_neg_80))
          # 15m down move, 1h high, 1d overbought
          short_entry_logic.append((rsi_3_15m_lt_90) | (stochrsi_k_1h_gt_30) | roc_9_1d_gt_neg_50)
          # 1h & 4h down move, 4h still high
          short_entry_logic.append((rsi_3_1h_lt_90) | (rsi_3_change_pct_4h < 65.0) | (stochrsi_k_4h_gt_50))
          # 1h & 4h down move, 4h still high
          short_entry_logic.append((rsi_3_1h_lt_90) | (rsi_3_4h_lt_85) | (stochrsi_k_4h_lt_10))
          # 1h down move, 4h still not low enough, 1d overbought
          short_entry_logic.append((rsi_3_1h_lt_90) | (aroond_14_4h_lt_25) | (roc_9_1d > -120.0))
          # 1h down move, 1h still not low enough, 4h still not low
          short_entry_logic.append((rsi_3_1h_lt_90) | (stochrsi_k_1h_gt_70) | (rsi_14_4h_gt_50))
          # 1h down move, 4h still high
          short_entry_logic.append((rsi_3_1h_lt_95) | (rsi_14_4h_gt_60))
          # 1h down move, 4h still high, 1d downtrend
          short_entry_logic.append((rsi_3_1h_lt_80) | (stochrsi_k_4h_gt_30) | roc_9_1d_lt_50)
          # 1h down move, 4h still high, 1d downtrend
          short_entry_logic.append((rsi_3_change_pct_1h > -65.0) | (stochrsi_k_4h_gt_30) | roc_9_1d_lt_50)
          # 4h & 1d down move, 1h still high
          short_entry_logic.append((rsi_3_4h_lt_90) | (roc_2_1d < 20.0) | (stochrsi_k_1h_gt_50))
          # 15m still high, 1h down move, 4h high
          short_entry_logic.append((aroond_14_15m_lt_50) | (rsi_3_change_pct_1h < 50.0) | (stochrsi_k_4h_gt_30))
          # 15m still high, 1h & 4h down move, 4h still high
          short_entry_logic.append((aroond_14_15m_lt_50) | (rsi_3_1h_lt_85) | (rsi_3_4h_lt_80) | (stochrsi_k_4h_gt_80))
          # 15m & 1h still high, 4h overbought
          short_entry_logic.append((aroond_14_15m_lt_50) | (aroond_14_1h_lt_50) | (roc_9_4h_gt_neg_40))
          # 15m still high, 1h down move, 1d downtrend
          short_entry_logic.append((stochrsi_k_15m_gt_30) | (rsi_3_4h_lt_90) | roc_9_1d_lt_50)
          # 1h & 4h still high, 1d strong down move
          short_entry_logic.append((stochrsi_k_1h_gt_50) | (uo_7_14_28_4h > 55.0) | (rsi_3_1d_lt_90))
          # 1h still high, 4h & 1d downtrend
          short_entry_logic.append((aroond_14_1h_lt_25) | (roc_9_4h_lt_20) | roc_9_1d_lt_50)
          # 4h moving down, 1d P&D
          short_entry_logic.append((roc_9_4h_lt_30) | (rsi_3_change_pct_1d < 50.0) | roc_9_1d_gt_neg_50)
          # 1d strong downtrend, 4h still high
          short_entry_logic.append((roc_2_1d < 20.0) | roc_9_1d_lt_50 | (stochrsi_k_4h_gt_70))
          # 1d P&D, 1d overbought
          short_entry_logic.append((roc_2_1d < 10.0) | roc_9_1d_gt_neg_50 | (stochrsi_k_1h > 5.0))
          # 1h red, previous 1h green, 1h overbought
          short_entry_logic.append(
            (change_pct_1h < 1.0) | (change_pct_1h_shift_12 > -5.0) | (rsi_14_1h_shift_12 < 80.0)
          )
          # 1h red, 1h stil high, 4h downtrend
          short_entry_logic.append((change_pct_1h < 5.0) | (stochrsi_k_1h_gt_50) | (roc_9_4h_gt_neg_25))
          # 4h red, 15m down move, 4h still high
          short_entry_logic.append((change_pct_4h < 5.0) | (rsi_3_15m_lt_90) | (stochrsi_k_4h_gt_30))
          # 4h red, previous 4h green, 4h overbought
          short_entry_logic.append(
            (change_pct_4h < 5.0) | (change_pct_4h_shift_48 > -5.0) | (roc_9_4h_shift_48 > -25.0)
          )
          # 4h red, 4h still not low enough, 1h downtrend, 1h overbought
          short_entry_logic.append(
            (change_pct_4h < 10.0) | (aroond_14_4h_lt_25) | (roc_9_1h_lt_20) | (roc_9_1d_gt_neg_40)
          )
          # 4h red, 4h still high, 1d downtrend
          short_entry_logic.append((change_pct_4h < 10.0) | (stochrsi_k_4h_gt_30) | (roc_9_1d_lt_40))
          # 1d P&D, 1d overbought
          short_entry_logic.append((change_pct_1d_lt_10) | (change_pct_1d_shift_288 > -10.0) | (roc_9_1d_gt_neg_100))
          # 1d P&D, 4h still high
          short_entry_logic.append((change_pct_1d_lt_15) | (change_pct_1d_shift_288 > -15.0) | (aroond_14_4h_lt_50))
          short_entry_logic.append((rsi_3_1h_lt_90) | (rsi_3_4h_lt_95) | (cci_20_change_pct_4h_lt_0))

          # Logic
          short_entry_logic.append(rsi_20 > rsi_20_shift_1)
          short_entry_logic.append(rsi_4 > 54.0)
          short_entry_logic.append(aroond_14_lt_25)
          short_entry_logic.append(close > sma_16 * 1.058)

        # Condition #504 - Normal mode (Short).
        if short_entry_condition_index == 504:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)

          short_entry_logic.append(rsi_3_1h >= 5.0)
          short_entry_logic.append(rsi_3_4h >= 20.0)
          short_entry_logic.append(rsi_3_1d >= 20.0)
          short_entry_logic.append(rsi_14_1h_gt_20)
          short_entry_logic.append(rsi_14_4h_gt_20)
          short_entry_logic.append(rsi_14_1d_gt_10)
          # 15m & 1h down move, 4h still high
          short_entry_logic.append((rsi_3_15m_lt_95) | (mfi_14_15m < 90.0) | (rsi_3_1h_lt_80) | (stochrsi_k_4h_gt_50))
          # 15m & 1h down move, 4h still high
          short_entry_logic.append((rsi_3_15m_lt_90) | (mfi_14_15m < 85.0) | (stochrsi_k_4h_gt_30))
          # 14m & 4h down move, 4h still high
          short_entry_logic.append((rsi_3_15m_lt_90) | (rsi_3_4h_lt_85) | (stochrsi_k_4h_gt_60))
          # 15m down move, 1h & 4h still high
          short_entry_logic.append((rsi_3_15m_lt_90) | (uo_7_14_28_1h < 45.0) | (stochrsi_k_4h_gt_30))
          # 1h strong down move, 4h still high
          short_entry_logic.append((rsi_3_1h_lt_95) | (rsi_14_change_pct_1h < 40.0) | (stochrsi_k_4h_gt_30))
          # 1h strong down move, 4h down move, 4h still high
          short_entry_logic.append((rsi_3_1h_lt_95) | (rsi_3_change_pct_4h < 50.0) | (stochrsi_k_4h_gt_50))
          # 1h & 4h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_95) | (rsi_3_4h_lt_90) | (stochrsi_k_4h_gt_75))
          # 1h & 4h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_95) | (rsi_3_4h_lt_75) | (aroond_14_4h_lt_50))
          # 15m down move, 1h strong downtrend
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_95) | (mfi_14_1h > 5.0))
          # 15m downtrend, 4h down move, 4h stil high
          short_entry_logic.append((roc_9_15m > -20.0) | (rsi_3_4h_lt_75) | (stochrsi_k_4h_gt_30))

          # Logic
          short_entry_logic.append(aroond_14_lt_25)
          short_entry_logic.append(aroond_14_15m_lt_25)
          short_entry_logic.append(close > (ema_9 * 1.058))
          short_entry_logic.append(close > (ema_20 * 1.040))

        # Condition #505 - ADX trend-birth (Short, experimental, RAW — mirror).
        if short_entry_condition_index == 505:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m up move & uptrend, 15m downtrend, 4h downtrend, 1d still high
            (
              (rsi_3_lt_46)
              | (aroonu_14_4h_gt_30)
              | (aroonu_14 < 95.0)
              | (aroonu_14_15m > 25.0)
              | (stochrsi_k_1d < 15.0)
            )
            # 5m up move & still high, 1d bot wick pct low & still high & down move
            & (
              (rsi_3_lt_50) | (bot_wick_pct_1d > 1.0) | (stochrsi_k_1d_lt_20) | (rsi_3_1d_gt_20) | (stochrsi_k < 70.0)
            )
            # 5m & 15m down move, 1d uptrend
            & ((rsi_3_gt_10) | (rsi_3_15m_gt_10) | (roc_9_1d_lt_0))
            # 5m up move, 15m & 1h uptrend
            & ((rsi_3_lt_40) | (aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_30))
            # 5m up move, 1h low & still high
            & ((rsi_3_lt_40) | (aroonu_14_1h_gt_0) | (stochrsi_k_1h_gt_30))
            # 5m up move, 1h uptrend, 4h high
            & ((rsi_3_lt_40) | (aroonu_14_1h_lt_40) | (stochrsi_k_4h_gt_10))
            # 5m up move, 15m down move & uptrend, 1h downtrend, 1d still high
            & ((rsi_3_lt_40) | (rsi_3_15m_gt_40) | (aroonu_14_15m_lt_40) | (stochrsi_k_1d_lt_20) | (aroonu_14_1h_gt_0))
            # 5m up move, 15m uptrend, 1h still high
            & ((rsi_3_lt_50) | (aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_30))
            # 5m up move, 15m & 1h uptrend
            & ((rsi_3_lt_50) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_40))
            # 5m up move & on the floor, 15m up move, 1h downtrend
            & ((rsi_3_lt_50) | (aroonu_14_1h_gt_20) | (stochrsi_k > 15.0) | (rsi_3_15m < 45.0))
            # 5m up move, 15m down move
            & ((rsi_3_lt_50) | (roc_9_15m > -25.0))
            # 5m up move, 1h up move, 4h down move, 1d down move
            & ((rsi_3_lt_50) | (roc_9_1h < -1.0) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_20))
            # 5m up move, 1h up move, 4h down move & uptrend, 1d washed out
            & ((rsi_3_lt_50) | (roc_9_1h < -5.0) | (rsi_3_4h_gt_5) | (aroonu_14_4h < 15.0) | (stochrsi_k_1d_gt_60))
            # 5m up move & rsi 20 high, 15m up move, 1d uptrend & still high
            & ((rsi_3_lt_50) | (rsi_20 < 45.0) | (rsi_3_15m_lt_80) | (aroonu_14_1d_lt_60) | (stochrsi_k_1d_lt_20))
            # 5m up move, 15m down move, 4h low
            & ((rsi_3_lt_50) | (rsi_3_15m_gt_45) | (aroonu_14_4h_gt_20))
            # 5m up move, 15m low, 1d uptrend
            & ((rsi_3_lt_50) | (stochrsi_k_15m_gt_20) | (roc_9_1d_lt_0))
            # 5m up move, 15m low, 1d still high
            & ((rsi_3_lt_90) | (aroonu_14_15m_gt_40) | (stochrsi_k_1d_gt_50))
            # 5m rsi 4 high & uptrend, 15m down move & downtrend, 1h down move
            & ((rsi_4 < 45.0) | (rsi_3_1h_gt_30) | (aroonu_14 < 95.0) | (rsi_3_15m > 65.0) | (aroonu_14_15m > 25.0))
            # 5m rsi 4 high & up move, 15m WILLR low & down move, 1d down move
            & ((rsi_4 < 45.0) | (willr_14_15m > -35.0) | (rsi_3 < 80.0) | (rsi_3_1d_gt_25) | (rsi_3_15m > 65.0))
            # 5m RSI high & uptrend, 15m down move
            & ((rsi_14 < 36.0) | (rsi_3_15m_gt_5) | (aroonu_14 < 5.0))
            # 5m RSI high & up move, 4h uptrend, 1d bot wick pct low & down move
            & ((rsi_14 < 45.0) | (bot_wick_pct_1d > 1.0) | (rsi_3 < 70.0) | (aroonu_14_4h < 10.0) | (rsi_3_1d_gt_30))
            # 5m money leaving & WILLR high & down move & overbought, 1h still high
            & ((cmf_20 > 0.0) | (willr_14 < -50.0) | (rsi_3 > 45.0) | (stochrsi_k_1h_lt_30) | (stochrsi_k < 80.0))
            # 5m downtrend, 4h still high & up move, 1d downtrend & still high
            & (
              (aroonu_14_gt_75)
              | (aroonu_14_1d_gt_30)
              | (stochrsi_k_4h < 25.0)
              | (stochrsi_k_1d < 55.0)
              | (rsi_3_4h < 25.0)
            )
            # 5m downtrend & washed out, 15m washed out, 1d down move & still high
            & (
              (aroonu_14_gt_75)
              | (stochrsi_k_gt_80)
              | (rsi_3_1d_gt_20)
              | (stochrsi_k_1d_lt_20)
              | (stochrsi_k_15m > 75.0)
            )
            # 5m uptrend & overbought & down move, 15m downtrend, 1d washed out
            & (
              (aroonu_14_lt_30) | (aroonu_14_15m_gt_60) | (stochrsi_k < 80.0) | (rsi_3 > 55.0) | (stochrsi_k_1d_gt_60)
            )
            # 5m & 4h & 1d uptrend, 15m up move, 4h still high
            & ((aroonu_14 < 5) | (rsi_3_15m < 25) | (aroonu_14_4h < 55) | (stochrsi_k_4h < 25) | (aroonu_14_1d < 45))
            # 5m low, 15m uptrend, 4h high
            & ((aroonu_14_gt_75) | (aroonu_14_15m_lt_60) | (stochrsi_k_4h_gt_10))
            # 5m low, 15m uptrend, 1h still high
            & ((aroonu_14_gt_75) | (aroonu_14_15m_lt_80) | (stochrsi_k_1h_gt_40))
            # 5m downtrend, 15m down move, 4h still high, 1d still high
            & ((aroonu_14_gt_75) | (rsi_3_15m_gt_50) | (stochrsi_k_4h < 55.0) | (stochrsi_k_1d < 10.0))
            # 5m & 4h low, 1h up move
            & ((aroonu_14_gt_75) | (rsi_3_1h_lt_60) | (aroonu_14_4h_gt_10))
            # 5m uptrend, 15m down move, 1d still high
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_50) | (stochrsi_k_1d_gt_40))
            # 5m uptrend, 15m up move & still high
            & ((aroonu_14_lt_25) | (rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_40))
            # 5m uptrend, 1d down move & low
            & ((aroonu_14_lt_25) | (rsi_3_1d_gt_35) | (aroonu_14_1d_gt_20))
            # 5m up move & uptrend, 1d low
            & ((aroonu_14_lt_25) | (rsi_3_lt_50) | (aroonu_14_1d_gt_50))
            # 5m & 1d uptrend, 15m still high
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_40) | (aroonu_14_1d_lt_60))
            # 5m uptrend, 15m still high, 4h low
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_40) | (aroonu_14_4h_gt_10))
            # 5m uptrend, 1h uptrend, 1d uptrend
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_lt_60))
            # 5m & 1h & 1d uptrend
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_30) | (aroonu_14_1d_lt_40))
            # 5m uptrend, 1h uptrend & washed out
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_20))
            # 5m uptrend & down move, 4h up move & down move, 1d still high
            & ((aroonu_14_lt_30) | (roc_9_4h < -8.0) | (rsi_3_4h_gt_10) | (stochrsi_k_1d < 55.0) | (rsi_3 > 35.0))
            # 5m & 15m uptrend, 15m down move
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_50) | (aroonu_14_15m_lt_40))
            # 5m uptrend, 15m up move & downtrend, 1h down move
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_25) | (rsi_3_15m_lt_75) | (aroonu_14_15m > 15.0))
            # 5m uptrend & up move & washed out, 15m down move, 1h down move
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_30) | (rsi_3 < 80.0) | (rsi_3_15m > 65.0) | (stochrsi_k > 85.0))
            # 5m uptrend, 1h up move, 4h high
            & ((aroonu_14_lt_30) | (rsi_3_1h_lt_40) | (stochrsi_k_4h_gt_10))
            # 5m uptrend, 4h down move, 1d oversold
            & ((aroonu_14_lt_30) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_15))
            # 5m uptrend, 15m still high, 4h low
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_40) | (aroonu_14_4h_gt_30))
            # 5m uptrend, 15m & 1d still high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_40) | (stochrsi_k_1d_gt_30))
            # 5m & 1h uptrend, 15m still high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_60) | (aroonu_14_1h_lt_30))
            # 5m uptrend, 15m still high, 1d high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_60) | (stochrsi_k_1d_gt_10))
            # 5m uptrend, 15m still not low enough, 1h still high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_80) | (stochrsi_k_1h_gt_50))
            # 5m still not low enough, 15m low, 4h down move
            & ((stochrsi_k_gt_80) | (aroonu_14_15m_gt_30) | (rsi_3_4h_gt_10))
            # 5m still not low enough, 15m uptrend, 1h low
            & ((stochrsi_k_gt_80) | (aroonu_14_15m_lt_80) | (aroonu_14_1h_gt_0))
            # 5m still not low enough, 1d uptrend & still high
            & ((stochrsi_k_gt_80) | (aroonu_14_1d_lt_60) | (stochrsi_k_1d_gt_60))
            # 5m still not low enough, 1h uptrend, 4h low
            & ((stochrsi_k_gt_80) | (aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_20))
            # 5m still not low enough, 1h uptrend, 4h low
            & ((stochrsi_k_gt_80) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_gt_10))
            # 5m still not low enough, 1h down move, 4h high
            & ((stochrsi_k_gt_80) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_gt_10))
            # 5m washed out & downtrend, 15m still high, 1h down move, 1d down move
            & ((stochrsi_k_gt_80) | (rsi_3_1h_gt_35) | (stochrsi_k_15m_lt_30) | (roc_9_1d > 0.0) | (aroonu_14_gt_75))
            # 5m WILLR high & uptrend, 15m WILLR low & down move, 1h down move
            & (
              (willr_14 < -50.0) | (willr_14_15m > -35.0) | (aroonu_14 < 95.0) | (rsi_3_15m > 65.0) | (rsi_3_1h_gt_30)
            )
            # 5m willr 480 high & up move, 1d bot wick pct low & uptrend & still high
            & (
              (willr_480 < -90.0)
              | (bot_wick_pct_1d > 1.0)
              | (rsi_3 < 80.0)
              | (aroonu_14_1d < 55.0)
              | (stochrsi_k_1d_lt_20)
            )
            # 5m downtrend & up move, 15m down move & uptrend, 1h rising fast
            & (
              (rsi_3_15m_gt_40)
              | (rsi_3_change_pct_1h < -20.0)
              | (aroonu_14 > 0.0)
              | (aroonu_14_15m < 45.0)
              | (rsi_3 < 15.0)
            )
            # 5m still high, 15m down move & overbought & uptrend, 4h downtrend
            & (
              (rsi_3_15m_gt_50)
              | (aroonu_14_4h_gt_30)
              | (stochrsi_k_15m < 95.0)
              | (aroonu_14_15m < 5.0)
              | (stochrsi_k < 25.0)
            )
            # 5m washed out, 15m up move & washed out, 4h down move & downtrend
            & (
              (rsi_3_15m_lt_55)
              | (rsi_3_4h_gt_10)
              | (stochrsi_k > 70.0)
              | (aroonu_14_4h > 25.0)
              | (stochrsi_k_15m > 85.0)
            )
            # 15m & 1h down move, 15m uptrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_20) | (rsi_3_1h_gt_20))
            # 15m down move, 4h uptrend, 1d oversold
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_20) | (roc_9_1d_gt_neg_15))
            # 5m down move & uptrend, 15m down move, 1h down move
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_5) | (rsi_3 > 30.0) | (aroonu_14 < 5.0))
            # 15m down move & low, 1h up move
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_gt_10) | (rsi_3_1h_lt_40))
            # 15m down move & uptrend, 4h low
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_20) | (aroonu_14_4h_gt_20))
            # 15m down move, 1h & 1d low
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_gt_10) | (stochrsi_k_1d_gt_20))
            # 15m down move & still high, 1h downtrend, 1d up move
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_gt_10) | (stochrsi_k_15m_lt_70) | (rsi_3_1d_lt_35))
            # 5m up move, 15m down move, 1h downtrend, 4h CCI low
            & ((rsi_3_15m_gt_30) | (cci_20_4h > -225.0) | (aroonu_14_1h_gt_0) | (rsi_3 < 15.0))
            # 15m down move, 1h money leaving & still high, 4h downtrend
            & ((rsi_3_15m_gt_30) | (cmf_20_1h > -0.1) | (stochrsi_k_1h < 75.0) | (aroonu_14_4h_gt_0))
            # 15m & 1h down move, 4h low
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_20) | (aroonu_14_4h_gt_30))
            # 15m down move, 1h uptrend, 1d low
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_gt_10))
            # 15m down move & low, 1d uptrend
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_gt_20) | (aroonu_14_1d_lt_40))
            # 15m down move & still high, 4h high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_15m_gt_40) | (stochrsi_k_4h_gt_10))
            # 5m still high, 15m down move, 1h up move, 4h down move, 1d uptrend
            & ((rsi_3_15m_gt_45) | (rsi_3_4h_gt_15) | (rsi_3_1h < 25.0) | (stochrsi_k < 15.0) | (aroonu_14_1d < 15.0))
            # 15m down move & low, 4h up move
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_gt_10) | (rsi_3_4h_lt_40))
            # 5m uptrend & down move, 15m down move, 1h still high, 1d uptrend
            & ((rsi_3_15m_gt_50) | (aroonu_14_1d_lt_50) | (aroonu_14 < 75.0) | (stochrsi_k_1h_lt_30) | (rsi_3 > 30.0))
            # 15m down move, 4h low, 1d uptrend
            & ((rsi_3_15m_gt_50) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_50))
            # 15m down move & still high, 4h low
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_gt_30) | (aroonu_14_4h_gt_10))
            # 15m & 1h down move, 15m still high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_gt_30) | (rsi_3_1h_gt_20))
            # 15m down move, 1h high, 1d low
            & ((rsi_3_15m_gt_50) | (stochrsi_k_1h_gt_10) | (aroonu_14_1d_gt_20))
            # 15m down move & uptrend, 1h up move
            & ((rsi_3_15m_gt_55) | (aroonu_14_15m_lt_90) | (rsi_3_1h_lt_60))
            # 15m down move, 1d up move & low
            & ((rsi_3_15m_gt_55) | (aroonu_14_1d_gt_10) | (rsi_3_1d_lt_35))
            # 15m down move, 1h down move & downtrend, 4h downtrend & up move
            & ((rsi_3_15m_gt_55) | (aroonu_14_4h_gt_50) | (rsi_3_4h < 35.0) | (rsi_3_1h_gt_35) | (aroonu_14_1h_gt_40))
            # 15m & 1h down move, 1d uptrend
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_gt_20) | (aroonu_14_1d_lt_40))
            # 15m down move, 1h up move, 4h low
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_lt_65) | (aroonu_14_4h_gt_30))
            # 15m up move, 15m & 1h low
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_20))
            # 15m up move & low, 4h uptrend
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_gt_10) | (aroonu_14_4h_lt_60))
            # 15m up move & low, 1h down move
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_gt_10) | (rsi_3_1h_gt_10))
            # 15m up move & low, 1h high
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_gt_20) | (stochrsi_k_1h_gt_10))
            # 15m & 4h up move, 15m uptrend
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_lt_90) | (rsi_3_4h_lt_40))
            # 15m up move, 1d low & uptrend
            & ((rsi_3_15m_lt_50) | (aroonu_14_1d_gt_20) | (roc_9_1d_lt_10))
            # 15m up move, 1h uptrend & still high
            & ((rsi_3_15m_lt_50) | (aroonu_14_1h_lt_20) | (stochrsi_k_1h_gt_40))
            # 5m downtrend, 15m up move, 1h up move, 4h down move
            & ((rsi_3_15m_lt_50) | (roc_9_1h < -1.0) | (rsi_3_4h_gt_5) | (aroonu_14 > 0.0))
            # 15m up move & washed out, 1h downtrend
            & ((rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_10))
            # 15m up move & still high, 1d uptrend
            & ((rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_40) | (aroonu_14_1d_lt_40))
            # 15m up move & washed out, 1d up move
            & ((rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_40) | (roc_9_1d_lt_15))
            # 15m & 1h up move, 15m still high
            & ((rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_40) | (rsi_3_1h_lt_40))
            # 15m up move & still not low enough, 1d oversold
            & ((rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_70) | (roc_9_1d_gt_neg_10))
            # 15m up move, 1h & 4h high
            & ((rsi_3_15m_lt_50) | (stochrsi_k_1h_gt_10) | (stochrsi_k_4h_gt_10))
            # 15m down move & uptrend, 1h up move
            & ((rsi_3_15m_lt_55) | (aroonu_14_15m_lt_40) | (rsi_3_1h_lt_65))
            # 15m down move & uptrend, 1h up move
            & ((rsi_3_15m_lt_55) | (aroonu_14_15m_lt_60) | (rsi_3_1h_lt_50))
            # 5m uptrend & down move, 15m up move, 1h down move, 1d up move
            & ((rsi_3_15m_lt_55) | (rsi_3_1h_gt_25) | (aroonu_14 < 90.0) | (roc_9_1d < -5.0) | (rsi_3 > 55.0))
            # 5m down move, 15m up move, 1h down move & uptrend, 4h on the floor
            & ((rsi_3_15m_lt_55) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_25) | (stochrsi_k_4h_gt_10) | (rsi_3 > 65.0))
            # 15m up move & downtrend, 1d downtrend
            & ((rsi_3_15m_lt_60) | (aroonu_14_15m_gt_10) | (aroonu_14_1d_gt_10))
            # 15m up move, 15m & 1h uptrend
            & ((rsi_3_15m_lt_60) | (aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_20))
            # 15m up move & uptrend & still high
            & ((rsi_3_15m_lt_60) | (aroonu_14_15m_lt_30) | (stochrsi_k_15m_gt_60))
            # 15m up move & uptrend, 1h low
            & ((rsi_3_15m_lt_60) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_gt_10))
            # 15m up move & uptrend, 1h still high
            & ((rsi_3_15m_lt_60) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_gt_30))
            # 15m up move, 1h uptrend, 4h high
            & ((rsi_3_15m_lt_60) | (aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_10))
            # 15m up move, 4h low, 1d uptrend
            & ((rsi_3_15m_lt_60) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m up move, 1h washed out, 1d down move
            & ((rsi_3_15m_lt_60) | (roc_9_1d_gt_neg_15) | (stochrsi_k_1h_gt_20))
            # 5m down move & overbought, 15m up move, 1h up move
            & ((rsi_3_15m_lt_60) | (roc_9_1h < -1.0) | (rsi_3 > 45.0) | (stochrsi_k < 80.0))
            # 5m overbought, 15m up move, 1h up move & still high, 4h down move
            & ((rsi_3_15m_lt_60) | (roc_9_1h < -1.0) | (rsi_3_4h_gt_15) | (stochrsi_k < 85.0) | (stochrsi_k_1h < 45.0))
            # 15m up move, 1h down move, 1d uptrend
            & ((rsi_3_15m_lt_60) | (rsi_3_1h_gt_30) | (roc_9_1d_lt_10))
            # 15m up move, 4h down move, 1d low
            & ((rsi_3_15m_lt_60) | (rsi_3_4h_gt_5) | (stochrsi_k_1d_gt_20))
            # 15m up move & still high, 4h low
            & ((rsi_3_15m_lt_60) | (stochrsi_k_15m_gt_40) | (aroonu_14_4h_gt_30))
            # 15m up move, 15m & 1h still high
            & ((rsi_3_15m_lt_60) | (stochrsi_k_15m_gt_40) | (stochrsi_k_1h_gt_40))
            # 15m up move & washed out, 4h uptrend
            & ((rsi_3_15m_lt_60) | (stochrsi_k_15m_gt_60) | (aroonu_14_4h_lt_60))
            # 15m up move & uptrend, 1h low
            & ((rsi_3_15m_lt_70) | (aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_20))
            # 15m up move, 1h uptrend
            & ((rsi_3_15m_lt_70) | (aroonu_14_1h_lt_70))
            # 15m up move, 4h uptrend, 1d low
            & ((rsi_3_15m_lt_70) | (aroonu_14_4h_lt_20) | (aroonu_14_1d_gt_50))
            # 15m up move & still not high enough, 1d uptrend
            & ((rsi_3_15m_lt_70) | (stochrsi_k_15m_gt_70) | (aroonu_14_1d_lt_60))
            # 15m up move & still not low enough, 1h uptrend
            & ((rsi_3_15m_lt_70) | (stochrsi_k_15m_gt_80) | (aroonu_14_1h_lt_30))
            # 15m up move, 1h & 1d low
            & ((rsi_3_15m_lt_70) | (stochrsi_k_1h_gt_20) | (stochrsi_k_1d_gt_20))
            # 15m down move, 15m & 4h low
            & ((rsi_3_15m_lt_75) | (aroonu_14_15m_gt_10) | (aroonu_14_4h_gt_10))
            # 15m down move & low, 1h up move
            & ((rsi_3_15m_lt_75) | (aroonu_14_15m_gt_30) | (rsi_3_1h_lt_50))
            # 15m & 1h down move, 1h low
            & ((rsi_3_15m_lt_75) | (aroonu_14_1h_gt_20) | (rsi_3_1h_gt_35))
            # 15m up move & low, 1d still high
            & ((rsi_3_15m_lt_80) | (aroonu_14_15m_gt_20) | (stochrsi_k_1d_gt_50))
            # 15m up move, 4h up move
            & ((rsi_3_15m_lt_80) | (rsi_3_4h_lt_40))
            # 5m uptrend, 15m RSI high, 1h down move, 4h uptrend
            & ((rsi_14_15m_lt_40) | (rsi_3_1h_gt_25) | (aroonu_14 < 90.0) | (aroonu_14_4h < 15.0))
            # 5m uptrend, 15m money coming in, 1h money coming in, 1d uptrend
            & ((cmf_20_15m < 0.1) | (mfi_14_1h < 40.0) | (aroonu_14_1d_lt_60) | (aroonu_14 < 15.0))
            # 5m downtrend, 15m money coming in, 1h money coming in, 1d uptrend
            & ((cmf_20_15m < 0.1) | (mfi_14_1h < 40.0) | (aroonu_14_1d_lt_60) | (aroonu_14 > 0.0))
            # 5m up move, 15m downtrend, 4h downtrend, 1d still high
            & ((aroonu_14_15m_gt_10) | (aroonu_14_4h_gt_10) | (stochrsi_k_1d < 75.0) | (rsi_3 < 30.0))
            # 15m & 1d low, 4h uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_4h_lt_50) | (stochrsi_k_1d_gt_20))
            # 5m up move, 15m downtrend, 1h up move & still high
            & ((aroonu_14_15m_gt_10) | (roc_9_1h < -1.0) | (stochrsi_k_1h < 75.0) | (rsi_3 < 25.0))
            # 15m low, 1h up move, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_40) | (aroonu_14_1d_lt_40))
            # 15m low, 1h up move, 4h uptrend
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_40) | (aroonu_14_4h_lt_30))
            # 15m low, 1h up move, 4h down move
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_40) | (rsi_3_4h_gt_5))
            # 15m downtrend, 1h up move, 1d downtrend
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_50) | (aroonu_14_1d_gt_10))
            # 15m & 1h low
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_0))
            # 15m downtrend, 1h downtrend, 4h uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_70))
            # 15m low, 1h & 1d uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_lt_30))
            # 15m low, 4h & 1d uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_4h_lt_20) | (aroonu_14_1d_lt_30))
            # 15m down move & low, 4h oversold
            & ((aroonu_14_15m_gt_20) | (rsi_3_15m_lt_55) | (roc_9_4h_gt_neg_15))
            # 15m & 1d low, 1d down move
            & ((aroonu_14_15m_gt_20) | (rsi_3_1d_gt_30) | (aroonu_14_1d_gt_10))
            # 15m low, 1h up move, 1d uptrend
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_50) | (aroonu_14_1d_lt_40))
            # 15m downtrend, 1h up move, 4h uptrend
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_50) | (aroonu_14_4h_lt_30))
            # 15m downtrend, 1h up move, 1d washed out
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_60) | (stochrsi_k_1d_gt_20))
            # 15m & 4h low, 1d uptrend
            & ((aroonu_14_15m_gt_30) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_90))
            # 15m downtrend, 4h up move, 1d downtrend
            & ((aroonu_14_15m_gt_30) | (rsi_3_4h_lt_40) | (aroonu_14_1d_gt_10))
            # 15m & 4h & 1d low
            & ((aroonu_14_15m_gt_30) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_20))
            # 15m low, 1d uptrend & still high
            & ((aroonu_14_15m_gt_40) | (aroonu_14_1d_lt_60) | (stochrsi_k_1d_gt_40))
            # 15m down move & low, 1h uptrend
            & ((aroonu_14_15m_gt_40) | (rsi_3_15m_gt_30) | (aroonu_14_1h_lt_75))
            # 15m down move & low, 4h uptrend
            & ((aroonu_14_15m_gt_40) | (rsi_3_15m_gt_40) | (aroonu_14_4h_lt_40))
            # 15m low, 1h up move & uptrend
            & ((aroonu_14_15m_gt_40) | (rsi_3_1h_lt_50) | (aroonu_14_1h_lt_20))
            # 5m down move, 15m downtrend, 1h up move, 4h down move, 1d down move
            & ((aroonu_14_15m_gt_50) | (roc_9_1h < -5.0) | (rsi_3_4h_gt_10) | (rsi_3 > 35.0) | (rsi_3_1d_gt_25))
            # 5m up move, 15m downtrend, 1h down move, 4h downtrend & up move
            & ((aroonu_14_15m_gt_60) | (aroonu_14_4h_gt_30) | (rsi_3 < 80.0) | (roc_9_4h < -10.0) | (rsi_3_1h_gt_60))
            # 5m overbought & up move, 15m downtrend & down move, 4h downtrend
            & ((aroonu_14_15m_gt_60) | (aroonu_14_4h_gt_30) | (stochrsi_k < 95.0) | (rsi_3_15m_gt_45) | (rsi_3 < 60.0))
            # 5m downtrend, 15m downtrend, 1h down move, 4h downtrend
            & ((aroonu_14_15m_gt_60) | (aroonu_14_4h_gt_50) | (roc_9_1h_gt_neg_15) | (aroonu_14 > 0.0))
            # 15m & 1d uptrend, 4h low
            & ((aroonu_14_15m_lt_20) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m uptrend, 1h up move, 1d low
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_lt_40) | (aroonu_14_1d_gt_30))
            # 15m & 1h uptrend, 4h low
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_gt_20))
            # 15m uptrend, 1h down move, 1d low
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_10) | (aroonu_14_1d_gt_20))
            # 15m uptrend & still high, 1d oversold
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_15m_gt_60) | (roc_9_1d_gt_neg_10))
            # 15m uptrend, 1h washed out, 4h downtrend
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_1h_gt_20) | (aroonu_14_4h_gt_10))
            # 15m uptrend, 1d uptrend & washed out
            & ((aroonu_14_15m_lt_40) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d_gt_30))
            # 15m & 4h uptrend, 1d low
            & ((aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_gt_30))
            # 15m & 1d uptrend, 1h down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_40) | (aroonu_14_1d_lt_90))
            # 15m uptrend, 1h down move, 1d low
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_40) | (stochrsi_k_1d_gt_20))
            # 15m uptrend, 15m & 1d low
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_20) | (aroonu_14_1d_gt_20))
            # 15m uptrend & still high, 1d low
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_60) | (aroonu_14_1d_gt_10))
            # 15m uptrend, 1h washed out, 4h on the floor
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_10))
            # 15m & 4h uptrend, 1h still high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_60) | (aroonu_14_4h_lt_40))
            # 15m & 1h uptrend, 1d still high
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_25) | (stochrsi_k_1d_gt_60))
            # 15m down move, 15m & 1d uptrend
            & ((aroonu_14_15m_lt_50) | (rsi_3_15m_gt_35) | (roc_9_1d_lt_0))
            # 15m uptrend & still not low enough, 1h still high
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_70) | (stochrsi_k_1h_gt_60))
            # 15m uptrend, 1d downtrend & on the floor
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1d_gt_10) | (stochrsi_k_1d_gt_10))
            # 15m & 1h & 1d uptrend
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_lt_60))
            # 15m uptrend, 1h & 1d down move
            & ((aroonu_14_15m_lt_60) | (rsi_3_1h_gt_40) | (rsi_3_1d_gt_30))
            # 15m uptrend, 1h & 1d down move
            & ((aroonu_14_15m_lt_60) | (rsi_3_1h_gt_50) | (rsi_3_1d_gt_25))
            # 15m uptrend & washed out, 1d uptrend
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_15m_gt_40) | (aroonu_14_1d_lt_60))
            # 15m uptrend, 4h downtrend, 1d up move
            & ((aroonu_14_15m_lt_70) | (aroonu_14_4h_gt_30) | (roc_9_1d_lt_15))
            # 15m & 1d uptrend, 1d down move
            & ((aroonu_14_15m_lt_70) | (rsi_3_1d_gt_30) | (roc_9_1d_lt_0))
            # 15m uptrend & washed out, 1d downtrend
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_15m_gt_40) | (aroonu_14_1d_gt_30))
            # 15m & 4h uptrend, 1h low
            & ((aroonu_14_15m_lt_80) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_lt_20))
            # 15m & 4h uptrend, 1d low
            & ((aroonu_14_15m_lt_80) | (aroonu_14_4h_lt_20) | (aroonu_14_1d_gt_20))
            # 15m uptrend, 1h low & still high
            & ((aroonu_14_15m_lt_90) | (aroonu_14_1h_gt_0) | (stochrsi_k_1h_gt_60))
            # 15m uptrend, 1h downtrend & washed out
            & ((aroonu_14_15m_lt_90) | (aroonu_14_1h_gt_10) | (stochrsi_k_1h_gt_40))
            # 15m & 1h uptrend
            & ((aroonu_14_15m_lt_90) | (aroonu_14_1h_lt_30))
            # 15m uptrend & washed out, 1h uptrend
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_15m_gt_80) | (aroonu_14_1h_lt_25))
            # 5m up move, 15m AROOND high & still high, 4h downtrend & up move
            & (
              (aroond_14_15m_lt_50)
              | (aroonu_14_4h_gt_30)
              | (rsi_3 < 80.0)
              | (roc_9_4h < -10.0)
              | (stochrsi_k_15m < 35.0)
            )
            # 15m AROOND low, 4h down move, 1d still high
            & ((aroond_14_15m > 30.0) | (rsi_3_4h_gt_3) | (stochrsi_k_1d < 75.0))
            # 5m still high, 15m AROOND high, 1h money coming in
            & ((aroond_14_15m_lt_80) | (mfi_14_1h < 50.0) | (stochrsi_k < 75.0))
            # 5m uptrend, 15m AROOND high, 4h still high, 1d RSI low
            & ((aroond_14_15m_lt_80) | (rsi_14_1d_gt_40) | (stochrsi_k_4h < 25.0) | (aroonu_14_lt_30))
            # 5m up move, 15m washed out & downtrend, 4h on the floor, 1d down move
            & (
              (stochrsi_k_15m_gt_40)
              | (stochrsi_k_4h_gt_10)
              | (rsi_3_1d_gt_20)
              | (aroonu_14_15m > 15.0)
              | (rsi_3 < 25.0)
            )
            # 5m up move, 15m washed out & downtrend, 4h down move, 1d downtrend
            & (
              (stochrsi_k_15m_gt_70)
              | (rsi_3_4h_gt_3)
              | (aroonu_14_15m > 15.0)
              | (aroonu_14_1d > 45.0)
              | (rsi_3 < 10.0)
            )
            # 15m & 1h low, 1h still high
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_20) | (stochrsi_k_1h_gt_40))
            # 15m & 1d low, 1h uptrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_gt_10))
            # 15m washed out, 1h uptrend, 4h on the floor
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_70) | (stochrsi_k_4h_gt_10))
            # 15m washed out, 1d up move
            & ((stochrsi_k_15m_gt_20) | (roc_9_1d_lt_30))
            # 5m down move, 15m washed out, 4h still high, 1d up move
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1d_lt_35) | (stochrsi_k_4h_lt_30) | (rsi_3 > 25.0))
            # 15m low, 4h high, 1d uptrend
            & ((stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_lt_60))
            # 15m still high, 1h low, 4h uptrend
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_70))
            # 15m still high, 4h low, 1d uptrend
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_40))
            # 15m still high, 1h up move, 4h low
            & ((stochrsi_k_15m_gt_40) | (rsi_3_1h_lt_50) | (aroonu_14_4h_gt_10))
            # 15m still high, 1h low, 1d uptrend
            & ((stochrsi_k_15m_gt_60) | (aroonu_14_1h_gt_10) | (roc_9_1d_lt_0))
            # 15m still high, 1h low, 1d uptrend
            & ((stochrsi_k_15m_gt_60) | (aroonu_14_1h_gt_20) | (aroonu_14_1d_lt_40))
            # 15m still high, 4h low, 1d uptrend
            & ((stochrsi_k_15m_gt_60) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m still high, 4h uptrend & high
            & ((stochrsi_k_15m_gt_60) | (aroonu_14_4h_lt_20) | (stochrsi_k_4h_gt_10))
            # 15m still high, 1h up move, 1d low
            & ((stochrsi_k_15m_gt_60) | (rsi_3_1h_lt_40) | (aroonu_14_1d_gt_10))
            # 15m washed out, 1h up move & uptrend
            & ((stochrsi_k_15m_gt_60) | (rsi_3_1h_lt_40) | (aroonu_14_1h_lt_40))
            # 15m still high, 4h up move & uptrend
            & ((stochrsi_k_15m_gt_60) | (rsi_3_4h_lt_40) | (aroonu_14_4h_lt_20))
            # 15m still not low enough, 1h down move & low
            & ((stochrsi_k_15m_gt_70) | (rsi_3_1h_gt_20) | (aroonu_14_1h_gt_10))
            # 15m still not low enough, 1d uptrend & still high
            & ((stochrsi_k_15m_gt_80) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_gt_30))
            # 5m down move, 15m down move, 1d down move & downtrend
            & ((roc_9_15m > -1.0) | (rsi_3_1d_gt_20) | (aroonu_14_1d_gt_10) | (rsi_3 > 30.0))
            # 15m down move, 1h down move
            & ((roc_9_15m > -30.0) | (rsi_3_1h_gt_5))
            # 15m uptrend, 1h down move & downtrend, 4h downtrend & up move
            & (
              (rsi_3_1h_gt_35)
              | (aroonu_14_4h_gt_30)
              | (rsi_3_4h < 35.0)
              | (aroonu_14_15m < 10.0)
              | (aroonu_14_1h > 15.0)
            )
            # 1h down move, 4h uptrend & low
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_lt_30) | (stochrsi_k_4h_gt_20))
            # 1h & 1d down move, 1h still high
            & ((rsi_3_1h_gt_30) | (stochrsi_k_1h_gt_30) | (rsi_3_1d_gt_30))
            # 5m washed out, 15m up move, 1h down move & up move
            & ((rsi_3_1h_gt_45) | (roc_9_1h < -5.0) | (rsi_3_15m_lt_75) | (stochrsi_k > 85.0))
            # 1h up move, 1d low & high
            & ((rsi_3_1h_lt_40) | (aroonu_14_1d_gt_20) | (stochrsi_k_1d_gt_10))
            # 1h up move, 1h & 1d uptrend
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_lt_50))
            # 1h up move & uptrend, 4h uptrend
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_30))
            # 1h up move, 1d down move & uptrend
            & ((rsi_3_1h_lt_40) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_50))
            # 1h up move, 1d low
            & ((rsi_3_1h_lt_50) | (aroonu_14_1d_gt_50) | (stochrsi_k_1d_gt_20))
            # 1h up move & downtrend, 1d uptrend
            & ((rsi_3_1h_lt_50) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_lt_80))
            # 1h up move & washed out, 1d downtrend
            & ((rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_60) | (aroonu_14_1d_gt_10))
            # 1h up move, 4h high, 1d uptrend
            & ((rsi_3_1h_lt_50) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_lt_40))
            # 1h up move & low, 1d uptrend
            & ((rsi_3_1h_lt_60) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_lt_60))
            # 1h up move, 4h uptrend, 1d low
            & ((rsi_3_1h_lt_60) | (aroonu_14_4h_lt_30) | (stochrsi_k_1d_gt_20))
            # 1h up move & still high, 1d low
            & ((rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_60) | (aroonu_14_1d_gt_20))
            # 5m uptrend & still high, 1h RSI low & UO high & down move
            & (
              (rsi_14_1h > 35.0) | (uo_7_14_28_1h < 50.0) | (aroonu_14 < 90.0) | (rsi_3_1h_gt_25) | (stochrsi_k < 75.0)
            )
            # 5m up move & uptrend, 15m overbought, 1h downtrend & up move
            & (
              (aroonu_14_1h_gt_20) | (roc_9_1h < -1.0) | (stochrsi_k_15m < 90.0) | (rsi_3 < 75.0) | (aroonu_14 < 60.0)
            )
            # 1h & 1d low, 1d high
            & ((aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_20) | (stochrsi_k_1d_gt_10))
            # 1h & 1d low
            & ((aroonu_14_1h_gt_0) | (stochrsi_k_1h_gt_20) | (aroonu_14_1d_gt_30))
            # 1h & 1d low, 4h uptrend
            & ((aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_gt_10))
            # 5m down move & uptrend, 15m up move, 1h downtrend, 4h up move
            & ((aroonu_14_1h_gt_10) | (roc_9_4h < -8.0) | (rsi_3_15m < 65.0) | (rsi_3 > 55.0) | (aroonu_14 < 55.0))
            # 5m up move, 1h downtrend & up move, 4h uptrend, 1d down move
            & ((aroonu_14_1h_gt_10) | (rsi_3_1d_gt_25) | (rsi_3 < 80.0) | (roc_9_1h < -5.0) | (aroonu_14_4h < 5.0))
            # 1h & 4h low, 1d uptrend
            & ((aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 5m uptrend, 1h downtrend & up move, 1d down move
            & ((aroonu_14_1h_gt_20) | (roc_9_1h < -5.0) | (rsi_3_1d_gt_10) | (aroonu_14 < 95.0))
            # 1h low & still high, 1d up move
            & ((aroonu_14_1h_gt_20) | (stochrsi_k_1h_gt_30) | (rsi_3_1d_lt_35))
            # 1h & 1d uptrend, 4h low
            & ((aroonu_14_1h_lt_20) | (aroonu_14_4h_gt_10) | (roc_9_1d_lt_10))
            # 1h & 4h uptrend, 4h high
            & ((aroonu_14_1h_lt_20) | (aroonu_14_4h_lt_50) | (stochrsi_k_4h_gt_10))
            # 1h uptrend, 4h up move, 1d low
            & ((aroonu_14_1h_lt_20) | (rsi_3_4h_lt_40) | (aroonu_14_1d_gt_20))
            # 1h uptrend, 4h high, 1d low
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 1h & 1d uptrend, 4h high
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_10) | (roc_9_1d_lt_0))
            # 1h & 1d uptrend, 4h low
            & ((aroonu_14_1h_lt_25) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_40))
            # 1h uptrend, 4h on the floor, 1d on the floor
            & ((aroonu_14_1h_lt_25) | (stochrsi_k_4h_gt_10) | (stochrsi_k_1d_gt_10))
            # 1h uptrend, 1d uptrend
            & ((aroonu_14_1h_lt_30) | (aroonu_14_1d_lt_90))
            # 1h uptrend, 4h & 1d low
            & ((aroonu_14_1h_lt_30) | (aroonu_14_4h_gt_10) | (stochrsi_k_1d_gt_20))
            # 1h uptrend, 4h & 1d low
            & ((aroonu_14_1h_lt_40) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 1h uptrend & low, 4h high
            & ((aroonu_14_1h_lt_40) | (stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_10))
            # 1h washed out & uptrend, 4h downtrend, 1d uptrend & washed out
            & (
              (stochrsi_k_1h_gt_50)
              | (aroonu_14_4h_gt_20)
              | (aroonu_14_1d < 65.0)
              | (stochrsi_k_1d > 35.0)
              | (aroonu_14_1h < 10.0)
            )
            # 1h & 4h high, 4h low
            & ((stochrsi_k_1h_gt_10) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_10))
            # 1h low, 4h & 1d uptrend
            & ((stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_80))
            # 1h low, 4h uptrend & high
            & ((stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_10))
            # 1h still high, 4h up move, 1d high
            & ((stochrsi_k_1h_gt_60) | (rsi_3_4h_lt_40) | (stochrsi_k_1d_gt_10))
            # 5m down move, 1h up move, 4h down move, 1d up move
            & ((roc_9_1h < -1.0) | (rsi_3_4h_gt_10) | (roc_9_1d < 5.0) | (rsi_3 > 45.0))
            # 5m down move, 15m up move, 1h up move, 1d down move & downtrend
            & ((roc_9_1h < -5.0) | (rsi_3_1d_gt_20) | (rsi_3_15m < 65.0) | (rsi_3 > 45.0) | (aroonu_14_1d > 60.0))
            # 5m down move, 1h up move, 4h down move, 1d down move
            & ((roc_9_1h < -5.0) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_10) | (rsi_3_gt_15))
            # 5m uptrend, 4h down move & downtrend, 1d still high
            & ((rsi_3_4h_gt_10) | (aroonu_14_4h_gt_10) | (stochrsi_k_1d < 75.0) | (aroonu_14 < 5.0))
            # 4h down move & downtrend, 1d still high
            & ((rsi_3_4h_gt_3) | (aroonu_14_4h_gt_10) | (stochrsi_k_1d < 75.0))
            # 4h up move & low, 1d uptrend
            & ((rsi_3_4h_lt_40) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_lt_60))
            # 4h & 1d low, 1d high
            & ((aroonu_14_4h_gt_20) | (aroonu_14_1d_gt_10) | (stochrsi_k_1d_gt_10))
            # 4h low, 1d down move & uptrend
            & ((aroonu_14_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_40))
            # 1h up move, 4h uptrend & still high, 1d downtrend
            & ((aroonu_14_4h_lt_30) | (aroonu_14_1d_gt_10) | (stochrsi_k_4h < 25.0) | (rsi_3_1h < 30.0))
            # 4h high, 1d low & uptrend
            & ((stochrsi_k_4h_gt_10) | (stochrsi_k_1d_gt_20) | (roc_9_1d_lt_0))
            # 5m pre-entry tightness low & uptrend, 4h down move, 1d up move & washed out
            & (
              (ph_pre_tight > 1.0) | (rsi_3_4h_gt_20) | (aroonu_14 < 75.0) | (roc_9_1d < -5.0) | (stochrsi_k_1d_gt_60)
            )
            # 5m pre-entry tightness low & uptrend, 4h on the floor & uptrend, 1d down move
            & (
              (ph_pre_tight > 1.0)
              | (stochrsi_k_4h_gt_10)
              | (aroonu_14 < 75.0)
              | (aroonu_14_4h < 15.0)
              | (rsi_3_1d_gt_35)
            )
            # 5m squeeze count low & down move, 15m up move, 1h uptrend
            & ((sqz_cnt_24 > 4.0) | (rsi_3_15m_lt_60) | (rsi_3 > 45.0) | (aroonu_14_1h < 10.0))
            # 5m vol rel high & washed out, 15m up move
            & ((vol_rel < 2.0) | (rsi_3_15m_lt_60) | (stochrsi_k > 60.0))
            # 15m rising fast, 1h down move, 4h uptrend
            & ((rsi_3_change_pct_15m < 70.0) | (rsi_3_1h_gt_5) | (aroonu_14_4h < 55.0))
            # 15m downtrend, 4h top wick low, 1d money coming in & down move
            & ((top_wick_pct_4h > 0.5) | (mfi_14_1d < 60.0) | (rsi_3_1d_gt_20) | (aroonu_14_15m_gt_50))
          )

          # Logic
          short_entry_logic.append(
            # 4h trend birth: ADX crossing up through 20 on the latest 4h candle
            (adx_14_4h > 20.0)
            & (np_shift(adx_14_4h, 48) <= 20.0)
            # pointing down, under the 200 EMA
            & (minus_di_14_4h > plus_di_14_4h)
            & (close < ema_200)
          )

        # Condition #506 - Donchian 7-day breakdown (Short, experimental, RAW — mirror).
        if short_entry_condition_index == 506:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m up move, 15m down move & downtrend, 1h downtrend, 4h washed out
            (
              (rsi_3 < 20.0)
              | (roc_9_15m > -3.0)
              | (aroonu_14_1h_gt_0)
              | (aroonu_14_15m_gt_30)
              | (stochrsi_k_4h > 55.0)
            )
            # 5m up move, 1h uptrend, 4h on the floor & uptrend, 1d up move
            & (
              (rsi_3 < 5.0) | (aroonu_14_1h_lt_40) | (stochrsi_k_4h > 5.0) | (roc_9_1d < -10.0) | (aroonu_14_4h < 5.0)
            )
            # daily no recent low, 1h stochastic at the floor and 5m momentum alive
            & ((rsi_3 < 20) | (stochrsi_k_1h > 5) | (aroond_14_1d > 55))
            # 5m up move & uptrend & still high, 1h down move
            & ((rsi_3 < 20.0) | (rsi_3_1h_gt_5) | (aroonu_14_lt_30) | (stochrsi_k < 45.0))
            # 5m up move, 1h down move, 4h washed out, 1d downtrend & up move
            & ((rsi_3 < 5.0) | (aroonu_14_1d_gt_50) | (rsi_3_1d_lt_35) | (roc_9_1h > -5.0) | (stochrsi_k_4h > 55.0))
            # 5m up move, 15m down move, 1h washed out & downtrend, 1d downtrend
            & ((rsi_3 < 5.0) | (rsi_3_15m_gt_10) | (stochrsi_k_1h_gt_20) | (aroonu_14_1h_gt_30) | (aroonu_14_1d_gt_50))
            # 5m & 4h down move, 15m low
            & ((rsi_3_gt_10) | (aroonu_14_15m_gt_10) | (rsi_3_4h_gt_5))
            # 5m & 1h down move, 1h uptrend
            & ((rsi_3_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_20))
            # 5m down move, 1h down move, 4h still high, 1d uptrend
            & ((rsi_3_gt_10) | (rsi_3_1h_gt_30) | (aroonu_14_1d_lt_80) | (stochrsi_k_4h < 35.0))
            # 5m down move, 1h high, 4h uptrend
            & ((rsi_3_gt_10) | (stochrsi_k_1h_gt_10) | (aroonu_14_4h_lt_20))
            # 5m down move, 4h still high, 1d oversold
            & ((rsi_3_gt_10) | (stochrsi_k_4h_gt_30) | (roc_9_1d_gt_neg_25))
            # 5m down move, 15m uptrend, 1h low
            & ((rsi_3_gt_15) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_gt_20))
            # 5m down move, 15m still high & down move, 1h down move, 1d on the floor
            & ((rsi_3_gt_15) | (stochrsi_k_1d_gt_10) | (rsi_3_1h_gt_5) | (stochrsi_k_15m < 15.0) | (rsi_3_15m_gt_20))
            # 5m down move, 4h still high, 1d uptrend
            & ((rsi_3_gt_15) | (stochrsi_k_4h_gt_30) | (aroonu_14_1d_lt_60))
            # 5m down move, 15m & 1h low
            & ((rsi_3_gt_3) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_0))
            # 5m down move, 15m low & still high
            & ((rsi_3_gt_3) | (aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_30))
            # 5m down move, 15m & 4h low
            & ((rsi_3_gt_3) | (aroonu_14_15m_gt_10) | (stochrsi_k_4h_gt_20))
            # 5m down move, 15m uptrend, 1h oversold
            & ((rsi_3_gt_3) | (aroonu_14_15m_lt_20) | (roc_9_1h_gt_neg_10))
            # 5m & 1d down move, 15m uptrend
            & ((rsi_3_gt_3) | (aroonu_14_15m_lt_20) | (rsi_3_1d_gt_10))
            # 5m down move, 15m uptrend, 1h low
            & ((rsi_3_gt_3) | (aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_20))
            # 5m & 1d down move, 15m uptrend
            & ((rsi_3_gt_3) | (aroonu_14_15m_lt_30) | (rsi_3_1d_gt_15))
            # 5m down move, 15m uptrend, 4h still high
            & ((rsi_3_gt_3) | (aroonu_14_15m_lt_40) | (stochrsi_k_4h_gt_30))
            # 5m down move, 15m uptrend, 4h low
            & ((rsi_3_gt_3) | (aroonu_14_15m_lt_50) | (aroonu_14_4h_gt_10))
            # 5m down move, 1h low, 4h oversold
            & ((rsi_3_gt_3) | (aroonu_14_1h_gt_10) | (roc_9_4h_gt_neg_10))
            # 5m down move, 1h & 4h uptrend
            & ((rsi_3_gt_3) | (aroonu_14_1h_lt_20) | (aroonu_14_4h_lt_60))
            # 5m down move, 1h uptrend, 4h low
            & ((rsi_3_gt_3) | (aroonu_14_1h_lt_30) | (aroonu_14_4h_gt_0))
            # 5m & 1d down move, 1h uptrend
            & ((rsi_3_gt_3) | (aroonu_14_1h_lt_60) | (rsi_3_1d_gt_15))
            # 5m down move, 4h low, 1d uptrend
            & ((rsi_3_gt_3) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_40))
            # 5m & 1d down move, 4h low
            & ((rsi_3_gt_3) | (aroonu_14_4h_gt_10) | (rsi_3_1d_gt_15))
            # 5m & 15m & 1h down move
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_25) | (rsi_3_1h_gt_20))
            # 5m down move, 1h up move & low
            & ((rsi_3_gt_3) | (rsi_3_1h_lt_50) | (aroonu_14_1h_gt_30))
            # 5m & 4h down move, 1d uptrend
            & ((rsi_3_gt_3) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_60))
            # 5m down move, 15m high, 1d uptrend
            & ((rsi_3_gt_3) | (stochrsi_k_15m_gt_10) | (aroonu_14_1d_lt_70))
            # 5m & 1d down move, 15m high
            & ((rsi_3_gt_3) | (stochrsi_k_15m_gt_10) | (rsi_3_1d_gt_20))
            # 5m down move, 4h still high, 1d high
            & ((rsi_3_gt_3) | (stochrsi_k_4h_gt_40) | (stochrsi_k_1d_gt_10))
            # 5m & 4h down move, 15m low
            & ((rsi_3_gt_5) | (aroonu_14_15m_gt_10) | (rsi_3_4h_gt_15))
            # 5m down move, 15m low
            & ((rsi_3_gt_5) | (aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_20))
            # 5m & 1h down move, 15m uptrend
            & ((rsi_3_gt_5) | (aroonu_14_15m_lt_20) | (rsi_3_1h_gt_10))
            # 5m & 4h down move, 15m uptrend
            & ((rsi_3_gt_5) | (aroonu_14_15m_lt_70) | (rsi_3_4h_gt_25))
            # 5m down move, 1h low, 1d uptrend
            & ((rsi_3_gt_5) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_lt_40))
            # 5m down move, 1h low, 1d oversold
            & ((rsi_3_gt_5) | (aroonu_14_1h_gt_10) | (roc_9_1d_gt_neg_20))
            # 5m down move & uptrend, 1h up move
            & ((rsi_3_gt_5) | (aroonu_14_lt_30) | (rsi_3_1h_lt_40))
            # 5m & 4h down move, 5m uptrend
            & ((rsi_3_gt_5) | (aroonu_14_lt_30) | (rsi_3_4h_gt_25))
            # 5m down move, 15m high, 4h still high
            & ((rsi_3_gt_5) | (stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_30))
            # 5m RSI high & downtrend, 15m stochk 14 3 3 low, 4h still high, 1d still high
            & (
              (rsi_14 < 28.0)
              | (stochk_14_3_3_15m > 15.0)
              | (stochrsi_k_4h < 65.0)
              | (stochrsi_k_1d < 25.0)
              | (aroonu_14 > 40.0)
            )
            # 5m downtrend & still high & down move, 15m downtrend, 4h on the floor
            & (
              (aroonu_14 > 10.0) | (aroonu_14_15m_gt_30) | (stochrsi_k < 70.0) | (stochrsi_k_4h > 5.0) | (rsi_3 > 20.0)
            )
            # 5m downtrend & down move, 15m on the floor, 1h downtrend, 1d still high
            & (
              (aroonu_14 > 10.0)
              | (aroonu_14_1h_gt_20)
              | (stochrsi_k_1d_lt_40)
              | (stochrsi_k_15m > 5.0)
              | (rsi_3_gt_15)
            )
            # 5m downtrend, 1h on the floor, 4h washed out, 1d downtrend & up move
            & (
              (aroonu_14 > 30.0)
              | (aroonu_14_1d_gt_10)
              | (roc_9_1d_lt_0)
              | (stochrsi_k_1h > 15.0)
              | (stochrsi_k_4h > 35.0)
            )
            # 5m downtrend, 4h up move, 1d downtrend
            & ((aroonu_14 > 10.0) | (aroonu_14_1d_gt_10) | (rsi_3_4h_lt_80))
            # 5m downtrend, 4h down move, 1d downtrend & up move & down move
            & ((aroonu_14 > 10.0) | (aroonu_14_1d_gt_50) | (rsi_3_4h_gt_5) | (roc_9_1d < -10.0) | (rsi_3_1d_gt_10))
            # 5m downtrend & still high & down move, 1h downtrend, 1d still high
            & ((aroonu_14 > 10.0) | (aroonu_14_1h_gt_10) | (stochrsi_k_1d_lt_40) | (stochrsi_k < 5.0) | (rsi_3_gt_15))
            # 5m downtrend & vol rel low & still high, 15m up move, 4h on the floor
            & ((aroonu_14 > 10.0) | (vol_rel > 3.0) | (stochrsi_k < 70.0) | (stochrsi_k_4h > 5.0) | (rsi_3_15m < 5.0))
            # 5m & 1d uptrend, 15m low
            & ((aroonu_14_lt_25) | (aroonu_14_15m_gt_10) | (aroonu_14_1d_lt_40))
            # 5m uptrend, 15m low, 4h still high
            & ((aroonu_14_lt_25) | (aroonu_14_15m_gt_10) | (stochrsi_k_4h_gt_40))
            # 5m & 15m & 4h uptrend
            & ((aroonu_14_lt_25) | (aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_40))
            # 5m & 15m uptrend, 4h up move
            & ((aroonu_14_lt_25) | (aroonu_14_15m_lt_30) | (rsi_3_4h_lt_40))
            # 5m & 15m uptrend, 15m high
            & ((aroonu_14_lt_25) | (aroonu_14_15m_lt_60) | (stochrsi_k_15m_gt_10))
            # 5m & 15m uptrend, 4h low
            & ((aroonu_14_lt_25) | (aroonu_14_15m_lt_70) | (aroonu_14_4h_gt_10))
            # 5m & 1h uptrend, 4h low
            & ((aroonu_14_lt_25) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_gt_10))
            # 5m uptrend, 4h low & high
            & ((aroonu_14_lt_25) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_10))
            # 5m uptrend, 15m down move, 4h still high
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_20) | (stochrsi_k_4h_gt_30))
            # 5m & 1h uptrend, 1h down move
            & ((aroonu_14_lt_25) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_20))
            # 5m uptrend, 1h up move, 1d low
            & ((aroonu_14_lt_25) | (rsi_3_1h_lt_40) | (aroonu_14_1d_gt_10))
            # 5m uptrend, 1h up move, 4h down move
            & ((aroonu_14_lt_25) | (rsi_3_1h_lt_40) | (rsi_3_4h_gt_10))
            # 5m uptrend, 1h up move & still high
            & ((aroonu_14_lt_25) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_30))
            # 5m uptrend & down move, 4h down move, 1d up move & washed out
            & ((aroonu_14_lt_25) | (rsi_3_4h_gt_10) | (rsi_3_1d < 20.0) | (stochrsi_k_1d > 35.0) | (rsi_3_gt_10))
            # 5m & 4h uptrend, 15m high
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_10) | (aroonu_14_4h_lt_50))
            # 5m uptrend, 1h & 4h low
            & ((aroonu_14_lt_25) | (stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m no recent low, 5m a new high and 15m cycle falling
            & ((aroonu_14_lt_30) | (aroond_14_15m > 30) | (cci_20_change_pct_15m > -195))
            # 5m & 15m uptrend, 4h low
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_30) | (stochrsi_k_4h_gt_20))
            # 5m & 15m & 1h uptrend
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_50))
            # 5m & 15m uptrend, 15m still high
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_40))
            # 5m & 15m uptrend, 1d high
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_50) | (stochrsi_k_1d_gt_10))
            # 5m uptrend, 1h low, 1d down move
            & ((aroonu_14_lt_30) | (aroonu_14_1h_gt_0) | (rsi_3_1d_gt_10))
            # 5m & 1d uptrend, 1h low
            & ((aroonu_14_lt_30) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_lt_60))
            # 5m & 1h uptrend, 1h high
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_20) | (stochrsi_k_1h_gt_10))
            # 5m & 1h uptrend, 4h down move
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_25) | (rsi_3_4h_gt_25))
            # 5m & 1h uptrend, 1d down move
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_50) | (rsi_3_1d_gt_10))
            # 5m uptrend, 15m still high, 4h uptrend & down move
            & ((aroonu_14_lt_30) | (aroonu_14_4h_lt_40) | (stochrsi_k_15m_lt_70) | (roc_9_4h > -5.0))
            # 5m & 1h uptrend, 15m down move
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_20) | (aroonu_14_1h_lt_30))
            # 5m uptrend, 15m down move, 4h low
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_30) | (stochrsi_k_4h_gt_20))
            # 5m & 1d uptrend, 1h down move
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_30))
            # 5m uptrend, 1h up move, 4h down move
            & ((aroonu_14_lt_30) | (rsi_3_1h_lt_40) | (rsi_3_4h_gt_20))
            # 5m uptrend, 1h up move, 1d oversold
            & ((aroonu_14_lt_30) | (rsi_3_1h_lt_50) | (roc_9_1d_gt_neg_10))
            # 5m uptrend, 4h down move & low
            & ((aroonu_14_lt_30) | (rsi_3_4h_gt_15) | (aroonu_14_4h_gt_10))
            # 5m uptrend, 15m high, 1h down move
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_15))
            # 5m uptrend, 15m & 4h low
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_20))
            # 5m uptrend, 15m still high, 4h down move
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_50) | (rsi_3_4h_gt_10))
            # 5m uptrend, 1h high, 1d down move
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_gt_10) | (rsi_3_1d_gt_20))
            # 5m uptrend, 4h high, 1d down move
            & ((aroonu_14_lt_30) | (stochrsi_k_4h_gt_10) | (rsi_3_1d_gt_10))
            # 1h no recent low, 5m a new high and 5m no recent low
            & ((aroond_14 > 5) | (aroonu_14 < 40) | (aroond_14_1h > 35))
            # 5m AROOND low, 15m washed out, 1h downtrend, 1d down move
            & ((aroond_14_gt_75) | (aroonu_14_1h_gt_10) | (stochrsi_k_15m_gt_20) | (roc_9_1d_gt_neg_20))
            # 5m stochastic at the floor, 1h no new high, daily stochastic high and 1h momentum alive
            & ((stochrsi_k > 5) | (aroonu_14_1h_gt_10) | (rsi_3_1h < 35) | (stochrsi_k_1d_lt_20))
            # daily stochastic high, 5m stochastic high, 1h momentum collapsing and daily no lower wick
            & ((stochrsi_k_lt_30) | (rsi_3_change_pct_1h > -50) | (bot_wick_pct_1d > 1) | (stochrsi_k_1d_lt_20))
            # 5m WILLR high & downtrend, 15m up move, 1h UO high, 1d up move
            & ((willr_14 < -97.0) | (uo_7_14_28_1h < 50.0) | (roc_9_1d_lt_0) | (aroonu_14 > 0.0) | (rsi_3_15m < 5.0))
            # 5m willr 480 low, 15m uptrend, 1h WILLR low, 4h uptrend, 1d uptrend
            & (
              (willr_480 > -95.0)
              | (willr_14_1h > -80.0)
              | (aroonu_14_4h < 55.0)
              | (aroonu_14_1d < 45.0)
              | (aroonu_14_15m < 5.0)
            )
            # 5m willr 480 high, 1h downtrend, 4h up move, 1d up move
            & ((willr_480 < -95.0) | (aroonu_14_1h_gt_10) | (rsi_3_4h_lt_40) | (roc_9_1d < 5.0))
            # 5m roc 2 low, 15m rising fast & uptrend, 1h on the floor, 4h down move
            & (
              (roc_2 > -0.0)
              | (rsi_14_change_pct_15m < -20.0)
              | (rsi_3_4h_gt_5)
              | (stochrsi_k_1h > 5.0)
              | (aroonu_14_15m < 15.0)
            )
            # 5m roc 2 low, 15m downtrend, 1h down move, 4h on the floor & up move
            & ((roc_2 > -0.0) | (aroonu_14_15m_gt_10) | (stochrsi_k_4h > 5.0) | (rsi_3_4h < 15.0) | (rsi_3_1h_gt_20))
            # 5m roc 288 low & still high, 15m uptrend, 4h down move, 1d daily change high
            & (
              (roc_288 > -10.0)
              | (change_pct_1d < -5.0)
              | (stochrsi_k < 35.0)
              | (aroonu_14_15m_lt_25)
              | (rsi_3_4h_gt_30)
            )
            # 5m roc 288 low & still high, 4h still high & down move, 1d money leaving
            & (
              (roc_288 > -10.0) | (mfi_14_1d > 30.0) | (stochrsi_k < 35.0) | (stochrsi_k_4h < 15.0) | (rsi_3_4h_gt_30)
            )
            # 5m uptrend, 15m up move, 4h uptrend & still high, 1d uptrend
            & (
              (rsi_3_15m < 10.0)
              | (aroonu_14_4h_lt_60)
              | (stochrsi_k_4h_lt_70)
              | (aroonu_14_lt_30)
              | (aroonu_14_1d < 10.0)
            )
            # 15m down move & still high, 1h uptrend & down move, 1d washed out
            & (
              (rsi_3_15m_gt_10)
              | (aroonu_14_1h_lt_50)
              | (stochrsi_k_15m_lt_30)
              | (rsi_3_1h_gt_20)
              | (stochrsi_k_1d > 35.0)
            )
            # 15m down move, 1h downtrend, 4h uptrend & down move, 1d still high
            & (
              (rsi_3_15m_gt_15)
              | (aroonu_14_4h_lt_20)
              | (stochrsi_k_1d_lt_30)
              | (aroonu_14_1h_gt_0)
              | (roc_9_4h > -5.0)
            )
            # 15m down move & uptrend & washed out, 1h washed out, 4h downtrend
            & (
              (rsi_3_15m_gt_15)
              | (stochrsi_k_1h_gt_20)
              | (aroonu_14_15m < 45.0)
              | (aroonu_14_4h_gt_10)
              | (stochrsi_k_15m > 45.0)
            )
            # 15m up move, 1h uptrend, 1d bot wick pct low
            & ((rsi_3_15m < 10.0) | (bot_wick_pct_1d > 0.5) | (aroonu_14_1h_lt_75))
            # 15m up move, 1h money leaving, 4h uptrend
            & ((rsi_3_15m < 10.0) | (cmf_20_1h_gt_neg_0_25) | (aroonu_14_4h_lt_60))
            # 5m still high, 15m up move & downtrend, 4h up move & down move
            & ((rsi_3_15m < 10.0) | (roc_9_4h < -8.0) | (rsi_3_4h_gt_5) | (aroonu_14_15m_gt_10) | (stochrsi_k < 35.0))
            # 15m up move, 1h up move, 1d uptrend & down move
            & ((rsi_3_15m < 10.0) | (rsi_3_1h_lt_40) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_20))
            # 5m up move, 15m up move, 1d rising fast
            & ((rsi_3_15m < 25.0) | (rsi_3_change_pct_1d < 50.0) | (rsi_3 < 15.0))
            # 5m still high, 15m up move, 1d rising fast
            & ((rsi_3_15m < 25.0) | (rsi_3_change_pct_1d < 50.0) | (stochrsi_k < 40.0))
            # 15m down move & low, 4h oversold
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_gt_10) | (roc_9_4h_gt_neg_10))
            # 15m down move & low, 1d high
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_gt_10) | (stochrsi_k_1d_gt_10))
            # 15m down move, 15m & 4h uptrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_60))
            # 15m down move & uptrend, 1d up move
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_70) | (rsi_3_1d_lt_35))
            # 15m down move, 1h low, 1d up move
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_gt_10) | (rsi_3_1d_lt_35))
            # 15m down move, 1h low, 4h up move
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_gt_30) | (rsi_3_4h_lt_40))
            # 15m down move, 1h uptrend, 4h low
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_30) | (stochrsi_k_4h_gt_20))
            # 15m down move, 1h & 1d uptrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_40))
            # 15m down move, 4h low, 1d uptrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15) | (rsi_3_4h_gt_20))
            # 15m & 1h down move, 1h uptrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_1h_lt_60))
            # 15m & 1h down move, 1h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (aroonu_14_1h_gt_20))
            # 15m & 1h & 1d down move
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_1d_gt_15))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_gt_40) | (rsi_3_1d_gt_15))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_10) | (stochrsi_k_1h_gt_50) | (rsi_3_1d_gt_10))
            # 15m down move, 4h high & oversold
            & ((rsi_3_15m_gt_10) | (stochrsi_k_4h_gt_10) | (roc_9_4h_gt_neg_10))
            # 15m down move & low, 1d uptrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_gt_10) | (roc_9_1d_lt_0))
            # 15m & 4h down move, 1h low
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_gt_10) | (rsi_3_4h_gt_5))
            # 15m & 1d down move, 4h uptrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_30) | (rsi_3_1d_gt_10))
            # 5m down move, 15m down move, 1h up move, 1d down move & up move
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_15) | (roc_9_1d < -5.0) | (roc_9_1h < 0.0) | (rsi_3_gt_5))
            # 15m & 1h down move, 4h uptrend
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_5) | (aroonu_14_4h_lt_60))
            # 15m down move, 1h still high, 1d uptrend
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_gt_30) | (aroonu_14_1d_lt_30))
            # 15m down move & low, 4h uptrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_gt_10) | (aroonu_14_4h_lt_20))
            # 15m down move & low, 4h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_gt_30) | (stochrsi_k_4h_gt_10))
            # 15m down move, 15m & 1d uptrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_50) | (roc_9_1d_lt_0))
            # 15m & 1h down move, 4h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_gt_10))
            # 15m & 4h down move, 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_10) | (aroonu_14_1d_gt_20))
            # 15m & 4h down move, 1d up move
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_lt_35))
            # 15m down move, 4h up move, 1d oversold
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_lt_40) | (roc_9_1d_gt_neg_15))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_gt_40) | (rsi_3_4h_gt_5))
            # 15m down move, 1h high, 1d uptrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_gt_10) | (aroonu_14_1d_lt_50))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_gt_10) | (rsi_3_1d_gt_10))
            # 15m down move & low, 4h uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_gt_10) | (aroonu_14_4h_lt_40))
            # 15m & 1h down move, 15m uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_20) | (rsi_3_1h_gt_10))
            # 15m & 4h down move, 15m uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_20) | (rsi_3_4h_gt_10))
            # 15m down move & uptrend, 4h up move
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_60) | (rsi_3_4h_lt_40))
            # 15m down move, 1h low, 1d uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_gt_20) | (roc_9_1d_lt_0))
            # 15m & 1d down move, 1d oversold
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 1h down move, 1d up move
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_15) | (rsi_3_1d_lt_35))
            # 15m & 4h down move, 1d low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_5) | (aroonu_14_1d_gt_20))
            # 15m down move & still high, 1h oversold
            & ((rsi_3_15m_gt_25) | (stochrsi_k_15m_gt_30) | (roc_9_1h_gt_neg_10))
            # 15m down move, 4h high, 1d low
            & ((rsi_3_15m_gt_25) | (stochrsi_k_4h_gt_10) | (stochrsi_k_1d_gt_20))
            # 5m downtrend, 15m down move, 4h up move, 1d uptrend & down move
            & ((rsi_3_15m_gt_3) | (aroonu_14_1d_lt_40) | (rsi_3_4h < 10.0) | (roc_9_1d > 5.0) | (aroonu_14 > 10.0))
            # 15m & 4h down move, 15m low
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_gt_20) | (rsi_3_4h_gt_5))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_30) | (stochrsi_k_4h_gt_10) | (rsi_3_1d_gt_15))
            # 15m down move & low, 1d uptrend
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_gt_10) | (aroonu_14_1d_lt_50))
            # 15m down move & low, 1d oversold
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_gt_10) | (roc_9_1d_gt_neg_15))
            # 15m down move, 15m & 4h low
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m down move & uptrend, 1h low
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_gt_20))
            # 15m down move & uptrend, 4h low
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_gt_10))
            # 15m down move, 1h uptrend & low
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_40) | (stochrsi_k_1h_gt_20))
            # 15m down move, 1h uptrend, 1d low
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_70) | (aroonu_14_1d_gt_10))
            # 15m down move, 4h low & high
            & ((rsi_3_15m_gt_5) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_10))
            # 15m down move, 4h overbought, 1d down move
            & ((rsi_3_15m_gt_5) | (roc_9_1d_gt_neg_30) | (stochrsi_k_4h < 85.0))
            # 15m & 1h down move, 1d uptrend
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_15) | (aroonu_14_1d_lt_40))
            # 15m & 1h down move, 1h uptrend
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_30))
            # 15m & 4h down move, 1d uptrend
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_5) | (aroonu_14_1d_lt_50))
            # 15m up move & low, 1h uptrend
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_20))
            # 15m up move & uptrend, 4h high
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_lt_20) | (stochrsi_k_4h_gt_10))
            # 15m up move, 1d high
            & ((rsi_3_15m_lt_50) | (stochrsi_k_1d_gt_10))
            # 5m up move, 15m RSI high & uptrend, 1h money coming in
            & ((rsi_14_15m_lt_30) | (cmf_20_1h < 0.1) | (aroonu_14_15m < 55.0) | (rsi_3 < 5.0))
            # 15m RSI high & uptrend & on the floor, 1h money coming in
            & ((rsi_14_15m_lt_30) | (cmf_20_1h < 0.1) | (aroonu_14_15m < 55.0) | (stochrsi_k_15m > 5.0))
            # 5m uptrend & up move, 15m RSI high, 1h up move, 1d uptrend
            & ((rsi_14_15m_lt_35) | (rsi_3_1h_lt_40) | (aroonu_14 < 60.0) | (aroonu_14_1d_lt_40) | (rsi_3 < 5.0))
            # 15m money leaving & up move, 1h down move & uptrend
            & ((cmf_20_15m > -0.2) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_80) | (rsi_3_15m < 5.0))
            # 5m down move, 15m money leaving, 4h down move, 1d top wick low & still high
            & ((mfi_14_15m > 30.0) | (top_wick_pct_1d > 1.0) | (rsi_3_4h_gt_5) | (stochrsi_k_1d < 25.0) | (rsi_3_gt_5))
            # 15m downtrend, 1h downtrend, 4h down move, 1d up move & downtrend
            & (
              (aroonu_14_15m_gt_10)
              | (aroonu_14_1h_gt_10)
              | (rsi_3_1d < 30.0)
              | (aroonu_14_1d_gt_50)
              | (rsi_3_4h_gt_25)
            )
            # 5m still high & down move, 15m downtrend, 4h downtrend, 1d on the floor
            & (
              (aroonu_14_15m_gt_10)
              | (aroonu_14_4h_gt_10)
              | (stochrsi_k < 60.0)
              | (stochrsi_k_1d > 5.0)
              | (rsi_3 > 20.0)
            )
            # 15m downtrend, 4h down move & washed out, 1d up move & downtrend
            & (
              (aroonu_14_15m_gt_10)
              | (rsi_3_4h_gt_35)
              | (rsi_3_1d_lt_35)
              | (aroonu_14_1d_gt_50)
              | (stochrsi_k_4h > 55.0)
            )
            # 15m downtrend & washed out, 1h down move, 4h washed out, 1d up move
            & (
              (aroonu_14_15m_gt_10)
              | (stochrsi_k_15m_gt_40)
              | (rsi_3_1d_lt_35)
              | (rsi_3_1h_gt_10)
              | (stochrsi_k_4h > 35.0)
            )
            # 15m downtrend, 1h washed out, 4h washed out, 1d up move & downtrend
            & (
              (aroonu_14_15m_gt_10)
              | (stochrsi_k_1h_gt_20)
              | (rsi_3_1d_lt_35)
              | (aroonu_14_1d_gt_50)
              | (stochrsi_k_4h > 55.0)
            )
            # 15m downtrend, 1h washed out & down move, 4h down move, 1d up move
            & (
              (aroonu_14_15m_gt_10) | (stochrsi_k_1h_gt_30) | (rsi_3_1d < 20.0) | (rsi_3_4h_gt_15) | (roc_9_1h > -5.0)
            )
            # 15m downtrend, 1h downtrend, 1d top wick low & uptrend & still high
            & (
              (aroonu_14_15m_gt_10)
              | (top_wick_pct_1d > 1.0)
              | (aroonu_14_1d < 55.0)
              | (stochrsi_k_1d_lt_40)
              | (aroonu_14_1h_gt_40)
            )
            # 15m downtrend, 1h washed out, 4h uptrend & still high, 1d uptrend
            & (
              (aroonu_14_15m_gt_30)
              | (stochrsi_k_1h_gt_20)
              | (aroonu_14_1d_lt_80)
              | (aroonu_14_4h < 5.0)
              | (stochrsi_k_4h_lt_30)
            )
            # 5m still high, 15m downtrend, 1h washed out & downtrend, 4h down move
            & (
              (aroonu_14_15m_gt_40)
              | (stochrsi_k_1h_gt_50)
              | (stochrsi_k < 40.0)
              | (aroonu_14_1h_gt_10)
              | (roc_9_4h > -5.0)
            )
            # 5m downtrend, 15m uptrend, 4h uptrend & still high, 1d up move
            & (
              (aroonu_14_15m_lt_30)
              | (aroonu_14_4h_lt_20)
              | (rsi_3_1d_lt_35)
              | (stochrsi_k_4h_lt_20)
              | (aroonu_14 > 15.0)
            )
            # 15m uptrend, 1h washed out, 1d uptrend & up move & down move
            & (
              (aroonu_14_15m_lt_30)
              | (stochrsi_k_1h_gt_50)
              | (aroonu_14_1d < 65.0)
              | (rsi_3_1d < 15.0)
              | (roc_9_1d > 0.0)
            )
            # 15m & 1h low, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_lt_30))
            # 15m & 1h low, 4h uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_20))
            # 15m & 1h low, 4h up move
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_20) | (rsi_3_4h_lt_60))
            # 5m washed out, 15m downtrend & overbought, 1h downtrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_20) | (stochrsi_k_15m < 90.0) | (stochrsi_k > 20.0))
            # 15m low, 1h uptrend, 4h high
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_10))
            # 15m & 4h low, 1h uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_30) | (aroonu_14_4h_gt_10))
            # 15m low, 1h uptrend, 1d high
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_30) | (stochrsi_k_1d_gt_10))
            # 15m low, 1h uptrend, 4h down move
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_40) | (rsi_3_4h_gt_30))
            # 5m up move, 15m downtrend, 1h uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_75) | (rsi_3 < 20.0))
            # 15m low, 4h uptrend & still high
            & ((aroonu_14_15m_gt_10) | (aroonu_14_4h_lt_70) | (stochrsi_k_4h_gt_40))
            # 5m up move, 15m downtrend & still high & down move, 1h up move
            & ((aroonu_14_15m_gt_10) | (roc_9_1h < -1.0) | (stochrsi_k_15m_lt_60) | (rsi_3 < 5.0) | (rsi_3_15m_gt_30))
            # 5m uptrend, 15m downtrend, 4h up move & still high & down move
            & ((aroonu_14_15m_gt_10) | (roc_9_4h < 0.0) | (aroonu_14_lt_25) | (stochrsi_k_4h_lt_70) | (rsi_3_4h_gt_40))
            # 5m uptrend, 15m downtrend, 1h up move & down move, 1d down move
            & ((aroonu_14_15m_gt_10) | (rsi_3_1d_gt_15) | (roc_9_1h < 0.0) | (aroonu_14 < 40.0) | (rsi_3_1h_gt_30))
            # 15m low, 1h & 4h down move
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_10))
            # 15m low, 1h down move, 1d oversold
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_gt_5) | (roc_9_1d_gt_neg_15))
            # 5m still high & up move, 15m downtrend, 1h up move, 4h washed out
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_40) | (stochrsi_k < 5.0) | (stochrsi_k_4h > 25.0) | (rsi_3 < 5.0))
            # 15m low, 1h up move & high
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_10))
            # 15m & 1h low, 1h up move
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_50) | (aroonu_14_1h_gt_10))
            # 15m & 1h low, 15m high
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_10) | (aroonu_14_1h_gt_10))
            # 15m low & high, 4h down move
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_10) | (rsi_3_4h_gt_25))
            # 15m low & high, 1h still high
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_10) | (stochrsi_k_1h_gt_50))
            # 15m low, 1d down move
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_20) | (rsi_3_1d_gt_10))
            # 15m low & still high, 1d oversold
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_30) | (roc_9_1d_gt_neg_30))
            # 15m low & still high, 1h down move
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_30) | (rsi_3_1h_gt_15))
            # 15m low & still high, 4h down move
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_30) | (rsi_3_4h_gt_15))
            # 15m low, 1h high, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_1h_gt_10) | (aroonu_14_1d_lt_30))
            # 15m & 1h low, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_1h_gt_20) | (aroonu_14_1d_lt_40))
            # 15m & 1h low, 4h uptrend
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_20))
            # 15m low, 4h still high, 1d high
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_4h_gt_30) | (stochrsi_k_1d_gt_10))
            # 5m downtrend, 15m downtrend & overbought, 1d top wick low
            & ((aroonu_14_15m_gt_10) | (top_wick_pct_1d > 1.0) | (stochrsi_k_15m < 85.0) | (aroonu_14 > 50.0))
            # 15m & 4h low, 1h uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_gt_10))
            # 15m & 4h low, 4h uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m low, 4h down move & uptrend
            & ((aroonu_14_15m_gt_20) | (rsi_3_4h_gt_5) | (aroonu_14_4h_lt_30))
            # 15m low, 4h down move
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_20))
            # 15m low & still high, 4h high
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_10))
            # 15m low, 1d uptrend
            & ((aroonu_14_15m_gt_30) | (aroonu_14_1d_lt_60) | (roc_9_1d_lt_0))
            # 15m low, 1h & 1d uptrend
            & ((aroonu_14_15m_gt_30) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_lt_70))
            # 15m low, 1h uptrend, 4h down move
            & ((aroonu_14_15m_gt_30) | (aroonu_14_1h_lt_40) | (rsi_3_4h_gt_20))
            # 15m low, 1h uptrend, 4h up move
            & ((aroonu_14_15m_gt_30) | (aroonu_14_1h_lt_80) | (rsi_3_4h_lt_40))
            # 15m & 4h low, 1d uptrend
            & ((aroonu_14_15m_gt_30) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_lt_60))
            # 15m low, 1d down move & uptrend
            & ((aroonu_14_15m_gt_30) | (rsi_3_1d_gt_10) | (aroonu_14_1d_lt_70))
            # 15m & 1d low, 1h up move
            & ((aroonu_14_15m_gt_30) | (rsi_3_1h_lt_40) | (aroonu_14_1d_gt_10))
            # 15m & 1d low, 1h down move
            & ((aroonu_14_15m_gt_40) | (rsi_3_1h_lt_55) | (aroonu_14_1d_gt_10))
            # 15m & 4h low, 1d uptrend
            & ((aroonu_14_15m_gt_40) | (stochrsi_k_4h_gt_20) | (roc_9_1d_lt_0))
            # 15m uptrend, 1h & 1d low
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_0))
            # 15m & 1h uptrend, 4h down move
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_15))
            # 15m uptrend, 4h low, 1d oversold
            & ((aroonu_14_15m_lt_20) | (aroonu_14_4h_gt_0) | (roc_9_1d_gt_neg_20))
            # 15m & 4h uptrend, 1d oversold
            & ((aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_60) | (roc_9_1d_gt_neg_15))
            # 15m & 1d uptrend, 1d up move
            & ((aroonu_14_15m_lt_20) | (rsi_3_1d_lt_35) | (aroonu_14_1d_lt_30))
            # 15m uptrend, 1h down move & low
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_10) | (aroonu_14_1h_gt_0))
            # 15m uptrend, 1h & 4h down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_5))
            # 15m uptrend, 1h down move, 1d oversold
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_5) | (roc_9_1d_gt_neg_10))
            # 15m uptrend, 1h & 4h down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_5) | (rsi_3_4h_gt_20))
            # 15m uptrend, 1h up move & low
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_lt_50) | (aroonu_14_1h_gt_10))
            # 15m uptrend, 4h down move, 1d high
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_gt_10))
            # 15m & 4h uptrend, 15m high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_10) | (aroonu_14_4h_lt_50))
            # 15m uptrend, 1h high, 1d oversold
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 1d uptrend, 1h still high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_30) | (aroonu_14_1d_lt_40))
            # 15m uptrend, 1h & 4h low
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_10))
            # 15m uptrend, 1h low, 4h up move
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_gt_10) | (rsi_3_4h_lt_40))
            # 15m & 1h uptrend, 4h high
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_10))
            # 15m & 1h & 1d uptrend
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_30) | (aroonu_14_1d_lt_50))
            # 15m & 1h uptrend, 1h still high
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_30) | (stochrsi_k_1h_gt_40))
            # 15m & 4h uptrend, 1d low
            & ((aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_gt_20))
            # 15m up move & uptrend, 1h down move
            & ((aroonu_14_15m_lt_30) | (rsi_3_15m_lt_50) | (rsi_3_1h_gt_35))
            # 15m uptrend, 1h down move, 4h low
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_10) | (aroonu_14_4h_gt_10))
            # 15m & 4h uptrend, 1h down move
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_20))
            # 15m uptrend, 1h & 4h down move
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_15))
            # 15m & 4h uptrend, 1h down move
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_30))
            # 15m uptrend, 4h down move, 1d low
            & ((aroonu_14_15m_lt_30) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_gt_20))
            # 15m & 1d uptrend, 4h up move
            & ((aroonu_14_15m_lt_30) | (rsi_3_4h_lt_40) | (aroonu_14_1d_lt_30))
            # 15m uptrend, 1h & 4h low
            & ((aroonu_14_15m_lt_40) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_10))
            # 15m & 1h uptrend, 1d low
            & ((aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_30) | (aroonu_14_1d_gt_0))
            # 15m uptrend, 1h down move & low
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_20) | (aroonu_14_1h_gt_20))
            # 15m uptrend, 1h down move, 4h low
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_25) | (aroonu_14_4h_gt_0))
            # 15m uptrend, 1h & 1d down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_10))
            # 15m uptrend & high, 1d down move
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_10) | (rsi_3_1d_gt_10))
            # 5m still high & down move, 15m uptrend & on the floor, 4h down move
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_10) | (stochrsi_k < 35.0) | (rsi_3_gt_15) | (rsi_3_4h_gt_30))
            # 15m uptrend & high, 1h still high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_10) | (stochrsi_k_1h_gt_50))
            # 15m uptrend, 15m & 4h low
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m & 4h uptrend, 1h high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_10) | (aroonu_14_4h_lt_50))
            # 15m uptrend, 1h still high, 1d down move
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_30) | (rsi_3_1d_gt_10))
            # 15m uptrend, 1h still high, 4h high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_30) | (stochrsi_k_4h_gt_10))
            # 15m & 1h & 1d uptrend
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_30) | (aroonu_14_1d_lt_40))
            # 15m & 1h uptrend, 4h low
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_gt_10))
            # 5m up move, 15m uptrend & on the floor, 1d down move
            & ((aroonu_14_15m_lt_50) | (roc_9_1d_gt_neg_20) | (stochrsi_k_15m > 5.0) | (rsi_3 < 10.0))
            # 15m uptrend & on the floor & up move, 1d down move
            & ((aroonu_14_15m_lt_50) | (roc_9_1d_gt_neg_20) | (stochrsi_k_15m > 5.0) | (rsi_3_15m < 10.0))
            # 15m uptrend, 1h up move, 4h low
            & ((aroonu_14_15m_lt_50) | (rsi_3_1h_lt_40) | (aroonu_14_4h_gt_20))
            # 15m & 1d uptrend, 15m high
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_10) | (aroonu_14_1d_lt_50))
            # 15m uptrend & high, 1d down move
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_10) | (rsi_3_1d_gt_15))
            # 15m uptrend & low, 1h still high
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_40))
            # 15m & 1d uptrend, 1h still high
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_1h_gt_50) | (aroonu_14_1d_lt_30))
            # 15m & 1d uptrend, 4h still high
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_4h_gt_30) | (aroonu_14_1d_lt_60))
            # 15m uptrend, 1h low, 4h down move
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_gt_30) | (rsi_3_4h_gt_10))
            # 15m & 4h & 1d uptrend
            & ((aroonu_14_15m_lt_60) | (aroonu_14_4h_lt_20) | (aroonu_14_1d_lt_60))
            # 15m & 4h uptrend, 1h up move
            & ((aroonu_14_15m_lt_60) | (rsi_3_1h_lt_50) | (aroonu_14_4h_lt_50))
            # 15m uptrend, 4h down move, 1d low
            & ((aroonu_14_15m_lt_60) | (rsi_3_4h_gt_5) | (aroonu_14_1d_gt_10))
            # 15m uptrend & low, 1d high
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1d_gt_10))
            # 15m uptrend, 1h still high, 4h low
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_1h_gt_50) | (aroonu_14_4h_gt_10))
            # 15m uptrend & still high, 4h low
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_20))
            # 15m uptrend & still high, 1h low
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_15m_gt_40) | (aroonu_14_1h_gt_0))
            # 15m uptrend, 1h still high, 1d down move
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_1h_gt_30) | (rsi_3_1d_gt_20))
            # 15m uptrend, 1h still high, 1d down move
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_1h_gt_50) | (rsi_3_1d_gt_10))
            # 5m up move, 15m uptrend, 1h downtrend, 4h still high
            & ((aroonu_14_15m_lt_75) | (aroonu_14_1h_gt_30) | (stochrsi_k_4h < 25.0) | (rsi_3 < 5.0))
            # 15m on the floor, 1h down move & up move, 1d down move & still high
            & (
              (stochrsi_k_15m_gt_10)
              | (roc_9_1d_gt_neg_15)
              | (stochrsi_k_1d < 25.0)
              | (rsi_3_1h_gt_20)
              | (roc_9_1h < -5.0)
            )
            # 5m still high & down move, 15m washed out & up move, 1d downtrend
            & (
              (stochrsi_k_15m_gt_30) | (aroonu_14_1d_gt_10) | (stochrsi_k < 55.0) | (rsi_3_15m < 25.0) | (rsi_3 > 20.0)
            )
            # 15m high, 1h low, 1d down move
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_gt_30) | (rsi_3_1d_gt_5))
            # 15m high, 1h uptrend, 4h low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_30) | (stochrsi_k_4h_gt_20))
            # 15m high, 1h uptrend, 1d low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_90) | (aroonu_14_1d_gt_20))
            # 15m high, 4h low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m high, 4h uptrend, 1d low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_4h_lt_70) | (stochrsi_k_1d_gt_20))
            # 15m high, 1h down move, 4h uptrend
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_40))
            # 15m high, 1h & 1d down move
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_15))
            # 15m high, 4h down move, 1d low
            & ((stochrsi_k_15m_gt_10) | (rsi_3_4h_gt_25) | (stochrsi_k_1d_gt_20))
            # 15m high, 4h down move & uptrend
            & ((stochrsi_k_15m_gt_10) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_40))
            # 15m high, 1h still high, 4h uptrend
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_1h_gt_30) | (aroonu_14_4h_lt_20))
            # 15m high, 1h still high, 1d down move
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_1h_gt_30) | (rsi_3_1d_gt_15))
            # 15m & 4h & 1d high
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_10) | (stochrsi_k_1d_gt_10))
            # 15m washed out & up move, 1d downtrend & up move
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1d_gt_10) | (rsi_3_15m < 25.0) | (roc_9_1d < -5.0))
            # 15m & 1h & 4h low
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_0))
            # 15m & 1h low, 4h down move
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_10) | (rsi_3_4h_gt_15))
            # 15m washed out, 1h down move & uptrend, 1d downtrend
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_gt_10))
            # 15m & 1h low, 1h up move
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1h_lt_40) | (aroonu_14_1h_gt_10))
            # 15m low, 4h down move & uptrend
            & ((stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_20))
            # 15m low, 4h & 1d down move
            & ((stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_15))
            # 15m & 1h low, 1d down move
            & ((stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_20) | (rsi_3_1d_gt_15))
            # 15m low, 1h & 4h still high
            & ((stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_30) | (stochrsi_k_4h_gt_30))
            # 15m still high, 1h low, 1d down move
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_1h_gt_10) | (rsi_3_1d_gt_5))
            # 15m still high, 1h uptrend & low
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_1h_lt_40) | (stochrsi_k_1h_gt_20))
            # 15m still high, 1h down move, 1d oversold
            & ((stochrsi_k_15m_gt_30) | (rsi_3_1h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m still high, 1h down move & low
            & ((stochrsi_k_15m_gt_30) | (rsi_3_1h_gt_15) | (aroonu_14_1h_gt_10))
            # 15m still high, 1h down move & uptrend
            & ((stochrsi_k_15m_gt_30) | (rsi_3_1h_gt_5) | (aroonu_14_1h_lt_20))
            # 15m still high, 4h down move, 1d high
            & ((stochrsi_k_15m_gt_30) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_gt_10))
            # 15m still high, 1h low, 4h uptrend
            & ((stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_20))
            # 15m still high, 4h high, 1d down move
            & ((stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_10) | (rsi_3_1d_gt_10))
            # 15m still high, 4h uptrend, 1d high
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_4h_lt_40) | (stochrsi_k_1d_gt_10))
            # 15m still high, 1h high, 4h low
            & ((stochrsi_k_15m_gt_40) | (stochrsi_k_1h_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m still high, 1h high, 1d oversold
            & ((stochrsi_k_15m_gt_50) | (stochrsi_k_1h_gt_10) | (roc_9_1d_gt_neg_15))
            # 15m CCI high, 1h down move, 4h -DI low, 1d down move
            & ((cci_20_15m < -115.0) | (minus_di_14_4h > 30.0) | (rsi_3_1h_gt_5) | (rsi_3_1d_gt_20))
            # 15m downtrend, 1h down move & downtrend, 4h uptrend & down move
            & (
              (rsi_3_1h_gt_10) | (aroonu_14_4h_lt_30) | (aroonu_14_1h_gt_0) | (aroonu_14_15m_gt_30) | (rsi_3_4h_gt_20)
            )
            # 5m downtrend, 1h down move & still high, 1d downtrend & up move
            & (
              (rsi_3_1h_gt_15) | (aroonu_14_1d_gt_10) | (stochrsi_k_1h < 35.0) | (rsi_3_1d < 15.0) | (aroonu_14 > 10.0)
            )
            # 15m on the floor, 1h down move & washed out, 4h washed out, 1d up move
            & (
              (rsi_3_1h_gt_15)
              | (stochrsi_k_1h_gt_30)
              | (rsi_3_1d_lt_35)
              | (stochrsi_k_15m_gt_10)
              | (stochrsi_k_4h > 45.0)
            )
            # 1h down move & downtrend, 1d top wick low & uptrend & still high
            & (
              (rsi_3_1h_gt_15)
              | (top_wick_pct_1d > 1.0)
              | (aroonu_14_1d < 55.0)
              | (stochrsi_k_1d_lt_20)
              | (aroonu_14_1h_gt_40)
            )
            # 1h down move & up move & still high & downtrend, 4h down move
            & (
              (rsi_3_1h_gt_20) | (roc_9_1h < -1.0) | (rsi_3_4h_gt_40) | (stochrsi_k_1h < 35.0) | (aroonu_14_1h > 50.0)
            )
            # 15m uptrend, 1h down move & uptrend, 1d uptrend & still high
            & (
              (rsi_3_1h_gt_25)
              | (aroonu_14_1h_lt_40)
              | (aroonu_14_15m_lt_40)
              | (aroonu_14_1d < 45.0)
              | (stochrsi_k_1d < 35.0)
            )
            # 1h down move, 1d uptrend & low
            & ((rsi_3_1h_gt_10) | (aroonu_14_1d_lt_30) | (stochrsi_k_1d_gt_20))
            # 1h down move & uptrend, 4h low
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_20) | (aroonu_14_4h_gt_20))
            # 1h down move, 1h & 4h uptrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_20))
            # 1h down move & uptrend, 4h high
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_40) | (stochrsi_k_4h_gt_10))
            # 1h down move & uptrend, 4h up move
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_lt_60) | (rsi_3_4h_lt_40))
            # 1h & 1d down move, 4h uptrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_lt_50) | (rsi_3_1d_gt_25))
            # 15m downtrend & down move, 1h down move, 1d down move & up move
            & ((rsi_3_1h_gt_10) | (roc_9_1d_gt_neg_20) | (rsi_3_1d < 30.0) | (aroonu_14_15m_gt_0) | (rsi_3_15m_gt_10))
            # 1h down move, 1h & 4h low
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_gt_10) | (stochrsi_k_4h_gt_20))
            # 1h & 4h down move, 1h uptrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_20))
            # 1h down move & uptrend, 4h low
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_25) | (aroonu_14_4h_gt_0))
            # 1h down move & uptrend, 4h oversold
            & ((rsi_3_1h_gt_15) | (aroonu_14_1h_lt_60) | (roc_9_4h_gt_neg_10))
            # 1h down move, 4h uptrend, 1d high
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_lt_30) | (stochrsi_k_1d_gt_10))
            # 1h down move, 4h oversold, 1d uptrend
            & ((rsi_3_1h_gt_15) | (roc_9_4h_gt_neg_10) | (aroonu_14_1d_lt_40))
            # 1h down move, 1h & 4h uptrend
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_50))
            # 1h & 4h down move, 1d uptrend
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_50))
            # 1h down move, 4h low, 1d high
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_10))
            # 1h down move, 4h oversold, 1d uptrend
            & ((rsi_3_1h_gt_25) | (roc_9_4h_gt_neg_10) | (aroonu_14_1d_lt_60))
            # 1h down move & low, 1d uptrend
            & ((rsi_3_1h_gt_30) | (aroonu_14_1h_gt_10) | (roc_9_1d_lt_0))
            # 1h down move, 4h low & high
            & ((rsi_3_1h_gt_30) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_10))
            # 1h & 1d down move, 4h up move
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_lt_40) | (rsi_3_1d_gt_15))
            # 1h & 1d down move, 4h still high
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_gt_30) | (rsi_3_1d_gt_5))
            # 1h down move, 4h uptrend & still high & down move, 1d up move
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_40) | (rsi_3_1d_lt_35) | (stochrsi_k_4h < 25.0) | (rsi_3_4h_gt_30))
            # 1h down move, 1h & 1d uptrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_lt_40))
            # 5m uptrend, 15m up move, 1h down move & uptrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_1h_lt_40) | (rsi_3_15m < 25.0) | (aroonu_14 < 15.0))
            # 1h up move & low, 1d high
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_gt_10) | (stochrsi_k_1d_gt_10))
            # 15m still high, 1h downtrend, 1d uptrend & still high & down move
            & (
              (aroonu_14_1h_gt_10)
              | (aroonu_14_1d_lt_50)
              | (stochrsi_k_1d < 45.0)
              | (stochrsi_k_15m < 10.0)
              | (rsi_3_1d_gt_30)
            )
            # 1h uptrend & washed out, 4h on the floor & up move, 1d up move
            & (
              (aroonu_14_1h_lt_25)
              | (stochrsi_k_1h_gt_30)
              | (stochrsi_k_4h > 5.0)
              | (rsi_3_4h < 10.0)
              | (roc_9_1d < -10.0)
            )
            # 15m uptrend, 1h uptrend, 4h down move & downtrend, 1d uptrend
            & (
              (aroonu_14_1h_lt_40)
              | (rsi_3_4h_gt_25)
              | (aroonu_14_1d < 45.0)
              | (aroonu_14_15m < 5.0)
              | (aroonu_14_4h > 40.0)
            )
            # 1h uptrend & washed out, 4h washed out, 1d up move & downtrend
            & (
              (aroonu_14_1h_lt_40)
              | (stochrsi_k_1h_gt_20)
              | (rsi_3_1d_lt_35)
              | (stochrsi_k_4h > 45.0)
              | (aroonu_14_1d > 45.0)
            )
            # 1h low, 4h uptrend, 1d high
            & ((aroonu_14_1h_gt_0) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_gt_10))
            # 1h low, 1d uptrend & oversold
            & ((aroonu_14_1h_gt_10) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_30))
            # 1h & 4h low, 1d uptrend
            & ((aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_40))
            # 1h low, 4h uptrend, 1d high
            & ((aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_30) | (stochrsi_k_1d_gt_10))
            # 1h low, 4h & 1d uptrend
            & ((aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_10))
            # 1h low, 1d down move & uptrend
            & ((aroonu_14_1h_gt_10) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_60))
            # 5m uptrend & down move, 15m downtrend, 1h downtrend, 4h down move
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_lt_25) | (aroonu_14_15m_gt_10) | (rsi_3_gt_10))
            # 1h low, 4h down move & uptrend
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_gt_5) | (aroonu_14_4h_lt_20))
            # 1h low, 4h up move, 1d oversold
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_lt_40) | (roc_9_1d_gt_neg_15))
            # 1h low, 4h still high, 1d down move
            & ((aroonu_14_1h_gt_10) | (stochrsi_k_4h_gt_30) | (rsi_3_1d_gt_10))
            # 1h low, 4h still high, 1d high
            & ((aroonu_14_1h_gt_10) | (stochrsi_k_4h_gt_30) | (stochrsi_k_1d_gt_10))
            # 1h low, 4h uptrend, 1d down move
            & ((aroonu_14_1h_gt_20) | (aroonu_14_4h_lt_20) | (rsi_3_1d_gt_10))
            # 1h low, 4h uptrend, 1d high
            & ((aroonu_14_1h_gt_20) | (aroonu_14_4h_lt_40) | (stochrsi_k_1d_gt_10))
            # 1h downtrend, 4h up move
            & ((aroonu_14_1h_gt_20) | (rsi_3_4h_lt_70))
            # 1h low, 4h uptrend, 1d down move
            & ((aroonu_14_1h_gt_30) | (aroonu_14_4h_lt_50) | (rsi_3_1d_gt_20))
            # 1h uptrend, 4h low
            & ((aroonu_14_1h_lt_20) | (aroonu_14_4h_gt_0) | (stochrsi_k_4h_gt_20))
            # 15m up move & on the floor, 1h uptrend, 4h down move
            & ((aroonu_14_1h_lt_20) | (rsi_3_4h_gt_25) | (rsi_3_15m < 30.0) | (stochrsi_k_15m > 5.0))
            # 1h uptrend, 4h up move & low
            & ((aroonu_14_1h_lt_20) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_20))
            # 1h & 1d uptrend, 4h low
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_20) | (roc_9_1d_lt_10))
            # 1h uptrend, 4h & 1d down move
            & ((aroonu_14_1h_lt_25) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_15))
            # 1h uptrend, 4h up move & low
            & ((aroonu_14_1h_lt_30) | (rsi_3_4h_lt_50) | (aroonu_14_4h_gt_10))
            # 1h uptrend & still high, 1d down move
            & ((aroonu_14_1h_lt_30) | (stochrsi_k_1h_gt_30) | (rsi_3_1d_gt_15))
            # 1h uptrend, 4h low
            & ((aroonu_14_1h_lt_40) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_20))
            # 1h & 4h uptrend, 4h low
            & ((aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_20) | (stochrsi_k_4h_gt_20))
            # 5m still high & down move, 1h uptrend & up move, 1d up move
            & ((aroonu_14_1h_lt_40) | (roc_9_1h < -5.0) | (rsi_3_1d_lt_35) | (stochrsi_k < 15.0) | (rsi_3 > 20.0))
            # 1h uptrend, 4h down move, 1d high
            & ((aroonu_14_1h_lt_40) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_gt_10))
            # 1h & 1d uptrend, 1h high
            & ((aroonu_14_1h_lt_40) | (stochrsi_k_1h_gt_10) | (aroonu_14_1d_lt_30))
            # 1h uptrend & high, 4h low
            & ((aroonu_14_1h_lt_40) | (stochrsi_k_1h_gt_10) | (aroonu_14_4h_gt_10))
            # 1h uptrend & still high, 4h down move
            & ((aroonu_14_1h_lt_40) | (stochrsi_k_1h_gt_40) | (rsi_3_4h_gt_25))
            # 1h & 1d uptrend, 4h down move
            & ((aroonu_14_1h_lt_50) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_70))
            # 1h uptrend, 4h low, 1d up move
            & ((aroonu_14_1h_lt_60) | (aroonu_14_4h_gt_10) | (rsi_3_1d_lt_35))
            # 1h uptrend & still high, 4h low
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_50) | (aroonu_14_4h_gt_30))
            # 1h uptrend, 4h high, 1d low
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 1h uptrend, 4h low & still high
            & ((aroonu_14_1h_lt_70) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_40))
            # 1h washed out, 4h down move, 1d up move & on the floor & downtrend
            & (
              (stochrsi_k_1h_gt_20)
              | (rsi_3_1d < 25.0)
              | (stochrsi_k_1d > 15.0)
              | (roc_9_4h > -5.0)
              | (aroonu_14_1d > 40.0)
            )
            # 15m uptrend & down move, 1h washed out, 4h up move, 1d on the floor
            & (
              (stochrsi_k_1h_gt_20)
              | (stochrsi_k_1d_gt_10)
              | (aroonu_14_15m_lt_60)
              | (roc_9_4h < -5.0)
              | (rsi_3_15m_gt_15)
            )
            # 15m downtrend, 1h washed out & up move, 4h washed out, 1d up move
            & (
              (stochrsi_k_1h_gt_40)
              | (roc_9_1h < -1.0)
              | (stochrsi_k_4h > 25.0)
              | (roc_9_1d < -10.0)
              | (aroonu_14_15m_gt_40)
            )
            # 1h high, 1d uptrend & oversold
            & ((stochrsi_k_1h_gt_10) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_10))
            # 1h on the floor & downtrend, 4h downtrend & up move
            & ((stochrsi_k_1h_gt_10) | (aroonu_14_4h_gt_10) | (rsi_3_4h < 45.0) | (aroonu_14_1h_gt_40))
            # 1h & 4h high, 4h uptrend
            & ((stochrsi_k_1h_gt_10) | (aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_10))
            # 1h high, 1d down move & uptrend
            & ((stochrsi_k_1h_gt_10) | (rsi_3_1d_gt_10) | (aroonu_14_1d_lt_30))
            # 1h & 4h low, 1d uptrend
            & ((stochrsi_k_1h_gt_20) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_30))
            # 1h & 1d low, 4h uptrend
            & ((stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_gt_20))
            # 5m still high, 1h washed out & up move
            & ((stochrsi_k_1h_gt_20) | (roc_9_1h < -1.0) | (stochrsi_k < 5.0))
            # 1h low, 4h still high, 1d high
            & ((stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_50) | (stochrsi_k_1d_gt_10))
            # 5m down move & washed out, 15m up move, 1h washed out, 4h up move
            & ((stochrsi_k_1h_gt_30) | (roc_9_4h < -8.0) | (rsi_3_15m < 30.0) | (rsi_3_gt_5) | (stochrsi_k > 20.0))
            # 1h still high, 4h high, 1d down move
            & ((stochrsi_k_1h_gt_40) | (stochrsi_k_4h_gt_10) | (rsi_3_1d_gt_20))
            # 1h still high, 4h up move & low
            & ((stochrsi_k_1h_gt_50) | (rsi_3_4h_lt_60) | (aroonu_14_4h_gt_10))
            # only a 15m flush while the 1h and the 1d are still high: too shallow to be a breakdown
            & ((stochrsi_k_1h_lt_20) | (stochrsi_k_1d_lt_60))
            # 15m up move, 1h WILLR low, 4h uptrend & washed out, 1d money leaving
            & (
              (willr_14_1h > -80.0)
              | (cmf_20_1d > -0.0)
              | (aroonu_14_4h_lt_60)
              | (stochrsi_k_4h_gt_50)
              | (rsi_3_15m < 10.0)
            )
            # 1h WILLR low, 1d roc 2 low & uptrend & up move & down move
            & (
              (willr_14_1h > -80.0) | (roc_2_1d > -3.0) | (aroonu_14_1d < 65.0) | (rsi_3_1d < 20.0) | (roc_9_1d > 0.0)
            )
            # 15m up move & uptrend, 1h WILLR low, 4h rising fast, 1d still high
            & (
              (willr_14_1h > -80.0)
              | (stochrsi_k_change_pct_4h < 5.0)
              | (stochrsi_k_1d < 25.0)
              | (rsi_3_15m < 5.0)
              | (aroonu_14_15m < 5.0)
            )
            # 5m uptrend, 15m still high, 1h up move, 4h uptrend, 1d still high
            & (
              (roc_9_1h < -5.0)
              | (aroonu_14_4h_lt_30)
              | (aroonu_14 < 60.0)
              | (stochrsi_k_1d < 25.0)
              | (stochrsi_k_15m_lt_50)
            )
            # 5m still high, 15m downtrend, 1h up move, 4h uptrend, 1d down move
            & (
              (roc_9_1h < -5.0) | (rsi_3_1d_gt_25) | (aroonu_14_4h_lt_30) | (stochrsi_k < 10.0) | (aroonu_14_15m_gt_0)
            )
            # 1h up move & washed out, 4h down move, 1d still high & uptrend
            & (
              (roc_9_1h < -5.0)
              | (rsi_3_4h_gt_10)
              | (stochrsi_k_1d < 45.0)
              | (aroonu_14_1d < 10.0)
              | (stochrsi_k_1h > 25.0)
            )
            # 5m up move, 1h up move, 4h downtrend, 1d on the floor
            & ((roc_9_1h < -1.0) | (aroonu_14_4h_gt_10) | (rsi_3 < 15.0) | (stochrsi_k_1d_gt_10))
            # 5m up move & downtrend, 1h up move, 1d top wick low
            & ((roc_9_1h < -1.0) | (top_wick_pct_1d > 1.0) | (rsi_3 < 15.0) | (aroonu_14 > 30.0))
            # 1h oversold, 4h down move & low
            & ((roc_9_1h_gt_neg_10) | (rsi_3_4h_gt_10) | (aroonu_14_4h_gt_10))
            # 4h down move & uptrend, 1d high
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_gt_10))
            # 5m downtrend, 4h down move, 1d washed out & uptrend & up move
            & ((rsi_3_4h_gt_25) | (stochrsi_k_1d_gt_20) | (aroonu_14_1d_lt_75) | (rsi_3_1d < 25.0) | (aroonu_14 > 0.0))
            # 4h down move, 1d up move & low
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_lt_35) | (stochrsi_k_1d_gt_20))
            # 4h up move, 1d uptrend & high
            & ((rsi_3_4h_lt_40) | (aroonu_14_1d_lt_60) | (stochrsi_k_1d_gt_10))
            # 4h up move, 4h & 1d low
            & ((rsi_3_4h_lt_50) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 4h up move, 4h & 1d uptrend
            & ((rsi_3_4h_lt_50) | (aroonu_14_4h_lt_20) | (aroonu_14_1d_lt_30))
            # 15m down move, 4h downtrend & down move, 1d down move & still high
            & (
              (aroonu_14_4h_gt_10) | (roc_9_1d_gt_neg_10) | (rsi_3_4h_gt_5) | (stochrsi_k_1d < 35.0) | (rsi_3_15m_gt_5)
            )
            # 15m washed out, 1h washed out, 4h downtrend, 1d on the floor & up move
            & (
              (aroonu_14_4h_gt_20)
              | (stochrsi_k_1d_gt_10)
              | (rsi_3_1d < 20.0)
              | (stochrsi_k_1h_gt_20)
              | (stochrsi_k_15m_gt_50)
            )
            # 5m up move & uptrend, 1h up move, 4h downtrend, 1d down move
            & ((aroonu_14_4h_gt_10) | (rsi_3_1d_gt_15) | (roc_9_1h < 0.0) | (rsi_3 < 15.0) | (aroonu_14 < 15.0))
            # 4h low, 4h & 1d high
            & ((aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_10) | (stochrsi_k_1d_gt_10))
            # 4h low & still high, 1d oversold
            & ((aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_30) | (roc_9_1d_gt_neg_20))
            # the 4h already rolled over and the money has left: a late break, not a fresh one
            & ((aroonu_14_4h_gt_20) | (cmf_20_1h > -0.2))
            # 4h & 1d uptrend, 1d high
            & ((aroonu_14_4h_lt_20) | (aroonu_14_1d_lt_30) | (stochrsi_k_1d_gt_10))
            # 4h & 1d uptrend, 1d oversold
            & ((aroonu_14_4h_lt_20) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h uptrend, 1d down move & up move
            & ((aroonu_14_4h_lt_20) | (roc_9_1d_gt_neg_20) | (rsi_3_1d < 40.0))
            # 5m up move, 4h uptrend & still high & down move, 1d down move
            & ((aroonu_14_4h_lt_20) | (roc_9_1d_gt_neg_20) | (stochrsi_k_4h_lt_50) | (rsi_3_4h_gt_15) | (rsi_3 < 5.0))
            # 5m still high, 4h uptrend, 1d down move & uptrend
            & ((aroonu_14_4h_lt_30) | (rsi_3_1d_gt_10) | (stochrsi_k < 50.0) | (aroonu_14_1d < 55.0))
            # 4h uptrend, 4h & 1d low
            & ((aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_10))
            # 4h & 1d uptrend, 1d low
            & ((aroonu_14_4h_lt_70) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_gt_20))
            # 1h downtrend, 4h on the floor, 1d uptrend & still high & down move
            & (
              (stochrsi_k_4h_gt_10)
              | (aroonu_14_1d_lt_40)
              | (stochrsi_k_1d_lt_50)
              | (rsi_3_1d_gt_40)
              | (aroonu_14_1h_gt_0)
            )
            # 5m still high, 4h washed out & uptrend, 1d washed out
            & ((stochrsi_k_4h_gt_30) | (stochrsi_k_1d_gt_20) | (aroonu_14_4h_lt_60) | (stochrsi_k < 50.0))
            # 15m on the floor, 1h downtrend, 4h up move, 1d down move & still high
            & (
              (roc_9_4h < -5.0)
              | (rsi_3_1d_gt_25)
              | (stochrsi_k_1d_lt_30)
              | (aroonu_14_1h_gt_40)
              | (stochrsi_k_15m > 5.0)
            )
            # 15m uptrend, 1h downtrend, 4h downtrend, 1d money leaving & bot wick pct low
            & (
              (mfi_14_1d > 30.0)
              | (bot_wick_pct_1d > 0.5)
              | (aroonu_14_4h > 75.0)
              | (aroonu_14_15m < 5.0)
              | (aroonu_14_1h_gt_10)
            )
            # the 1d is near a recent high and money is flowing in: this is not a breakdown
            & ((aroonu_14_1d_lt_30) | (cmf_20_1h < 0.1))
            # no daily downtrend yet and no selling on the 15m: the break is cosmetic
            & ((aroond_14_1d > 20.0) | (rsi_14_15m < 30.0))
            # 1d still high, 1h uptrend, 5m barely squeezed
            & ((stochrsi_k_1d < 40.0) | (aroonu_14_1h > 5.0) | (sqz_cnt_24 > 1.0))
            # 1d still strong, 15m not sold into: the break is a dip, not a breakdown
            & ((stochrsi_k_1d_lt_50) | (rsi_14_15m < 20.0))
            # 5m base position low & downtrend, 15m still high, 1h down move, 1d downtrend
            & (
              (ph_base_pos > 0.5)
              | (aroonu_14_1d_gt_10)
              | (rsi_3_1h_gt_5)
              | (stochrsi_k_15m_lt_20)
              | (aroonu_14 > 15.0)
            )
            # 5m 12-bar low high, 15m still high, 1h up move, 1d money leaving & up move
            & (
              (quad_s93_min_12 < 5.0)
              | (mfi_14_1d > 45.0)
              | (stochrsi_k_15m_lt_70)
              | (roc_9_1d < -10.0)
              | (rsi_3_1h < 30.0)
            )
            # 5m engulf bear high & up move, 1h up move, 1d down move
            & ((engulf_bear < 0.5) | (rsi_3_1d_gt_15) | (roc_9_1h < 0.0) | (rsi_3 < 15.0))
            # 5m pre-entry tightness low & uptrend, 15m RSI low
            & ((ph_pre_tight > 1.0) | (rsi_14_15m > 25.0) | (aroonu_14_lt_25))
            # 5m 12-bar low high & washed out, 15m CCI high, 4h uptrend
            & ((quad_s93_min_12 < 5.0) | (cci_20_15m < -115.0) | (aroonu_14_4h_lt_60) | (stochrsi_k > 40.0))
            # 4h momentum snapping up, 4h money leaving and 5m long cycle high
            & ((stoch_60_10 < 20) | (cmf_20_4h_gt_neg_0_25) | (rsi_3_change_pct_4h < 65))
            # 5m vol rel high & on the floor, 15m still high, 1h UO high
            & ((vol_rel < 4.0) | (uo_7_14_28_1h < 50.0) | (stochrsi_k_15m < 65.0) | (stochrsi_k > 10.0))
            # 5m downtrend, 15m rising fast & uptrend, 1h down move, 4h rising fast
            & (
              (uo_7_14_28_change_pct_15m < -5.0)
              | (stochrsi_k_change_pct_4h < -10.0)
              | (aroonu_14_15m_lt_40)
              | (rsi_3_1h_gt_15)
              | (aroonu_14 > 10.0)
            )
            # 4h momentum snapping up, 1h momentum collapsing and daily falling
            & ((rsi_3_change_pct_1h > -60) | (rsi_3_change_pct_4h < 65) | (roc_9_1d_gt_neg_20))
          )

          # Logic
          short_entry_logic.append(
            # first close below the prior 7-day low
            (close < open_rate)
            & (np_shift(close, 1) >= dc_low_7d)
            & (close < dc_low_7d)
            # not after a 24h crash: a breakdown there is the capitulation low
            & (roc_288 > -15.0)
          )

        # Condition #541 - Quick mode (Short).
        if short_entry_condition_index == 541:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)

          # 5m & 15m down move, 4h still high
          short_entry_logic.append((rsi_3_lt_95) | (rsi_3_change_pct_15m < 50.0) | (rsi_14_4h_gt_50))
          # 5m & 15m & 1h down move
          short_entry_logic.append((rsi_3_lt_95) | (rsi_3_15m_lt_95) | (rsi_3_1h_lt_95))
          # 5m strong down move
          short_entry_logic.append((rsi_3_lt_98) | (roc_9 < 50.0))
          # 15m & 1h strong down move & downtrend
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_95) | (mfi_14_1h > 5.0))
          # 15m strong down move, 4h high
          short_entry_logic.append((rsi_3_15m_lt_95) | (stochrsi_k_4h_gt_10))
          # 15m & 1h down move
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_95) | (cci_20_change_pct_1h > 0.0))
          # 15m & 1h down move, 4h high
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_85) | (stochrsi_k_4h_gt_30))
          # 15m & 1h down move, 4h still high
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_change_pct_1h < 50.0) | (mfi_14_4h > 50.0))
          # 15m strong down move, 1h still high
          short_entry_logic.append((rsi_3_15m_lt_95) | (mfi_14_15m < 90.0) | (stochrsi_k_1h_gt_50))
          # 15m & 1h down move, 1h not low enough
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_95) | (stochrsi_k_1h_gt_80))
          # 15m down move, 1h strong down move
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_14_change_pct_1h < 70.0))
          # 15m down move, 4h & 1d downtrend
          short_entry_logic.append((rsi_3_15m_lt_95) | (roc_9_4h_lt_30) | roc_9_1d_lt_50)
          # 15m down move, 1h strong down move, 4h stil high
          short_entry_logic.append((rsi_3_15m_lt_90) | (rsi_3_1h_lt_95) | (stochrsi_k_4h_gt_50))
          # 15m down move, 1h & 4h still high
          short_entry_logic.append((rsi_3_15m_lt_85) | (stochrsi_k_1h_gt_50) | (stochrsi_k_4h_gt_50))
          # 15m down move, 1h downtrend, 4h still high
          short_entry_logic.append((rsi_3_15m_lt_90) | (roc_9_1h_lt_20) | (stochrsi_k_4h_gt_50))
          # 15m & 1h down move, 4h high
          short_entry_logic.append((rsi_3_15m_lt_90) | (rsi_3_1h_lt_85) | (stochrsi_k_4h_gt_30))
          # 15m down move, 1h down move, 4h high
          short_entry_logic.append((rsi_3_15m_lt_85) | (rsi_3_change_pct_1h < 30.0) | (stochrsi_k_4h_gt_10))
          # 1m down move, 1h still dropping, 4h overbought
          short_entry_logic.append((rsi_3_15m_lt_90) | (cci_20_change_pct_1h_lt_0) | (rsi_14_4h_gt_20))
          # 15m down move, 1h high
          short_entry_logic.append((rsi_3_change_pct_15m < 70.0) | (stochrsi_k_1h_gt_10))
          # 1h strong down move, 4h high
          short_entry_logic.append((rsi_3_1h_lt_95) | (stochrsi_k_4h_gt_10))
          # 1h down move, 4h downtrend, 4h not low enough
          short_entry_logic.append((rsi_3_1h_lt_95) | (cmf_20_4h_gt_neg_0_25) | (stochrsi_k_4h_gt_70))
          # 1h down move, 4h high, 1d overbought
          short_entry_logic.append((rsi_3_1h_lt_90) | (rsi_14_4h_gt_40) | roc_9_1d_gt_neg_50)
          # 1h down move, 4h strong down move
          short_entry_logic.append((rsi_3_1h_lt_95) | (rsi_14_change_pct_4h < 40.0))
          # 1h & 4h down move, 4h still going down
          short_entry_logic.append((rsi_3_1h_lt_95) | (rsi_3_4h_lt_95) | (cci_20_change_pct_4h_lt_0))
          # 1h & 4h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_95) | (rsi_3_change_pct_4h < 65.0) | (stochrsi_k_4h_gt_70))
          # 1h down move, 4h down move, 4h P&D
          short_entry_logic.append((rsi_3_1h_lt_90) | (rsi_3_change_pct_4h < 70.0) | (rsi_14_4h_shift_48 > 30.0))
          # 1h & 4h down move, 4h still not low enough, 1d still high
          short_entry_logic.append(
            (rsi_3_1h_lt_90) | (rsi_3_change_pct_4h < 50.0) | (aroond_14_4h_lt_25) | (stochrsi_k_1d_gt_60)
          )
          # 1h down move, 1h still high, 1d going down
          short_entry_logic.append((rsi_3_1h_lt_85) | (stochrsi_k_1h_gt_50) | (roc_2_1d > -50.0))
          # 4h downtrend, 4h still high, 1d strong downtrend
          short_entry_logic.append((rsi_3_4h_lt_85) | (stochrsi_k_4h_gt_70) | (roc_9_1d_lt_60))
          # 15m down move, 1h strong down move, 1d overbought
          short_entry_logic.append((mfi_14_15m < 80.0) | (rsi_3_change_pct_1h < 80.0) | roc_9_1d_gt_neg_50)
          # 1h not low enough, 4h high, 1d strong downtrend
          short_entry_logic.append((stochrsi_k_1h_gt_70) | (stochrsi_k_4h_gt_10) | (roc_9_1d_lt_60))
          # 1h down move, 4h still high, 1d downtrend
          short_entry_logic.append((rsi_3_change_pct_1h < 65.0) | (stochrsi_k_4h_gt_30) | roc_9_1d_lt_50)
          # 15m strong down move, 1h still high
          short_entry_logic.append((roc_9_15m < 15.0) | (stochrsi_k_1h_gt_30))
          # 15m downtrend, 4h down move, 4h stil high
          short_entry_logic.append((roc_9_15m < 15.0) | (rsi_3_4h_lt_75) | (stochrsi_k_4h_gt_30))
          # 1h downtrend, 4h overbought
          short_entry_logic.append((roc_2_1h < 5.0) | (rsi_14_4h_gt_20) | (roc_9_4h_gt_neg_25))
          # 1h P&D, 4h still high
          short_entry_logic.append((roc_2_1h < 10.0) | (roc_9_1h > -5.0) | (stochrsi_k_4h_gt_30))
          # 1h downtrend, 4h down move, 1d downtrend
          short_entry_logic.append((roc_9_1h_lt_40) | (rsi_3_4h_lt_90) | roc_9_1d_lt_50)
          short_entry_logic.append((roc_9_4h > -200.0) | (rsi_14_4h_gt_20))
          # 4h down move, 1d P&D
          short_entry_logic.append((roc_9_4h_lt_20) | (roc_2_1d < 20.0) | roc_9_1d_gt_neg_50)
          # 1h P&D, 4h overbought
          short_entry_logic.append((change_pct_1h < 2.0) | (change_pct_1h_shift_12 > 2.0) | (rsi_14_4h_gt_20))
          # 1h P&D, 1d overbought
          short_entry_logic.append((change_pct_1h < 5.0) | (change_pct_1h_shift_12 > -5.0) | (roc_9_1d_gt_neg_100))
          # 1h & 4h red, 1h not low enough
          short_entry_logic.append((change_pct_1h < 10.0) | (change_pct_4h < 10.0) | (mfi_14_1h > 50.0))
          # 1h red, 1h still not low enough, 1d down move
          short_entry_logic.append((change_pct_1h < 15.0) | (mfi_14_1h > 50.0) | (rsi_3_1d_lt_90))
          # 4h red, previous 4h green, 4h overbought
          short_entry_logic.append(
            (change_pct_4h < 5.0) | (change_pct_4h_shift_48 > -5.0) | (rsi_14_4h_shift_48 > 20.0)
          )
          # 1d P&D, 1d overbought
          short_entry_logic.append((change_pct_1d_lt_10) | (change_pct_1d_shift_288 > -10.0) | (roc_9_1d_gt_neg_100))
          # 1d P&D, 4h still high
          short_entry_logic.append((change_pct_1d_lt_15) | (change_pct_1d_shift_288 > -15.0) | (aroond_14_4h_lt_50))

          # Logic
          short_entry_logic.append(rsi_14 > 64.0)
          short_entry_logic.append(aroond_14_lt_25)
          short_entry_logic.append(aroonu_14_gt_75)
          short_entry_logic.append(ema_9 > (ema_26 * 1.040))

        # Condition #542 - Quick mode (Short).
        if short_entry_condition_index == 542:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)

          # 5m & 15m up move, 15m stil low
          short_entry_logic.append(
            ((rsi_3_lt_90) | (rsi_3_15m_lt_80) | (aroonu_14_15m_gt_60))
            # 15m & 1h up move, 4h still low
            & ((rsi_3_15m_lt_95) | (rsi_3_1h_lt_95) | (rsi_14_4h_gt_60))
            # 15m & 1h up move, 4h still not high enough
            & ((rsi_3_15m_lt_95) | (rsi_3_1h_lt_95) | (stochrsi_k_4h_gt_80))
            # 15m & 1h up move, 1h still moving higher
            & ((rsi_3_15m_lt_95) | (rsi_3_1h_lt_90) | (cci_20_change_pct_1h_lt_neg_0))
            # 15m & 1d up move, 1d uptrend
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_80) | (roc_9_1d_lt_50))
            # 15m & 4h up move, 4h still moving higher
            & ((rsi_3_15m_lt_90) | (rsi_3_4h_lt_95) | (cci_20_change_pct_4h_lt_neg_0))
            # 15m & 1d up move, 4h uptrend
            & ((rsi_3_15m_lt_90) | (rsi_3_1d_lt_80) | (roc_9_4h_lt_20))
            # 15m up move, 15m & 4h high
            & ((rsi_3_15m_lt_90) | (aroonu_14_15m_lt_100) | (aroonu_14_4h_lt_100))
            # 15m up move, 15m still not high enough, 1d uptrend
            & ((rsi_3_15m_lt_90) | (stochrsi_k_15m_gt_80) | (roc_9_1d_lt_80))
            # 15m & 4h up move, 15m still not high enough
            & ((rsi_3_15m_lt_85) | (rsi_3_4h_lt_90) | (stochrsi_k_15m_gt_70))
            # 15m & 4h up move, 1d uptrend
            & ((rsi_3_15m_lt_85) | (rsi_3_4h_lt_85) | roc_9_1d_lt_50)
            # 15m & 4h up move, 4h still not high enough
            & ((rsi_3_15m_lt_85) | (rsi_3_4h_lt_80) | (rsi_14_4h_gt_60))
            # 15m up move, 15m still not high enough, 4h still low
            & ((rsi_3_15m_lt_85) | (stochrsi_k_15m_gt_80) | (aroonu_14_4h_gt_50))
            # 15m up move, 4h overbought
            & ((rsi_3_15m_lt_85) | (roc_9_4h_lt_50))
            # 15m & 1h up move, 15m & 1h uptrend
            & ((rsi_3_15m_lt_80) | (rsi_3_1h_lt_80) | (aroonu_14_15m_lt_100) | (aroonu_14_1h_lt_100))
            # 15m & 1h up move, 1h uptrend, 4h uptrend
            & ((rsi_3_15m_lt_80) | (rsi_3_1h_lt_80) | (aroonu_14_1h_lt_100) | (roc_9_4h_lt_10))
            # 15m & 1h up move, 15m still low
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_lt_70) | (aroonu_14_15m_gt_40))
            # 15m & 1h up move, 15m still low
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_lt_70) | (stochrsi_k_15m_gt_40))
            # # 15m & 1h up move, 4h low
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_lt_60) | (aroonu_14_4h > 40.0))
            # 1h & 1d up move, 1h still moving higher
            & ((rsi_3_1h < 97.0) | (rsi_3_1d_lt_95) | (cci_20_change_pct_1h_lt_neg_0))
            # 1h & 4h up move, 15m still not high enough
            & ((rsi_3_1h_lt_95) | (rsi_3_4h_lt_95) | (stochrsi_k_15m_gt_80))
            # 1h & 4h up move, 1d uptrend
            & ((rsi_3_1h_lt_95) | (rsi_3_4h_lt_95) | (roc_9_1d_lt_100))
            # 1h & 4h up move, 1d still low
            & ((rsi_3_1h_lt_95) | (rsi_3_4h_lt_85) | (rsi_14_1d_gt_50))
            # 1h up move, 4h still low, 1h still moving higher
            & ((rsi_3_1h_lt_95) | (rsi_14_4h_gt_60) | (cci_20_change_pct_1h_lt_neg_0))
            # 1h up move, 4h low
            & ((rsi_3_1h_lt_95) | (aroonu_14_4h_gt_10))
            # 1h & 4h up move, 1h still moving higher
            & ((rsi_3_1h_lt_90) | (rsi_3_4h_lt_85) | (cci_20_change_pct_1h_lt_neg_0))
            # 1h & 4h up move, 4h still not high enough
            & ((rsi_3_1h_lt_90) | (rsi_3_4h_lt_70) | (stochrsi_k_4h_gt_80))
            # 1h & 1d up move, 15m still low
            & ((rsi_3_1h_lt_90) | (rsi_3_1d_lt_90) | (stochrsi_k_15m_gt_60))
            # 1h up move, 15m high
            & ((rsi_3_1h_lt_90) | (aroonu_14_15m_lt_100))
            # 1h up move, 4h low
            & ((rsi_3_1h_lt_90) | (stochrsi_k_4h_gt_30))
            # 1h up move, 4h still low, 1h still moving higher
            & ((rsi_3_1h_lt_90) | (stochrsi_k_4h_gt_60) | (cci_20_change_pct_1h_lt_neg_0))
            # 1h up move, 15m uptrend
            & ((rsi_3_1h_lt_90) | (roc_9_15m < 30.0))
            # 1h up move, 15m & 4h uptrend
            & ((rsi_3_1h_lt_90) | (roc_9_15m < 20.0) | (roc_9_4h_lt_20))
            # 1h & 4h up move, 4h still moving higher
            & ((rsi_3_1h_lt_85) | (rsi_3_4h_lt_80) | (cci_20_change_pct_4h_lt_neg_0))
            # 1h up move, 15m low
            & ((rsi_3_1h_lt_85) | (aroonu_14_15m_gt_40))
            # 1h up move, 4h still not high enough, 1d low
            & ((rsi_3_1h_lt_85) | (aroonu_14_4h_gt_80) | (rsi_14_1d_gt_40))
            # 1h & 4h up move, 4h still low
            & ((rsi_3_1h_lt_80) | (rsi_3_4h_lt_80) | (aroonu_14_4h_gt_50))
            # 1h & 4h up move, 1d still low
            & ((rsi_3_1h_lt_80) | (rsi_3_4h_lt_80) | (aroonu_14_1d_gt_50))
            # 1h & 4h up move, 1d low
            & ((rsi_3_1h_lt_80) | (rsi_3_4h_lt_70) | (stochrsi_k_1d_gt_30))
            # 1h up move, 1d still low, 1d uptrend
            & ((rsi_3_1h_lt_80) | (aroonu_14_1d_gt_50) | (roc_9_1d_lt_30))
            # 1h up move, 1d low
            & ((rsi_3_1h_lt_80) | (stochrsi_k_1d_gt_20))
            # 1h up move, 4h & 1d uptrend
            & ((rsi_3_1h_lt_80) | (roc_9_4h_lt_20) | (roc_9_1d_lt_40))
            # 4h up move, 1d low
            & ((rsi_3_4h_lt_95) | (rsi_14_1d_gt_40))
            # 4h down move, 15m still not high enough, 1d low
            & ((rsi_3_4h_lt_95) | (stochrsi_k_15m_gt_80) | (aroond_14_1d < 75.0))
            # 4h up move, 1h & 4h uptrend
            & ((rsi_3_4h_lt_95) | (roc_9_1h_lt_20) | (roc_9_4h_lt_20))
            # 4h up move, 15m low
            & ((rsi_3_4h_lt_90) | (stochrsi_k_15m > 45.0))
            # 4h up move, 4h & 1d uptrend
            & ((rsi_3_4h_lt_90) | (roc_9_4h_lt_20) | (roc_9_1d_lt_40))
            # 4h up move, 15m still not high enough
            & ((rsi_3_4h_lt_85) | (aroonu_14_15m_gt_60))
            # 4h up move, 15m low
            & ((rsi_3_4h_lt_85) | (stochrsi_k_15m_gt_30))
            # 4h up move, 4h uptrend
            & ((rsi_3_4h_lt_80) | (aroonu_14_4h_lt_100) | (roc_9_4h_lt_20))
            # 4h up move, 15m still low, 4h still not high enough
            & ((rsi_3_4h_lt_80) | (stochrsi_k_15m_gt_60) | (aroonu_14_4h_gt_80))
            # 4h up move, 15m still low, 4h still not high enough
            & ((rsi_3_4h_lt_75) | (stochrsi_k_15m_gt_60) | (stochrsi_k_4h_gt_80))
            # 1d up move, 4h low
            & ((rsi_3_1d < 85.0) | (stochrsi_k_4h_gt_40))
            # 4h still not high enough, 4h overbought, 4h uptrend
            & ((rsi_14_4h_gt_80) | (roc_9_4h_lt_40) | (cci_20_change_pct_4h_lt_0))
            # 15m & 1h high, 4h uptrend
            & ((aroonu_14_15m_lt_100) | (aroonu_14_1h_lt_100) | (roc_9_4h_lt_20))
            # 15m & 1h high, 1d uptrend
            & ((aroonu_14_15m_lt_100) | aroonu_14_1h_lt_100 | (roc_9_1d_lt_50))
            # 15m & 4h high, 1h uptrend
            & ((aroonu_14_15m_lt_100) | aroonu_14_4h_lt_100 | (roc_9_1h_lt_20))
            # 15m & 4h high, 1d uptrend
            & ((aroonu_14_15m_lt_100) | aroonu_14_4h_lt_100 | (roc_9_1d_lt_50))
            # 15m high, 1d low
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_1d_gt_20))
            # 15m high & uptrend
            & ((aroonu_14_15m_lt_100) | (roc_9_15m < 30.0))
            # 15m high, 1h & 4h uptrend
            & ((aroonu_14_15m_lt_100) | (roc_9_1h_lt_20) | (roc_9_4h_lt_20))
            # 1h high, 15m uptrend
            & ((aroonu_14_1h_lt_100) | (roc_9_15m < 20.0))
            # 15m & 4h still not high enough
            & ((stochrsi_k_15m_gt_70) | (stochrsi_k_4h_gt_70))
            # 1h & 4h overbought, 1h uptrend
            & ((roc_9_1h_lt_10) | (roc_9_4h_lt_40) | (cci_20_change_pct_1h_lt_0))
            # 1h & 4h overbought, 4h uptrend
            & ((roc_9_1h_lt_10) | (roc_9_4h_lt_40) | (cci_20_change_pct_4h_lt_0))
            # 1d bot wick, 4h still not high enough
            & ((bot_wick_pct_1d < 30.0) | (stochrsi_k_4h_gt_80))
            # rise in the last 12 hours, relatively stable before the 12 hours
            & ((close < (low_min_12_1h * 1.30)) | (low_min_12_1h > (low_min_24_1h * 1.10)))
            # big pump in the last 30 days, 4h up move
            & ((close < (low_min_30_1d * 4.0)) | (rsi_3_4h_lt_85))
          )

          # Logic
          short_entry_logic.append(
            (willr_14 > -50.0)
            & (aroonu_14_gt_75)
            & (aroond_14_lt_25)
            & (stochrsi_k_gt_80)
            & (willr_84_1h > -30.0)
            & (stochrsi_k_1h_gt_80)
            & (bbb_20_2_0_1h > 8.0)
            # 4h downtrend not extreme, 1d range calm
            & (minus_di_14_4h < 30.0)
            & (range_pct_14_1d < 22.0)
            & (close_min_48 <= (close * 0.90))
          )

        # Condition #543 - Overbought Exhaustion (Short).
        # Shorts an exhausted overbought spike: RSI/StochRSI/WillR maxed with close well above
        # BB-upper and momentum rolling over (cci_change < 0). Guards reject spikes that keep
        # running (mid-band 4h ROC / extreme multi-TF momentum = squeeze). 2022 + 2021: 100% WR.
        if short_entry_condition_index == 543:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m up move, 4h uptrend & high
            ((rsi_3_lt_95) | (aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_10))
            # 5m up move, 4h down move, 1d uptrend
            & ((rsi_3_lt_97) | (rsi_3_4h_gt_20) | (aroonu_14_1d_lt_60))
            # 5m up move, 4h low, 1d down move
            & ((rsi_3_lt_97) | (stochrsi_k_4h_gt_20) | (rsi_3_1d_gt_30))
            # 5m up move, 4h & 1d still high
            & ((rsi_3_lt_97) | (stochrsi_k_4h_gt_30) | (stochrsi_k_1d_gt_30))
            # 5m strong down move, 1h up move, 1d uptrend
            & ((rsi_3_lt_98) | (rsi_3_1h_lt_50) | (roc_9_1d_lt_10))
            # 15m up move, 4h not falling
            & ((rsi_3_15m_lt_75) | (rsi_3_4h_gt_10))
            # 15m up move, 1d down move & uptrend
            & ((rsi_3_15m_lt_80) | (aroonu_14_1d_lt_80) | (rsi_3_1d_gt_20))
            # 15m up move & still high, 1h low
            & ((rsi_3_15m_lt_80) | (stochrsi_k_15m_gt_40) | (aroonu_14_1h_gt_60))
            # 15m down move, 1d low & uptrend
            & ((rsi_3_15m_lt_85) | (aroonu_14_1d_gt_20) | (roc_9_1d_lt_0))
            # 15m & 4h down move, 1h uptrend
            & ((rsi_3_15m_lt_85) | (aroonu_14_1h_lt_40) | (rsi_3_4h_gt_30))
            # 15m up move, 1d uptrend & still high
            & ((rsi_3_15m_lt_90) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d_gt_40))
            # 15m up move, 4h uptrend, 1d down move
            & ((rsi_3_15m_lt_90) | (aroonu_14_4h_lt_60) | (rsi_3_1d_gt_20))
            # 15m & 1d up move, 1d still high
            & ((rsi_3_15m_lt_90) | (rsi_3_1d_lt_35) | (stochrsi_k_1d_gt_40))
            # 15m up move, 1h & 1d down move
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_gt_65) | (rsi_3_1d_gt_30))
            # 15m low, 1d down move & uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1d_lt_30) | (rsi_3_1d_gt_20))
            # 15m low & still not low enough, 1h high
            & ((aroonu_14_15m_gt_40) | (stochrsi_k_15m_gt_70) | (stochrsi_k_1h_gt_10))
            # 15m & 1h low, 4h still high
            & ((aroonu_14_15m_gt_60) | (aroonu_14_1h_gt_20) | (stochrsi_k_4h_gt_30))
            # 15m low, 1h down move
            & ((aroonu_14_15m_gt_60) | (stochrsi_k_15m_gt_20) | (rsi_3_1h_gt_40))
            # 15m & 1h uptrend, 1h still high
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_50))
            # 15m still not low enough, 1h & 4h down move
            & ((stochrsi_k_15m_gt_80) | (rsi_3_1h_gt_65) | (rsi_3_4h_gt_20))
            # 15m & 1h still not low enough, 4h down move
            & ((stochrsi_k_15m_gt_80) | (stochrsi_k_1h_gt_70) | (rsi_3_4h_gt_20))
            # 15m & 1h still not low enough, 4h oversold
            & ((stochrsi_k_15m_gt_90) | (stochrsi_k_1h_gt_80) | (roc_9_4h_gt_neg_15))
            # 1h down move, 4h low, 1d still high
            & ((rsi_3_1h_gt_50) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_40))
            # 1h up move & still not low enough, 4h low
            & ((rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_80) | (aroonu_14_4h_gt_10))
            # 1h up move & still not low enough, 1d uptrend
            & ((rsi_3_1h_lt_70) | (stochrsi_k_1h_gt_70) | (aroonu_14_1d_lt_80))
            # 1h low, 4h up move & uptrend
            & ((aroonu_14_1h_gt_20) | (rsi_3_4h_lt_50) | (aroonu_14_4h_lt_50))
            # 1h & 4h up move, 1h low
            & ((aroonu_14_1h_gt_60) | (rsi_3_1h_lt_60) | (rsi_3_4h_lt_50))
            # 1h uptrend, 4h still high, 1d low
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_40) | (stochrsi_k_1d_gt_20))
            # 1h & 4h uptrend, 1d down move
            & ((aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_30) | (rsi_3_1d_gt_30))
            # 4h down move, 1d low & uptrend
            & ((rsi_3_4h_gt_30) | (aroonu_14_1d_gt_20) | (roc_9_1d_lt_0))
          )

          # Logic
          short_entry_logic.append(
            # the 4h has already turned down — exhaustion into a rising 4h is the squeeze
            (roc_9_4h < 0.0)
            # price is at the top of the 48-candle range and clear of the upper band
            & (close > (close_max_48 * 0.99))
            & (close > (bbu_20_2_0 * 1.005))
            # 5m is stretched on every reading
            & (rsi_3 > 85.0)
            & (rsi_14 > 72.0)
            & (stochrsi_k > 85.0)
            & (willr_14 > -10.0)
            # but the money is not there and the 1h is already rolling over
            & (cmf_20 < 0.25)
            & (mfi_14 < 65.0)
            & (cci_20_change_pct_1h < 0.0)
          )

        # Condition #544 - Momentum Breakdown / Rollover Continuation (Short).
        # Shorts a confirmed 4h momentum rollover (ema_12 < ema_26, rsi_3 flushed under 30). The
        # breakdown-quality guards keep it off uptrend-dips and spent-aroon late entries (both
        # squeeze). Robust in both regimes — 2022 + 2021: 100% WR / 0 loss.
        if short_entry_condition_index == 544:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m down move, 15m low, 1h uptrend
            ((rsi_3_gt_10) | (aroonu_14_15m_gt_40) | (aroonu_14_1h_lt_90))
            # 5m & 4h down move, 15m uptrend
            & ((rsi_3_gt_10) | (aroonu_14_15m_lt_80) | (rsi_3_4h_gt_55))
            # 5m down move & uptrend, 1h up move
            & ((rsi_3_gt_10) | (aroonu_14_lt_30) | (rsi_3_1h_lt_70))
            # 5m & 15m & 1h down move
            & ((rsi_3_gt_10) | (rsi_3_15m_gt_25) | (rsi_3_1h_gt_60))
            # 5m & 1h down move, 1d uptrend
            & ((rsi_3_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_1d_lt_75))
            # 5m down move, 15m still high, 1d uptrend
            & ((rsi_3_gt_10) | (stochrsi_k_15m_gt_30) | (roc_9_1d_lt_20))
            # 5m & 4h down move, 15m up move
            & ((rsi_3_gt_15) | (rsi_3_15m_lt_50) | (rsi_3_4h_lt_75))
            # 5m & 1h down move, 4h still not low enough
            & ((rsi_3_gt_15) | (rsi_3_1h_gt_55) | (stochrsi_k_4h_gt_70))
            # 5m & 4h down move, 1d low
            & ((rsi_3_gt_15) | (rsi_3_4h_lt_75) | (aroonu_14_1d_gt_20))
            # 5m & 1d down move, 15m still high
            & ((rsi_3_gt_15) | (stochrsi_k_15m_gt_30) | (rsi_3_1d_gt_30))
            # 5m down move, 1h still not low enough, 1d low
            & ((rsi_3_gt_15) | (stochrsi_k_1h_gt_70) | (aroonu_14_1d_gt_20))
            # 5m down move, 15m low, 1h up move
            & ((rsi_3_gt_5) | (aroonu_14_15m_gt_60) | (rsi_3_1h_lt_80))
            # 5m & 15m & 4h down move
            & ((rsi_3_gt_5) | (rsi_3_15m_gt_20) | (rsi_3_4h_gt_55))
            # 5m uptrend, 15m low, 1d up move
            & ((aroonu_14_lt_25) | (aroonu_14_15m_gt_10) | (rsi_3_1d_lt_90))
            # 5m uptrend, 15m down move, 1d low
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_25) | (aroonu_14_1d_gt_20))
            # 5m uptrend, 15m high, 1d low
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_10) | (aroonu_14_1d_gt_50))
            # 5m uptrend, 1h high, 4h up move
            & ((aroonu_14_lt_25) | (stochrsi_k_1h_gt_10) | (rsi_3_4h_lt_70))
            # 5m uptrend, 1h still not high enough, 4h low
            & ((aroonu_14_lt_25) | (stochrsi_k_1h_gt_70) | (aroonu_14_4h_gt_20))
            # 5m & 15m uptrend, 4h down move
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_60) | (rsi_3_4h_gt_60))
            # 5m & 1h & 4h uptrend
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_80))
            # 5m uptrend, 15m down move, 1h still high
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_35) | (stochrsi_k_1h_gt_30))
            # 5m uptrend, 1h down move, 4h up move
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_30) | (rsi_3_4h_lt_70))
            # 5m uptrend, 15m high, 4h up move
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_10) | (rsi_3_4h_lt_90))
            # 5m uptrend, 15m still high, 4h down move
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_40) | (rsi_3_4h_gt_60))
            # 15m down move & low, 4h up move
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_gt_10) | (rsi_3_4h_lt_70))
            # 15m down move & low, 1h uptrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_85))
            # 5m & 1h down move, 15m uptrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_30) | (rsi_3_1h_gt_45))
            # 15m & 1h down move, 15m uptrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_80) | (rsi_3_1h_gt_50))
            # 15m down move & uptrend, 1h up move
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_90) | (rsi_3_1h_lt_70))
            # 15m down move, 1h up move, 1d uptrend
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_lt_50) | (roc_9_1d_lt_0))
            # 15m & 1d down move, 15m low
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_gt_20) | (rsi_3_1d_gt_40))
            # 15m down move & low, 1h up move
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_gt_50) | (rsi_3_1h_lt_60))
            # 15m & 1d down move, 15m low
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_gt_60) | (rsi_3_1d_gt_30))
            # 15m down move, 15m & 4h uptrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_80))
            # 15m down move, 4h low, 1d uptrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_gt_30) | (roc_9_1d_lt_0))
            # 15m down move, 4h low & uptrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_gt_50) | (roc_9_4h_lt_5))
            # 15m & 1h & 1d down move
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_60) | (rsi_3_1d_gt_30))
            # 15m & 1h down move, 1d uptrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_65) | (aroonu_14_1d_lt_75))
            # 15m & 4h down move, 1d uptrend
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_65) | (roc_9_1d_lt_20))
            # 15m & 4h & 1d down move
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_lt_75) | (rsi_3_1d_gt_40))
            # 15m down move, 1h low, 1d still high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_gt_20) | (stochrsi_k_1d_gt_40))
            # 15m down move, 1h still high, 1d oversold
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_gt_60) | (roc_9_1d_gt_neg_10))
            # 15m down move, 1h still not low enough, 4h still high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_gt_90) | (stochrsi_k_4h_gt_30))
            # 15m down move & low, 1h uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_75))
            # 15m down move & low, 1d still not low enough
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_gt_10) | (stochrsi_k_1d_gt_70))
            # 15m & 4h down move, 15m uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_30) | (rsi_3_4h_lt_85))
            # 15m down move, 15m & 1h uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_60) | (roc_9_1h_lt_10))
            # 15m down move, 1h uptrend & still high
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_85) | (stochrsi_k_1h_gt_40))
            # 15m down move, 4h low, 1d up move
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_gt_20) | (rsi_3_1d_lt_90))
            # 15m down move, 4h & 1d low
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_gt_50) | (aroonu_14_1d_gt_20))
            # 15m down move, 1h up move, 4h high
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_lt_90) | (stochrsi_k_4h_gt_10))
            # 15m down move, 4h up move, 1d oversold
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_lt_80) | (roc_9_1d_gt_neg_10))
            # 15m down move, 1h still high, 1d up move
            & ((rsi_3_15m_gt_25) | (stochrsi_k_1h_gt_40) | (rsi_3_1d_lt_90))
            # 15m down move, 1h still high, 1d low
            & ((rsi_3_15m_gt_25) | (stochrsi_k_1h_gt_50) | (aroonu_14_1d_gt_50))
            # 15m & 1h down move, 15m low
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_gt_10) | (rsi_3_1h_lt_55))
            # 15m down move, 15m & 4h uptrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_80))
            # 15m down move & uptrend, 1h still high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_40))
            # 15m & 1h down move, 1d uptrend
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_lt_75) | (roc_9_1d_lt_0))
            # 15m & 1d down move, 1h still high
            & ((rsi_3_15m_gt_30) | (stochrsi_k_1h_gt_60) | (rsi_3_1d_gt_30))
            # 15m down move & low, 1h uptrend
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_85))
            # 15m down move & low, 1h up move
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_gt_30) | (rsi_3_1h_lt_60))
            # 15m down move, 1h uptrend, 4h up move
            & ((rsi_3_15m_gt_35) | (aroonu_14_1h_lt_85) | (rsi_3_4h_lt_90))
            # 15m & 1h & 1d down move
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_60) | (rsi_3_1d_gt_20))
            # 15m down move, 4h & 1d up move
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_lt_95) | (rsi_3_1d_lt_80))
            # 15m down move, 4h low, 1d oversold
            & ((rsi_3_15m_gt_35) | (stochrsi_k_4h_gt_20) | (roc_9_1d_gt_neg_10))
            # 15m down move & uptrend, 1h still not low enough
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_75) | (stochrsi_k_1h_gt_70))
            # 15m & 1h down move, 1h still high
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_lt_75) | (stochrsi_k_1h_gt_60))
            # 15m down move, 1h still high, 1d low
            & ((rsi_3_15m_gt_40) | (stochrsi_k_1h_gt_40) | (aroonu_14_1d_gt_20))
            # 15m & 4h down move, 1h still high
            & ((rsi_3_15m_gt_40) | (stochrsi_k_1h_gt_50) | (rsi_3_4h_gt_35))
            # 15m up move & low, 4h down move
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_gt_10) | (rsi_3_4h_lt_85))
            # 15m & 1h up move, 15m low
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_gt_60) | (rsi_3_1h_lt_90))
            # 15m up move, 15m & 1d uptrend
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_lt_60) | (aroonu_14_1d_lt_75))
            # 15m up move, 4h & 1d down move
            & ((rsi_3_15m_lt_50) | (rsi_3_4h_gt_65) | (rsi_3_1d_gt_60))
            # 15m & 4h up move, 1d still not high enough
            & ((rsi_3_15m_lt_50) | (rsi_3_4h_lt_70) | (stochrsi_k_1d_gt_70))
            # 15m up move, 4h down move & still not low enough
            & ((rsi_3_15m_lt_50) | (rsi_3_4h_lt_75) | (stochrsi_k_4h_gt_70))
            # 15m up move & low, 1d still high
            & ((rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1d_gt_40))
            # 15m up move, 1h still not low enough, 1d down move
            & ((rsi_3_15m_lt_50) | (stochrsi_k_1h_gt_80) | (rsi_3_1d_gt_50))
            # 15m down move & low, 1h uptrend
            & ((rsi_3_15m_lt_55) | (aroonu_14_15m_gt_40) | (aroonu_14_1h_lt_90))
            # 15m & 4h down move, 4h still not low enough
            & ((rsi_3_15m_lt_55) | (rsi_3_4h_gt_60) | (stochrsi_k_4h_gt_70))
            # 15m down move, 1h still high, 4h still not low enough
            & ((rsi_3_15m_lt_55) | (stochrsi_k_1h_gt_50) | (stochrsi_k_4h_gt_70))
            # 15m down move, 1h still not low enough, 4h low
            & ((rsi_3_15m_lt_55) | (stochrsi_k_1h_gt_70) | (aroonu_14_4h_gt_30))
            # 15m up move, 15m & 1d low
            & ((rsi_3_15m_lt_60) | (aroonu_14_15m_gt_60) | (stochrsi_k_1d_gt_20))
            # 15m up move & low, 1h down move
            & ((rsi_3_15m_lt_70) | (aroonu_14_15m_gt_20) | (rsi_3_1h_gt_45))
            # 15m aroonu, 1d aroond, 15m rsi
            & ((aroonu_14_15m < 45) | (aroond_14_1d > 10) | (rsi_3_change_pct_15m < 70))
            # 15m aroonu, 1h stochrsik, 15m rsi
            & ((aroonu_14_15m < 45) | (stochrsi_k_1h_gt_75) | (rsi_3_change_pct_15m < 70))
            # 15m & 4h low, 1d up move
            & ((aroonu_14_15m_gt_10) | (aroonu_14_4h_gt_20) | (rsi_3_1d_lt_80))
            # 15m low, 1h & 1d down move
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_gt_65) | (rsi_3_1d_gt_40))
            # 15m low, 1h & 4h up move
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_50) | (rsi_3_4h_lt_90))
            # 15m low & high, 1d still high
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_10) | (stochrsi_k_1d_gt_40))
            # 15m low, 1h high, 4h up move
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_1h_gt_10) | (rsi_3_4h_lt_70))
            # 15m low, 1h uptrend, 4h down move
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_85) | (rsi_3_4h_gt_60))
            # 15m & 1h low, 1h uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_85) | (stochrsi_k_1h_gt_20))
            # 15m & 4h & 1d low
            & ((aroonu_14_15m_gt_20) | (aroonu_14_4h_gt_80) | (aroonu_14_1d_gt_20))
            # 15m & 4h low, 1d still high
            & ((aroonu_14_15m_gt_20) | (aroonu_14_4h_gt_80) | (stochrsi_k_1d_gt_40))
            # 15m & 1d low, 1d up move
            & ((aroonu_14_15m_gt_20) | (rsi_3_1d_lt_80) | (aroonu_14_1d_gt_20))
            # 15m low, 1h down move, 1d still high
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_gt_45) | (stochrsi_k_1d_gt_30))
            # 15m low, 1h up move, 1d uptrend
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_70) | (aroonu_14_1d_lt_50))
            # 15m & 4h low, 4h up move
            & ((aroonu_14_15m_gt_20) | (rsi_3_4h_lt_80) | (aroonu_14_4h_gt_80))
            # 15m & 4h low
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_20) | (aroonu_14_4h_gt_20))
            # 15m & 1d low, 1h still high
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_1h_gt_40) | (stochrsi_k_1d_gt_20))
            # 15m low, 1h uptrend, 1d down move
            & ((aroonu_14_15m_gt_30) | (aroonu_14_1h_lt_85) | (rsi_3_1d_gt_65))
            # 15m low, 1h & 4h uptrend
            & ((aroonu_14_15m_gt_30) | (aroonu_14_1h_lt_90) | (roc_9_4h_lt_5))
            # 15m low, 4h uptrend, 1d down move
            & ((aroonu_14_15m_gt_30) | (aroonu_14_4h_lt_80) | (rsi_3_1d_gt_40))
            # 15m low, 1h & 4h down move
            & ((aroonu_14_15m_gt_30) | (rsi_3_1h_gt_50) | (rsi_3_4h_gt_50))
            # 15m low, 1h up move, 4h uptrend
            & ((aroonu_14_15m_gt_30) | (rsi_3_1h_lt_60) | (roc_9_4h_lt_5))
            # 15m & 4h low, 4h down move
            & ((aroonu_14_15m_gt_30) | (rsi_3_4h_gt_65) | (aroonu_14_4h_gt_20))
            # 15m low & high, 1h uptrend
            & ((aroonu_14_15m_gt_30) | (stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_85))
            # 15m & 1h low, 4h down move
            & ((aroonu_14_15m_gt_30) | (stochrsi_k_1h_gt_20) | (rsi_3_4h_gt_50))
            # 15m low, 4h & 1d still high
            & ((aroonu_14_15m_gt_30) | (stochrsi_k_4h_gt_30) | (stochrsi_k_1d_gt_40))
            # 15m low, 1h uptrend, 4h up move
            & ((aroonu_14_15m_gt_40) | (aroonu_14_1h_lt_90) | (rsi_3_4h_lt_80))
            # 15m & 4h low, 4h still not low enough
            & ((aroonu_14_15m_gt_40) | (aroonu_14_4h_gt_20) | (stochrsi_k_4h_gt_70))
            # 15m low, 1h down move, 4h still high
            & ((aroonu_14_15m_gt_40) | (rsi_3_1h_gt_60) | (stochrsi_k_4h_gt_30))
            # 15m low, 1h & 4h up move
            & ((aroonu_14_15m_gt_40) | (rsi_3_1h_lt_65) | (rsi_3_4h_lt_70))
            # 15m & 1d low, 4h down move
            & ((aroonu_14_15m_gt_40) | (rsi_3_4h_gt_65) | (aroonu_14_1d_gt_50))
            # 15m low, 4h still high & uptrend
            & ((aroonu_14_15m_gt_40) | (stochrsi_k_4h_gt_30) | (roc_9_4h_lt_5))
            # 15m & 1d low, 4h still not low enough
            & ((aroonu_14_15m_gt_40) | (stochrsi_k_4h_gt_70) | (aroonu_14_1d_gt_50))
            # 15m low, 4h still not low enough, 1d uptrend
            & ((aroonu_14_15m_gt_40) | (stochrsi_k_4h_gt_80) | (roc_9_1d_lt_35))
            # 15m & 1d low, 1h up move
            & ((aroonu_14_15m_gt_50) | (rsi_3_1h_lt_70) | (stochrsi_k_1d_gt_20))
            # 15m low & high, 1d up move
            & ((aroonu_14_15m_gt_50) | (stochrsi_k_15m_gt_10) | (rsi_3_1d_lt_80))
            # 15m low, 1h & 1d uptrend
            & ((aroonu_14_15m_gt_60) | (aroonu_14_1h_lt_100) | (aroonu_14_1d_lt_75))
            # 15m low, 1h uptrend & still not low enough
            & ((aroonu_14_15m_gt_60) | (aroonu_14_1h_lt_100) | (stochrsi_k_1h_gt_70))
            # 15m low, 1h & 4h uptrend
            & ((aroonu_14_15m_gt_60) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_80))
            # 15m low, 1h uptrend & still high
            & ((aroonu_14_15m_gt_60) | (aroonu_14_1h_lt_90) | (stochrsi_k_1h_gt_40))
            # 15m down move, 15m & 4h low
            & ((aroonu_14_15m_gt_60) | (rsi_3_15m_gt_25) | (aroonu_14_4h_gt_50))
            # 15m & 4h low, 1h up move
            & ((aroonu_14_15m_gt_60) | (rsi_3_1h_lt_70) | (aroonu_14_4h_gt_20))
            # 15m low, 1h up move, 1d downtrend
            & ((aroonu_14_15m_gt_60) | (rsi_3_1h_lt_70) | (roc_9_1d_lt_50))
            # 15m & 4h low, 1h up move
            & ((aroonu_14_15m_gt_60) | (rsi_3_1h_lt_80) | (aroonu_14_4h_gt_30))
            # 15m & 1d low, 1h down move
            & ((aroonu_14_15m_gt_60) | (rsi_3_1h_lt_85) | (aroonu_14_1d_gt_20))
            # 15m low, 1h & 4h still high
            & ((aroonu_14_15m_gt_60) | (stochrsi_k_1h_gt_30) | (stochrsi_k_4h_gt_40))
            # 15m low, 4h & 1d still high
            & ((aroonu_14_15m_gt_60) | (stochrsi_k_4h_gt_50) | (stochrsi_k_1d_gt_30))
            # 15m & 4h uptrend, 1d down move
            & ((aroonu_14_15m_lt_20) | (roc_9_4h_lt_5) | (rsi_3_1d_gt_60))
            # 15m & 1d uptrend, 1h down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_50) | (aroonu_14_1d_lt_50))
            # 15m uptrend & still high, 1h high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_40) | (stochrsi_k_1h_gt_10))
            # 15m & 1d uptrend, 1d low
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1d_gt_20) | (roc_9_1d_lt_10))
            # 15m uptrend, 15m & 1h still high
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_30))
            # 15m & 1d uptrend, 1d down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_75))
            # 15m uptrend, 1h down move, 4h low
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_40) | (aroonu_14_4h_gt_80))
            # 15m uptrend, 1h down move, 1d low
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_60) | (aroonu_14_1d_gt_20))
            # 15m & 1d uptrend, 1h down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_lt_75) | (roc_9_1d_lt_0))
            # 15m & 1d uptrend, 4h down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_4h_lt_75) | (aroonu_14_1d_lt_75))
            # 15m uptrend, 4h down move, 1d up move
            & ((aroonu_14_15m_lt_40) | (rsi_3_4h_lt_85) | (rsi_3_1d_lt_90))
            # 15m uptrend, 1h still high, 4h up move
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_50) | (rsi_3_4h_lt_90))
            # 15m uptrend, 1h still high, 4h still not low enough
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_60) | (stochrsi_k_4h_gt_70))
            # 15m uptrend, 1d down move & low
            & ((aroonu_14_15m_lt_50) | (rsi_3_1d_gt_20) | (aroonu_14_1d_gt_20))
            # 15m uptrend, 1d low & still high
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1d_gt_20) | (stochrsi_k_1d_gt_50))
            # 15m uptrend, 1h & 4h down move
            & ((aroonu_14_15m_lt_60) | (rsi_3_1h_gt_55) | (rsi_3_4h_gt_65))
            # 15m uptrend, 4h & 1d up move
            & ((aroonu_14_15m_lt_60) | (rsi_3_4h_lt_80) | (rsi_3_1d_lt_90))
            # 15m uptrend, 1h still high, 1d down move
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_1h_gt_50) | (rsi_3_1d_gt_65))
            # 15m uptrend, 1h down move, 1d low
            & ((aroonu_14_15m_lt_70) | (rsi_3_1h_gt_50) | (stochrsi_k_1d_gt_20))
            # 15m & 1d uptrend, 4h down move
            & ((aroonu_14_15m_lt_70) | (rsi_3_4h_gt_55) | (roc_9_1d_lt_20))
            # 15m uptrend, 1h still not high enough, 4h low
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_1h_gt_70) | (aroonu_14_4h_gt_50))
            # 15m uptrend, 4h high, 1d up move
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_4h_gt_10) | (rsi_3_1d_lt_90))
            # 15m & 1h & 4h uptrend
            & ((aroonu_14_15m_lt_80) | (aroonu_14_1h_lt_85) | (aroonu_14_4h_lt_80))
            # 15m uptrend, 4h & 1d low
            & ((aroonu_14_15m_lt_80) | (aroonu_14_4h_gt_30) | (aroonu_14_1d_gt_20))
            # 15m uptrend, 1h down move, 4h low
            & ((aroonu_14_15m_lt_80) | (rsi_3_1h_gt_50) | (aroonu_14_4h_gt_30))
            # 15m uptrend, 1h up move & still not low enough
            & ((aroonu_14_15m_lt_80) | (rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_90))
            # 15m uptrend, 1h up move, 4h low
            & ((aroonu_14_15m_lt_80) | (rsi_3_1h_lt_90) | (aroonu_14_4h_gt_50))
            # 15m uptrend & high, 1h up move
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_15m_gt_10) | (rsi_3_1h_lt_50))
            # 15m uptrend, 4h still high, 1d down move
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_4h_gt_40) | (rsi_3_1d_gt_40))
            # 15m uptrend, 4h still high, 1d low
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_4h_gt_50) | (aroonu_14_1d_gt_20))
            # 15m & 4h uptrend, 1d down move
            & ((aroonu_14_15m_lt_90) | (aroonu_14_4h_lt_60) | (rsi_3_1d_gt_60))
            # 15m uptrend, 1h up move & still high
            & ((aroonu_14_15m_lt_90) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_30))
            # 15m high, 1h uptrend & still high
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_80) | (stochrsi_k_1h_gt_60))
            # 15m high, 1h uptrend & still not low enough
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_85) | (stochrsi_k_1h_gt_70))
            # 15m high, 1h uptrend, 1d low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_90) | (aroonu_14_1d_gt_20))
            # 15m high, 4h low, 1d still high
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_4h_gt_80) | (stochrsi_k_1d_gt_40))
            # 15m high, 1h & 4h down move
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_65) | (rsi_3_4h_gt_60))
            # 15m high, 1h up move, 4h uptrend
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_lt_50) | (aroonu_14_4h_lt_80))
            # 15m high, 1h down move, 4h up move
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_lt_55) | (rsi_3_4h_lt_70))
            # 15m high, 1h up move, 1d down move
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_lt_80) | (rsi_3_1d_gt_30))
            # 15m high, 4h up move & still not low enough
            & ((stochrsi_k_15m_gt_10) | (rsi_3_4h_lt_70) | (stochrsi_k_4h_gt_80))
            # 15m high, 4h up move & low
            & ((stochrsi_k_15m_gt_10) | (rsi_3_4h_lt_90) | (aroonu_14_4h_gt_30))
            # 15m & 1h high, 1d up move
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_1h_gt_10) | (rsi_3_1d_lt_80))
            # 15m high, 1h still high, 4h low
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_1h_gt_60) | (aroonu_14_4h_gt_50))
            # 15m high, 1h still high, 1d oversold
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_1h_gt_60) | (roc_9_1d_gt_neg_10))
            # 15m low, 4h uptrend, 1d oversold
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_40) | (roc_9_1d_gt_neg_15))
            # 15m & 4h low, 4h uptrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m low, 1h up move & still high
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_40))
            # 15m low, 1h up move, 4h uptrend
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1h_lt_60) | (aroonu_14_4h_lt_80))
            # 15m low, 1h up move, 4h down move
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1h_lt_70) | (rsi_3_4h_lt_85))
            # 15m low, 4h down move, 1d up move
            & ((stochrsi_k_15m_gt_20) | (rsi_3_4h_lt_85) | (rsi_3_1d_lt_90))
            # 15m low, 4h & 1d up move
            & ((stochrsi_k_15m_gt_20) | (rsi_3_4h_lt_95) | (rsi_3_1d_lt_80))
            # 15m low, 1d still high & uptrend
            & ((stochrsi_k_15m_gt_20) | (stochrsi_k_1d_gt_60) | (roc_9_1d_lt_20))
            # 15m still high, 1h uptrend, 1d down move
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_1h_lt_100) | (rsi_3_1d_gt_20))
            # 15m still high, 4h uptrend, 1d low
            & ((stochrsi_k_15m_gt_30) | (roc_9_4h_lt_5) | (aroonu_14_1d_gt_20))
            # 15m still high, 4h & 1d up move
            & ((stochrsi_k_15m_gt_30) | (rsi_3_4h_lt_90) | (rsi_3_1d_lt_90))
            # 15m still high, 1h high, 4h still not low enough
            & ((stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_10) | (stochrsi_k_4h_gt_90))
            # 15m & 4h still high, 1h low
            & ((stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_60))
            # 15m still high, 1h up move, 1d low
            & ((stochrsi_k_15m_gt_40) | (rsi_3_1h_lt_90) | (stochrsi_k_1d_gt_20))
            # 1h down move, 1d uptrend & still high
            & ((rsi_3_1h_gt_40) | (aroonu_14_1d_lt_75) | (stochrsi_k_1d_gt_40))
            # 1h & 1d down move, 1h uptrend
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_lt_85) | (rsi_3_1d_gt_65))
            # 1h down move, 1h & 1d low
            & ((rsi_3_1h_gt_40) | (stochrsi_k_1h_gt_20) | (aroonu_14_1d_gt_20))
            # 1h & 1d down move, 4h still not low enough
            & ((rsi_3_1h_gt_40) | (stochrsi_k_4h_gt_80) | (rsi_3_1d_gt_65))
            # 1h down move, 4h low
            & ((rsi_3_1h_gt_45) | (aroonu_14_4h_gt_50))
            # 1h & 1d down move, 1d uptrend
            & ((rsi_3_1h_gt_45) | (rsi_3_1d_gt_65) | (roc_9_1d_lt_15))
            # 1h & 4h down move, 1d still not low enough
            & ((rsi_3_1h_gt_45) | (rsi_3_4h_gt_60) | (stochrsi_k_1d_gt_70))
            # 1h down move, 4h low, 1d uptrend
            & ((rsi_3_1h_gt_50) | (aroonu_14_4h_gt_20) | (roc_9_1d_lt_0))
            # 1h & 1d down move, 4h uptrend
            & ((rsi_3_1h_gt_50) | (roc_9_4h_lt_5) | (rsi_3_1d_gt_50))
            # 1h & 1d down move, 1h uptrend
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_100) | (rsi_3_1d_gt_60))
            # 1h & 4h down move, 1h uptrend
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_90) | (rsi_3_4h_gt_60))
            # 1h down move & uptrend, 4h still not low enough
            & ((rsi_3_1h_gt_55) | (aroonu_14_1h_lt_90) | (stochrsi_k_4h_gt_70))
            # 1h & 4h down move, 4h still not low enough
            & ((rsi_3_1h_gt_55) | (rsi_3_4h_lt_75) | (stochrsi_k_4h_gt_70))
            # 1h down move, 4h still high, 1d low
            & ((rsi_3_1h_gt_55) | (stochrsi_k_4h_gt_40) | (aroonu_14_1d_gt_20))
            # 1h down move, 1h & 4h uptrend
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_40))
            # 1h down move & uptrend, 1d low
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_85) | (stochrsi_k_1d_gt_20))
            # 1h down move, 4h low, 1d uptrend
            & ((rsi_3_1h_gt_60) | (aroonu_14_4h_gt_50) | (aroonu_14_1d_lt_80))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_gt_60) | (rsi_3_4h_gt_65) | (rsi_3_1d_gt_60))
            # 1h down move, 4h still high, 1d low
            & ((rsi_3_1h_gt_60) | (stochrsi_k_4h_gt_50) | (stochrsi_k_1d_gt_20))
            # 1h up move, 4h down move & uptrend
            & ((rsi_3_1h_lt_50) | (rsi_3_4h_gt_65) | (aroonu_14_4h_lt_90))
            # 1h & 4h up move, 1d down move
            & ((rsi_3_1h_lt_50) | (rsi_3_4h_lt_90) | (rsi_3_1d_gt_30))
            # 1h down move, 4h & 1d uptrend
            & ((rsi_3_1h_lt_55) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_lt_30))
            # 1h & 4h down move, 4h uptrend
            & ((rsi_3_1h_lt_55) | (rsi_3_4h_lt_75) | (aroonu_14_4h_lt_60))
            # 1h & 4h down move, 1h still not low enough
            & ((rsi_3_1h_lt_55) | (stochrsi_k_1h_gt_70) | (rsi_3_4h_lt_75))
            # 1h down move, 4h still not low enough, 1d oversold
            & ((rsi_3_1h_lt_55) | (stochrsi_k_4h_gt_80) | (roc_9_1d_gt_neg_15))
            # 1h up move, 4h uptrend, 1d low
            & ((rsi_3_1h_lt_60) | (roc_9_4h_lt_5) | (aroonu_14_1d_gt_50))
            # 1h up move, 4h down move & uptrend
            & ((rsi_3_1h_lt_60) | (rsi_3_4h_gt_60) | (roc_9_4h_lt_10))
            # 1h & 4h up move, 1d oversold
            & ((rsi_3_1h_lt_60) | (rsi_3_4h_lt_80) | (roc_9_1d_gt_neg_10))
            # 1h up move & still high, 4h low
            & ((rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_40) | (aroonu_14_4h_gt_70))
            # 1h up move & still high, 4h uptrend
            & ((rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_60) | (aroonu_14_4h_lt_90))
            # 1h up move, 1d low & still high
            & ((rsi_3_1h_lt_65) | (aroonu_14_1d_gt_20) | (stochrsi_k_1d_gt_50))
            # 1h up move, 4h uptrend, 1d down move
            & ((rsi_3_1h_lt_65) | (roc_9_4h_lt_5) | (rsi_3_1d_gt_40))
            # 1h & 4h up move, 4h still high
            & ((rsi_3_1h_lt_65) | (rsi_3_4h_lt_70) | (stochrsi_k_4h_gt_50))
            # 1h up move, 1d low & uptrend
            & ((rsi_3_1h_lt_70) | (aroonu_14_1d_gt_50) | (roc_9_1d_lt_0))
            # 1h & 4h up move, 1d low
            & ((rsi_3_1h_lt_70) | (rsi_3_4h_lt_70) | (aroonu_14_1d_gt_20))
            # 1h & 4h up move, 1d low
            & ((rsi_3_1h_lt_70) | (rsi_3_4h_lt_70) | (stochrsi_k_1d_gt_20))
            # 1h up move, 4h down move, 1d low
            & ((rsi_3_1h_lt_70) | (rsi_3_4h_lt_75) | (aroonu_14_1d_gt_50))
            # 1h up move, 4h uptrend & still not low enough
            & ((rsi_3_1h_lt_80) | (aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_70))
            # 1h & 4h up move, 4h uptrend
            & ((rsi_3_1h_lt_80) | (rsi_3_4h_lt_70) | (roc_9_4h_lt_5))
            # 1h up move, 1d low & uptrend
            & ((rsi_3_1h_lt_80) | (stochrsi_k_1d_gt_20) | (roc_9_1d_lt_0))
            # 1h up move, 4h low, 1d still not high enough
            & ((rsi_3_1h_lt_80) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_70))
            # 1h down move, 4h low
            & ((rsi_3_1h_lt_85) | (aroonu_14_4h_gt_10))
            # 1h & 1d down move, 4h uptrend
            & ((rsi_3_1h_lt_85) | (aroonu_14_4h_lt_70) | (rsi_3_1d_gt_60))
            # 1h & 1d down move, 1d low
            & ((rsi_3_1h_lt_85) | (rsi_3_1d_gt_60) | (aroonu_14_1d_gt_20))
            # 1h & 4h & 1d uptrend
            & ((aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_lt_75))
            # 1h & 4h uptrend, 1d down move
            & ((aroonu_14_1h_lt_100) | (aroonu_14_4h_lt_80) | (rsi_3_1d_gt_20))
            # 1h uptrend & still high, 1d still not high enough
            & ((aroonu_14_1h_lt_100) | (stochrsi_k_1h_gt_30) | (stochrsi_k_1d_gt_70))
            # 1h uptrend & still not low enough, 4h low
            & ((aroonu_14_1h_lt_100) | (stochrsi_k_1h_gt_75) | (aroonu_14_4h_gt_20))
            # 1h & 1d uptrend, 1h still not low enough
            & ((aroonu_14_1h_lt_100) | (stochrsi_k_1h_gt_90) | (aroonu_14_1d_lt_75))
            # 1h uptrend & high, 1d up move
            & ((aroonu_14_1h_lt_75) | (stochrsi_k_1h_gt_10) | (rsi_3_1d_lt_90))
            # 1h uptrend, 4h down move, 1d up move
            & ((aroonu_14_1h_lt_85) | (rsi_3_4h_gt_65) | (rsi_3_1d_lt_80))
            # 1h uptrend, 1d still not high enough & downtrend
            & ((aroonu_14_1h_lt_85) | (stochrsi_k_1d_gt_70) | (roc_9_1d_lt_40))
            # 1h & 1d uptrend, 1h still high
            & ((aroonu_14_1h_lt_85) | (stochrsi_k_1h_gt_50) | (aroonu_14_1d_lt_75))
            # 1h & 1d uptrend, 1d oversold
            & ((aroonu_14_1h_lt_90) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_25))
            # 1h & 1d low, 4h uptrend
            & ((stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_90) | (aroonu_14_1d_gt_20))
            # 1h still high, 1d down move & uptrend
            & ((stochrsi_k_1h_gt_30) | (rsi_3_1d_gt_65) | (roc_9_1d_lt_0))
            # 1h still high, 4h low, 1d up move
            & ((stochrsi_k_1h_gt_40) | (aroonu_14_4h_gt_80) | (rsi_3_1d_lt_90))
            # 1h still high, 1d down move & uptrend
            & ((stochrsi_k_1h_gt_60) | (rsi_3_1d_gt_60) | (roc_9_1d_lt_0))
            # 1h still high, 4h still not low enough, 1d down move
            & ((stochrsi_k_1h_gt_60) | (stochrsi_k_4h_gt_80) | (rsi_3_1d_gt_65))
            # 1h still not low enough, 4h down move & low
            & ((stochrsi_k_1h_gt_70) | (rsi_3_4h_gt_60) | (aroonu_14_4h_gt_30))
            # 1h & 1d still not low enough, 4h still high
            & ((stochrsi_k_1h_gt_70) | (stochrsi_k_4h_gt_60) | (stochrsi_k_1d_gt_70))
            # 1h still not low enough, 4h & 1d low
            & ((stochrsi_k_1h_gt_80) | (aroonu_14_4h_gt_70) | (aroonu_14_1d_gt_20))
            # 1h still not low enough, 4h still high, 1d down move
            & ((stochrsi_k_1h_gt_80) | (stochrsi_k_4h_gt_40) | (rsi_3_1d_gt_65))
            # 4h down move, 4h & 1d uptrend
            & ((rsi_3_4h_gt_35) | (aroonu_14_4h_lt_60) | (roc_9_1d_lt_0))
            # 4h down move, 4h & 1d still high
            & ((rsi_3_4h_gt_55) | (stochrsi_k_4h_gt_30) | (stochrsi_k_1d_gt_50))
            # 4h & 1d down move, 1d uptrend
            & ((rsi_3_4h_gt_60) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_50))
            # 4h & 1d down move, 4h uptrend
            & ((rsi_3_4h_gt_65) | (roc_9_4h_lt_5) | (rsi_3_1d_gt_40))
            # 4h down move & low, 1d uptrend
            & ((rsi_3_4h_lt_75) | (aroonu_14_4h_gt_50) | (aroonu_14_1d_lt_75))
            # 4h & 1d low, 1d uptrend
            & ((aroonu_14_4h_gt_30) | (aroonu_14_1d_gt_50) | (roc_9_1d_lt_10))
            # 4h low, 1d still high & uptrend
            & ((aroonu_14_4h_gt_70) | (stochrsi_k_1d_gt_50) | (roc_9_1d_lt_20))
            # 4h & 1d uptrend, 1d down move
            & ((aroonu_14_4h_lt_50) | (rsi_3_1d_gt_60) | (aroonu_14_1d_lt_75))
            # 4h uptrend & still high, 1d low
            & ((aroonu_14_4h_lt_50) | (stochrsi_k_4h_gt_30) | (aroonu_14_1d_gt_20))
            # 4h uptrend, 1d down move & low
            & ((aroonu_14_4h_lt_60) | (rsi_3_1d_gt_65) | (aroonu_14_1d_lt_75))
            # 4h uptrend & low, 1d still high
            & ((aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_60))
            # 4h uptrend & still high, 1d down move
            & ((aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_40) | (rsi_3_1d_gt_50))
            # 4h & 1d uptrend, 1d oversold
            & ((aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_10))
            # 4h still high, 1d up move & low
            & ((stochrsi_k_4h_gt_40) | (rsi_3_1d_lt_80) | (aroonu_14_1d_gt_20))
            # 4h still high & uptrend, 1d down move
            & ((stochrsi_k_4h_gt_70) | (roc_9_4h_lt_5) | (rsi_3_1d_gt_60))
            # 4h uptrend, 1d low & still high
            & ((roc_9_4h_lt_5) | (aroonu_14_1d_gt_20) | (stochrsi_k_1d_gt_40))
            # 1d aroond, 15m cci, 5m quad
            & ((aroond_14_1d > 10) | (cci_20_change_pct_15m < 0.0) | (quad_s93_max_12 > 70))
            # 1d stochrsik, 1d aroond, 1h rsi
            & ((stochrsi_k_1d < 65) | (aroond_14_1d < 70) | (rsi_3_change_pct_1h < 30))
            # 1d roc, 4h rsi, 4h mfi
            & ((roc_9_1d < 5) | (rsi_3_4h_gt_65) | (mfi_14_4h > 50))
          )

          # Logic
          short_entry_logic.append(
            # 1h still high and the 4h has not rolled over yet
            (rsi_14_1h > 55.0)
            & (aroonu_14_1h > 60.0)
            # but money is leaving on the 1h — the push is not being paid for
            & (cmf_20_1h < 0.0)
            & (mfi_14_1h < 50.0)
            # the 5m has started to break, without having fallen away already
            & (rsi_3 < 30.0)
            & (ema_12 < ema_26)
            & (roc_9_1h > -8.0)
            & (close > (ema_26 * 0.97))
          )
        # Condition #545 - Distribution / Failed Breakout (Short).
        # Shorts a rejected breakout / distribution top (close pushed above BB-upper then fading).
        # Profitable in bear markets (tops resolve down, 2022: 100% WR); the guards below reject the
        # two bull-market failure modes that squeeze a short: deep-crash dead-cat bounces and
        # strong-uptrend pullbacks. 2022 + 2021 both 100% WR / 0 loss after guards.
        if short_entry_condition_index == 545:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m & 1h up move, 1d uptrend
            ((rsi_3_lt_90) | (rsi_3_1h_lt_90) | (roc_9_1d_lt_30))
            # 5m up move, 15m still not low enough, 4h down move
            & ((rsi_3_lt_95) | (stochrsi_k_15m_gt_90) | (rsi_3_4h_gt_50))
            # 5m & 15m up move, 4h still not low enough
            & ((rsi_3_lt_97) | (rsi_3_15m_lt_95) | (stochrsi_k_4h_gt_80))
            # 5m still not low enough, 15m up move, 4h down move
            & ((stochrsi_k_gt_80) | (rsi_3_15m_lt_95) | (rsi_3_4h_gt_65))
            # 5m & 15m still not low enough, 1d low
            & ((stochrsi_k_gt_80) | (stochrsi_k_15m_gt_90) | (aroonu_14_1d_gt_20))
            # 15m up move, 4h uptrend, 1d down move
            & ((rsi_3_15m_lt_95) | (roc_9_4h_lt_5) | (rsi_3_1d_gt_30))
            # 15m & 4h up move, 4h uptrend
            & ((rsi_3_15m_lt_95) | (rsi_3_4h_lt_80) | (aroonu_14_4h_lt_20))
            # 15m up move & still not low enough, 4h uptrend
            & ((rsi_3_15m_lt_95) | (stochrsi_k_15m_gt_90) | (aroonu_14_4h_lt_20))
            # 15m up move, 1d uptrend & still high
            & ((rsi_3_15m_lt_97) | (aroonu_14_1d_lt_60) | (stochrsi_k_1d_gt_40))
            # 15m up move, 4h low & still high
            & ((rsi_3_15m_lt_97) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_50))
            # 15m up move, 4h uptrend & still not high enough
            & ((rsi_3_15m_lt_97) | (aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_70))
            # 15m up move, 1h up move
            & ((rsi_3_15m_lt_97) | (rsi_3_1h > 90.0))
            # 15m up move, 4h & 1d down move
            & ((rsi_3_15m_lt_97) | (rsi_3_4h_gt_60) | (rsi_3_1d_gt_20))
            # 15m still high, 1h still not low enough, 4h down move
            & ((stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_80) | (rsi_3_4h_lt_75))
            # 15m still not low enough, 4h down move & uptrend
            & ((stochrsi_k_15m_gt_70) | (rsi_3_4h_gt_50) | (aroonu_14_4h_lt_60))
            # 15m still not high enough, 4h up move & low
            & ((stochrsi_k_15m_gt_70) | (rsi_3_4h_lt_80) | (aroonu_14_4h_gt_20))
            # 15m still not low enough, 1d uptrend & oversold
            & ((stochrsi_k_15m_gt_90) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_30))
            # 15m still not low enough, 1h & 4h up move
            & ((stochrsi_k_15m_gt_90) | (rsi_3_1h_lt_90) | (rsi_3_4h_lt_90))
            # 1h & 4h & 1d down move
            & ((rsi_3_1h_lt_85) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_20))
            # 1h down move, 4h up move & low
            & ((rsi_3_1h_lt_85) | (rsi_3_4h_lt_70) | (stochrsi_k_4h_gt_20))
            # 1h & 4h up move, 1d uptrend
            & ((rsi_3_1h_lt_95) | (rsi_3_4h_lt_60) | (aroonu_14_1d_lt_80))
            # 1h & 4h up move, 1d high
            & ((rsi_3_1h_lt_95) | (rsi_3_4h_lt_80) | (stochrsi_k_1d_gt_10))
            # 1h still not low enough, 4h up move, 1d uptrend
            & ((stochrsi_k_1h_gt_90) | (rsi_3_4h_lt_70) | (aroonu_14_1d_lt_80))
            # 1h & 4h still not low enough, 1d low
            & ((stochrsi_k_1h_gt_90) | (stochrsi_k_4h_gt_80) | (stochrsi_k_1d_gt_20))
            # 4h down move, 1d still high & uptrend
            & ((rsi_3_4h_gt_65) | (roc_9_1d_lt_0) | (stochrsi_k_1d_gt_30))
            # 4h up move & still high, 1d high
            & ((rsi_3_4h_lt_60) | (stochrsi_k_4h_gt_40) | (stochrsi_k_1d_gt_10))
            # 4h up move & still not low enough, 1d down move
            & ((rsi_3_4h_lt_70) | (stochrsi_k_4h_gt_70) | (rsi_3_1d_gt_20))
            # 4h low, 1d up move & oversold
            & ((aroonu_14_4h_gt_10) | (roc_9_1d_gt_neg_10) | (rsi_3_1d_lt_35))
            # 4h low, 4h & 1d uptrend
            & ((aroonu_14_4h_gt_10) | (roc_9_4h_lt_5) | (aroonu_14_1d_lt_60))
            # 4h & 1d uptrend, 4h oversold
            & ((aroonu_14_4h_lt_20) | (roc_9_4h_gt_neg_10) | (roc_9_1d_lt_30))
            # 4h & 1d uptrend, 1d down move
            & ((aroonu_14_4h_lt_20) | (rsi_3_1d_gt_30) | (roc_9_1d_lt_0))
            # 4h uptrend & still not low enough, 1d low
            & ((aroonu_14_4h_lt_50) | (stochrsi_k_4h_gt_80) | (stochrsi_k_1d_gt_20))
            # 4h still not low enough, 1d low & uptrend
            & ((stochrsi_k_4h_gt_80) | (aroonu_14_1d_gt_50) | (roc_9_1d_lt_20))
          )

          # Logic
          short_entry_logic.append(
            # room to fall — a wide band on both timeframes
            (bbb_20_2_0 > 4.0)
            & (bbb_20_2_0_1h > 8.0)
            # price pushed clear of the upper band, short-term overbought
            & (close > (bbu_20_2_0 * 1.002))
            & (rsi_14 > 75.0)
            & (stochrsi_k_1h > 30.0)
            # 1h at the top of its range
            & (willr_14_1h > -20.0)
            & (aroonu_14_1h > 70.0)
            # the higher timeframes do not confirm the push — this is distribution
            & (rsi_14_4h < 60.0)
            & (cci_20_4h < 120.0)
            & (obv_change_pct < 0.0)
          )

        # Condition #546 - BB Upper Rejection + Multi-TF Overbought Stack (Short).
        # Shorts a hard rejection off BB-upper (bbp > 0.92, roc_2 < 0) with a multi-TF overbought
        # stack. The doc overbought-stack guard plus per-loss CCI/momentum guards reject blow-off
        # tops that keep ripping (high-CCI squeeze). 2022 + 2021: 100% WR / 0 loss.
        if short_entry_condition_index == 546:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 15m up move, 4h low, 1d uptrend
            ((rsi_3_15m_lt_95) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m up move, 4h down move & uptrend
            & ((rsi_3_15m_lt_95) | (aroonu_14_4h_lt_20) | (rsi_3_4h_gt_55))
            # 15m up move, 4h low
            & ((rsi_3_15m_lt_95) | (aroonu_14_4h_lt_30))
            # 15m up move, 4h down move, 1d still high
            & ((rsi_3_15m_lt_95) | (rsi_3_4h_gt_55) | (stochrsi_k_1d_gt_60))
            # 15m up move, 1h & 4h uptrend
            & ((rsi_3_15m_lt_97) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_20))
            # 15m up move, 1h & 4h down move
            & ((rsi_3_15m_lt_97) | (rsi_3_1h_lt_85) | (rsi_3_4h_lt_75))
            # 15m & 1h & 4h up move
            & ((rsi_3_15m_lt_97) | (rsi_3_1h_lt_95) | (rsi_3_4h_lt_60))
            # 15m & 4h up move, 1d uptrend
            & ((rsi_3_15m_lt_97) | (rsi_3_4h_lt_70) | (aroonu_14_1d_lt_40))
            # 15m still high, 4h down move
            & ((stochrsi_k_15m_gt_60) | (rsi_3_4h_gt_60))
            # 15m still not low enough, 4h uptrend, 1d down move
            & ((stochrsi_k_15m_gt_70) | (aroonu_14_4h_lt_20) | (rsi_3_1d_gt_20))
            # 15m still not low enough, 4h down move & uptrend
            & ((stochrsi_k_15m_gt_80) | (aroonu_14_4h_lt_40) | (rsi_3_4h_gt_55))
            # 15m still not low enough, 1h & 4h up move
            & ((stochrsi_k_15m_gt_90) | (rsi_3_1h_lt_90) | (rsi_3_4h_lt_70))
            # 1h down move, 4h up move
            & ((rsi_3_1h_gt_65) | (rsi_3_4h_lt_50))
            # 1h up move, 4h uptrend & low
            & ((rsi_3_1h_lt_80) | (aroonu_14_4h_lt_30) | (stochrsi_k_4h_gt_20))
            # 1h down move, 1d uptrend & still high
            & ((rsi_3_1h_lt_85) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_gt_40))
            # 1h up move, 4h down move & high
            & ((rsi_3_1h_lt_90) | (rsi_3_4h_gt_50) | (stochrsi_k_4h_gt_10))
            # 1h up move, 4h down move, 1d still high
            & ((rsi_3_1h_lt_90) | (rsi_3_4h_gt_60) | (stochrsi_k_1d_gt_40))
            # 1h up move & still not low enough, 1d still high
            & ((rsi_3_1h_lt_90) | (stochrsi_k_1h_gt_90) | (stochrsi_k_1d_gt_60))
            # 1h up move, 1h & 4h uptrend
            & ((rsi_3_1h_lt_95) | (aroonu_14_1h_lt_90) | (aroonu_14_4h_lt_30))
            # 1h & 4h uptrend, 1d oversold
            & ((aroonu_14_1h_lt_80) | (aroonu_14_4h_lt_30) | (roc_9_1d_gt_neg_10))
            # 1h still not low enough, 4h up move, 1d down move
            & ((stochrsi_k_1h_gt_80) | (rsi_3_4h_lt_50) | (rsi_3_1d_gt_40))
            # 1h still not low enough, 1d low
            & ((stochrsi_k_1h_gt_90) | (aroonu_14_1d_gt_20) | (stochrsi_k_1d_gt_20))
            # 4h & 1d down move, 1d still not low enough
            & ((rsi_3_4h_gt_50) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_gt_70))
            # 4h down move & still high, 1d downtrend
            & ((rsi_3_4h_gt_65) | (stochrsi_k_4h_gt_30) | (roc_9_1d_lt_40))
            # 4h up move, 4h & 1d uptrend
            & ((rsi_3_4h_lt_50) | (aroonu_14_4h_lt_50) | (roc_9_1d_lt_10))
            # 4h & 1d low
            & ((aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_20))
            # 4h & 1d low, 1d uptrend
            & ((aroonu_14_4h_gt_30) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_gt_20))
            # 4h & 1d uptrend, 1d down move
            & ((aroonu_14_4h_lt_20) | (aroonu_14_1d_lt_60) | (rsi_3_1d_gt_30))
          )

          # Logic
          short_entry_logic.append(
            # the 4h has already turned down — selling a top into a rising 4h is the squeeze
            (roc_9_4h < 0.0)
            # rejected at the top of a wide band, right under the 48-candle high
            & (bbp_20_2_0 > 0.92)
            & (bbb_20_2_0 > 4.0)
            & (close > (close_max_48 * 0.98))
            & (roc_2 < 0.0)
            # overbought on 5m and 1h at once
            & (stochrsi_k > 85.0)
            & (rsi_14 > 68.0)
            & (stochrsi_k_1h > 70.0)
            & (willr_14_1h > -15.0)
            # and the push is not being paid for
            & (obv_change_pct < 0.0)
          )

        # Condition #548 - Market-order bubble on a 15m trend pullback (Short, experimental).
        if short_entry_condition_index == 548:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m up move, 1d low & high
            ((rsi_3_lt_90) | (aroonu_14_1d_gt_20) | (stochrsi_k_1d_gt_10))
            # 5m & 1h up move, 1d oversold
            & ((rsi_3_lt_90) | (rsi_3_1h_lt_50) | (roc_9_1d_gt_neg_25))
            # 5m low, 15m up move, 1d uptrend
            & ((aroonu_14_gt_75) | (rsi_3_15m_lt_60) | (aroonu_14_1d_lt_30))
            # 5m low, 15m up move, 1h still high
            & ((aroonu_14_gt_75) | (rsi_3_15m_lt_60) | (stochrsi_k_1h_gt_40))
            # 5m low, 1h down move, 4h still not low enough
            & ((aroonu_14_gt_75) | (rsi_3_1h_gt_50) | (stochrsi_k_4h_gt_70))
            # 5m low, 4h up move, 1d high
            & ((aroonu_14_gt_75) | (rsi_3_4h_lt_60) | (stochrsi_k_1d_gt_10))
            # 5m still not low enough, 15m low, 1d uptrend
            & ((stochrsi_k_gt_80) | (aroonu_14_15m_gt_20) | (aroonu_14_1d_lt_40))
            # 5m still not low enough, 15m up move, 1h down move
            & ((stochrsi_k_gt_80) | (rsi_3_15m_lt_70) | (rsi_3_1h_gt_45))
            # 5m still not low enough, 4h down move, 1d uptrend
            & ((stochrsi_k_gt_80) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_30))
            # 5m still not low enough, 4h still high, 1d low
            & ((stochrsi_k_gt_80) | (stochrsi_k_4h_gt_40) | (stochrsi_k_1d_gt_20))
            # 15m down move & low, 1h uptrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_60))
            # 15m down move, 4h uptrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_4h_lt_30))
            # 15m & 1h down move, 15m uptrend
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_80) | (rsi_3_1h_gt_40))
            # 15m down move, 1h up move & low
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_gt_40) | (rsi_3_1h_lt_50))
            # 15m & 4h down move
            & ((rsi_3_15m_gt_40) | (rsi_3_4h_gt_40))
            # 15m down move, 15m low, 1h oversold
            & ((rsi_3_15m_gt_45) | (aroonu_14_15m_gt_40) | (stochrsi_k_1h_gt_50))
            # 15m & 1h down move, 15m low
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_gt_20) | (rsi_3_1h_lt_55))
            # 15m down move, 15m & 1d low
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_gt_50) | (aroonu_14_1d_gt_20))
            # 15m down move & uptrend, 4h low
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_50) | (stochrsi_k_4h_gt_20))
            # 15m down move & uptrend, 4h still high
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_75) | (stochrsi_k_4h_gt_40))
            # 15m down move, 1h & 1d low
            & ((rsi_3_15m_gt_50) | (aroonu_14_1h_gt_30) | (aroonu_14_1d_gt_20))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_50) | (stochrsi_k_15m_gt_60) | (rsi_3_4h_gt_45))
            # 15m & 1h down move, 1d uptrend
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_lt_55) | (aroonu_14_1d_lt_30))
            # 15m up move, 4h down move, 1d uptrend
            & ((rsi_3_15m_lt_50) | (rsi_3_4h_gt_50) | (roc_9_1d_lt_0))
            # 15m up move, 4h low, 1d uptrend
            & ((rsi_3_15m_lt_50) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_40))
            # 15m up move & low, 1h uptrend
            & ((rsi_3_15m_lt_60) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_60))
            # 15m up move, 1h & 1d down move
            & ((rsi_3_15m_lt_60) | (rsi_3_1h_gt_50) | (rsi_3_1d_gt_15))
            # 15m up move & low, 1h uptrend
            & ((rsi_3_15m_lt_70) | (aroonu_14_15m_gt_40) | (aroonu_14_1h_lt_40))
            # 15m up move, 15m & 1h low
            & ((rsi_3_15m_lt_70) | (aroonu_14_15m_gt_50) | (aroonu_14_1h_gt_20))
            # 15m up move, 4h uptrend & still not low enough
            & ((rsi_3_15m_lt_70) | (aroonu_14_4h_lt_30) | (stochrsi_k_4h_gt_70))
            # 15m & 4h up move, 1h down move
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_gt_40) | (rsi_3_4h_lt_70))
            # 15m up move, 1h down move, 4h still high
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_gt_65) | (stochrsi_k_4h_gt_40))
            # 15m & 1h up move, 4h down move
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_lt_50) | (rsi_3_4h_gt_20))
            # 15m & 1h up move, 1h still high
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_30))
            # 15m & 1h overbought, 1h high
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_lt_80) | (aroonu_14_1h_lt_30))
            # 15m up move, 4h still high, 1d oversold
            & ((rsi_3_15m_lt_70) | (stochrsi_k_4h_gt_40) | (roc_9_1d_gt_neg_30))
            # 15m up move, 1h up move, 1h high
            & ((rsi_3_15m_lt_75) | (rsi_3_1h_lt_70) | (aroonu_14_1h_lt_30))
            # 15m up move, 15m & 4h uptrend
            & ((rsi_3_15m_lt_80) | (aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_20))
            # 15m up move & uptrend, 4h down move
            & ((rsi_3_15m_lt_80) | (aroonu_14_15m_lt_25) | (rsi_3_4h_gt_40))
            # 15m up move & uptrend, 1h still high
            & ((rsi_3_15m_lt_80) | (aroonu_14_15m_lt_75) | (stochrsi_k_1h_gt_30))
            # 15m up move, 1h low, 1d down move
            & ((rsi_3_15m_lt_80) | (aroonu_14_1h_gt_10) | (rsi_3_1d_gt_20))
            # 15m & 1h up move, 1h uptrend
            & ((rsi_3_15m_lt_80) | (aroonu_14_1h_lt_20) | (rsi_3_1h_lt_70))
            # 15m up move, 1d not rising hard
            & ((rsi_3_15m_lt_80) | (roc_9_1d_lt_0))
            # 15m & 1d down move, 4h still high
            & ((rsi_3_15m_lt_85) | (stochrsi_k_4h_gt_30) | (rsi_3_1d_gt_25))
            # 15m up move, 4h & 1d low
            & ((rsi_3_15m_lt_90) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 15m up move, 1h still high, 1d low
            & ((rsi_3_15m_lt_90) | (stochrsi_k_1h_gt_40) | (aroonu_14_1d_gt_0))
            # 15m low, 1h high & 4h overbought
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_70) | (stochrsi_k_4h_lt_70))
            # 15m & 4h low, 1h uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_gt_0))
            # 15m low, 1h up move, 4h still high
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_50) | (stochrsi_k_4h_gt_60))
            # 15m low & still high, 4h down move
            & ((aroonu_14_15m_gt_30) | (stochrsi_k_15m_gt_60) | (rsi_3_4h_gt_50))
            # 15m low, 4h uptrend, 1d down move
            & ((aroonu_14_15m_gt_50) | (aroonu_14_4h_lt_20) | (rsi_3_1d_gt_10))
            # 15m low, 1h down move & still high
            & ((aroonu_14_15m_gt_50) | (rsi_3_1h_gt_30) | (stochrsi_k_1h_gt_30))
            # 15m low, 4h up move & uptrend
            & ((aroonu_14_15m_gt_50) | (rsi_3_4h_lt_40) | (aroonu_14_4h_lt_20))
            # 15m low, 1h up move & uptrend
            & ((aroonu_14_15m_gt_60) | (rsi_3_1h_lt_50) | (aroonu_14_1h_lt_50))
            # 15m uptrend, 1h still high, 4h low
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_1h_gt_40) | (aroonu_14_4h_gt_0))
            # 15m high then oversold, 1d low
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_15m_gt_60) | (rsi_3_1d_gt_5))
            # 15m & 1h uptrend, 1d high
            & ((aroonu_14_15m_lt_75) | (aroonu_14_1h_lt_20) | (stochrsi_k_1d_gt_10))
            # 15m & 4h uptrend, 15m still high
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_gt_60) | (aroonu_14_4h_lt_20))
            # 15m up move & uptrend, 4h down move
            & ((aroonu_14_15m_lt_80) | (rsi_3_15m_lt_70) | (rsi_3_4h_gt_35))
            # 15m still high, 1d down move & low
            & ((stochrsi_k_15m_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1d_gt_30))
            # 15m still high, 1h uptrend, 1d down move
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_1h_lt_60) | (rsi_3_1d_gt_15))
            # 15m still not low enough, 1h uptrend, 4h down move
            & ((stochrsi_k_15m_gt_70) | (aroonu_14_1h_lt_60) | (rsi_3_4h_gt_40))
            # 15m still not low enough, 1h & 4h up move
            & ((stochrsi_k_15m_gt_70) | (rsi_3_1h_lt_60) | (rsi_3_4h_lt_50))
            # 15m still not low enough, 1h up move, 1d low
            & ((stochrsi_k_15m_gt_80) | (rsi_3_1h_lt_70) | (aroonu_14_1d_gt_20))
            # 15m still not low enough, 1h low, 1d down move
            & ((stochrsi_k_15m_gt_90) | (stochrsi_k_1h_gt_20) | (rsi_3_1d_gt_10))
            # 15m & 4h overbought, 1h oversold
            & ((stochrsi_k_15m_lt_60) | (rsi_3_1h_gt_40) | (rsi_3_4h_lt_60))
            # 1h & 4h down move, 1d low
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_50) | (stochrsi_k_1d_gt_20))
            # 1h down move & low, 4h up move
            & ((rsi_3_1h_gt_40) | (aroonu_14_1h_gt_10) | (rsi_3_4h_lt_40))
            # 1h down move, 1h high, 4h down move
            & ((rsi_3_1h_gt_45) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_25))
            # 1h down move & low, 1d up move
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_gt_30) | (rsi_3_1d_lt_35))
            # 1h down move, 4h & 1d low
            & ((rsi_3_1h_gt_60) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_20))
            # 1h down move, 1h & 4h still high
            & ((rsi_3_1h_gt_65) | (stochrsi_k_1h_gt_60) | (stochrsi_k_4h_gt_40))
            # 1h up move, 1h & 4h uptrend
            & ((rsi_3_1h_lt_50) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_20))
            # 1h up move & still high, 1d low
            & ((rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_50) | (aroonu_14_1d_gt_10))
            # 1h up move & uptrend, 4h still high
            & ((rsi_3_1h_lt_60) | (aroonu_14_1h_lt_40) | (stochrsi_k_4h_gt_50))
            # 1h up move, 4h low, 1d high
            & ((rsi_3_1h_lt_60) | (aroonu_14_4h_gt_0) | (stochrsi_k_1d_gt_10))
            # 1h & 4h up move, 1h uptrend
            & ((rsi_3_1h_lt_70) | (aroonu_14_1h_lt_40) | (rsi_3_4h_lt_60))
            # 1h up move, 4h down move & still high
            & ((rsi_3_1h_lt_70) | (rsi_3_4h_gt_30) | (stochrsi_k_4h_gt_60))
            # 1h & 4h overbought, 1d low
            & ((rsi_3_1h_lt_70) | (stochrsi_k_4h_lt_80) | (rsi_3_1d_gt_15))
            # 1h up move, 1h & 4h low
            & ((rsi_3_1h_lt_80) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_10))
            # 1h overbought, 4h oversold, 1d low
            & ((rsi_3_1h_lt_85) | (stochrsi_k_4h_gt_40) | (aroonu_14_1d_gt_10))
            # 1h low, 4h up move & uptrend
            & ((aroonu_14_1h_gt_20) | (rsi_3_4h_lt_40) | (aroonu_14_4h_lt_30))
            # 1h low, 4h still high, 1d high
            & ((aroonu_14_1h_gt_20) | (stochrsi_k_4h_gt_30) | (stochrsi_k_1d_gt_10))
            # 1h uptrend, 4h & 1d still high
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_50) | (stochrsi_k_1d_gt_30))
            # 1h & 1d uptrend, 4h still high
            & ((aroonu_14_1h_lt_30) | (stochrsi_k_4h_gt_50) | (aroonu_14_1d_lt_30))
            # 1h uptrend, 4h down move
            & ((aroonu_14_1h_lt_60) | (rsi_3_4h_gt_20))
            # 1h uptrend, 4h down move, 1d oversold
            & ((aroonu_14_1h_lt_60) | (rsi_3_4h_gt_50) | (roc_9_1d_gt_neg_20))
            # 1h uptrend & still high, 1d oversold
            & ((aroonu_14_1h_lt_70) | (stochrsi_k_1h_gt_50) | (roc_9_1d_gt_neg_30))
            # 1h high then oversold, 4h oversold
            & ((aroonu_14_1h_lt_70) | (stochrsi_k_1h_gt_50) | (stochrsi_k_4h_gt_60))
            # 1h uptrend, 1d down move
            & ((aroonu_14_1h_lt_75) | (rsi_3_1d_gt_25))
            # 1h still high, 1d down move & low
            & ((stochrsi_k_1h_gt_30) | (rsi_3_1d_gt_20) | (aroonu_14_1d_gt_0))
            # 1h still high, 4h down move, 1d uptrend
            & ((stochrsi_k_1h_gt_40) | (rsi_3_4h_gt_50) | (aroonu_14_1d_lt_30))
            # 1h still high, 4h low, 1d oversold
            & ((stochrsi_k_1h_gt_40) | (stochrsi_k_4h_gt_20) | (roc_9_1d_gt_neg_20))
            # 1h still high, 4h up move, 1d low
            & ((stochrsi_k_1h_gt_50) | (rsi_3_4h_lt_40) | (aroonu_14_1d_gt_0))
            # 1h still high, 4h up move, 1d high
            & ((stochrsi_k_1h_gt_60) | (rsi_3_4h_lt_50) | (stochrsi_k_1d_gt_10))
            # 4h up move & still high
            & ((rsi_3_4h_lt_70) | (stochrsi_k_4h_gt_60))
            # 4h & 1d uptrend, 1d high
            & ((aroonu_14_4h_lt_20) | (aroonu_14_1d_lt_30) | (stochrsi_k_1d_gt_10))
            # 4h & 1d low, 1d down move
            & ((stochrsi_k_4h_gt_20) | (rsi_3_1d_gt_30) | (aroonu_14_1d_gt_10))
          )

          # Logic
          short_entry_logic.append(
            # the 1d has rolled over — a 15m bounce inside a rising daily runs the short over
            (stochrsi_k_1d < 50.0)
            # the 1h bounce has not gone far — a recovered 1h is what runs the short over
            & (stochrsi_k_1h < 80.0)
            # neither the 4h nor the 1d is making new highs
            & (aroonu_14_4h < 50.0)
            & (aroonu_14_1d < 50.0)
            # 15m in a downtrend, price back at the 50 EMA but still below the 200
            & (ema_50_15m < ema_200_15m)
            & (close >= (ema_50_15m * 0.998))
            & (close < ema_200_15m)
            # a market-order bubble, and the sellers are the ones making it
            & (volume > large_bubble_thr)
            & (cvd_sell_vol > cvd_buy_vol)
          )

        # Condition #561 - Downtrend Pullback / Continuation mode (Short). Mirror of code-64.
        if short_entry_condition_index == 561:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(
            # 5m up move, 15m low, 1h uptrend
            ((rsi_3_lt_46) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_20))
            # 5m up move, 15m still high, 4h uptrend
            & ((rsi_3_lt_50) | (stochrsi_k_15m_gt_50) | (aroonu_14_4h_lt_20))
            # 5m & 15m low, 1h up move
            & ((aroonu_14_gt_75) | (aroonu_14_15m_gt_20) | (rsi_3_1h_lt_50))
            # 5m & 15m low, 1h high
            & ((aroonu_14_gt_75) | (aroonu_14_15m_gt_20) | (stochrsi_k_1h_gt_10))
            # 5m & 15m low, 4h still high
            & ((aroonu_14_gt_75) | (aroonu_14_15m_gt_20) | (stochrsi_k_4h_gt_30))
            # 5m & 1h low, 4h uptrend
            & ((aroonu_14_gt_75) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_30))
            # 5m low, 15m still not low enough, 1d uptrend
            & ((aroonu_14_gt_75) | (stochrsi_k_15m_gt_80) | (aroonu_14_1d_lt_30))
            # 5m low & still not low enough, 1d uptrend
            & ((aroonu_14_gt_75) | (stochrsi_k_gt_80) | (aroonu_14_1d_lt_40))
            # 5m still not low enough, 15m low, 4h uptrend
            & ((stochrsi_k_gt_80) | (aroonu_14_15m_gt_20) | (aroonu_14_4h_lt_50))
            # 5m still not low enough, 15m & 4h low
            & ((stochrsi_k_gt_80) | (aroonu_14_15m_gt_20) | (stochrsi_k_4h_gt_20))
            # 5m still not low enough, 15m up move, 1d oversold
            & ((stochrsi_k_gt_80) | (rsi_3_15m_lt_70) | (roc_9_1d_gt_neg_10))
            # 5m still not low enough, 15m down move, 4h uptrend
            & ((stochrsi_k_gt_80) | (rsi_3_15m_lt_75) | (aroonu_14_4h_lt_20))
            # 5m still not low enough, 1h down move, 1d oversold
            & ((stochrsi_k_gt_80) | (rsi_3_1h_gt_40) | (roc_9_1d_gt_neg_25))
            # 5m still not low enough, 4h high, 1d uptrend
            & ((stochrsi_k_gt_80) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_lt_40))
            # 15m up move, 1h uptrend, 4h oversold
            & ((rsi_3_15m_lt_70) | (aroonu_14_1h_lt_30) | (roc_9_4h_gt_neg_15))
            # 15m up move, 1h uptrend, 4h low
            & ((rsi_3_15m_lt_70) | (aroonu_14_1h_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m up move, 1h down move & uptrend
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_gt_40) | (aroonu_14_1h_lt_20))
            # 15m up move & still not high enough, 1h low
            & ((rsi_3_15m_lt_70) | (stochrsi_k_15m_gt_70) | (stochrsi_k_1h_gt_20))
            # 15m up move, 1h still high, 4h high
            & ((rsi_3_15m_lt_70) | (stochrsi_k_1h_gt_30) | (stochrsi_k_4h_gt_10))
            # 15m down move & low, 1h up move
            & ((rsi_3_15m_lt_75) | (aroonu_14_15m_gt_20) | (rsi_3_1h_lt_50))
            # 15m down move & low, 4h still high
            & ((rsi_3_15m_lt_75) | (aroonu_14_15m_gt_20) | (stochrsi_k_4h_gt_40))
            # 15m down move, 1h & 1d low
            & ((rsi_3_15m_lt_75) | (stochrsi_k_1h_gt_20) | (stochrsi_k_1d_gt_20))
            # 15m down move, 4h still high, 1d low
            & ((rsi_3_15m_lt_75) | (stochrsi_k_4h_gt_30) | (aroonu_14_1d_gt_20))
            # 15m & 1h low, 4h uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_20))
            # 15m & 1h low, 4h up move
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_10) | (rsi_3_4h_lt_40))
            # 15m low, 1h & 4h uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_50))
            # 15m & 1d low, 4h uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_4h_lt_20) | (aroonu_14_1d_gt_10))
            # 15m low, 4h oversold, 1d down move
            & ((aroonu_14_15m_gt_20) | (roc_9_4h_gt_neg_20) | (rsi_3_1d_gt_15))
            # 15m low, 1h up move, 4h high
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_60) | (stochrsi_k_4h_gt_10))
            # 15m & 1h low, 15m still high
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_60) | (aroonu_14_1h_gt_10))
            # 15m low & still not low enough, 1h oversold
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_70) | (roc_9_1h_gt_neg_10))
            # 15m low & still not low enough, 4h oversold
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_80) | (roc_9_4h_gt_neg_10))
            # 15m low & still not low enough, 4h high
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_90) | (stochrsi_k_4h_gt_10))
            # 15m low, 1h high, 1d oversold
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_1h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m low, 4h high, 1d uptrend
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_lt_50))
            # 15m low, 4h & 1d uptrend
            & ((aroonu_14_15m_gt_50) | (aroonu_14_4h_lt_20) | (aroonu_14_1d_lt_30))
            # 15m low, 4h high, 1d uptrend
            & ((aroonu_14_15m_gt_50) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m & 1d low, 4h high
            & ((aroonu_14_15m_gt_60) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_gt_20))
            # 15m uptrend, 1h up move & low
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_20))
            # 15m uptrend, 4h up move, 1d high
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_lt_40) | (stochrsi_k_1d_gt_10))
            # 15m uptrend & still high, 4h low
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_60) | (aroonu_14_4h_gt_20))
            # 15m & 4h uptrend, 1h still high
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_1h_gt_40) | (aroonu_14_4h_lt_30))
            # 15m uptrend, 1d low & high
            & ((aroonu_14_15m_lt_75) | (aroonu_14_1d_gt_20) | (stochrsi_k_1d_gt_10))
            # 15m uptrend, 1h low, 1d down move
            & ((aroonu_14_15m_lt_75) | (aroonu_14_1h_gt_10) | (rsi_3_1d_gt_5))
            # 15m uptrend, 1h up move & low
            & ((aroonu_14_15m_lt_75) | (rsi_3_1h_lt_70) | (aroonu_14_1h_gt_10))
            # 15m uptrend, 1h still high, 1d down move
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_1h_gt_50) | (rsi_3_1d_gt_30))
            # 15m still not low enough, 1h uptrend, 1d high
            & ((stochrsi_k_15m_gt_80) | (aroonu_14_1h_lt_30) | (stochrsi_k_1d_gt_10))
            # 15m still not low enough, 1h up move, 1d uptrend
            & ((stochrsi_k_15m_gt_80) | (rsi_3_1h_lt_60) | (aroonu_14_1d_lt_30))
            # 15m still not low enough, 1h still high, 4h high
            & ((stochrsi_k_15m_gt_80) | (stochrsi_k_1h_gt_60) | (stochrsi_k_4h_gt_10))
            # 15m still not low enough, 1h up move, 4h uptrend
            & ((stochrsi_k_15m_gt_90) | (rsi_3_1h_lt_40) | (aroonu_14_4h_lt_40))
            # 1h down move, 4h low, 1d oversold
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_gt_20) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 1d oversold
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_30))
            # 1h up move & uptrend, 1d low
            & ((rsi_3_1h_lt_50) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_gt_30))
            # 1h & 4h up move, 4h low
            & ((rsi_3_1h_lt_50) | (rsi_3_4h_lt_40) | (aroonu_14_4h_gt_20))
            # 1h & 4h down move, 4h low
            & ((rsi_3_1h_lt_55) | (rsi_3_4h_gt_15) | (aroonu_14_4h_gt_10))
            # 1h up move & still high, 4h low
            & ((rsi_3_1h_lt_55) | (stochrsi_k_1h_gt_60) | (aroonu_14_4h_gt_30))
            # 1h up move, 1d low & high
            & ((rsi_3_1h_lt_60) | (aroonu_14_1d_gt_10) | (stochrsi_k_1d_gt_10))
            # 1h up move, 4h low
            & ((rsi_3_1h_lt_60) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_20))
            # 1h up move, 4h high, 1d uptrend
            & ((rsi_3_1h_lt_60) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_lt_50))
            # 1h & 4h & 1d low
            & ((aroonu_14_1h_gt_10) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_10))
            # 1h low, 1h & 1d high
            & ((aroonu_14_1h_gt_20) | (stochrsi_k_1h_gt_10) | (stochrsi_k_1d_gt_10))
            # 1h uptrend, 4h oversold
            & ((aroonu_14_1h_lt_30) | (roc_9_4h_gt_neg_20))
            # 1h low, 4h high, 1d oversold
            & ((stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_10) | (roc_9_1d_gt_neg_25))
            # 1h still high, 1d down move & oversold
            & ((stochrsi_k_1h_gt_60) | (rsi_3_1d_gt_10) | (roc_9_1d_gt_neg_25))
            # both stochastics topped out while the hour is making no new high
            & ((stochrsi_k_1h_lt_80) | (stochrsi_k_4h_lt_20) | (aroonu_14_1h > 5.0))
            # 4h & 1d down move, 1d high
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_gt_10))
            # 4h down move, 1d uptrend
            & ((rsi_3_4h_gt_5) | (aroonu_14_1d_lt_50))
            # 4h uptrend & still high, 1d up move
            & ((aroonu_14_4h_lt_20) | (stochrsi_k_4h_gt_30) | (rsi_3_1d_lt_35))
            # 4h & 1d uptrend, 1d high
            & ((aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_50) | (stochrsi_k_1d_gt_10))
          )

          # Logic — Bounce in downtrend
          short_entry_logic.append(
            # 1d actually falling — a bounce without it is not a downtrend bounce
            (roc_9_1d < 0.0)
            & (rsi_3 < 90.0)
            & (rsi_3_15m_lt_80)
            # & (rsi_3_1h < 80.0)
            & (rsi_14 > 55.0)
            & (willr_14 > -30.0)
            & (willr_14 < -15.0)
            & (stochrsi_k > 70.0)
            & (aroond_14_15m < 90.0)
            & (stochrsi_k_15m_gt_20)
            & (close > ema_12)
            & (close < ema_200)
            & (close < (bbu_20_2_0 * 0.99))
          )

        # Condition #562 - Trend Breakdown mode (Short).
        if short_entry_condition_index == 562:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(roc_9_1d < 5.0)
          # TAG562: no shorts within 12% of the 30d high, read off the 1d frame
          short_entry_logic.append(((close / high_max_30_1d - 1.0) < -0.12) | np.isnan(high_max_30_1d))
          # TAG562-R2: no shorts into weekly rips, read off the 1d frame
          short_entry_logic.append((roc_7_1d < 8.0) | np.isnan(roc_7_1d))
          short_entry_logic.append(rsi_14_4h < 48.0)
          short_entry_logic.append(rsi_14_1d < 50.0)
          short_entry_logic.append(rsi_14_1d > 25.0)

          short_entry_logic.append(
            # Downtrend confirmation (higher TF)
            (ema_12_4h < ema_200_4h)
            & (rsi_14_4h < 50.0)
            & (aroonu_14_4h < 60.0)
            & (roc_9_4h < 2.0)
            # 1h also bearish
            & (rsi_14_1h < 42.0)
            & (aroonu_14_1h < 40.0)
            # Daily momentum negative
            & (roc_9_1d < 0.0)
            # 1h + 4h capitulation oversold = double-exhaustion bottom
            & ((rsi_3_4h_gt_5) | (rsi_3_1h_gt_5) | (stochrsi_k_1h_gt_10))
            # 4h still in oversold zone post first leg + 1d sustained drop = continuation V-trap
            & ((rsi_3_4h_gt_20) | (stochrsi_k_4h > 10.0) | (rsi_3_1d_gt_40))
            # 1d capitulation but 4h mid = bottom formation, skip shorts
            & ((rsi_3_1d_gt_20) | (stochrsi_k_4h_lt_50) | (rsi_3_4h_gt_60))
            # 4h crash already extreme (>50% drop) = oversold bottom, dead cat
            & ((roc_9_4h_gt_neg_50) | (rsi_3_4h_gt_15) | (stochrsi_k_4h_gt_10))
            # 1d ultra-capitulation (STOCHRSIk = 0, RSI_3 < 10) = absolute bottom
            & ((rsi_3_1d_gt_10) | (stochrsi_k_1d > 5.0) | (rsi_3_4h_gt_40))
            # 4h drop ended (STOCHRSIk recovered) + 1h rallied = bull pullback over
            & ((stochrsi_k_4h_lt_50) | (stochrsi_k_1h < 60.0))
            # 1d AROONU high = recent 1d high made = bull pullback, not bear
            & ((aroonu_14_1d_lt_60) | (rsi_3_4h_gt_25))
            # 15m + 1h ultra-cap + 4h CMF positive = institutional buying, V-bottom
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (cmf_20_4h < -0.05))
            # 4h CMF nearly neutral + 1h rallied = money outflow stopping, bounce starting
            & ((cmf_20_4h < -0.05) | (stochrsi_k_1h < 70.0))
            # 1d massive crash already + 1h rallied = capitulation done, bounce starting
            & ((roc_9_1d > -25.0) | (stochrsi_k_1h < 60.0))
            # 15m + 1h ultra-capitulation = V-bottom forming regardless of CMF
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_15))
            # 1h overbought + 1d CMF positive = bull pullback bouncing on inflow
            & ((stochrsi_k_1h < 70.0) | (cmf_20_1d < 0.0))
            # 4h STOCHRSIk still extreme + 1h moderate = second leg waiting bounce
            & ((stochrsi_k_4h > 10.0) | (rsi_3_1h_gt_30))
            # 1d STOCHRSIk floor + 1d CMF positive = institutional buying after crash
            & ((stochrsi_k_1d > 5.0) | (cmf_20_1d < 0.0) | (rsi_3_4h_gt_45))
            # 1d big crash + 1h moderate overbought = bull pullback after sell-off
            & ((roc_9_1d > -22.0) | (stochrsi_k_1h < 70.0))
            ##########################################################################################################
            # 15m & 1h down move, 1h low, 15m low
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_25) | (aroonu_14_1h_gt_0) | (stochrsi_k_15m_gt_10))
            # 15m & 1h & 4h down move, 15m low
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (stochrsi_k_15m_gt_10))
            # 15m & 4h & 1d down move, 1d low
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1d_gt_20))
            # 15m & 4h & 1d down move, 1h & 1d low
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_30))
            # 15m & 1d down move, 15m & 1d low
            & ((rsi_3_15m_gt_5) | (rsi_3_1d_gt_15) | (stochrsi_k_15m_gt_10) | (stochrsi_k_1d_gt_30))
            # 15m & 1d down move, 1d low
            & ((rsi_3_15m_gt_5) | (rsi_3_1d_gt_20) | (aroonu_14_1d_gt_0))
            # 15m & 1d down move, 15m & 4h low
            & ((rsi_3_15m_gt_5) | (rsi_3_1d_gt_20) | (stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_30))
            # 15m & 1h & 4h down move, 1h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_gt_10))
            # 15m & 1h & 4h down move, 15m low, 1h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (aroonu_14_1h_gt_10) | (stochrsi_k_15m_gt_10))
            # 15m & 1h & 4h down move, 4h low, 15m low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (aroonu_14_4h_gt_0) | (stochrsi_k_15m_gt_10))
            # 15m & 1h & 1d down move, 15m low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_15m_gt_20))
            # 15m & 1h & 1d down move, 15m low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (rsi_3_1d_gt_30) | (stochrsi_k_15m_gt_10))
            # 15m & 1h down move, 15m & 1h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_20) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_20))
            # 15m & 1h & 1d down move, 1h low, 1d oversold
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_gt_10) | (roc_9_1d_gt_neg_10))
            # 15m & 1h & 1d down move, 15m low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_30) | (stochrsi_k_15m_gt_10))
            # 15m & 1h & 4h down move, 15m low, 1d oversold
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_15m_gt_0) | (roc_9_1d_gt_neg_20))
            # 15m & 1 & 4h down move, 1h low, 15m low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_1h_gt_10) | (stochrsi_k_15m_gt_10))
            # 15m & 1h down move, 1h & 4h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_10))
            # 15m & 1h down move, 1h & 1d low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_10))
            # 15m & 1h down move, 15m & 4h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_30) | (stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m & 1h down move, 15m & 1h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_15m_gt_0) | (aroonu_14_1h_gt_30))
            # 15m & 1h down move, 1h & 4h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_20))
            # 15m & 1h down move, 1h & 1d low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_10))
            # 15m & 1h down move, 1h low, 15m low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_1h_gt_10) | (stochrsi_k_15m_gt_10))
            # 15m & 1h down move, 1h low, 1d oversold
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_1h_gt_20) | (roc_9_1d_gt_neg_10))
            # 15m & 1h down move, 4h low, 1h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_35) | (aroonu_14_4h_gt_0) | (stochrsi_k_1h_gt_30))
            # 15m & 4h down move, 15m & 1h low
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_20))
            # 15m & 4h & 1d down move, 4h low
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_gt_20))
            # 15m & 4h & 1d down move, 1d low, 1h low
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_35) | (stochrsi_k_1d_gt_20) | (stochrsi_k_1h_gt_30))
            # 15m & 4h & 1d down move, 1h & 1d low
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_50) | (aroonu_14_1h_gt_30) | (aroonu_14_1d_gt_30))
            # 15m & 4h & 1d down move, 1d low, 4h low
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_1d_gt_10) | (stochrsi_k_4h_gt_30))
            # 15m & 4h & 1d down move, 4h & 1d low
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_40) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_gt_30))
            # 15m & 4h down move, 15m & 4h low
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_30) | (aroonu_14_15m_gt_0) | (aroonu_14_4h_gt_0))
            # 15m & 4h & 1d down move, 1h & 4h low
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_45) | (aroonu_14_1h_gt_30) | (aroonu_14_4h_gt_30))
            # 15m & 4h down move, 15m low, 4h low
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_45) | (stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m & 1d down move, 4h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_10) | (aroonu_14_4h_gt_30))
            # 15m & 1d down move, 4h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_20) | (aroonu_14_4h_gt_0) | (stochrsi_k_4h_gt_10))
            # 15m & 1d down move, 1d low
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_20) | (stochrsi_k_1d_gt_10))
            # 15m & 1d down move, 15m & 1h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_25) | (stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_30))
            # 15m & 1h & 1d down move, 15m low
            & (
              (rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_10)
            )
            # 15m & 1h & 1d down move, 15m & 4h low
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (rsi_3_1d_gt_30) | (aroonu_14_15m_gt_30) | (aroonu_14_4h_gt_30))
            # 15m & 1h down move, 1h low, 15m low
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_1h_gt_30) | (stochrsi_k_15m_gt_10))
            # 15m & 1h down move, 4h low
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (aroonu_14_4h_gt_10))
            # 15m & 1h down move, 15m & 1h low
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_15) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_20))
            # 15m & 1h & 4h down move, 1h love
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (aroonu_14_1h_gt_0))
            # 15m & 1h down move, 15m & 4h low
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_20) | (stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m & 1h & 1d down move, 15m & 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_15m_gt_20) | (aroonu_14_1d_gt_20))
            # 15m & 1h down move, 4h & 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_25) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_gt_30))
            # 15m & 1h & 4h down move, 4h low, 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_4h_gt_10) | (stochrsi_k_1d_gt_10))
            # 15m & 1h & 4h down move, 1h low, 15m low
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_1h_gt_30) | (stochrsi_k_15m_gt_30))
            # 15m & 1h & 1d down move, 15m & 1h low
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_20))
            # 15m & 1h down move, 1d low, 1d oversold
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_30) | (stochrsi_k_1d_gt_20) | (roc_9_1d_gt_neg_10))
            # 15m & 1h & 4h down move, 1h low, 4h downtrend not confirmed
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_40) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_50))
            # 15m & 1h & 1d down move, 1h low, 4h downtrend not confirmed
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_30) | (aroonu_14_4h_lt_40))
            # 15m  & 1h down move, 1h & 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_35) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_30))
            # 15m & 1h down move, 1h low, 1d oversold
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_40) | (aroonu_14_1h_gt_0) | (roc_9_1d_gt_neg_10))
            # 15m & 4h down move, 1h & 4h low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_30))
            # 15m & 4h & 1d down move, 4h low, 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_40) | (aroonu_14_4h_gt_20) | (stochrsi_k_1d_gt_20))
            # 15m & 4h down move, 15m & 1h low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_10))
            # 15m & 4h down move, 1h & 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_20))
            # 15m & 4h down move, 1h low, 4h low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_1h_gt_0) | (stochrsi_k_4h_gt_30))
            # 15m & 4h down move, 4h low, 1d oversold
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_4h_gt_0) | (roc_9_1d_gt_neg_10))
            # 15m & 4h down move, 15m & 4h low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_30))
            # 15m & 4h & 1d down move, 1h low, 4h low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m & 4h & 1d down move, 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_35) | (aroonu_14_1d_gt_0) | (stochrsi_k_1d_gt_10))
            # 15m & 4h down move, 15m & 1h & 4h low
            & (
              (rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_15m_gt_0) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_20)
            )
            # 15m & 4h down move, 15m & 4h low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_15m_gt_0) | (aroonu_14_4h_gt_10))
            # 15m & 4h down move, 1h downtrend not confirmed, 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_25) | (stochrsi_k_1h_lt_40) | (stochrsi_k_1d_gt_20))
            # 15m & 4h & 1d down move, 1h low, 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1h_gt_0) | (stochrsi_k_1d_gt_10))
            # 15m & 4h down move, 15m & 4h low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_30) | (aroonu_14_15m_gt_0) | (aroonu_14_4h_gt_30))
            # 15m & 4h down move, 4h & 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_30) | (aroonu_14_4h_gt_30) | (aroonu_14_1d_gt_30))
            # 15m & 1h & 1d down move, 1h & 4h low
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_30))
            # 15m & 4h down move, 1h low, 4h oversold
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_35) | (aroonu_14_1h_gt_0) | (roc_9_4h_gt_neg_20))
            # 15m & 1d down move, 15m & 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_15m_gt_10) | (aroonu_14_1d_gt_20))
            # 15m & 1d down move, 1h & 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_1h_gt_20) | (aroonu_14_1d_gt_30))
            # 15m & 1d down move, 1d downtrend not confirmed, 1h low
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_25) | (rsi_14_1d_lt_40) | (aroonu_14_1h_gt_0))
            # 15m & 1d down move, 15m low, 1d oversold
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_15m_gt_30) | (roc_9_1d_gt_neg_15))
            # 15m & 1d down move, 1h & 1d low
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_10))
            # 15m down move, 1h downtrend not confirmed, 15m & 1h low
            & ((rsi_3_15m_gt_15) | (rsi_14_1h_lt_40) | (stochrsi_k_15m_gt_10) | (stochrsi_k_1h_gt_30))
            # 15m & 1h & 4h down move, 15m & 1h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_20))
            # 15m & 1h & 4h down move, 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (aroonu_14_4h_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m & 1h & 4h down move, 15m low, 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_4h_gt_45) | (aroonu_14_15m_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m & 1h & 1d down move, 15m low, 1d oversold
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_15m_gt_0) | (roc_9_1d_gt_neg_10))
            # 15m & 1h down move, 15m & 1h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (aroonu_14_15m_gt_0) | (aroonu_14_4h_gt_0))
            # 15m & 1h down move, 5h & 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_gt_0))
            # 15m & 1h down move, 1h uptrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_20) | (cmf_20_1h_lt_0_10))
            # 15m & 1h & 4h down move, 1h & 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_20))
            # 15m & 1h & 4h down move, 1h low, 15m low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_1h_gt_0) | (stochrsi_k_15m_gt_10))
            # 15m & 1h & 1d down move, 1h & 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m & 1h down move, 15m & 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_25) | (stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m & 1h & 4h down move, 4h downtrend not confirmed, 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (rsi_14_4h_lt_40) | (aroonu_14_4h_gt_0))
            # 15m & 1h & 4h down move, 15m & 1h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_15m_gt_30) | (aroonu_14_1h_gt_30))
            # 15m & 1h & 4h down move, 4h downtrend not confirmed, 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_35) | (rsi_14_4h_lt_40) | (aroonu_14_1d_gt_10))
            # 15m & 1h & 4h down move, 1h & 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_10))
            # 15m & 1h & 4h & 1d down move, 1h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1h_gt_0))
            # 15m & 1h & 1d down move, 1h low, 1d oversold
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_1h_gt_0) | (roc_9_1d_gt_neg_10))
            # 15m & 1h down move, 15m & 1h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_30) | (aroonu_14_15m_gt_0) | (aroonu_14_1h_gt_0))
            # 15m & 1h & 4h down move, 15m & 1h high
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (aroonu_14_15m_gt_0) | (aroonu_14_1h_gt_20))
            # 15m & 1h & 4h down move, 4h low, 1d oversold
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (aroonu_14_4h_gt_10) | (roc_9_1d_gt_neg_10))
            # 15m & 1h down move, 1h low, 4h downtrend not confirmed
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_gt_35) | (aroonu_14_1h_gt_0) | (stochrsi_k_4h_lt_60))
            # 15m & 4h & 1d down move, 1h low, 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_35) | (aroonu_14_1h_gt_20) | (stochrsi_k_1d_gt_10))
            # 15m & 4h down move, 1h downtrend not confirmed, 4h downtrend not confirmed
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (rsi_14_1h_lt_40) | (aroonu_14_4h_lt_50))
            # 15m & 4h down move, 1h low, 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1h_gt_0) | (stochrsi_k_4h_gt_10))
            # 15m & 4h down move, 1d low, 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1d_gt_0) | (stochrsi_k_4h_gt_20))
            # 15m & 4h & 1d down move, 1h & 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_30))
            # 15m & 4h & 1d down move, 4h & 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_gt_30))
            # 15m & 1h & 1d down move, 15m low, 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_35) | (aroonu_14_15m_gt_0) | (stochrsi_k_4h_gt_10))
            # 15m & 4h & 1d down move, 15m & 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_60) | (aroonu_14_15m_gt_10) | (aroonu_14_4h_gt_30))
            # 15m & 4h down move, 4h downtrend not confirmed, 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_50) | (stochrsi_k_1d_gt_20))
            # 15m & 4h & 1d down move, 4h downtrend not confirmed, 15m low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (rsi_14_4h_lt_40) | (stochrsi_k_15m_gt_20))
            # 15m & 4h & 1d down move, 4h & 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_4h_gt_30) | (aroonu_14_1d_gt_30))
            # 15m & 4h & 1d down move, 1d low, 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1d_gt_10) | (stochrsi_k_4h_gt_10))
            # 15m & 4h & 1d down move, 4h low, 1d oversold
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (stochrsi_k_4h_gt_20) | (roc_9_1d_gt_neg_10))
            # 15m & 4h & 1d down move, 1d low, 1d oversold
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_1d_gt_0) | (roc_9_1d_gt_neg_10))
            # 15m & 4h & 1d down move, 1h & 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_45) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_30))
            # 15m & 4h & 1d down move, 1h & 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_50) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_10))
            # 15m & 4h & 1d down move, 1h low, 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_45) | (aroonu_14_1h_gt_30) | (stochrsi_k_4h_gt_10))
            # 15m & 4h down move, 1h & 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_35) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_20))
            # 15m & 4h & 1d down move, 1h & 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_20))
            # 15m & 4h & 1d down move, 1h & 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_10))
            # 15m & 4h & 1d down move, 1h low, 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_20) | (stochrsi_k_4h_gt_10))
            # 15m & 4h down move, 15m & 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_40) | (stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m & 1d down move, 15m & 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_15m_gt_30) | (aroonu_14_4h_gt_30))
            # 15m & 1d down move, 1h & 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_30))
            # 15m & 1d down move, 4h & 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_4h_gt_30) | (aroonu_14_1d_gt_30))
            # 15m & 1d down move, 4h low, 1d oversold
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_4h_gt_30) | (roc_9_1d_gt_neg_20))
            # 15m & 1d down move, 15m & 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1d_gt_20))
            # 15m & 1d down move, 15m & 1h & 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_30) | (aroonu_14_15m_gt_0) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_0))
            # 15m & 1d down move, 1d low, 1d oversold
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_30) | (aroonu_14_1d_gt_0) | (roc_9_1d_gt_neg_10))
            # 15m down move, 1h & 1d low
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_0))
            # 15m & 1h & 4h down move, 1d low, 1d oversold
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_1d_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 1h & 4h down move, 1h & 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_1h_gt_30) | (aroonu_14_4h_gt_30))
            # 15m & 1h & 4h down move, 15m & 4h low
            & (
              (rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_20)
            )
            # 15m & 1h & 4h down move, 1h & 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_35) | (stochrsi_k_1h_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m & 1h & 4h down move, 1h & 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (stochrsi_k_1h_gt_10) | (stochrsi_k_4h_gt_30))
            # 15m & 1h & 4h down move, 15m & 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_4h_gt_45) | (aroonu_14_15m_gt_0) | (aroonu_14_4h_gt_30))
            # 15m & 1h & 1d down move, 15m & 1h low
            & (
              (rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_3_1d_gt_45) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_30)
            )
            # 15m & 1h down move, 4h & 1d downtrend not confirmed, 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (rsi_14_4h_lt_40) | (rsi_14_1d_lt_40) | (aroonu_14_4h_gt_30))
            # 15m & 1h down move, 1h & 1d low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_0))
            # 15m & 1h down move, 1d low, 15m low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (aroonu_14_1d_gt_0) | (stochrsi_k_15m_gt_10))
            # 15m & 1h down move, 15m & 1h low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_25) | (stochrsi_k_15m_gt_10) | (stochrsi_k_1h_gt_20))
            # 15m & 1h & 4h down move, 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_4h_gt_0))
            # 15m & 1h & 4h & 1d down move, 15m low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_15m_gt_0))
            # 15m & 1h down move, 15m & 1h low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_35) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_10))
            # 15m & 1h & 4h down move, 1h & 1d low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (aroonu_14_1h_gt_30) | (aroonu_14_1d_gt_30))
            # 15m & 1h & 4h down move, 1h & 1d low
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_gt_45) | (rsi_3_4h_gt_45) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_10))
            # 15m & 4h & 1d down move, 1h & 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (aroonu_14_1h_gt_30) | (aroonu_14_4h_gt_30))
            # 15m & 4h & 1d down move, 4h downtrend not confirmed, 1d low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_35) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_gt_20))
            # 15m & 4h down move, 4h low, 1d oversold
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_4h_gt_20) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 1h & 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_25) | (stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m & 4h & 1d down move, 15m & 1h low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_20))
            # 15m & 4h & 1d down move, 4h & 1d low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 15m & 4h & 1d down move, 1h low, 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_20) | (stochrsi_k_4h_gt_10))
            # 15m & 4h & 1d down move, 1h low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_10))
            # 15m & 4h down move, 15m & 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_35) | (stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_10))
            # 15m & 4h & 1d down move, 1h & 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_0))
            # 15m & 4h & 1d down move, 1h & 1d low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_45) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_30))
            # 15m & 4h & 1d down move, 1h & 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_45) | (stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m & 4h & 1d down move, 1h & 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_10))
            # 15m & 1d down move, 15m & 1h low
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_20))
            # 15m & 1d down move, 15m low, 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_15m_gt_30) | (stochrsi_k_4h_gt_20))
            # 15m & 1d down move, 4h low, 1d oversold
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_4h_gt_0) | (roc_9_1d_gt_neg_10))
            # 15m & 1d down move, 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_25) | (stochrsi_k_4h_gt_10))
            # 15m & 1d down move, 15m & 4h low
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_30) | (aroonu_14_15m_gt_20) | (aroonu_14_4h_gt_20))
            # 15m down move, 1h low, 4h low, 15m low
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_20) | (stochrsi_k_15m_gt_20))
            # 15m & 1h & 4h down move, 15m & 1d low
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_15m_gt_0) | (aroonu_14_1d_gt_10))
            # 15m & 1h & 4h down move, 15m low, 1h low
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_15m_gt_0) | (stochrsi_k_1h_gt_20))
            # 15m & 1h down move, 4h low, 1h downtrend not confirmed
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (aroonu_14_4h_gt_20) | (stochrsi_k_1h_lt_60))
            # 15m & 1h down move, 1h & 1d low, 15m low
            & (
              (rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_0) | (stochrsi_k_15m_gt_10)
            )
            # 15m & 1h & 4h down move, 4h low, 1d oversold
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (stochrsi_k_4h_gt_10) | (roc_9_1d_gt_neg_10))
            # 15m & 1h & 4h down move, 1h & 1d low
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_30))
            # 15m & 1h & 4h down move, 1h & 4h low
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_20))
            # 15m & 1h & 4h down move, 4h downtrend not confirmed, 1h low
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (rsi_14_4h_lt_40) | (aroonu_14_1h_gt_30))
            # 15m & 1h down move, 15m & 1h low, 1d oversold
            & (
              (rsi_3_15m_gt_30) | (rsi_3_1h_gt_40) | (aroonu_14_15m_gt_0) | (aroonu_14_1h_gt_0) | (roc_9_1d_gt_neg_10)
            )
            # 15m & 4h & 1d down move, 15m low, 4h low
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_15m_gt_0) | (stochrsi_k_4h_gt_30))
            # 15m & 4h & 1d down move, 15m low, 4h low
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_15m_gt_10) | (stochrsi_k_4h_gt_10))
            # 15m & 4h & 1d down move, 15m & 4h low
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_40) | (aroonu_14_15m_gt_0) | (aroonu_14_4h_gt_10))
            # 15m & 4h down move, 1h & 1d low
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_0))
            # 15m & 4h down move, 1h low, 1d oversold
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_1h_gt_0) | (roc_9_1d_gt_neg_10))
            # 15m & 4h & 1d down move, 1h & 4h low
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (stochrsi_k_1h_gt_30) | (stochrsi_k_4h_gt_30))
            # 15m & 4h & 1d down move, 4h & 1d low
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_40) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 15m down move, 1h low, 1d low, 4h low
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_gt_30) | (aroonu_14_1d_gt_0) | (stochrsi_k_4h_gt_10))
            # 15m & 1h & 1d down move, 15m & 1h low
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_15m_gt_0) | (aroonu_14_1h_gt_0))
            # 15m & 1h & 1d down move, 1h & 4h low
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_gt_40) | (rsi_3_1d_gt_45) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_10))
            # 15m & 4h down move, 4h downtrend not confirmed, 15m low
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_35) | (rsi_14_4h_lt_40) | (aroonu_14_4h_lt_40) | (aroonu_14_15m_gt_10))
            # 15m & 4h & 1d down move, 15m & 1d low
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_15m_gt_0) | (aroonu_14_1d_gt_0))
            # 15m & 4h & 1d down move, 1h low, 4h low
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_0) | (stochrsi_k_4h_gt_10))
            # 15m & 4h & 1d down move, 4h low, 1d oversold
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_4h_gt_0) | (roc_9_1d_gt_neg_10))
            # 15m & 4h down move, 15m & 4h low
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_40) | (stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m & 4h & 1d down move, 15m & 1h low
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_20))
            # 15m & 4h & 1d down move, 1h low, 15m low
            & ((rsi_3_15m_gt_35) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1h_gt_0) | (stochrsi_k_15m_gt_10))
            # 15m & 4h down move, 15m & 4h low
            & ((rsi_3_15m_gt_40) | (rsi_3_4h_gt_40) | (aroonu_14_15m_gt_10) | (aroonu_14_4h_gt_10))
            # 15m high, 4h down move & still high
            & ((aroonu_14_15m_lt_75) | (rsi_3_4h_gt_25) | (stochrsi_k_4h_lt_20))
            # 1h & 4h down move, 15m & 4h low
            & ((rsi_3_1h_gt_3) | (rsi_3_4h_gt_30) | (aroonu_14_15m_gt_20) | (aroonu_14_4h_gt_30))
            # 1h & 1d down move, 15m & 4h low
            & ((rsi_3_1h_gt_5) | (rsi_3_1d_gt_30) | (aroonu_14_15m_gt_0) | (aroonu_14_4h_gt_10))
            # 1h down move, 1h & 4h low
            & ((rsi_3_1h_gt_5) | (stochrsi_k_1h_gt_10) | (stochrsi_k_4h_gt_30))
            # 1h & 4h & 1d down move, 4h & 1d oversold
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_20) | (roc_9_4h_gt_neg_30) | (roc_9_1d_gt_neg_40))
            # 1h & 4h down move, 1h low
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_gt_10))
            # 1h & 4h down move, 15m low, 4h downtrend not confirmed
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_30) | (aroonu_14_15m_gt_0) | (aroonu_14_4h_lt_50))
            # 1h & 4h down move, 15m & 1h low
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_35) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_20))
            # 1h & 4h & 1d down move, 4h & 1d low
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_gt_20))
            # 1h & 1d down move, 4h & 1d low
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_30) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_gt_10))
            # 1h & 1d down move, 1d low, 1h low
            & ((rsi_3_1h_gt_10) | (rsi_3_1d_gt_30) | (aroonu_14_1d_gt_0) | (stochrsi_k_1h_gt_20))
            # 1h down move, 15m low, 4h oversold
            & ((rsi_3_1h_gt_10) | (aroonu_14_15m_gt_0) | (roc_9_4h_gt_neg_20))
            # 1h down move, 4h low
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_gt_0))
            # 1h down move, 1h low, 4h low
            & ((rsi_3_1h_gt_10) | (aroonu_14_4h_gt_10) | (stochrsi_k_1h_gt_10))
            # 1h down move, 15m & 4h low, 1d oversold
            & ((rsi_3_1h_gt_10) | (stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_30) | (roc_9_1d_gt_neg_10))
            # 1h & 4h down move, 1h & 4h low
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_1h_gt_30) | (stochrsi_k_4h_gt_30))
            # 1h & 4h down move, 1h & 4h low
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_gt_10) | (stochrsi_k_4h_gt_20))
            # 1h & 4h & 1d down move, 1h & 1d low
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (stochrsi_k_1h_gt_10) | (stochrsi_k_1d_gt_10))
            # 1h & 4h down move, 15m low, 1h low
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_25) | (aroonu_14_15m_gt_10) | (stochrsi_k_1h_gt_10))
            # 1h & 4h & 1d down move, 15m & 4h low
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_40) | (aroonu_14_15m_gt_10) | (aroonu_14_4h_gt_20))
            # 1h & 4h & 1d down move, 1d low, 1d oversold
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1d_gt_0) | (roc_9_1d_gt_neg_10))
            # 1h & 4h & 1d down move, 1h & 4h low
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_30) | (aroonu_14_4h_gt_30))
            # 1h & 4h & 1d down move, 15m low, 1h low
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_15m_gt_0) | (stochrsi_k_1h_gt_10))
            # 1h & 1d down move, 15m & 4h & 1d low
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_30) | (aroonu_14_15m_gt_0) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_gt_0))
            # 1h down move, 15m & 4h low, 1h low
            & ((rsi_3_1h_gt_15) | (aroonu_14_15m_gt_0) | (aroonu_14_4h_gt_0) | (stochrsi_k_1h_gt_10))
            # 1h down move, 15m low, 1h low
            & ((rsi_3_1h_gt_15) | (aroonu_14_15m_gt_0) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_10))
            # 1h down move, 15m & 1h low
            & ((rsi_3_1h_gt_15) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_20))
            # 1h down move, 4h low, 1d downtrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_4h_gt_20) | (roc_9_1d_gt_neg_10))
            # 1h down move, 15m & 1h low, 1d oversold
            & ((rsi_3_1h_gt_15) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_30) | (roc_9_1d_gt_neg_10))
            # 1h & 4h & 1d down move, 1h low, 4h downtrend not confirmed
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_35) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_lt_50))
            # 1h & 4h down move, 1h & 4h low, 1d oversold
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_30) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 1h & 4h & 1d low
            & (
              (rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_gt_20)
            )
            # 1h & 4h down move, 1h low, 1d oversold
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_20) | (stochrsi_k_1h_gt_10) | (roc_9_1d_gt_neg_30))
            # 1h & 4h down move, 1h & 4h low
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_20))
            # 1h & 4h & 1d down move, 15m & 1h low
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_15m_gt_30) | (aroonu_14_1h_gt_30))
            # 1h & 3h & 1d down move, 1h & 1d low
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (aroonu_14_1h_gt_20) | (aroonu_14_1d_gt_30))
            # 1h & 4h down move, 15m & 1h low
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (aroonu_14_15m_gt_0) | (aroonu_14_1h_gt_0))
            # 1h & 4h down move, 15m & 4h low
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_40) | (aroonu_14_15m_gt_0) | (aroonu_14_4h_gt_0))
            # 1h & 1d down move, 15m & 1h low
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_10))
            # 1h & 1d down move, 1d low, 4h low
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_30) | (aroonu_14_1d_gt_10) | (stochrsi_k_4h_gt_20))
            # 1h & 1d down move, 1h & 1d low
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_30) | (stochrsi_k_1h_gt_10) | (stochrsi_k_1d_gt_10))
            # 1h down move, 1d low, 4h downtrend not confirmed, 1h low
            & ((rsi_3_1h_gt_25) | (aroonu_14_1d_gt_0) | (aroonu_14_4h_lt_50) | (stochrsi_k_1h_gt_20))
            # 1h & 1d down move, 1h & 1d low
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_10))
            # 1h & 1d down move, 4h & 1d low
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_30))
            # 1h down move, 1h low, 4h high
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1h_gt_10) | (stochrsi_k_4h_lt_70))
            # 1h & 4h & 1d down move, 1h & 4h low
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_30))
            # 1h & 4h down move, 4h downtrend not confirmed, 4h low
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_30) | (rsi_14_4h_lt_40) | (aroonu_14_4h_gt_0))
            # 1h & 4h down move, 1h & 4h low, 15m low
            & (
              (rsi_3_1h_gt_25) | (rsi_3_4h_gt_40) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_20) | (stochrsi_k_15m_gt_10)
            )
            # 1h & 1d down move, 1d uptrend, 4h & 1d low
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_30) | (cmf_20_1d_lt_0_10) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_gt_30))
            # 1h & 1d down move, 1h & 1d low
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_45) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_0))
            # 1h down move, 15m low, 1h low, 1d downtrend not confirmed
            & ((rsi_3_1h_gt_25) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_20) | (stochrsi_k_1h_lt_50))
            # 1h down move, 1h low, 4h low, 15m low
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_20) | (stochrsi_k_15m_gt_10))
            # 1h & 4h & 1d down move, 4h low, 1d oversold
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_4h_gt_0) | (roc_9_1d_gt_neg_10))
            # 1 & 4h & 1d down move, 1h low, 4h low
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_50) | (aroonu_14_1h_gt_0) | (stochrsi_k_4h_gt_30))
            # 1h & 4h & 1d down move, 4h & 1d low
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_30) | (rsi_3_1d_gt_60) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_gt_0))
            # 1h & 4h & 1d down move, 4h & 1d low
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_gt_0))
            # 1h & 1d down move, 1h & 1d low, 1d oversold
            & (
              (rsi_3_1h_gt_30) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_10) | (stochrsi_k_1d_gt_10) | (roc_9_1d_gt_neg_30)
            )
            # 1h down move, 1h low, 1d oversold
            & ((rsi_3_1h_gt_30) | (stochrsi_k_1h_gt_10) | (roc_9_1d_gt_neg_20))
            # 1h & 4h down move, 4h downtrend not confirmed, 1d low, 1d oversold
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (rsi_14_4h_lt_40) | (aroonu_14_1d_gt_10) | (roc_9_1d_gt_neg_10))
            # 1h & 4h down move, 1h & 1d low
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_gt_35) | (aroonu_14_1h_gt_30) | (aroonu_14_1d_gt_30))
            # 1h & 1d down move, 1h & 1d low
            & ((rsi_3_1h_gt_35) | (rsi_3_1d_gt_45) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_0))
            # 1h down move, 1h & 4h low, 1d oversold
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 1h down move, 4h & 1d low, 1h downtrend not confirmed
            & ((rsi_3_1h_gt_35) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_gt_0) | (stochrsi_k_1h_lt_70))
            # 1h down move & low, 1d high
            & ((rsi_3_1h_gt_35) | (aroonu_14_1h_gt_20) | (aroonu_14_1d_lt_60))
            # 1h & 4h & 1d down move, 15m low, 1d oversold
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_15m_gt_0) | (roc_9_1d_gt_neg_10))
            # 1h & 4h & 1d down move, 1h low, 1d oversold
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_0) | (roc_9_1d_gt_neg_15))
            # 1h & 4h & 1d down move, 1h & 1d low
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_gt_45) | (rsi_3_1d_gt_45) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_20))
            # 1h & 1d down move, 1h & 1d low
            & ((rsi_3_1h_gt_40) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_10))
            # 1h down move, 15m low, 1h low
            & ((rsi_3_1h_gt_45) | (aroonu_14_15m_gt_0) | (aroonu_14_1h_gt_0))
            # 1h high & still high, 4h low
            & ((aroonu_14_1h_lt_30) | (stochrsi_k_1h_lt_60) | (aroonu_14_4h_gt_30))
            # 4h down move, 1h low, 4h low
            & ((rsi_3_4h_gt_5) | (aroonu_14_1h_gt_10) | (stochrsi_k_4h_gt_10))
            # 4h down move, 1d low, 4h low
            & ((rsi_3_4h_gt_5) | (aroonu_14_1d_gt_20) | (stochrsi_k_4h_gt_10))
            # 4h & 1d down move, 1h & 1d low
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_0))
            # 4h & 1d down move, 4h low, 1d oversold
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_40) | (stochrsi_k_4h_gt_20) | (roc_9_1d_gt_neg_20))
            # 4h & 1d down move, 4h low, 1d oversold
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_45) | (stochrsi_k_4h_gt_10) | (roc_9_1d_gt_neg_10))
            # 4h down move, 15m & 1h low
            & ((rsi_3_4h_gt_10) | (aroonu_14_15m_gt_0) | (aroonu_14_1h_gt_0))
            # 4h down move, 15m low, 4h low
            & ((rsi_3_4h_gt_10) | (aroonu_14_15m_gt_0) | (stochrsi_k_4h_gt_20))
            # 4h down move, 1d low, 4h low
            & ((rsi_3_4h_gt_10) | (aroonu_14_1d_gt_0) | (stochrsi_k_4h_gt_20))
            # 4h down move, 4h downtrend not confirmed, 1d low
            & ((rsi_3_4h_gt_10) | (rsi_14_4h_lt_40) | (aroonu_14_1d_gt_0))
            # 4h & 1d down move, 4h & 1d low
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_20) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_20))
            # 4h & 1d down move, 1h & 1d low
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (stochrsi_k_1h_gt_10) | (stochrsi_k_1d_gt_10))
            # 4h & 1d down move, 15m & 1d low
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_25) | (aroonu_14_15m_gt_10) | (aroonu_14_1d_gt_10))
            # 4h & 1d down move, 1d low
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_30) | (stochrsi_k_1d_gt_10))
            # 4h & 1d down move, 1h low, 4h low
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_35) | (aroonu_14_1h_gt_20) | (stochrsi_k_4h_gt_30))
            # 4h & 1d down move, 1d low, 1d oversold
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_35) | (aroonu_14_1d_gt_0) | (roc_9_1d_gt_neg_10))
            # 4h & 1d down move, 1h & 1d low
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_40) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_10))
            # 4h & 1d down move, 4h downtrend not confirmed, 1d low
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_45) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_gt_20))
            # 4h & 1d down move, 1d low, 1h low
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_40) | (aroonu_14_1d_gt_0) | (stochrsi_k_1h_gt_20))
            # 4h & 1d down move, 4h & 1d low
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_gt_60) | (stochrsi_k_4h_gt_10) | (stochrsi_k_1d_gt_30))
            # 4h down move, 15m & 4h low
            & ((rsi_3_4h_gt_15) | (aroonu_14_15m_gt_0) | (aroonu_14_4h_gt_10))
            # 4h down move, 1h & 1d low
            & ((rsi_3_4h_gt_15) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_0))
            # 4h down move, 4h low, 1d oversold
            & ((rsi_3_4h_gt_15) | (stochrsi_k_4h_gt_10) | (roc_9_1d_gt_neg_30))
            # 4h & 1d down move, 1h low, 1d low
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (aroonu_14_1h_gt_20) | (stochrsi_k_1d_gt_10))
            # 4h & 1d down move, 4h & 1d low
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_35) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_gt_20))
            # 4h down move, 15m & 1h low
            & ((rsi_3_4h_gt_20) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_30))
            # 4h down move, 1h & 4h & 1d low
            & ((rsi_3_4h_gt_20) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_gt_30))
            # 4h down move, 1h low, 4h downtrend not confirmed
            & ((rsi_3_4h_gt_20) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_50))
            # 4h down move, 1h low, 4h low, 1d downtrend not confirmed
            & ((rsi_3_4h_gt_20) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_50))
            # 4h & 1d down move, 1h & 4h low
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_20))
            # 4h & 1d down move, 4h & 1d low
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_25) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_gt_0))
            # 4h & 1d down move, 1h low, 1d oversold
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (aroonu_14_1h_gt_0) | (roc_9_1d_gt_neg_10))
            # 4h & 1d down move, 1d high, 4h high
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_30) | (aroonu_14_1d_gt_10) | (stochrsi_k_4h_gt_10))
            # 4h & 1d down move, 1d low, 4h low
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_40) | (aroonu_14_1d_gt_0) | (stochrsi_k_4h_gt_10))
            # 4h & 1d down move, 1h & 1d low
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_45) | (aroonu_14_1h_gt_20) | (aroonu_14_1d_gt_20))
            # 4h & 1d down move, 15m & 4h low
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_gt_40) | (aroonu_14_15m_gt_20) | (aroonu_14_4h_gt_20))
            # 4h & 1d down move, 1h & 4h & 1d low
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_gt_20))
            # 4h & 1d down move, 15m & 1d low
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_15m_gt_10) | (aroonu_14_1d_gt_10))
            # 4h & 1d down move, 4h low
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_30) | (aroonu_14_4h_gt_0))
            # 4h & 1d down move, 4h & 1d low
            & ((rsi_3_4h_gt_30) | (rsi_3_1d_gt_35) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 4h down move, 15m & 1h low, 4h no downtrend confirmed
            & ((rsi_3_4h_gt_30) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_lt_50))
            # 4h down move, 15m low, 1h downtrend not confirmed, 4h oversold
            & ((rsi_3_4h_gt_30) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_lt_80) | (roc_9_4h_gt_neg_10))
            # 4h & 1d down move, 4h oversold, 4h low
            & ((rsi_3_4h_gt_35) | (rsi_3_1d_gt_35) | (roc_9_4h_gt_neg_10) | (aroonu_14_4h_gt_0))
            # 4h & 1d down move, 4h & 1d low
            & ((rsi_3_4h_gt_35) | (rsi_3_1d_gt_40) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_gt_10))
            # 4h down move, 15m & 1h low, 4h no downtrend confirmed
            & ((rsi_3_4h_gt_35) | (aroonu_14_15m_gt_0) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_50))
            # 4h down move, 4h low, 4h downtrend not confirmed, 1d oversold
            & ((rsi_3_4h_gt_35) | (aroonu_14_4h_gt_0) | (stochrsi_k_4h_lt_50) | (roc_9_1d_gt_neg_20))
            # 1d down move, 1d low, 1d oversold
            & ((rsi_3_1d_gt_10) | (stochrsi_k_1d_gt_20) | (roc_9_1d_gt_neg_20))
            # 1d down move, 15m & 1h uptrend, 1d low
            & ((rsi_3_1d_gt_15) | (cmf_20_15m_lt_0_20) | (cmf_20_1h_lt_0_20) | (stochrsi_k_1d_gt_20))
            # 1d down move, 4h & 1d low
            & ((rsi_3_1d_gt_15) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_gt_0))
            # 1d down move, 4h low, 1d oversold
            & ((rsi_3_1d_gt_15) | (aroonu_14_4h_gt_0) | (roc_9_1d_gt_neg_20))
            # 1d down move, 4h low, 1d low
            & ((rsi_3_1d_gt_15) | (aroonu_14_4h_gt_10) | (stochrsi_k_1d_gt_10))
            # 15m down move, 4h high, 1d low
            & ((rsi_3_1d_gt_15) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_gt_20) | (stochrsi_k_1d_gt_10))
            # 1d down move, 1h & 1d low
            & ((rsi_3_1d_gt_15) | (stochrsi_k_1h_gt_10) | (stochrsi_k_1d_gt_20))
            # 1d down move, 4h & 1d low
            & ((rsi_3_1d_gt_15) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_30))
            # 1d down move, 1h low, 4h downtrend not confirmed
            & ((rsi_3_1d_gt_20) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_lt_40))
            # 1d down move, 1h & 4h low
            & ((rsi_3_1d_gt_20) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_10))
            # 1d down move, 4h low, 1d oversold
            & ((rsi_3_1d_gt_20) | (aroonu_14_4h_gt_0) | (roc_9_1d_gt_neg_10))
            # 1d down move, 4h low, 1d low
            & ((rsi_3_1d_gt_20) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_gt_20) | (stochrsi_k_4h_gt_20))
            # 1d down move, 15m uptrend, 1d low
            & ((rsi_3_1d_gt_20) | (cmf_20_15m_lt_0_10) | (aroonu_14_1d_gt_0))
            # 1d down move, 1d low, 4h oversold
            & ((rsi_3_1d_gt_20) | (stochrsi_k_1d_gt_10) | (roc_9_4h_gt_neg_30))
            # 1d down move, 15m & 1h & 1d low
            & ((rsi_3_1d_gt_25) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_20))
            # 1d down move, 1h low, 4h low
            & ((rsi_3_1d_gt_25) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_0) | (stochrsi_k_1h_gt_20))
            # 1d down move, 1h & 4h low, 1d oversold
            & ((rsi_3_1d_gt_25) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_20) | (roc_9_1d_gt_neg_10))
            # 1d down move, 15m & 4h low
            & ((rsi_3_1d_gt_25) | (stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_10))
            # 1d down move, 15m & 1d low
            & ((rsi_3_1d_gt_25) | (stochrsi_k_15m_gt_10) | (stochrsi_k_1d_gt_20))
            # 1d down move, 15m & 1d low
            & ((rsi_3_1d_gt_30) | (stochrsi_k_15m_gt_10) | (stochrsi_k_1d_gt_10))
            # 1d down move, 1h high, 1d low
            & ((rsi_3_1d_gt_30) | (stochrsi_k_1h_lt_70) | (stochrsi_k_1d_gt_20))
            # 1d down move, 1h & 1d low
            & ((rsi_3_1d_gt_40) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_0))
            # 1h & 4h low
            & ((aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_0))
            # 1h high, 4h low
            & ((stochrsi_k_1h_lt_80) | (stochrsi_k_4h_gt_10))
          )

          # Logic — Breakdown below BB lower in downtrend
          short_entry_logic.append(
            (rsi_3 < 20.0)
            & (rsi_3_15m < 35.0)
            & (rsi_14 > 15.0)
            & (rsi_14 < 32.0)
            & (cmf_20 < -0.08)
            & (obv_change_pct_15m < 0.0)
            & (ema_12 < ema_26)
            & (close < bbl_20_2_0)
          )

        # Condition #563 - Dead Cat Bounce mode (Short).
        if short_entry_condition_index == 563:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m still not low enough, 4h up move
            ((rsi_14 < 65.0) | (rsi_3_4h < 35.0))
            # 5m high, 15m down move, 1h up move
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_lt_60) | (aroonu_14 < 80.0))
            # 5m down move, 15m up move, 1h overbought
            & ((rsi_3_15m_lt_70) | (roc_2_1h < 5.0) | (rsi_3 > 30.0))
            # 5m down move, 15m up move, 1d downtrend
            & ((rsi_3_15m_lt_70) | (roc_9_1d_gt_neg_40) | (rsi_3 > 30.0))
            # 15m low, 1h down move & uptrend
            & ((aroonu_14_15m_gt_40) | (rsi_3_1h_gt_45) | (aroonu_14_1h_lt_40))
            # 15m uptrend & still not low enough, 1h down move
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_15m_gt_90) | (rsi_3_1h_gt_50))
            # 15m uptrend, 4h high, 1d low
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 1h up move, 4h low
            & ((rsi_3_1h_lt_50) | (aroonu_14_4h_gt_20) | (stochrsi_k_4h_gt_20))
            # 1h still not low enough, 4h still low
            & ((rsi_14_1h_lt_40) | (rsi_14_4h > 25.0))
            # 1h still bearish
            & (rsi_14_1h < 45.0)
            # 1h still high, 4h & 1d oversold
            & ((stochrsi_k_1h_gt_50) | (roc_9_4h_gt_neg_10) | (roc_9_1d_gt_neg_15))
            # 1h WILLR high
            & (willr_14_1h < -50.0)
            # 15m still high, 4h down move
            & ((rsi_3_4h_gt_15) | (stochrsi_k_15m < 90.0))
            # 4h down move & downtrend
            & ((rsi_3_4h_gt_5) | (roc_9_4h_gt_neg_25))
            # 15m still high & high, 4h down move
            & ((rsi_3_4h_gt_5) | (stochrsi_k_15m_lt_80) | (aroonu_14_15m_lt_80))
            # 4h still not low enough & up move
            & ((rsi_14_4h < 35.0) | (rsi_3_4h < 35.0))
            # 4h still low & still not low enough
            & ((rsi_14_4h > 25.0) | (mfi_14_4h < 40.0))
            # 4h RSI high
            & (rsi_14_4h_lt_40)
            # 4h low, 1d uptrend & oversold
            & ((aroonu_14_4h_gt_20) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_10))
            # 4h uptrend
            & (aroonu_14_4h < 35.0)
            # Context: recent large drop, 4h downtrend
            & (roc_9_4h < -8.0)
            # 1d up move & still high
            & ((rsi_3_1d < 30.0) | (stochrsi_k_1d_lt_40))
            # 1h falling, 4h down move, 1d down move
            & ((rsi_3_1d_gt_10) | (cci_20_change_pct_1h > -35.0) | (rsi_3_4h_gt_20))
            # 1h still not low enough, 4h downtrend, 1d down move
            & ((rsi_3_1d_gt_10) | (roc_9_4h_gt_neg_20) | (rsi_14_1h_lt_40))
            # 4h down move, 1d down move & low
            & ((rsi_3_1d_gt_10) | (stochrsi_k_1d > 5.0) | (rsi_3_4h_gt_40))
            # 1d down move
            & (rsi_3_1d_gt_5)
            # 4h still low, 1d still not low enough
            & ((rsi_14_1d_lt_40) | (rsi_14_4h > 25.0))
            # and the daily is weak with it
            & (rsi_14_1d < 45.0)
            # 1h rising, 1d low
            & ((stochrsi_k_1d > 0.0) | (cci_20_change_pct_1h < -5.0))
            # 1d low & still not low enough
            & ((stochrsi_k_1d > 0.0) | (rsi_14_1d_lt_40))
            # 5m down move, 1d overbought
            & ((roc_9_1d < -5.0) | (rsi_3 > 30.0))
            # 4h still low & low, 1d downtrend
            & ((roc_9_1d_gt_neg_25) | (mfi_14_4h > 20.0) | (stochrsi_k_4h_gt_10) | (aroonu_14_4h_gt_10))
            # 1h high, 1d downtrend
            & ((roc_9_1d_gt_neg_40) | (aroonu_14_1h_lt_40))
            # the day itself is falling, not merely off its high
            & (roc_9_1d_lt_0)
            # 15m uptrend, 1h down move & low
            & ((aroonu_14_15m_lt_80) | (aroonu_14_1h_gt_10) | (rsi_3_1h_gt_65))
          )

          # Logic — Bounce that fails to reclaim resistance
          short_entry_logic.append(
            # the 4h is in a downtrend: a failed bounce only means anything there
            (ema_12_4h < ema_200_4h)
            # bounced into the 55-68 band but no further: strength without a breakout
            & (rsi_14 > 55.0)
            & (rsi_14 < 68.0)
            # still under the 200 EMA, so the bounce is inside a downtrend
            & (close < ema_200)
            # but above the fast EMA, so the bounce is actually happening
            & (close > ema_12)
            # the 5m leg is already rolling over
            & (rsi_3 < 35.0)
            # and the hour is turning down with it: CCI falling, money leaving
            & (cci_20_change_pct_1h < 0.0)
            & (mfi_14_1h < 45.0)
          )

        if short_entry_condition_index == 592:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m low, 15m up move, 1d oversold
            ((aroonu_14_gt_75) | (rsi_3_15m_lt_50) | (roc_9_1d_gt_neg_20))
            # 5m still not low enough, 1h high, 4h uptrend
            & ((stochrsi_k_gt_80) | (stochrsi_k_1h_gt_10) | (aroonu_14_4h_lt_80))
            # 15m down move & low, 1h uptrend
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_60))
            # 15m down move & low, 4h up move
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_gt_10) | (rsi_3_4h_lt_60))
            # 15m down move & uptrend, 4h still high
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_20) | (stochrsi_k_4h_gt_60))
            # 15m & 1h down move, 15m uptrend
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_25) | (rsi_3_1h_gt_20))
            # 15m & 1h up move, 15m low
            & ((rsi_3_15m_lt_60) | (stochrsi_k_15m_gt_20) | (rsi_3_1h_lt_40))
            # 15m up move & still high, 1h low
            & ((rsi_3_15m_lt_60) | (stochrsi_k_15m_gt_30) | (aroonu_14_1h_gt_20))
            # 15m up move, 1h uptrend, 4h down move
            & ((rsi_3_15m_lt_70) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_40))
            # 15m & 1h down move, 15m low
            & ((aroonu_14_15m_gt_0) | (rsi_3_15m_gt_35) | (rsi_3_1h_gt_5))
            # 15m low & still high, 4h up move
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_30) | (rsi_3_4h_lt_80))
            # 15m low & still high, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_50) | (aroonu_14_1d_lt_30))
            # 15m low, 1h uptrend
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_20))
            # 15m uptrend & still high, 1h low
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_40) | (aroonu_14_1h_gt_10))
            # 15m still high, 4h down move & uptrend
            & ((stochrsi_k_15m_gt_30) | (rsi_3_4h_gt_40) | (aroonu_14_4h_lt_75))
            # 1h & 1d down move, 4h low
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_gt_20) | (rsi_3_1d_gt_50))
            # 1h uptrend & low, 4h still not low enough
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_80))
            # 1h & 4h low, 4h down move
            & ((stochrsi_k_1h_gt_20) | (aroonu_14_4h_gt_50) | (rsi_3_4h_gt_60))
          )

          # Logic
          short_entry_logic.append(
            # embedded down-regime + quad-overbought bounce + 5-candle shift kink
            (stoch_60_10 < 20.0)
            & (stoch_9_3 > 80.0)
            & (stoch_14_3 > 80.0)
            & (stoch_4_4 > 80.0)
            & (close > np_shift(close, 5))
            & (stoch_9_3 < np_shift(stoch_9_3, 5))
          )

        # Condition #593 - Quad-rotation TRUE pivot divergence (Short, experimental).
        if short_entry_condition_index == 593:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m & 15m low, 4h still not low enough
            ((aroonu_14_gt_75) | (aroonu_14_15m_gt_0) | (stochrsi_k_4h_gt_70))
            # 15m & 1h down move, 4h low
            & ((rsi_3_15m_lt_55) | (rsi_3_1h_gt_20) | (aroonu_14_4h_gt_20))
            # 15m down move & still not low enough, 4h uptrend
            & ((rsi_3_15m_lt_55) | (stochrsi_k_15m_gt_80) | (roc_9_4h_lt_5))
            # 15m down move & uptrend, 1h low
            & ((rsi_3_15m_lt_75) | (aroonu_14_15m_lt_20) | (aroonu_14_1h_gt_10))
            # 15m down move & low, 1h up move
            & ((aroonu_14_15m_gt_0) | (rsi_3_15m_gt_45) | (rsi_3_1h_lt_40))
            # 15m up move & low, 1h down move
            & ((aroonu_14_15m_gt_0) | (rsi_3_15m_lt_70) | (rsi_3_1h_gt_10))
            # 15m uptrend, 1d down move & low
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1d_gt_50) | (rsi_3_1d_gt_50))
            # 15m & 1d low, 1h uptrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_30) | (stochrsi_k_1d_gt_20))
            # 15m not rich, 4h trend not up
            & ((stochrsi_k_15m_gt_50) | (aroonu_14_4h_gt_50))
            # 1h low & high, 1d uptrend
            & ((aroonu_14_1h_gt_40) | (stochrsi_k_1h_gt_10) | (roc_9_1d_lt_0))
          )

          # Logic
          short_entry_logic.append(
            # embedded down-regime + quad-overbought
            (stoch_60_10 < 20.0)
            & (stoch_9_3 > 80.0)
            & (stoch_14_3 > 80.0)
            & (stoch_4_4 > 80.0)
            # price HIGHER-HIGH across swing windows while stoch makes a LOWER-HIGH (real divergence)
            & (quad_high_max_12 > np_shift(quad_high_max_12, 12))
            & (quad_s93_max_12 < np_shift(quad_s93_max_12, 12))
          )

        # Condition #605 - Williams %R snapback (Short, experimental — mirror).
        if short_entry_condition_index == 605:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m up move, 1h downtrend, 4h downtrend
            ((rsi_3_lt_90) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_30))
            # 5m downtrend, 15m uptrend, 4h on the floor
            & ((aroonu_14_gt_75) | (aroonu_14_15m_lt_90) | (stochrsi_k_4h_gt_10))
            # 5m low & still not low enough, 1d still high
            & ((aroonu_14_gt_75) | (stochrsi_k_gt_80) | (stochrsi_k_1d_gt_30))
            # 5m still not low enough, 15m uptrend, 4h up move
            & ((stochrsi_k_gt_80) | (aroonu_14_15m_lt_90) | (rsi_3_4h_lt_70))
            # 5m still not low enough, 4h & 1d low
            & ((stochrsi_k_gt_80) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_gt_20))
            # 5m washed out, 15m up move & washed out
            & ((stochrsi_k_gt_80) | (rsi_3_15m_lt_85) | (stochrsi_k_15m_gt_70))
            # 5m washed out, 15m washed out, 1h washed out
            & ((stochrsi_k_gt_80) | (stochrsi_k_15m_gt_90) | (stochrsi_k_1h_gt_80))
            # 15m up move & washed out, 4h up move
            & ((rsi_3_15m_lt_80) | (stochrsi_k_15m_gt_40) | (rsi_3_4h_lt_70))
            # 15m up move & washed out, 1h downtrend
            & ((rsi_3_15m_lt_80) | (stochrsi_k_15m_gt_60) | (aroonu_14_1h_gt_20))
            # 15m up move & uptrend, 4h up move
            & ((rsi_3_15m_lt_85) | (aroonu_14_15m_lt_100) | (rsi_3_4h_lt_80))
            # 15m down move, 4h low & high
            & ((rsi_3_15m_lt_85) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_10))
            # 15m up move & overbought, 4h downtrend, 1d on the floor
            & ((rsi_3_15m_lt_85) | (aroonu_14_4h_gt_20) | (stochrsi_k_1d_gt_10) | (stochrsi_k_15m < 85.0))
            # 5m washed out, 15m up move & washed out, 1h downtrend
            & ((rsi_3_15m_lt_85) | (stochrsi_k_15m_gt_70) | (stochrsi_k > 85.0) | (aroonu_14_1h > 90.0))
            # 15m up move & washed out, 1h downtrend
            & ((rsi_3_15m_lt_85) | (stochrsi_k_15m_gt_80) | (aroonu_14_1h_gt_20))
            # 15m up move, 4h low, 1d still high
            & ((rsi_3_15m_lt_90) | (aroonu_14_4h_gt_20) | (stochrsi_k_1d_gt_30))
            # 15m up move & overbought, 1d daily change low & uptrend
            & ((rsi_3_15m_lt_90) | (change_pct_1d_gt_neg_10) | (aroonu_14_1d < 25.0) | (stochrsi_k_15m < 95.0))
            # 5m washed out & up move, 15m up move, 4h -DI low
            & ((rsi_3_15m_lt_90) | (minus_di_14_4h > 20.0) | (stochrsi_k > 85.0) | (rsi_3 < 75.0))
            # 15m up move, 1h up move, 4h up move
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_90) | (rsi_3_4h_lt_70))
            # 15m up move & washed out, 1h down move, 1d still high
            & ((rsi_3_15m_lt_90) | (stochrsi_k_15m_gt_90) | (stochrsi_k_1d < 65.0) | (rsi_3_1h > 80.0))
            # 15m uptrend, 1d uptrend & washed out
            & ((aroonu_14_15m_lt_100) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d_gt_50))
            # 15m uptrend & still high, 4h low
            & ((aroonu_14_15m_lt_100) | (stochrsi_k_15m_gt_60) | (stochrsi_k_4h_gt_20))
            # 15m uptrend, 4h downtrend & on the floor
            & ((aroonu_14_15m_lt_90) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_10))
            # 15m washed out, 4h washed out, 1d downtrend
            & ((stochrsi_k_15m_gt_50) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_30))
            # 15m washed out, 1h uptrend, 4h up move
            & ((stochrsi_k_15m_gt_70) | (aroonu_14_1h_lt_75) | (rsi_3_4h_lt_80))
            # 15m still not low enough, 1d low
            & ((stochrsi_k_15m_gt_80) | (aroonu_14_1d_gt_20) | (stochrsi_k_1d_gt_20))
            # 1h up move & still not low enough, 4h still high
            & ((rsi_3_1h_lt_80) | (stochrsi_k_1h_gt_90) | (stochrsi_k_4h_gt_30))
            # 1h down move & still not low enough, 4h up move
            & ((rsi_3_1h_lt_85) | (stochrsi_k_1h_gt_90) | (rsi_3_4h_lt_70))
            # 5m overbought, 15m up move, 1h downtrend, 4h downtrend
            & ((aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_30) | (stochrsi_k < 95.0) | (rsi_3_15m_lt_90))
            # 1h & 4h low, 1d uptrend
            & ((aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 1h still not low enough, 4h low & still high
            & ((stochrsi_k_1h_gt_80) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_40))
            # 4h up move & uptrend, 1d still high
            & ((rsi_3_4h_lt_70) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_gt_50))
            # 4h up move & uptrend, 1d downtrend
            & ((rsi_3_4h_lt_80) | (aroonu_14_4h_lt_20) | (aroonu_14_1d_gt_30))
          )

          # Logic
          short_entry_logic.append(
            # yesterday was a clearly weak day: fade the pop in the direction of the day
            (change_pct_1d < -5.0)
            # but not a capitulated day: a pop there is the relief squeeze
            & (rsi_3_1d > 20.0)
            # 1h close crosses INTO the overbought extreme
            & (willr_14_1h > -10.0)
            & (np_shift(willr_14_1h, 12) <= -10.0)
            # 4h trend must agree: the pop is against it
            & (ema_12_4h < ema_200_4h)
            # only below the daily 200 EMA: in a bull market the pop is the trend
            & (close < ema_200_1d)
          )

        # # Condition #620 - Grind mode (Short).
        # if short_entry_condition_index == 620:
        #   # Protections
        #   short_entry_logic.append(num_open_short_grind_mode < self.grind_mode_max_slots)
        #   short_entry_logic.append(is_pair_short_grind_mode)
        #   short_entry_logic.append(df["RSI_3"] <= 40.0)
        #   short_entry_logic.append(rsi_3_15m >= 10.0)
        #   short_entry_logic.append(rsi_3_1h >= 5.0)
        #   short_entry_logic.append(rsi_3_4h >= 5.0)
        #   short_entry_logic.append(rsi_14_1h < 85.0)
        #   short_entry_logic.append(df["RSI_14_4h"] < 85.0)
        #   short_entry_logic.append(rsi_14_1d < 85.0)
        #   short_entry_logic.append(close_max_48 >= (df["close"] * 1.10))

        #   # Logic
        #   short_entry_logic.append(stochrsi_k_gt_80)
        #   short_entry_logic.append(willr_14 > -20.0)
        #   short_entry_logic.append(aroond_14_lt_25)

        # Condition #641 - Top Coins mode (Short).
        if short_entry_condition_index == 641:
          # Protections
          short_entry_logic.append(is_pair_short_top_coins_mode)

          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)

          short_entry_logic.append(rsi_3_1h >= 5.0)
          short_entry_logic.append(rsi_3_4h >= 20.0)
          short_entry_logic.append(rsi_3_1d >= 20.0)
          short_entry_logic.append(rsi_14_1h_gt_20)
          short_entry_logic.append(rsi_14_4h_gt_20)
          short_entry_logic.append(rsi_14_1d_gt_10)
          # 5m down move, 1h still not low enough, 4h high
          short_entry_logic.append((rsi_3_lt_90) | (stochrsi_k_1h_gt_90) | (stochrsi_k_4h_gt_30))
          # 5m down move, 1h high, 4h still not low enough
          short_entry_logic.append((rsi_3_lt_90) | (stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_90))
          # 15m down move, 15m still not low enough, 1h still high
          short_entry_logic.append((rsi_3_15m_lt_95) | (aroond_14_15m_lt_25) | (stochrsi_k_1h_gt_50))
          # 15m & 1h down move, 1d still not low enough
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_95) | (stochrsi_k_1d_gt_70))
          # 15m & 1h down move, 1h still not low enough
          short_entry_logic.append((rsi_3_15m_lt_85) | (rsi_3_1h_lt_85) | (stochrsi_k_1h_gt_70))
          # 15m down move, 1h high, 4h still high
          short_entry_logic.append((rsi_3_15m_lt_85) | (stochrsi_k_1h_gt_30) | (stochrsi_k_4h_gt_75))
          # 15m & 1h down move, 4h still high
          short_entry_logic.append((rsi_3_15m_lt_80) | (rsi_3_1h_lt_70) | (stochrsi_k_4h_gt_50))
          # 15m down move, 1h still not low enough, 4h still high
          short_entry_logic.append((rsi_3_15m_lt_75) | (stochrsi_k_1h_gt_80) | (stochrsi_k_4h_gt_60))
          # 1h & 4h & 1d down move
          short_entry_logic.append((rsi_3_1h_lt_95) | (rsi_3_4h_lt_90) | (rsi_3_1d_lt_80))
          # 1h & 4h down move, 15m not low enough
          short_entry_logic.append((rsi_3_1h_lt_90) | (rsi_3_4h_lt_90) | (stochrsi_k_15m > 75.0))
          # 1h down move, 1h still not low enough, 4h still high
          short_entry_logic.append((rsi_3_1h_lt_90) | (stochrsi_k_1h_gt_90) | (stochrsi_k_4h_gt_50))
          # 1h & 4h down move, 1h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_85) | (rsi_3_4h_lt_75) | (stochrsi_k_1h_gt_90))
          # 1h & 4h down move, 4h still high
          short_entry_logic.append((rsi_3_1h_lt_85) | (rsi_3_4h_lt_75) | (stochrsi_k_4h_gt_50))
          # 1h & 4h down move, 1h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_80) | (rsi_3_4h_lt_85) | (stochrsi_k_1h_gt_75))
          # 1h & 4h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_80) | (rsi_3_4h_lt_85) | (stochrsi_k_4h_gt_75))
          # 1h down move, 1h & 4h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_80) | (stochrsi_k_1h_gt_90) | (stochrsi_k_4h_gt_70))
          # 4h down move, 15m still high, 1h still not low enough
          short_entry_logic.append((rsi_3_4h_lt_85) | (stochrsi_k_15m_gt_50) | (stochrsi_k_1h_gt_75))
          # 4h down move, 15m & 4h still not low enough
          short_entry_logic.append((rsi_3_4h < 15.0) | (stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_80))

          # Logic
          short_entry_logic.append(rsi_20 > rsi_20_shift_1)
          short_entry_logic.append(rsi_3 > 70.0)
          short_entry_logic.append(aroond_14_lt_25)
          short_entry_logic.append(close > sma_16 * 1.044)

        # Condition #642 - Top Coins mode (Short).
        if short_entry_condition_index == 642:
          # Protections
          short_entry_logic.append(is_pair_short_top_coins_mode)

          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)

          # 5m & 1h & 4h down move
          short_entry_logic.append((rsi_3_lt_90) | (rsi_3_1h_lt_95) | (rsi_3_4h_lt_90))
          # 5m down move, 15m & 4h still high
          short_entry_logic.append((rsi_3_lt_90) | (stochrsi_k_15m_gt_60) | (stochrsi_k_4h_gt_60))
          # 5m down move, 15m still high, 1h high
          short_entry_logic.append((rsi_3 < 85.0) | (aroond_14_15m_lt_50) | (stochrsi_k_1h_gt_20))
          # 15m & 1h down move, 1h still not low enough
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_95) | (stochrsi_k_1h_gt_90))
          # 15m & 1h down move, 1d still not low enough
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_95) | (stochrsi_k_1d_gt_70))
          # 15m strong down move, 4h high
          short_entry_logic.append((rsi_3_15m_lt_95) | (stochrsi_k_4h_gt_20))
          # 15m & 1h down move, 1h still not low enough
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_80) | (stochrsi_k_1h_gt_80))
          # 15m down move, 15m stil high, 1h still not low enough
          short_entry_logic.append((rsi_3_15m_lt_90) | (stochrsi_k_15m_gt_50) | (stochrsi_k_1h_gt_80))
          # 15m down move, 1h & 4h still high
          short_entry_logic.append((rsi_3_15m_lt_90) | (stochrsi_k_1h_gt_60) | (stochrsi_k_4h_gt_60))
          # 15m & 1h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_15m_lt_95) | (rsi_3_1h_lt_70) | (stochrsi_k_4h_gt_50))
          # 15m down move, 15m still not low enough, 4h high
          short_entry_logic.append((rsi_3_15m_lt_85) | (stochrsi_k_15m_gt_80) | (stochrsi_k_4h_gt_20))
          # 15m down move, 4h still high, 1d high
          short_entry_logic.append((rsi_3_15m_lt_85) | (stochrsi_k_4h_gt_60) | (stochrsi_k_1d_gt_30))
          # 15m & 4h down move, 1d still high
          short_entry_logic.append((rsi_3_15m_lt_85) | (rsi_3_4h_lt_75) | (stochrsi_k_1d_gt_50))
          # 15m & 1h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_15m_lt_80) | (rsi_3_1h_lt_80) | (stochrsi_k_4h_gt_70))
          # 15m & 1h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_15m_lt_75) | (rsi_3_1h_lt_75) | (stochrsi_k_4h_gt_70))
          # 15m & 4h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_15m_lt_75) | (rsi_3_4h_lt_75) | (stochrsi_k_4h_gt_80))
          # 15m down move, 1h still high, 4h still high
          short_entry_logic.append((rsi_3_15m_lt_75) | (stochrsi_k_1h_gt_80) | (stochrsi_k_4h_gt_60))
          # 15m down move, 1h still not low enough, 4h high
          short_entry_logic.append((rsi_3_15m_lt_75) | (stochrsi_k_1h_gt_90) | (stochrsi_k_4h_gt_30))
          # 15m down move, 1h high, 4h still not low enough
          short_entry_logic.append((rsi_3_15m_lt_75) | (stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_90))
          # 15m down move, 4h high, 1d stil high
          short_entry_logic.append((rsi_3_15m_lt_75) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_50))
          # 15m & 4h down move, 1h still not low enough
          short_entry_logic.append((rsi_3_15m_lt_70) | (rsi_3_4h_lt_85) | (stochrsi_k_1h_gt_70))
          # 15m & 4h down move, 1h still high
          short_entry_logic.append((rsi_3_15m_lt_70) | (rsi_3_4h_lt_80) | (stochrsi_k_1h_gt_50))
          # 15m down move, 15m still high 4h still high
          short_entry_logic.append((rsi_3_15m_lt_70) | (stochrsi_k_15m_gt_70) | (stochrsi_k_4h_gt_50))
          # 15m down move, 1h still high, 4h high
          short_entry_logic.append((rsi_3_15m_lt_70) | (stochrsi_k_1h_gt_50) | (stochrsi_k_4h_gt_10))
          # 1h & 4h down move, 1h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_95) | (rsi_3_4h_lt_95) | (stochrsi_k_1h_gt_90))
          # 1h & 4h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_95) | (rsi_3_4h_lt_85) | (stochrsi_k_4h_gt_80))
          # 1h & 4h down move, 1h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_90) | (rsi_3_4h_lt_90) | (stochrsi_k_1h_gt_90))
          # 1h & 4h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_90) | (rsi_3_4h_lt_90) | (stochrsi_k_4h_gt_80))
          # 1h & 4h down move, 1h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_90) | (rsi_3_4h_lt_85) | (stochrsi_k_1h > 85.0))
          # 1h & 4h down move, 1d still high
          short_entry_logic.append((rsi_3_1h_lt_90) | (rsi_3_4h_lt_85) | (stochrsi_k_1d_gt_50))
          # 1h & 4h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_85) | (rsi_3_4h_lt_75) | (stochrsi_k_4h > 85.0))
          # 1h down move, 4h still high, 1d high
          short_entry_logic.append((rsi_3_1h_lt_80) | (stochrsi_k_4h_gt_60) | (stochrsi_k_1d_gt_30))
          # 1h & 4h down move, 1h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_80) | (rsi_3_4h_lt_85) | (stochrsi_k_1h_gt_75))
          # 1h & 4h down move, 15m still high
          short_entry_logic.append((rsi_3_1h_lt_80) | (rsi_3_4h_lt_80) | (stochrsi_k_15m_gt_50))
          # 1h & 4h down move, 4h still not low enough
          short_entry_logic.append((rsi_3_1h_lt_75) | (rsi_3_4h_lt_90) | (stochrsi_k_1h_gt_75))
          # 1h & 4h down move, 1h still high
          short_entry_logic.append((rsi_3_1h_lt_70) | (rsi_3_4h_lt_85) | (stochrsi_k_1h_gt_60))
          # 1h down move, 1h still not low enough, 4h still high
          short_entry_logic.append((rsi_3_1h_lt_70) | (stochrsi_k_1h_gt_80) | (stochrsi_k_4h_gt_50))
          # 4h down move, 15m still high, 1h still not low enough
          short_entry_logic.append((rsi_3_4h_lt_85) | (stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_80))
          # 4h down move, 15m still high, 4h still not low enough
          short_entry_logic.append((rsi_3_4h_lt_75) | (stochrsi_k_15m_gt_50) | (stochrsi_k_4h_gt_75))
          # 4h down move, 1h still not low enough, 1d still high
          short_entry_logic.append((rsi_3_4h < 25.0) | (stochrsi_k_1h_gt_70) | (stochrsi_k_1d_gt_50))
          # 15m & 1h still high, 4h high
          short_entry_logic.append((stochrsi_k_15m_gt_70) | (stochrsi_k_1h_gt_70) | (stochrsi_k_4h_gt_10))
          # 15m still high, 1h & 1d high
          short_entry_logic.append((stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_30) | (stochrsi_k_1d_gt_30))
          # 15m & 4h high
          short_entry_logic.append((stochrsi_k_15m_gt_50) | (stochrsi_k_4h_gt_20))
          # 15m high, 1h & 4h still not low enough
          short_entry_logic.append((stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_75) | (stochrsi_k_4h_gt_75))
          # 15m & 4h high
          short_entry_logic.append((stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_30))
          # 1h & 4h still high, 1d high
          short_entry_logic.append((stochrsi_k_1h_gt_70) | (stochrsi_k_4h_gt_70) | (stochrsi_k_1d_gt_50))
          # 1h & 4h high
          short_entry_logic.append((stochrsi_k_1h_gt_30) | (stochrsi_k_4h_gt_10))
          # 1h & 4h high
          short_entry_logic.append((stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_20))
          # 4h & 1d high
          short_entry_logic.append((stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_20))
          # 1d red, 1d high
          short_entry_logic.append((change_pct_1d < 5.0) | (stochrsi_k_1d_gt_20))
          # 1d P&D, 1d high
          short_entry_logic.append((change_pct_1d_lt_10) | (change_pct_1d_shift_288 > -10.0) | (stochrsi_k_1d_gt_50))

          # Logic
          short_entry_logic.append(rsi_4 > 54.0)
          short_entry_logic.append(rsi_20 > rsi_20_shift_1)
          short_entry_logic.append(close > sma_16 * 1.042)

        # Condition #661 - Scalp mode (Short).
        if short_entry_condition_index == 661:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)

          # 15m down move, 15m high
          short_entry_logic.append((rsi_3_15m_lt_75) | (aroond_14_15m_lt_80))
          # 15m & 1h down move, 15m still high
          short_entry_logic.append((rsi_3_15m_lt_70) | (rsi_3_1h_lt_40) | (aroond_14_15m_lt_50))
          # 15m down move, 15m & 4h still high
          short_entry_logic.append((rsi_3_15m_lt_70) | (stochrsi_k_15m_gt_50) | (stochrsi_k_4h_gt_50))
          # 15m & 1h down move, 1h high
          short_entry_logic.append((rsi_3_15m_lt_60) | (rsi_3_1h_lt_60) | (aroond_14_1h_lt_70))
          # 15m & 1h down move, 1h still high
          short_entry_logic.append((rsi_3_15m_lt_60) | (rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_50))
          # 15m & 1h down move, 4h high
          short_entry_logic.append((rsi_3_15m_lt_60) | (rsi_3_1h_lt_40) | (aroond_14_4h_lt_80))
          # 15m & 4h down move, 15m high
          short_entry_logic.append((rsi_3_15m_lt_60) | (rsi_3_4h_lt_60) | (stochrsi_k_15m_gt_50))
          # 15m & 4h down move, 15m high
          short_entry_logic.append((rsi_3_15m_lt_60) | (rsi_3_4h_lt_40) | (stochrsi_k_15m_gt_30))
          # 15m down move, 15m & 1h still high
          short_entry_logic.append((rsi_3_15m_lt_60) | (aroond_14_15m_lt_50) | (stochrsi_k_1h_gt_50))
          # 15m down move, 15m & 1h still high
          short_entry_logic.append((rsi_3_15m_lt_60) | (stochrsi_k_15m_gt_50) | (stochrsi_k_1h_gt_50))
          # 15m down move, 4h still high, 1d overbought
          short_entry_logic.append((rsi_3_15m_lt_60) | (aroond_14_4h_lt_50) | (roc_9_1d_gt_neg_100))
          # 15m down move, 15m high, 4h still high
          short_entry_logic.append((rsi_3_15m_lt_55) | (aroond_14_15m > 30.0) | (stochrsi_k_4h_gt_50))
          # 15m down move, 15m & 1h still high
          short_entry_logic.append((rsi_3_15m_lt_55) | (stochrsi_k_15m > 55.0) | (stochrsi_k_1h_gt_60))
          # 15m down move, 15m still not low enough, 4h high
          short_entry_logic.append((rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_70) | (stochrsi_k_4h_gt_10))
          # 1h down move, 4h still high, 1d high
          short_entry_logic.append((rsi_3_1h_lt_75) | (aroond_14_4h_lt_50) | (stochrsi_k_1d > 10.0))
          short_entry_logic.append((rsi_3_1h_lt_70) | (stochrsi_k_1h_gt_60) | (stochrsi_k_1d > 10.0))
          # 1h & 4h down move, 4h high
          short_entry_logic.append((rsi_3_1h_lt_65) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_20))
          # 1h down move, 15m & 1h still high
          short_entry_logic.append((rsi_3_1h_lt_60) | (stochrsi_k_15m_gt_50) | (stochrsi_k_1h_gt_50))
          # 1h down move, 1h still high, 4h high
          short_entry_logic.append((rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_50) | (stochrsi_k_4h_gt_70))
          # 1h down move, 1h high
          short_entry_logic.append((rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_40))
          # 1h down move, 4h & 1d high
          short_entry_logic.append((rsi_3_1h_lt_60) | (aroond_14_4h_lt_85) | (aroond_14_1d < 90.0))
          # 1h down move, 1h still high, 4h high
          short_entry_logic.append((rsi_3_1h_lt_55) | (aroond_14_1h_lt_50) | (aroond_14_4h < 90.0))
          # 1h down move, 1h high
          short_entry_logic.append((rsi_3_1h_lt_55) | (stochrsi_k_1h_gt_40))
          # 1h & 4h down move, 15m high
          short_entry_logic.append((rsi_3_1h_lt_50) | (rsi_3_4h_lt_40) | (aroond_14_15m_lt_70))
          # 1h down move, 15m still high, 4h high
          short_entry_logic.append((rsi_3_1h_lt_50) | (aroond_14_15m_lt_50) | (aroond_14_4h_lt_80))
          # 1h down move, 15m high, 1h still high
          short_entry_logic.append((rsi_3_1h_lt_50) | (aroond_14_15m_lt_70) | (stochrsi_k_1h_gt_60))
          # 1h down move, 15m still high, 4h high
          short_entry_logic.append((rsi_3_1h_lt_50) | (stochrsi_k_15m_gt_50) | (stochrsi_k_4h_gt_20))
          # 1h down move, 15m & 1h high
          short_entry_logic.append((rsi_3_1h_lt_50) | (stochrsi_k_15m_gt_40) | (aroond_14_1h < 60.0))
          # 1h down move, 1h & 1d high
          short_entry_logic.append((rsi_3_1h_lt_50) | (aroond_14_1h_lt_70) | (stochrsi_k_1d_gt_20))
          # 1h down move, 4h still high, 1d high
          short_entry_logic.append((rsi_3_1h_lt_50) | (stochrsi_k_4h_gt_50) | (stochrsi_k_1d > 10.0))
          # 1h down move, 5m up move, 1h still high
          short_entry_logic.append((rsi_3_1h_lt_40) | (rsi_3 > 40.0) | (stochrsi_k_1h_gt_50))
          # 1h down move, 15m still not low enough, 1h high
          short_entry_logic.append((rsi_3_1h_lt_40) | (stochrsi_k_15m_gt_70) | (aroond_14_1h_lt_70))
          # 1h down move, 15m still not low enough, 1h high
          short_entry_logic.append((rsi_3_1h_lt_40) | (stochrsi_k_15m_gt_70) | (stochrsi_k_1h_gt_40))
          # 1h down move, 15m & 4h still high
          short_entry_logic.append((rsi_3_1h_lt_40) | (stochrsi_k_15m_gt_50) | (stochrsi_k_4h_gt_50))
          # 1h down move, 15m & 1h high
          short_entry_logic.append((rsi_3_1h_lt_40) | (aroond_14_15m_lt_70) | (aroond_14_1h < 90.0))
          # 1h down move, 1h still high, 4h high
          short_entry_logic.append((rsi_3_1h_lt_40) | (aroond_14_1h_lt_50) | (stochrsi_k_4h_gt_10))
          # 1h down move, 1h high, 4h still high
          short_entry_logic.append((rsi_3_1h_lt_40) | (aroond_14_1h < 80.0) | (aroond_14_4h_lt_40))
          # 1h down move, 1h still high, 4h high
          short_entry_logic.append((rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_60) | (aroond_14_4h_lt_70))
          # 1h down move, 1h & 1d high
          short_entry_logic.append((rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_30) | (aroond_14_1d < 90.0))
          # 1h down move, 4h & 1d high
          short_entry_logic.append((rsi_3_1h_lt_40) | (rsi_14_4h_gt_30) | (rsi_14_1d > 20.0))
          # 4h down move, 15m high
          short_entry_logic.append((rsi_3_4h_lt_80) | (aroond_14_15m_lt_80))
          # 4h down move, 1h high
          short_entry_logic.append((rsi_3_4h_lt_75) | (stochrsi_k_1h_gt_20))
          # 4h down move, 1h & 4h still high
          short_entry_logic.append((rsi_3_4h < 65.0) | (stochrsi_k_1h_gt_50) | (aroond_14_4h_lt_50))
          # 4h down move, 15m & 1h high
          short_entry_logic.append((rsi_3_4h_lt_60) | (aroond_14_15m_lt_80) | (stochrsi_k_1h_gt_30))
          # 4h down move, 15m still high, 1h high
          short_entry_logic.append((rsi_3_4h_lt_60) | (stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_20))
          # 4h down move, 1h still high, 4h still moving down
          short_entry_logic.append((rsi_3_4h_lt_60) | (stochrsi_k_1h_gt_50) | (cci_20_change_pct_4h_lt_0))
          # 4h down move, 1h high, 4h still high
          short_entry_logic.append((rsi_3_4h < 55.0) | (aroond_14_1h_lt_70) | (aroond_14_4h_lt_50))
          # 4h down move, 15m high, 4h still high
          short_entry_logic.append((rsi_3_4h_lt_50) | (aroond_14_15m_lt_70) | (stochrsi_k_4h_gt_60))
          # 4h down move, 15m still high, 1h high
          short_entry_logic.append((rsi_3_4h_lt_50) | (stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_30))
          # 4h down move, 15m & 4h still high
          short_entry_logic.append((rsi_3_4h_lt_50) | (stochrsi_k_15m_gt_50) | (aroond_14_4h_lt_50))
          # 4h down move, 15m high, 4h still not low enough
          short_entry_logic.append((rsi_3_4h_lt_50) | (stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_70))
          # 4h down move, 1h still high, 4h high
          short_entry_logic.append((rsi_3_4h_lt_50) | (stochrsi_k_1h_gt_50) | (aroond_14_4h_lt_70))
          # 4h down move, 15m & 4h high
          short_entry_logic.append((rsi_3_4h_lt_40) | (aroond_14_15m_lt_70) | (aroond_14_4h_lt_70))
          # 4h down move, 15m high, 4h still high
          short_entry_logic.append((rsi_3_4h_lt_40) | (aroond_14_15m_lt_80) | (aroond_14_4h_lt_40))
          # 4h down move, 15m still high, 4h high
          short_entry_logic.append((rsi_3_4h_lt_40) | (stochrsi_k_15m_gt_50) | (stochrsi_k_4h_gt_30))
          # 4h down move, 15m & 4h high
          short_entry_logic.append((rsi_3_4h_lt_40) | (stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_40))
          # 4h down move, 1h & 4h high
          short_entry_logic.append((rsi_3_4h_lt_40) | (stochrsi_k_1h_gt_30) | (aroond_14_4h_lt_70))
          # 4h down move, 4h still high, 1d high
          short_entry_logic.append((rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_50) | (stochrsi_k_1d_gt_20))
          # 15m high, 4h high
          short_entry_logic.append((aroond_14_15m_lt_70) | (aroond_14_4h_lt_85))
          # 15m high, 4h still high
          short_entry_logic.append((aroond_14_15m_lt_80) | (stochrsi_k_4h_gt_50))
          # 15m high, 1h still high
          short_entry_logic.append((stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_60))
          # 15m & 4h high
          short_entry_logic.append((stochrsi_k_15m_gt_30) | (aroond_14_4h_lt_70))
          # 15m high, 1h still not low enough
          short_entry_logic.append((stochrsi_k_15m > 20.0) | (stochrsi_k_1h_gt_70))

          # Logic
          short_entry_logic.append(rsi_14 > 50.0)
          short_entry_logic.append(aroond_14_15m < 90.0)
          short_entry_logic.append(stochrsi_k_15m > 10.0)
          if not np.isnan(sma_200[-1]):
            short_entry_logic.append(sma_21_shift_1 > sma_200_shift_1)
            short_entry_logic.append(sma_21 < sma_200)
          else:
            short_entry_logic.append(np.full(len(df), False))
          if not np.isnan(ema_200_1h[-1]):
            short_entry_logic.append(close < ema_200_1h)
          else:
            short_entry_logic.append(np.full(len(df), False))
          if not np.isnan(ema_200_4h[-1]):
            short_entry_logic.append(close < ema_200_4h)
          else:
            short_entry_logic.append(np.full(len(df), False))
          short_entry_logic.append(bbb_20_2_0_1h > 4.0)

        # Condition #662 - 4h opening-range fakeout (Short, experimental).
        if short_entry_condition_index == 662:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)

          # Logic
          short_entry_logic.append(
            # don't fade an upside break out of a washed 4h with money outflow (that break is a real reversal rally)
            ((stochrsi_k_4h > 50.0) | (cmf_20_4h > -0.05))
            # prev 5m candle CLOSED above the day's first-4h range high; current closes back INSIDE
            & (np_shift(close, 1) > orange_h)
            & (close < orange_h)
            & (close > orange_l)
          )

        # Condition #663 - Fib golden-pocket continuation (Short, experimental, protected).
        if short_entry_condition_index == 663:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)

          short_entry_logic.append(
            # Mar/May fast break in 4h trend: +DI4h >= 15, ROC2_4h >= -4, RSI change <= -12; need relief
            ((rsi_14_change_pct > -12) | (plus_di_14_4h < 15) | (roc_2_4h < -4))
            # Aug/Dec no-flow bounce: Aroon-up1h >= 30, CMF15m <= -0.05, WILLR15m <= -35; need one escape
            & ((cmf_20_15m > -0.05) | (willr_14_15m > -35) | aroonu_14_1h_lt_30)
            # Sep/Dec outflow bounce: 1h Aroon-up >= 20, CMF <= -0.15, RSI surge >= 20; need one escape
            & (aroonu_14_1h_lt_20 | (cmf_20_1h > -0.15) | (rsi_14_change_pct_1h < 20))
            # Dec-20 crash rebound: 4h ROC <= -14, 1h RSI acceleration >= 50; need either side softer
            & ((rsi_14_change_pct_1h < 50) | (roc_2_4h > -14))
          )

          # Logic
          # wick-anchored 48-candle impulse: high/low, their order and the retrace depth
          # (0 = at the low, 1 = at the high)
          _fib_high_wick_663 = ta.MAX(high_px, timeperiod=48)
          _fib_low_wick_663 = ta.MIN(low_px, timeperiod=48)
          _fib_high_index_663 = ta.MAXINDEX(high_px, timeperiod=48)
          _fib_low_index_663 = ta.MININDEX(low_px, timeperiod=48)
          _fib_ordered_663 = np.where(_fib_high_index_663 < _fib_low_index_663, 1.0, 0.0)
          _fib_rng_663 = _fib_high_wick_663 - _fib_low_wick_663
          _fib_retr_663 = (close - _fib_low_wick_663) / _fib_rng_663
          _fib_retr_prev_663 = np_shift(_fib_retr_663, 1)
          short_entry_logic.append(
            (ema_12_4h < ema_200_4h)
            # R1 (eyeball): only a clean active downtrend
            & (rsi_14_4h < 45.0)
            & (aroond_14_4h > 70.0)
            # R1: anti-capitulation mirror
            & (roc_9_1d > -30.0)
            & (_fib_rng_663 > (_fib_low_wick_663 * 0.04))
            # The engulfing candle closes back through the wick-anchored pocket's 0.618 edge.
            & (_fib_ordered_663 > 0.5)
            & (_fib_retr_prev_663 >= 0.618)
            & (_fib_retr_prev_663 <= 0.786)
            & (_fib_retr_663 >= 0.5)
            & (_fib_retr_663 < 0.618)
            & (engulf_bear > 0.5)
          )

        # Condition #664 - Squeeze Momentum release (Short, experimental, RAW — mirror).
        if short_entry_condition_index == 664:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m up move, 15m down move, 1d uptrend gone
            ((rsi_3 < 20) | (rsi_3_15m_gt_15) | (aroonu_14_1d_gt_10))
            # 5m up move, 15m still high, 1h high
            & ((rsi_3 < 20) | (stochrsi_k_15m_lt_70) | (aroonu_14_1h_lt_40))
            # 5m down move, 15m high, 1h low
            & ((rsi_3_gt_10) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_gt_30))
            # 5m down move, 1h uptrend, 1d low
            & ((rsi_3_gt_10) | (aroonu_14_1h_lt_20) | (stochrsi_k_1d_gt_20))
            # 5m down move, 1h low, 4h still high
            & ((rsi_3_gt_10) | (stochrsi_k_1h_gt_10) | (stochrsi_k_4h_lt_60))
            # 5m down move, 15m low, 1h up move
            & ((rsi_3_gt_3) | (aroonu_14_15m_gt_40) | (rsi_3_1h_lt_70))
            # 5m & 4h down move, 15m uptrend
            & ((rsi_3_gt_3) | (aroonu_14_15m_lt_60) | (rsi_3_4h_gt_10))
            # 5m down move, 1h & 4h uptrend
            & ((rsi_3_gt_3) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_30))
            # 5m & 15m down move, 4h low
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_10) | (aroonu_14_4h_gt_10))
            # 5m & 1h down move, 1h low
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_25) | (aroonu_14_1h_gt_20))
            # 5m down move, 15m low, 1h down move
            & ((rsi_3_gt_3) | (stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_25))
            # 5m down move, 15m low
            & ((rsi_3_gt_5) | (aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_20))
            # 5m down move, 4h low, 1d uptrend
            & ((rsi_3_gt_5) | (aroonu_14_4h_gt_10) | (roc_9_1d_lt_15))
            # 5m down move, 4h high
            & ((rsi_3_gt_5) | (aroonu_14_4h_lt_80))
            # 5m & 15m & 4h down move
            & ((rsi_3_gt_5) | (rsi_3_15m_gt_10) | (rsi_3_4h_gt_10))
            # 5m & 1h down move, 4h uptrend
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_40))
            # 5m & 1h down move, 1d uptrend
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_20) | (roc_9_1d_lt_10))
            # 5m down move, 1h down move
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_5))
            # 5m down move, 1h up move, 1d low
            & ((rsi_3_gt_5) | (rsi_3_1h_lt_60) | (aroonu_14_1d_gt_20))
            # 5m down move, 15m high, 1d uptrend
            & ((rsi_3_gt_5) | (stochrsi_k_15m_gt_10) | (aroonu_14_1d_lt_80))
            # 5m down move, 15m low, 1d oversold
            & ((rsi_3_gt_5) | (stochrsi_k_15m_gt_20) | (roc_9_1d_gt_neg_30))
            # 5m down move, 1h still high, 1d uptrend
            & ((rsi_3_gt_5) | (stochrsi_k_1h_gt_40) | (aroonu_14_1d_lt_80))
            # 5m uptrend, 15m low, 1d oversold
            & ((aroonu_14_lt_25) | (aroonu_14_15m_gt_30) | (roc_9_1d_gt_neg_20))
            # 5m uptrend, 1d low
            & ((aroonu_14_lt_25) | (aroonu_14_1d_gt_30) | (stochrsi_k_1d_gt_20))
            # 5m uptrend, 1h low
            & ((aroonu_14_lt_25) | (aroonu_14_1h_gt_10) | (stochrsi_k_1h_gt_20))
            # 5m & 1h uptrend, 4h high
            & ((aroonu_14_lt_25) | (aroonu_14_1h_lt_50) | (stochrsi_k_4h_gt_10))
            # 5m uptrend, 15m down move, 4h high
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_20) | (stochrsi_k_4h_gt_10))
            # 5m & 1d uptrend, 15m high
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_10) | (roc_9_1d_lt_10))
            # 5m & 4h uptrend, 1h low
            & ((aroonu_14_lt_30) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_60))
            # 5m uptrend, 1h up move & low
            & ((aroonu_14_lt_30) | (rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_20))
            # 5m & 4h uptrend, 4h down move
            & ((aroonu_14_lt_30) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_20))
            # 5m uptrend, 15m still high, 1h up move
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_30) | (rsi_3_1h_lt_40))
            # 5m uptrend, 15m still high, 4h down move
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_40) | (rsi_3_4h_gt_40))
            # 5m uptrend, 1h still high, 4h up move
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_gt_60) | (rsi_3_4h_lt_50))
            # 5m & 1d uptrend, 4h low
            & ((aroonu_14_lt_30) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_40))
            # 5m & 1d uptrend, 4h still high
            & ((aroonu_14_lt_30) | (stochrsi_k_4h_gt_40) | (aroonu_14_1d_lt_60))
            # 5m still high, 15m high, 1d still high
            & ((stochrsi_k_lt_30) | (aroonu_14_15m_lt_25) | (stochrsi_k_1d_lt_70))
            # 5m still high, 1d uptrend gone, 1d still high
            & ((stochrsi_k_lt_30) | (aroonu_14_1d_gt_20) | (stochrsi_k_1d_lt_50))
            # 5m still high, 15m down move, 1h still high
            & ((stochrsi_k_lt_30) | (rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_50))
            # 15m down move, 1h high, 4h down move
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_25) | (rsi_3_4h_gt_5))
            # 15m down move, 4h uptrend & high
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_10))
            # 15m down move, 4h uptrend, 1d down move
            & ((rsi_3_15m_gt_10) | (roc_9_4h < -8) | (rsi_3_1d_gt_15))
            # 15m down move, 1h down move, 1d low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_25) | (stochrsi_k_1d_gt_10))
            # 15m down move, 1h up move & uptrend
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_lt_50) | (aroonu_14_1h_lt_20))
            # 15m down move, 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m down move, 15m uptrend gone, 4h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_gt_10) | (aroonu_14_4h_lt_60))
            # 15m down move & uptrend, 1d oversold
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_20) | (roc_9_1d_gt_neg_25))
            # 15m down move & uptrend, 4h low
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_gt_10))
            # 15m down move & uptrend, 1h still high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_gt_40))
            # 15m down move, 1h high
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_90))
            # 15m down move, 1d downtrend
            & ((rsi_3_15m_gt_15) | (roc_9_1d_gt_neg_30))
            # 15m down move, 1h downtrend, 4h uptrend gone
            & ((rsi_3_15m_gt_15) | (roc_9_1h_gt_neg_10) | (aroonu_14_4h_gt_10))
            # 15m down move, 1d down move, 1d uptrend gone
            & ((rsi_3_15m_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_1d_gt_10))
            # 15m down move, 1h down move, 4h low
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_gt_5) | (stochrsi_k_4h_gt_10))
            # 15m down move, 1h & 4h up move
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_lt_50) | (rsi_3_4h_lt_50))
            # 15m down move, 1h up move, 1d down move
            & ((rsi_3_15m_gt_15) | (rsi_3_1h_lt_70) | (rsi_3_1d_gt_15))
            # 15m & 4h & 1d down move
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_10))
            # 15m down move, 4h down move, 4h still high
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_15) | (stochrsi_k_4h_lt_30))
            # 15m down move & low, 1d still high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_gt_10) | (stochrsi_k_1d_gt_50))
            # 15m down move, 15m & 4h uptrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_60) | (aroonu_14_4h_lt_60))
            # 15m down move, 4h low, 1d still high
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_gt_10) | (stochrsi_k_1d_gt_40))
            # 15m & 1d down move, 1d uptrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_60))
            # 15m down move, 1h up move & uptrend
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_lt_50) | (aroonu_14_1h_lt_40))
            # 15m down move, 1h up move, 4h down move
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_lt_50) | (rsi_3_4h_gt_20))
            # 15m down move, 1h up move, 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_lt_80) | (stochrsi_k_4h_gt_20))
            # 15m down move, 4h up move & uptrend
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_lt_50) | (aroonu_14_4h_lt_20))
            # 15m down move & low, 1d uptrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_gt_20) | (aroonu_14_1d_lt_30))
            # 15m down move, 15m still high, 1d still high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_lt_70) | (stochrsi_k_1d_lt_70))
            # 15m down move, 1d low & uptrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1d_gt_20) | (roc_9_1d_lt_15))
            # 15m down move, 1h still high, 1d low
            & ((rsi_3_15m_gt_20) | (stochrsi_k_1h_lt_70) | (aroonu_14_1d_gt_10))
            # 15m down move, 1h & 1d uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_60))
            # 15m down move, 4h & 1d uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_50))
            # 15m down move, 1d uptrend
            & ((rsi_3_15m_gt_25) | (roc_9_1d_lt_50))
            # 15m down move, 4h oversold, 1d uptrend
            & ((rsi_3_15m_gt_25) | (roc_9_4h_gt_neg_20) | (aroonu_14_1d_lt_60))
            # 15m down move, 4h still high, 1d downtrend
            & ((rsi_3_15m_gt_25) | (stochrsi_k_4h_lt_70) | (roc_9_1d_gt_neg_15))
            # 15m down move & uptrend, 1d high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_50) | (stochrsi_k_1d_gt_10))
            # 15m down move, 1h up move, 1d uptrend
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_lt_65) | (aroonu_14_1d_lt_80))
            # 15m & 4h down move, 1h up move
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_lt_65) | (rsi_3_4h_gt_40))
            # 15m down move, 4h up move & uptrend
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_lt_40) | (aroonu_14_4h_lt_30))
            # 15m down move, 4h up move, 1d still high
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_lt_60) | (stochrsi_k_1d_gt_40))
            # 15m up move & uptrend, 1h low
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_gt_20))
            # 15m up move & uptrend, 4h high
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_lt_80) | (stochrsi_k_4h_gt_10))
            # 15m up move, 1h uptrend, 4h still high
            & ((rsi_3_15m_lt_50) | (aroonu_14_1h_lt_30) | (stochrsi_k_4h_gt_30))
            # 15m up move, 1h uptrend
            & ((rsi_3_15m_lt_50) | (aroonu_14_1h_lt_70))
            # 15m & 4h up move
            & ((rsi_3_15m_lt_50) | (rsi_3_4h_lt_50))
            # 15m up move, 15m & 1h still high
            & ((rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_40) | (stochrsi_k_1h_gt_40))
            # 15m down move & low, 1h uptrend
            & ((rsi_3_15m_lt_55) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_40))
            # 15m still not low enough, 1d down move & still high
            & ((rsi_14_15m_lt_40) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_70))
            # 15m & 1h low, 1d oversold
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_30) | (roc_9_1d_gt_neg_10))
            # 15m & 1h low, 4h uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_60) | (aroonu_14_4h_lt_90))
            # 15m & 4h low, 1h uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_60) | (stochrsi_k_4h_gt_20))
            # 15m low, 1h uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_80))
            # 15m & 4h low, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_60))
            # 15m low, 1h down move, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_gt_40) | (aroonu_14_1d_lt_80))
            # 15m low, 1h up move, 4h uptrend
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_50) | (aroonu_14_4h_lt_30))
            # 15m low, 4h down move, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (rsi_3_4h_gt_40) | (aroonu_14_1d_lt_30))
            # 15m & 1d low, 4h up move
            & ((aroonu_14_15m_gt_10) | (rsi_3_4h_lt_40) | (aroonu_14_1d_gt_50))
            # 15m low & still high, 4h uptrend
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_30) | (aroonu_14_4h_lt_80))
            # 15m low & still high, 1h oversold
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_50) | (roc_9_1h_gt_neg_10))
            # 15m uptrend gone, 1h still high, 1d still high
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_1h_lt_70) | (stochrsi_k_1d_lt_80))
            # 15m & 1h low, 4h still high
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_10) | (stochrsi_k_4h_gt_30))
            # 15m low, 4h high, 1d down move
            & ((aroonu_14_15m_gt_20) | (aroonu_14_4h_lt_30) | (rsi_3_1d_gt_20))
            # 15m low, 1h up move, 4h down move
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_40) | (rsi_3_4h_gt_20))
            # 15m & 1d low, 1h up move
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_60) | (aroonu_14_1d_gt_20))
            # 15m low, 1h up move
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_70))
            # 15m low, 4h up move & uptrend
            & ((aroonu_14_15m_gt_20) | (rsi_3_4h_lt_50) | (aroonu_14_4h_lt_50))
            # 15m low & still high, 1h down move
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_40) | (rsi_3_1h_gt_20))
            # 15m & 1d low, 4h still high
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_4h_gt_30) | (stochrsi_k_1d_gt_20))
            # 15m low, 1h uptrend, 4h high
            & ((aroonu_14_15m_gt_30) | (aroonu_14_1h_lt_50) | (stochrsi_k_4h_gt_10))
            # 15m low, 1h up move, 4h uptrend
            & ((aroonu_14_15m_gt_30) | (rsi_3_1h_lt_40) | (aroonu_14_4h_lt_40))
            # 15m uptrend gone, 1h up move, 1d uptrend gone
            & ((aroonu_14_15m_gt_30) | (rsi_3_1h_lt_50) | (aroonu_14_1d_gt_10))
            # 15m low, 1h up move, 4h uptrend
            & ((aroonu_14_15m_gt_50) | (rsi_3_1h_lt_70) | (aroonu_14_4h_lt_70))
            # 15m & 1h uptrend, 1d low
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_20) | (stochrsi_k_1d_gt_20))
            # 15m uptrend, 1d up move
            & ((aroonu_14_15m_lt_20) | (rsi_3_1d_lt_80))
            # 15m & 4h uptrend, 1h down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_60))
            # 15m uptrend, 4h & 1d down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_30))
            # 15m uptrend, 4h down move, 1d low
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_gt_30) | (aroonu_14_1d_gt_20))
            # 15m & 4h uptrend, 15m low
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_20))
            # 15m & 1d uptrend, 4h high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_4h_gt_10) | (roc_9_1d_lt_25))
            # 15m & 1h uptrend, 4h down move
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_10))
            # 15m & 1h uptrend, 1h still not low enough
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_70) | (stochrsi_k_1h_gt_80))
            # 15m high, 1h down move, 1d high
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_25) | (aroonu_14_1d_lt_80))
            # 15m high, 1h down move, 4h still high
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_lt_50))
            # 15m & 1d uptrend, 1h low
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_1h_gt_20) | (aroonu_14_1d_lt_80))
            # 15m & 1d uptrend, 4h low
            & ((aroonu_14_15m_lt_40) | (aroonu_14_4h_gt_10) | (roc_9_1d_lt_20))
            # 15m uptrend, 1h down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_20))
            # 15m high, 1h down move, 4h low
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_gt_10))
            # 15m uptrend, 1h down move, 4h low
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_30) | (aroonu_14_4h_gt_10))
            # 15m uptrend, 4h down move & low
            & ((aroonu_14_15m_lt_40) | (rsi_3_4h_gt_20) | (aroonu_14_4h_gt_10))
            # 15m & 1h uptrend, 15m high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_80))
            # 15m uptrend & still high, 1h low
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_50) | (stochrsi_k_1h_gt_20))
            # 15m & 1d uptrend, 1h low
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_gt_10) | (roc_9_1d_lt_20))
            # 15m high, 1d still high & downtrend
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_1d_lt_60) | (roc_9_1d_gt_neg_10))
            # 15m uptrend, 1h low, 4h up move
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_1h_gt_20) | (rsi_3_4h_lt_40))
            # 15m high, 1h uptrend gone, 4h up move
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_gt_10) | (rsi_3_4h_lt_60))
            # 15m uptrend, 1h & 4h low
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m & 1h & 1d uptrend
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_50))
            # 15m & 4h & 1d uptrend
            & ((aroonu_14_15m_lt_60) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_80))
            # 15m high, 1h up move, 4h down move
            & ((aroonu_14_15m_lt_60) | (rsi_3_1h_lt_50) | (rsi_3_4h_gt_10))
            # 15m uptrend & still high, 1h low
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_20))
            # 15m & 1h uptrend, 4h still high
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_70) | (stochrsi_k_4h_gt_50))
            # 15m & 4h uptrend, 4h high
            & ((aroonu_14_15m_lt_70) | (aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_10))
            # 15m uptrend, 4h down move & low
            & ((aroonu_14_15m_lt_70) | (rsi_3_4h_gt_10) | (aroonu_14_4h_gt_20))
            # 15m uptrend & still high, 1h down move
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_15m_gt_50) | (rsi_3_1h_gt_50))
            # 15m uptrend & still high, 1h still not low enough
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_15m_gt_50) | (stochrsi_k_1h_gt_80))
            # 15m uptrend, 15m & 1h still high
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_60))
            # 15m uptrend, 1h still high, 4h up move
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_1h_gt_40) | (rsi_3_4h_lt_40))
            # 15m high, 1h down move, 1d uptrend
            & ((aroonu_14_15m_lt_75) | (rsi_3_1h_gt_45) | (roc_9_1d_lt_0))
            # 15m high, 1h low, 1d uptrend gone
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_1h_gt_60) | (aroonu_14_1d_gt_10))
            # 15m & 1h uptrend, 4h still high
            & ((aroonu_14_15m_lt_80) | (aroonu_14_1h_lt_60) | (stochrsi_k_4h_gt_40))
            # 15m high, 1d uptrend
            & ((aroonu_14_15m_lt_80) | (roc_9_1d_lt_10))
            # 15m high, 1h down move, 1d uptrend gone
            & ((aroonu_14_15m_lt_80) | (rsi_3_1h_gt_50) | (aroonu_14_1d_gt_10))
            # 15m & 1d uptrend, 15m still high
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_15m_gt_40) | (aroonu_14_1d_lt_30))
            # 15m high, 1h low, 1d uptrend gone
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_1h_gt_50) | (aroonu_14_1d_gt_20))
            # 15m high, 4h low, 1d uptrend gone
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_50))
            # 15m & 1d uptrend, 1d still not high enough
            & ((aroonu_14_15m_lt_90) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d_gt_70))
            # 15m & 4h uptrend, 4h low
            & ((aroonu_14_15m_lt_90) | (aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m uptrend & still high, 1h low
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_15m_gt_60) | (aroonu_14_1h_gt_10))
            # 15m high, 1h uptrend, 1d low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_gt_20))
            # 15m high, 4h oversold
            & ((stochrsi_k_15m_gt_10) | (roc_9_4h_gt_neg_20))
            # 15m low, 1h down move
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_10))
            # 15m low, 1h down move & high
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_25) | (aroonu_14_1h_lt_75))
            # 15m high, 1h & 4h up move
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_lt_50) | (rsi_3_4h_lt_70))
            # 15m & 4h low, 1d down move
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_20) | (rsi_3_1d_gt_20))
            # 15m & 1h low, 1h uptrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_50) | (stochrsi_k_1h_gt_20))
            # 15m & 1d low, 4h uptrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_40) | (aroonu_14_1d_gt_20))
            # 15m low, 1d up move
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1d_lt_80))
            # 15m & 1h low, 1h up move
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1h_lt_40) | (aroonu_14_1h_gt_10))
            # 15m & 1d low, 4h down move
            & ((stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_15) | (aroonu_14_1d_gt_30))
            # 15m low, 4h down move, 1d oversold
            & ((stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_40) | (roc_9_1d_gt_neg_15))
            # 15m low, 1h high, 4h down move
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_1h_lt_60) | (rsi_3_4h_gt_25))
            # 15m & 1h still high, 1h uptrend
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_40))
            # 15m still high, 4h uptrend, 1d low
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_4h_lt_70) | (aroonu_14_1d_gt_20))
            # 15m still high, 1d up move & low
            & ((stochrsi_k_15m_gt_30) | (rsi_3_1d_lt_35) | (aroonu_14_1d_gt_30))
            # 15m low, 1h up move, 4h down move
            & ((stochrsi_k_15m_gt_30) | (rsi_3_1h_lt_40) | (rsi_3_4h_gt_20))
            # 15m still high, 4h down move & low
            & ((stochrsi_k_15m_gt_30) | (rsi_3_4h_gt_10) | (aroonu_14_4h_gt_10))
            # 15m still high, 1h up move, 1d low
            & ((stochrsi_k_15m_gt_40) | (rsi_3_1h_lt_50) | (aroonu_14_1d_gt_20))
            # 15m still high, 4h down move, 1d oversold
            & ((stochrsi_k_15m_gt_40) | (rsi_3_4h_gt_35) | (roc_9_1d_gt_neg_15))
            # 15m still high, 1h down move, 1d uptrend
            & ((stochrsi_k_15m_gt_50) | (rsi_3_1h_gt_20) | (roc_9_1d_lt_10))
            # 15m still high, 1h down move, 1d low
            & ((stochrsi_k_15m_gt_50) | (rsi_3_1h_gt_35) | (aroonu_14_1d_gt_20))
            # 15m & 1h still high, 1h up move
            & ((stochrsi_k_15m_gt_50) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_60))
            # 15m still high, 4h down move, 1d uptrend
            & ((stochrsi_k_15m_gt_50) | (rsi_3_4h_gt_10) | (roc_9_1d_lt_10))
            # 15m low, 4h down move, 1d uptrend gone
            & ((stochrsi_k_15m_gt_50) | (rsi_3_4h_gt_15) | (aroonu_14_1d_gt_10))
            # 15m & 1h still high, 1d low
            & ((stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_60) | (aroonu_14_1d_gt_30))
            # 15m still high, 4h still high, 1d still high
            & ((stochrsi_k_15m_lt_40) | (stochrsi_k_4h_lt_40) | (stochrsi_k_1d_lt_60))
            # 15m still high, 1h high, 4h still low
            & ((stochrsi_k_15m_lt_60) | (aroonu_14_1h_lt_25) | (rsi_14_4h_gt_30))
            # 15m still high, 1h still high, 1d still high
            & ((stochrsi_k_15m_lt_60) | (stochrsi_k_1h_lt_40) | (stochrsi_k_1d_lt_80))
            # 15m still high, 1h uptrend gone, 4h still high
            & ((stochrsi_k_15m_lt_70) | (aroonu_14_1h_gt_20) | (stochrsi_k_4h_lt_40))
            # 15m still high, 1h up move, 1d still high
            & ((stochrsi_k_15m_lt_70) | (rsi_3_1h_lt_60) | (stochrsi_k_1d_lt_70))
            # 15m still high, 4h still high, 1d still high
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_4h_lt_40) | (stochrsi_k_1d_lt_20))
            # 15m downtrend, 1h still high, 4h low
            & ((roc_9_15m > -1) | (stochrsi_k_1h_lt_90) | (stochrsi_k_4h_gt_20))
            # 15m oversold, 1h uptrend
            & ((roc_9_15m > -3) | (aroonu_14_1h_lt_80))
            # the 15m oscillator already high, the hourly rsi holding and no daily downtrend
            & ((uo_7_14_28_15m < 55.0) | (rsi_14_change_pct_1h > -5.0) | (aroond_14_1d > 10.0))
            # 1h down move, 1d down move, 1d uptrend
            & ((rsi_3_1h_gt_15) | (rsi_3_1d_gt_50) | (roc_9_1d_lt_0))
            # 1h down move, 1d high, 1d low
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_90) | (stochrsi_k_1d_gt_60))
            # 1h down move & uptrend, 4h oversold
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_30) | (roc_9_4h_gt_neg_10))
            # 1h & 1d down move, 1h uptrend
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_60) | (rsi_3_1d_gt_30))
            # 1h down move, 4h up move
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_lt_40))
            # 1h down move, 4h & 1d low
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_20))
            # 1h down move, 1h uptrend gone, 4h still high
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_gt_20) | (stochrsi_k_4h_lt_70))
            # 1h & 4h down move, 1h uptrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_50) | (rsi_3_4h_gt_15))
            # 1h down move, 1d down move, 1d high
            & ((rsi_3_1h_gt_25) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_90))
            # 1h down move, 4h high, 1d low
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_gt_20))
            # 1h down move, 4h low, 1d uptrend
            & ((rsi_3_1h_gt_30) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_90))
            # 1h down move, 4h up move
            & ((rsi_3_1h_gt_35) | (rsi_3_4h_lt_60))
            # 1h down move, 4h low, 1d uptrend gone
            & ((rsi_3_1h_gt_35) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_10))
            # 1h & 1d down move, 4h uptrend
            & ((rsi_3_1h_gt_40) | (aroonu_14_4h_lt_40) | (rsi_3_1d_gt_30))
            # 1h down move & low, 4h up move
            & ((rsi_3_1h_gt_50) | (aroonu_14_1h_gt_10) | (rsi_3_4h_lt_50))
            # 1h up move, 1d uptrend
            & ((rsi_3_1h_lt_40) | (aroonu_14_1d_lt_80) | (roc_9_1d_lt_0))
            # 1h up move, 4h uptrend, 1d low
            & ((rsi_3_1h_lt_40) | (aroonu_14_4h_lt_20) | (aroonu_14_1d_gt_20))
            # 1h up move, 1h & 1d low
            & ((rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_20) | (stochrsi_k_1d_gt_20))
            # 1h up move & still high, 1d down move
            & ((rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_40) | (rsi_3_1d_gt_10))
            # 1h up move & uptrend, 4h down move
            & ((rsi_3_1h_lt_50) | (aroonu_14_1h_lt_50) | (rsi_3_4h_gt_30))
            # 1h up move, 4h & 1d uptrend
            & ((rsi_3_1h_lt_50) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_80))
            # 1h up move, 4h & 1d uptrend
            & ((rsi_3_1h_lt_50) | (aroonu_14_4h_lt_50) | (roc_9_1d_lt_20))
            # 1h & 1d up move
            & ((rsi_3_1h_lt_50) | (rsi_3_1d_lt_80))
            # 1h up move & still high, 1d low
            & ((rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_40) | (stochrsi_k_1d_gt_20))
            # 1h up move & still high, 4h low
            & ((rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_60) | (stochrsi_k_4h_gt_20))
            # 1h up move, 4h still high, 1d oversold
            & ((rsi_3_1h_lt_50) | (stochrsi_k_4h_gt_30) | (roc_9_1d_gt_neg_25))
            # 1h up move, 1d high, 1d downtrend
            & ((rsi_3_1h_lt_55) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_25))
            # 1h down move & uptrend, 4h high
            & ((rsi_3_1h_lt_55) | (aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_10))
            # 1h & 1d down move, 1d uptrend
            & ((rsi_3_1h_lt_55) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_40))
            # 1h up move, 4h uptrend & high
            & ((rsi_3_1h_lt_60) | (aroonu_14_4h_lt_30) | (stochrsi_k_4h_gt_10))
            # 1h up move, 4h & 1d uptrend
            & ((rsi_3_1h_lt_60) | (aroonu_14_4h_lt_40) | (aroonu_14_1d_lt_80))
            # 1h up move, 1d uptrend
            & ((rsi_3_1h_lt_60) | (roc_9_1d_lt_25))
            # 1h up move & still high, 1d low
            & ((rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_60) | (stochrsi_k_1d_gt_20))
            # 1h up move & still not low enough, 1d low
            & ((rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_80) | (aroonu_14_1d_gt_20))
            # 1h up move, 1d uptrend & low
            & ((rsi_3_1h_lt_70) | (aroonu_14_1d_lt_60) | (stochrsi_k_1d_gt_20))
            # 1h up move, 4h down move
            & ((rsi_3_1h_lt_70) | (rsi_3_4h_gt_40))
            # 1h up move, 4h high
            & ((rsi_3_1h_lt_70) | (stochrsi_k_4h_gt_10))
            # 1h low, 4h down move, 1d uptrend
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_gt_20) | (roc_9_1d_lt_10))
            # 1h low, 4h up move, 1d uptrend
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_lt_40) | (aroonu_14_1d_lt_80))
            # 1h low, 4h up move, 1d uptrend
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_lt_50) | (aroonu_14_1d_lt_60))
            # 1h low, 4h up move & uptrend
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_lt_50) | (aroonu_14_4h_lt_50))
            # 1h low, 1d uptrend & oversold
            & ((aroonu_14_1h_gt_20) | (aroonu_14_1d_lt_60) | (roc_9_1d_gt_neg_30))
            # 1h & 1d low, 1d uptrend
            & ((aroonu_14_1h_gt_20) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d_gt_20))
            # 1h low, 4h uptrend, 1d oversold
            & ((aroonu_14_1h_gt_30) | (aroonu_14_4h_lt_60) | (roc_9_1d_gt_neg_20))
            # 1h low, 4h down move & uptrend
            & ((aroonu_14_1h_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_60))
            # 1h low & still high, 4h up move
            & ((aroonu_14_1h_gt_30) | (stochrsi_k_1h_gt_40) | (rsi_3_4h_lt_50))
            # 1h uptrend, 4h low & high
            & ((aroonu_14_1h_lt_30) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_10))
            # 1h uptrend, 4h oversold, 1d low
            & ((aroonu_14_1h_lt_30) | (roc_9_4h_gt_neg_10) | (aroonu_14_1d_gt_20))
            # 1h uptrend, 4h down move, 1d oversold
            & ((aroonu_14_1h_lt_30) | (rsi_3_4h_gt_30) | (roc_9_1d_gt_neg_30))
            # 1h uptrend, 4h high, 1d low
            & ((aroonu_14_1h_lt_30) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_gt_20))
            # 1h high, 4h & 1d down move
            & ((aroonu_14_1h_lt_40) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_50))
            # 1h uptrend, 4h down move, 1d still high
            & ((aroonu_14_1h_lt_40) | (rsi_3_4h_gt_25) | (stochrsi_k_1d_gt_30))
            # 1h uptrend, 4h low
            & ((aroonu_14_1h_lt_50) | (aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_20))
            # 1h uptrend, 4h down move
            & ((aroonu_14_1h_lt_50) | (rsi_3_4h_gt_10))
            # 1h & 1d uptrend, 4h down move
            & ((aroonu_14_1h_lt_50) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_60))
            # 1h & 1d uptrend, 1d still high
            & ((aroonu_14_1h_lt_60) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d_gt_40))
            # 1h & 1d uptrend, 4h low
            & ((aroonu_14_1h_lt_60) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_lt_80))
            # 1h high & low, 1d overbought
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_20) | (roc_9_1d_lt_0))
            # 1h high, 1h low, 1d downtrend
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_60) | (roc_9_1d_gt_neg_20))
            # 1h uptrend, 4h high
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_4h_gt_10))
            # 1h uptrend, 1d up move
            & ((aroonu_14_1h_lt_70) | (rsi_3_1d_lt_80))
            # 1h & 1d uptrend, 4h up move
            & ((aroonu_14_1h_lt_80) | (rsi_3_4h_lt_60) | (aroonu_14_1d_lt_80))
            # 1h & 1d uptrend, 1d oversold
            & ((aroonu_14_1h_lt_90) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_15))
            # no hourly downtrend, the 4h trend still pointing up and the daily not sold off
            & ((aroond_14_1h > 35.0) | (plus_di_14_4h > 10.0) | (rsi_3_1d < 25.0))
            # 1h & 1d low, 4h uptrend
            & ((stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_40) | (stochrsi_k_1d_gt_20))
            # 1h & 4h low, 4h up move
            & ((stochrsi_k_1h_gt_20) | (rsi_3_4h_lt_40) | (aroonu_14_4h_gt_10))
            # 1h low, 4h up move
            & ((stochrsi_k_1h_gt_20) | (rsi_3_4h_lt_50))
            # 1h low, 4h high, 1d oversold
            & ((stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 1h low, 4h up move, 1d down move
            & ((stochrsi_k_1h_gt_40) | (rsi_3_4h_lt_40) | (rsi_3_1d_gt_25))
            # 1h still high, 4h up move, 1d low
            & ((stochrsi_k_1h_gt_40) | (rsi_3_4h_lt_40) | (stochrsi_k_1d_gt_20))
            # 1h & 4h & 1d low
            & ((stochrsi_k_1h_gt_50) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_10))
            # 1h & 1d still high, 1d down move
            & ((stochrsi_k_1h_gt_60) | (rsi_3_1d_gt_10) | (stochrsi_k_1d_gt_60))
            # 1h still high, 4h up move & high
            & ((stochrsi_k_1h_gt_60) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_10))
            # 1h still not low enough, 4h up move, 1d low
            & ((stochrsi_k_1h_gt_80) | (rsi_3_4h_lt_60) | (stochrsi_k_1d_gt_20))
            # 1h still high, 4h downtrend, 1d still high
            & ((stochrsi_k_1h_lt_80) | (roc_9_4h_gt_neg_10) | (stochrsi_k_1d_lt_60))
            # the hour off its low, the daily money flow gone and the hour not falling
            & ((willr_14_1h > -80.0) | (mfi_14_1d > 45.0) | (roc_9_1h < -1.0))
            # 15m at the floor, 1h money flowing out, 15m not oversold
            & ((mfi_14_1h > 35.0) | (willr_14_15m > -75.0) | (rsi_14_15m < 45.0))
            # 4h & 1d down move, 1d uptrend
            & ((rsi_3_4h_gt_10) | (rsi_3_1d_gt_20) | (roc_9_1d_lt_0))
            # 4h down move, 4h uptrend gone, 1d uptrend
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_gt_10) | (roc_9_1d_lt_0))
            # 4h down move, 4h high
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_60))
            # 4h & 1d down move, 1d still high
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_25) | (stochrsi_k_1d_lt_30))
            # 4h down move, 1d down move, 1d uptrend
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_35) | (roc_9_1d_lt_20))
            # 4h down move, 1d uptrend & still high
            & ((rsi_3_4h_gt_35) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d_gt_60))
            # 4h down move, 1d uptrend
            & ((rsi_3_4h_gt_5) | (roc_9_1d_lt_0))
            # 4h & 1d up move, 1d still high
            & ((rsi_3_4h_lt_40) | (rsi_3_1d_lt_35) | (stochrsi_k_1d_gt_30))
            # 4h up move, 1d down move & uptrend
            & ((rsi_3_4h_lt_50) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_80))
            # 4h up move & uptrend, 1d low
            & ((rsi_3_4h_lt_60) | (aroonu_14_4h_lt_30) | (stochrsi_k_1d_gt_20))
            # 4h up move & uptrend, 1d still high
            & ((rsi_3_4h_lt_60) | (aroonu_14_4h_lt_40) | (stochrsi_k_1d_gt_40))
            # 4h up move & still high, 1d low
            & ((rsi_3_4h_lt_60) | (stochrsi_k_4h_gt_50) | (stochrsi_k_1d_gt_20))
            # the 4h making no new high with its downtrend maxed out and the daily oscillator high
            & ((aroonu_14_4h > 5.0) | (aroond_14_4h < 90.0) | (stochrsi_k_1d_lt_60))
            # the 4h fully exhausted: no new high, stochastic on the floor, money flow gone
            & ((aroonu_14_4h > 5.0) | (stochrsi_k_4h > 5.0) | (mfi_14_4h > 30.0))
            # 4h & 1d low, 1d uptrend
            & ((aroonu_14_4h_gt_30) | (aroonu_14_1d_gt_50) | (roc_9_1d_lt_20))
            # 4h & 1d uptrend, 1d low
            & ((aroonu_14_4h_lt_20) | (aroonu_14_1d_gt_20) | (roc_9_1d_lt_0))
            # 4h high, 1d low
            & ((aroonu_14_4h_lt_30) | (aroonu_14_1d_gt_30) | (stochrsi_k_1d_gt_10))
            # 4h uptrend & low, 1d down move
            & ((aroonu_14_4h_lt_30) | (stochrsi_k_4h_gt_20) | (rsi_3_1d_gt_30))
            # 4h high, 4h still high
            & ((aroonu_14_4h_lt_30) | (stochrsi_k_4h_lt_90))
            # 4h uptrend & low, 1d still high
            & ((aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_40))
            # 4h uptrend, 1d up move
            & ((aroonu_14_4h_lt_60) | (rsi_3_1d_lt_80))
            # 4h high, 1d uptrend
            & ((aroonu_14_4h_lt_80) | (roc_9_1d_lt_10))
            # 4h not bouncing, or 1d not recovered
            & ((stochrsi_k_4h_lt_50) | (rsi_14_1d_lt_50))
            # 4h low, 1d uptrend gone, 1d uptrend
            & ((stochrsi_k_4h_gt_10) | (aroonu_14_1d_gt_10) | (roc_9_1d_lt_10))
            # 4h high, 1d down move & uptrend
            & ((stochrsi_k_4h_gt_10) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_0))
            # 4h low, 1d uptrend & still high
            & ((stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_gt_40))
            # 4h low, 1d down move & uptrend
            & ((stochrsi_k_4h_gt_20) | (rsi_3_1d_gt_40) | (aroonu_14_1d_lt_40))
            # 4h momentum low, 1d without a recent high, 15m without a fresh low
            & ((stochrsi_k_4h_lt_50) | (aroonu_14_1d > 15.0) | (aroond_14_15m > 0.0))
            # 1d down move & uptrend
            & ((rsi_3_1d_gt_20) | (aroonu_14_1d_lt_80))
            # 1d up move & low
            & ((rsi_3_1d_lt_80) | (aroonu_14_1d_gt_50))
            # 1d low & still high & uptrend
            & ((aroonu_14_1d_gt_50) | (stochrsi_k_1d_gt_30) | (roc_9_1d_lt_10))
            # no daily downtrend, the daily oscillator at its ceiling and the 4h one on the floor
            & ((aroond_14_1d > 5.0) | (stochrsi_k_1d < 85.0) | (stochrsi_k_4h > 5.0))
            # the daily oscillator up at its ceiling while 4h money is already leaving
            & ((stochrsi_k_1d_lt_60) | (cmf_20_4h_gt_neg_0_10) | (mfi_14_1h < 65.0))
            # 1d still high, 1d downtrend
            & ((stochrsi_k_1d_lt_70) | (roc_9_1d_gt_neg_20))
            # 4h money still flowing in, 1d not collapsed, 4h stochastic at the floor
            & ((cmf_20_4h_lt_0_15) | (roc_9_1d_gt_neg_10) | (stochrsi_k_4h_gt_20))
            # 1d strong down move, or 4h not bouncing
            & ((roc_9_1d < -10.0) | (rsi_3_4h_lt_50))
            # 1d down move, 1d not high, 1d not overbought
            & ((roc_9_1d_gt_neg_30) | (rsi_14_1d_gt_60) | (stochrsi_k_1d_gt_70))
          )

          # Logic
          short_entry_logic.append(
            (np_shift(sqz_on, 1) > 0.5)
            & (sqz_on < 0.5)
            & (np_shift(sqz_cnt_24, 1) >= 12.0)
            # expansion direction: close breaks through the lower band
            & (close < bbl_20_2_0)
            # the 4h is falling into the release — a coil breaking against a rising 4h is a fake one
            & (roc_9_4h < 0.0)
          )

        # Condition #665 - Engulfing continuation (Short, experimental, RAW — mirror).
        if short_entry_condition_index == 665:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m down move, 1d oversold
            ((rsi_3_gt_10) | (roc_9_1d_gt_neg_40))
            # 5m down move, 15m & 1h still high
            & ((rsi_3_gt_10) | (stochrsi_k_15m_gt_40) | (stochrsi_k_1h_gt_50))
            # 5m down move, 1h high, 1d oversold
            & ((rsi_3_gt_10) | (stochrsi_k_1h_gt_10) | (roc_9_1d_gt_neg_30))
            # 5m down move, 15m uptrend, 1h oversold
            & ((rsi_3_gt_15) | (aroonu_14_15m_lt_20) | (roc_9_1h_gt_neg_10))
            # 5m down move, 15m uptrend & high
            & ((rsi_3_gt_15) | (aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_10))
            # 5m & 1d down move, 1d uptrend
            & ((rsi_3_gt_15) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_50))
            # 5m & 1h & 1d down move
            & ((rsi_3_gt_15) | (rsi_3_1h_gt_35) | (rsi_3_1d_gt_15))
            # 5m & 1h down move, 1h oversold
            & ((rsi_3_gt_15) | (rsi_3_1h_gt_5) | (roc_9_1h_gt_neg_15))
            # 5m down move, 1h up move & still high
            & ((rsi_3_gt_15) | (rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_40))
            # 5m & 4h down move, 15m low
            & ((rsi_3_gt_15) | (stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_15))
            # 5m down move, 15m still high, 1h low
            & ((rsi_3_gt_15) | (stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_20))
            # 5m down move, 15m still high, 4h high
            & ((rsi_3_gt_15) | (stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_10))
            # 5m & 4h down move, 15m still high
            & ((rsi_3_gt_15) | (stochrsi_k_15m_gt_40) | (rsi_3_4h_gt_10))
            # 5m up move, 15m uptrend, 4h low
            & ((rsi_3_lt_40) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_gt_0))
            # 5m up move, 15m uptrend
            & ((rsi_3_lt_40) | (aroonu_14_15m_lt_60))
            # 5m up move, 1d uptrend
            & ((rsi_3_lt_40) | (aroonu_14_1d_lt_30))
            # 5m up move, 1h low & high
            & ((rsi_3_lt_40) | (aroonu_14_1h_gt_0) | (stochrsi_k_1h_gt_10))
            # 5m up move, 1h & 4h uptrend
            & ((rsi_3_lt_40) | (aroonu_14_1h_lt_25) | (aroonu_14_4h_lt_30))
            # 5m up move, 1h uptrend & high
            & ((rsi_3_lt_40) | (aroonu_14_1h_lt_30) | (stochrsi_k_1h_gt_10))
            # 5m up move, 1h uptrend
            & ((rsi_3_lt_40) | (aroonu_14_1h_lt_40))
            # 5m up move, 4h low, 1d oversold
            & ((rsi_3_lt_40) | (aroonu_14_4h_gt_0) | (roc_9_1d_gt_neg_20))
            # 5m up move & uptrend, 1d down move
            & ((rsi_3_lt_40) | (aroonu_14_lt_30) | (rsi_3_1d_gt_10))
            # 5m up move & uptrend, 1h down move
            & ((rsi_3_lt_40) | (aroonu_14_lt_30) | (rsi_3_1h_gt_30))
            # 5m up move, 1d uptrend
            & ((rsi_3_lt_40) | (roc_9_1d_lt_0))
            # 5m up move, 15m & 1d down move
            & ((rsi_3_lt_40) | (rsi_3_15m_gt_30) | (rsi_3_1d_gt_10))
            # 5m up move, 1h & 1d down move
            & ((rsi_3_lt_40) | (rsi_3_1h_gt_5) | (rsi_3_1d_gt_10))
            # 5m up move, 4h down move & low
            & ((rsi_3_lt_40) | (rsi_3_4h_gt_20) | (aroonu_14_4h_gt_0))
            # 5m & 4h up move
            & ((rsi_3_lt_40) | (rsi_3_4h_lt_40))
            # 5m up move, 15m & 1h low
            & ((rsi_3_lt_40) | (stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_0))
            # 5m up move, 15m low, 4h uptrend
            & ((rsi_3_lt_40) | (stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_20))
            # 5m up move, 15m low, 1h high
            & ((rsi_3_lt_40) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_10))
            # 5m up move, 15m still high, 1h down move
            & ((rsi_3_lt_40) | (stochrsi_k_15m_gt_30) | (rsi_3_1h_gt_10))
            # 5m up move, 15m low, 1h uptrend
            & ((rsi_3_lt_46) | (aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_20))
            # 5m & 1h up move, 15m low
            & ((rsi_3_lt_46) | (aroonu_14_15m_gt_20) | (rsi_3_1h_lt_40))
            # 5m up move, 15m uptrend, 4h low
            & ((rsi_3_lt_46) | (aroonu_14_15m_lt_20) | (aroonu_14_4h_gt_0))
            # 5m up move, 15m uptrend
            & ((rsi_3_lt_46) | (aroonu_14_15m_lt_40))
            # 5m up move, 1h low, 1d oversold
            & ((rsi_3_lt_46) | (aroonu_14_1h_gt_10) | (roc_9_1d_gt_neg_30))
            # 5m up move, 4h uptrend
            & ((rsi_3_lt_46) | (aroonu_14_4h_lt_30))
            # 5m up move, 15m down move, 4h low
            & ((rsi_3_lt_46) | (rsi_3_15m_gt_35) | (aroonu_14_4h_gt_10))
            # 5m up move, 15m low
            & ((rsi_3_lt_50) | (aroonu_14_15m_gt_20))
            # 5m & 15m up move
            & ((rsi_3_lt_50) | (rsi_3_15m < 35))
            # 5m up move, 1h down move
            & ((rsi_3_lt_50) | (rsi_3_1h_gt_10))
            # the base still strong, the 15m not down and the daily making new highs
            & ((rsi_20 < 45.0) | (rsi_3_15m_gt_25) | (aroonu_14_1d_lt_30))
            # money already leaving the base, the daily stochastic not yet on the floor and the hour topped out
            & ((mfi_14 < 40.0) | (stochrsi_k_1d_lt_30) | (stochrsi_k_1h_lt_60))
            # 5m uptrend, 15m low
            & ((aroonu_14_lt_25) | (aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_20))
            # 5m & 15m uptrend, 4h oversold
            & ((aroonu_14_lt_25) | (aroonu_14_15m_lt_20) | (roc_9_4h_gt_neg_25))
            # 5m & 15m uptrend, 1h down move
            & ((aroonu_14_lt_25) | (aroonu_14_15m_lt_30) | (rsi_3_1h_gt_25))
            # 5m & 15m uptrend, 4h high
            & ((aroonu_14_lt_25) | (aroonu_14_15m_lt_30) | (stochrsi_k_4h_gt_10))
            # 5m uptrend, 1h & 4h low
            & ((aroonu_14_lt_25) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_0))
            # 5m & 4h uptrend, 1h low
            & ((aroonu_14_lt_25) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_lt_30))
            # 5m & 1h uptrend, 4h down move
            & ((aroonu_14_lt_25) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_25))
            # 5m & 1h uptrend, 1d down move
            & ((aroonu_14_lt_25) | (aroonu_14_1h_lt_60) | (rsi_3_1d_gt_25))
            # 5m & 4h & 1d uptrend
            & ((aroonu_14_lt_25) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_40))
            # 5m uptrend, 15m & 4h down move
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_10) | (rsi_3_4h_gt_5))
            # 5m uptrend, 15m down move, 1h high
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_15) | (stochrsi_k_1h_gt_10))
            # 5m & 1d uptrend, 15m down move
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_20) | (aroonu_14_1d_lt_30))
            # 5m & 1h uptrend, 15m down move
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_20) | (aroonu_14_1h_lt_25))
            # 5m & 1h uptrend, 1h down move
            & ((aroonu_14_lt_25) | (rsi_3_1h_gt_10) | (aroonu_14_1h_lt_20))
            # 5m & 1h uptrend, 1h down move
            & ((aroonu_14_lt_25) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_40))
            # 5m uptrend, 1h up move & low
            & ((aroonu_14_lt_25) | (rsi_3_1h_lt_60) | (aroonu_14_1h_gt_10))
            # 5m uptrend, 4h up move, 1d low
            & ((aroonu_14_lt_25) | (rsi_3_4h_lt_40) | (aroonu_14_1d_gt_10))
            # 5m uptrend, 4h up move & low
            & ((aroonu_14_lt_25) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_20))
            # 5m uptrend, 15m still high, 1h low
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_30) | (aroonu_14_1h_gt_0))
            # 5m uptrend, 15m still high, 1d oversold
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_30) | (roc_9_1d_gt_neg_20))
            # 5m & 1d uptrend, 15m still high
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_40) | (aroonu_14_1d_lt_40))
            # 5m uptrend, 15m still high, 4h down move
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_40) | (rsi_3_4h_gt_20))
            # 5m uptrend, 15m still high, 1h high
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_40) | (stochrsi_k_1h_gt_10))
            # 5m uptrend, 15m still high, 4h low
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_40) | (stochrsi_k_4h_gt_20))
            # 5m uptrend, 15m still high, 1h down move
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_50) | (rsi_3_1h_gt_20))
            # 5m uptrend, 15m still not low enough, 4h down move
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_70) | (rsi_3_4h_gt_5))
            # 5m & 15m uptrend, 1h oversold
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_20) | (roc_9_1h_gt_neg_10))
            # 5m & 15m uptrend, 4h oversold
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_20) | (roc_9_4h_gt_neg_15))
            # 5m & 15m uptrend, 1h down move
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_20) | (rsi_3_1h_gt_10))
            # 5m & 15m uptrend, 4h down move
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_30) | (rsi_3_4h_gt_15))
            # 5m & 15m uptrend, 1h still high
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_50) | (stochrsi_k_1h_gt_30))
            # 5m uptrend, 1d low & oversold
            & ((aroonu_14_lt_30) | (aroonu_14_1d_gt_10) | (roc_9_1d_gt_neg_30))
            # 5m & 1d uptrend
            & ((aroonu_14_lt_30) | (aroonu_14_1d_lt_70))
            # 5m uptrend, 1h & 1d low
            & ((aroonu_14_lt_30) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_0))
            # 5m uptrend, 1h & 4h low
            & ((aroonu_14_lt_30) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_10))
            # 5m uptrend, 1h low, 1d down move
            & ((aroonu_14_lt_30) | (aroonu_14_1h_gt_0) | (rsi_3_1d_gt_15))
            # 5m uptrend, 1h low, 1d high
            & ((aroonu_14_lt_30) | (aroonu_14_1h_gt_0) | (stochrsi_k_1d_gt_10))
            # 5m & 1h uptrend, 4h still high
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_40) | (stochrsi_k_4h_gt_30))
            # 5m & 4h uptrend, 1d high
            & ((aroonu_14_lt_30) | (aroonu_14_4h_lt_40) | (stochrsi_k_1d_gt_10))
            # 5m uptrend, 1h oversold, 4h low
            & ((aroonu_14_lt_30) | (roc_9_1h_gt_neg_10) | (aroonu_14_4h_gt_0))
            # 5m uptrend, 15m down move, 1d low
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_10) | (aroonu_14_1d_gt_10))
            # 5m uptrend, 15m down move, 1d oversold
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_15) | (roc_9_1d_gt_neg_25))
            # 5m uptrend, 15m down move, 1h still high
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_25) | (stochrsi_k_1h_gt_50))
            # 5m uptrend, 15m down move, 1d up move
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_30) | (rsi_3_1d_lt_35))
            # 5m uptrend, 1d down move & low
            & ((aroonu_14_lt_30) | (rsi_3_1d_gt_5) | (aroonu_14_1d_gt_10))
            # 5m uptrend, 1h down move, 1d up move
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_10) | (rsi_3_1d_lt_35))
            # 5m uptrend, 1h & 1d up move
            & ((aroonu_14_lt_30) | (rsi_3_1h_lt_40) | (rsi_3_1d_lt_35))
            # 5m uptrend, 1h down move, 4h low
            & ((aroonu_14_lt_30) | (rsi_3_1h_lt_55) | (aroonu_14_4h_gt_20))
            # 5m uptrend, 4h down move & low
            & ((aroonu_14_lt_30) | (rsi_3_4h_gt_20) | (aroonu_14_4h_gt_10))
            # 5m uptrend, 4h up move & still high
            & ((aroonu_14_lt_30) | (rsi_3_4h_lt_50) | (stochrsi_k_4h_gt_30))
            # 5m uptrend, 15m high, 1h low
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_10) | (aroonu_14_1h_gt_10))
            # 5m uptrend, 15m low, 1d high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1d_gt_10))
            # 5m uptrend, 15m & 4h still high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_30))
            # 5m & 1d uptrend, 15m still high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_50) | (aroonu_14_1d_lt_30))
            # 5m uptrend, 15m still high, 1h up move
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_50) | (rsi_3_1h_lt_40))
            # 5m uptrend, 15m & 1h still high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_50) | (stochrsi_k_1h_gt_50))
            # 5m uptrend, 15m still high, 4h low
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_60) | (aroonu_14_4h_gt_0))
            # 5m & 4h uptrend, 15m still high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_60) | (aroonu_14_4h_lt_40))
            # 5m uptrend, 15m still high, 1h high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_10))
            # 5m uptrend, 1d high & oversold
            & ((aroonu_14_lt_30) | (stochrsi_k_1d_gt_10) | (roc_9_1d_gt_neg_20))
            # 5m uptrend, 1h low, 1d down move
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_gt_20) | (rsi_3_1d_gt_10))
            # 5m flat between extremes, 4h still high, 1h already washed
            & ((aroond_14 > 5) | (aroonu_14_lt_25) | (stochrsi_k_4h > 5) | (stochrsi_k_1h < 55))
            # 5m & 4h no new low, 1h momentum spike, 4h collapse already spent
            & ((aroond_14 > 5) | (rsi_3_change_pct_1h < 80) | (aroond_14_4h > 50) | (rsi_3_change_pct_4h > -40))
            # base stochastic on the floor, its 15m oscillator collapsing and no 4h downtrend to carry the short
            & ((stochrsi_k_lt_30) | (uo_7_14_28_change_pct_15m > -15.0) | (aroond_14_4h > 50.0))
            # 5m uptrend, 4h oversold
            & ((roc_9 < 0.5) | (roc_9_4h_gt_neg_20))
            # the base has already fallen hard while the 15m is turning up
            & ((roc_9 > -15.0) | (rsi_3_15m < 35.0))
            # 15m up move & uptrend
            & ((rsi_3_15m < 35) | (aroonu_14_15m_lt_80))
            # 15m up move, 15m & 1h uptrend
            & ((rsi_3_15m < 40) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_25))
            # 15m up move, 1h & 4h uptrend
            & ((rsi_3_15m < 40) | (aroonu_14_1h_lt_20) | (aroonu_14_4h_lt_30))
            # 15m & 1d up move, 4h uptrend
            & ((rsi_3_15m < 40) | (aroonu_14_4h_lt_30) | (rsi_3_1d_lt_35))
            # the 15m has moved up, the hourly cci is rising and its oscillator is already high
            & ((rsi_3_15m < 40.0) | (cci_20_change_pct_1h_lt_0) | (uo_7_14_28_15m < 55.0))
            # the 15m flat, the daily already sold off and 4h money flow still present
            & ((rsi_3_15m < 40.0) | (rsi_3_1d_gt_10) | (mfi_14_4h < 40.0))
            # 15m down move, 15m & 1d low
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_gt_10) | (stochrsi_k_1d_gt_20))
            # 15m & 1h down move, 15m uptrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_25) | (rsi_3_1h_gt_20))
            # 15m down move, 1h & 1d low
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_gt_0) | (aroonu_14_1d_gt_10))
            # 15m & 1d down move, 1h low
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_gt_10) | (rsi_3_1d_gt_5))
            # 15m down move, 1h uptrend, 4h low
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_gt_10))
            # 15m down move, 4h uptrend & high
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_20) | (stochrsi_k_4h_gt_10))
            # 15m & 1h down move, 4h low
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m down move & uptrend, 1h still high
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_50))
            # 15m down move, 15m & 1h uptrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_25))
            # 15m down move, 15m & 4h uptrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_20))
            # 15m down move, 1h uptrend, 1d low
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_gt_10))
            # 15m down move, 4h low, 1d up move
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_gt_10) | (rsi_3_1d_lt_35))
            # 15m & 4h down move, 1d oversold
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m down move, 4h low, 1d oversold
            & ((rsi_3_15m_gt_15) | (stochrsi_k_4h_gt_20) | (roc_9_1d_gt_neg_30))
            # 15m down move & uptrend, 1h high
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_10))
            # 15m down move & uptrend, 1d low
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_50) | (aroonu_14_1d_gt_0))
            # 15m down move, 1h uptrend & high
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_40) | (stochrsi_k_1h_gt_10))
            # the 15m flat, the hour making new highs and the 4h stochastic not yet topped out
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_75) | (stochrsi_k_4h < 75.0))
            # 15m down move, 4h low, 1d up move
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_gt_0) | (rsi_3_1d_lt_35))
            # 15m & 4h down move, 1d uptrend
            & ((rsi_3_15m_gt_20) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_30))
            # 15m down move, 1h low, 1d uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_lt_50))
            # 15m down move, 1h & 1d uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_lt_50))
            # 15m down move, 4h uptrend, 1d high
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_40) | (stochrsi_k_1d_gt_10))
            # 15m & 1d down move, 4h oversold
            & ((rsi_3_15m_gt_25) | (roc_9_4h_gt_neg_10) | (rsi_3_1d_gt_10))
            # 15m & 1d down move, 1d uptrend
            & ((rsi_3_15m_gt_25) | (rsi_3_1d_gt_10) | (aroonu_14_1d_lt_30))
            # 15m down move, 1h up move & oversold
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_lt_40) | (roc_9_1h_gt_neg_10))
            # the 15m flat, the 4h not sold off and the daily stochastic still mid-range
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_lt_40) | (stochrsi_k_1d_lt_30))
            # 15m down move & high, 4h low
            & ((rsi_3_15m_gt_25) | (stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m & 4h down move, 15m still high
            & ((rsi_3_15m_gt_25) | (stochrsi_k_15m_gt_40) | (rsi_3_4h_gt_15))
            # 15m & 1d down move, 1h high
            & ((rsi_3_15m_gt_25) | (stochrsi_k_1h_gt_10) | (rsi_3_1d_gt_25))
            # 15m down move & uptrend
            & ((rsi_3_15m_gt_3) | (aroonu_14_15m_lt_40))
            # 15m & 4h down move, 15m uptrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_20) | (rsi_3_4h_gt_10))
            # 15m down move & uptrend, 1h low
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_gt_20))
            # 15m down move & uptrend, 4h still high
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_70) | (stochrsi_k_4h_gt_40))
            # 15m down move, 1d uptrend & oversold
            & ((rsi_3_15m_gt_30) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_25))
            # 15m & 1h down move, 4h low
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_10) | (aroonu_14_4h_gt_0))
            # 15m & 1h & 4h down move
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_10))
            # 15m & 4h down move, 1h up move
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_lt_40) | (rsi_3_4h_gt_10))
            # 15m down move, 1h up move
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_lt_50))
            # 15m & 4h down move, 1d uptrend
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_gt_5) | (aroonu_14_1d_lt_50))
            # 15m & 1d down move, 4h up move
            & ((rsi_3_15m_gt_30) | (rsi_3_4h_lt_50) | (rsi_3_1d_gt_25))
            # 15m down move, 1h high, 4h low
            & ((rsi_3_15m_gt_30) | (stochrsi_k_1h_gt_10) | (aroonu_14_4h_gt_20))
            # 15m & 4h down move, 1h uptrend
            & ((rsi_3_15m_gt_35) | (aroonu_14_1h_lt_40) | (rsi_3_4h_gt_15))
            # 15m down move, 1h up move & uptrend
            & ((rsi_3_15m_gt_35) | (rsi_3_1h_lt_40) | (aroonu_14_1h_lt_40))
            # 15m down move, 1h low, 4h high
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_gt_10) | (stochrsi_k_4h_gt_10))
            # 15m down move, 1h still high, 1d high
            & ((rsi_3_15m_gt_5) | (stochrsi_k_1h_gt_30) | (stochrsi_k_1d_gt_10))
            # shorting into a washed-out market: 15m money leaving, the daily stochastic on the floor and the daily itself not yet sold off
            & ((mfi_14_15m > 30.0) | (stochk_14_3_3_1d > 30.0) | (rsi_3_1d_lt_35))
            # 15m & 4h low, 1h uptrend
            & ((aroonu_14_15m_gt_0) | (aroonu_14_1h_lt_20) | (aroonu_14_4h_gt_10))
            # 15m & 4h low, 1d uptrend
            & ((aroonu_14_15m_gt_0) | (stochrsi_k_4h_gt_20) | (roc_9_1d_lt_0))
            # 15m & 4h low, 1h uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_25) | (aroonu_14_4h_gt_10))
            # 15m low, 1h & 1d uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_30))
            # no 15m high at all, the 4h making new highs and its stochastic already low
            & ((aroonu_14_15m_gt_10) | (aroonu_14_4h_lt_30) | (stochrsi_k_4h_lt_40))
            # 15m & 4h low, 1h down move
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_4h_gt_20))
            # 15m & 4h low, 1h down move
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_gt_20) | (aroonu_14_4h_gt_0))
            # 15m low, 1h down move & uptrend
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_gt_25) | (roc_9_1h < 0))
            # 15m low, 1h up move, 4h uptrend
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_40) | (aroonu_14_4h_lt_20))
            # 15m low, 1h up move, 1d down move
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_40) | (rsi_3_1d_gt_10))
            # 15m low, 4h up move, 1d down move
            & ((aroonu_14_15m_gt_10) | (rsi_3_4h_lt_40) | (rsi_3_1d_gt_20))
            # 15m low, 1d down move
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_20) | (rsi_3_1d_gt_15))
            # 15m & 1h low, 1d oversold
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_1h_gt_20) | (roc_9_1d_gt_neg_30))
            # 15m low, 1h uptrend, 1d up move
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_50) | (rsi_3_1d_lt_35))
            # 15m low, 1d down move & uptrend
            & ((aroonu_14_15m_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_30))
            # 15m low, 1h up move, 1d uptrend
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_40) | (aroonu_14_1d_lt_30))
            # 15m low, 1h up move & uptrend
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_40) | (aroonu_14_1h_lt_30))
            # 15m & 4h low, 4h down move
            & ((aroonu_14_15m_gt_20) | (rsi_3_4h_gt_15) | (aroonu_14_4h_gt_0))
            # 15m low, 4h up move, 1d down move
            & ((aroonu_14_15m_gt_20) | (rsi_3_4h_lt_40) | (rsi_3_1d_gt_10))
            # 15m low & high, 1d oversold
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_10) | (roc_9_1d_gt_neg_40))
            # 15m low, 1h down move
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_20) | (rsi_3_1h_gt_10))
            # 15m low, 1h uptrend
            & ((aroonu_14_15m_gt_30) | (aroonu_14_1h_lt_80))
            # 15m low, 1h up move
            & ((aroonu_14_15m_gt_30) | (rsi_3_1h_lt_50))
            # 15m low, 1h up move, 1d high
            & ((aroonu_14_15m_gt_50) | (rsi_3_1h_lt_60) | (stochrsi_k_1d_gt_10))
            # 15m low, 1h up move & still high
            & ((aroonu_14_15m_gt_60) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_40))
            # 15m & 1d uptrend
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1d_lt_40))
            # 15m uptrend, 1h low & still high
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_gt_0) | (stochrsi_k_1h_gt_30))
            # 15m uptrend, 1h low & high
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_gt_10) | (stochrsi_k_1h_gt_10))
            # 15m & 1h uptrend, 1d down move
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_30) | (rsi_3_1d_gt_5))
            # 15m & 1h uptrend, 4h low
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_30) | (stochrsi_k_4h_gt_20))
            # 15m & 1h uptrend, 1d low
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_gt_10))
            # 15m & 1h uptrend, 1h low
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_40) | (stochrsi_k_1h_gt_20))
            # 15m uptrend, 1h down move, 4h low
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_10) | (aroonu_14_4h_gt_0))
            # 15m uptrend, 1h down move & low
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_15) | (aroonu_14_1h_gt_10))
            # 15m & 4h uptrend, 1h down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_15) | (roc_9_4h_lt_5))
            # 15m & 4h uptrend, 4h down move
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_gt_10) | (aroonu_14_4h_lt_30))
            # 15m uptrend, 4h down move, 1d oversold
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_gt_5) | (roc_9_1d_gt_neg_30))
            # 15m uptrend & low, 4h down move
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_25))
            # 15m uptrend & low, 1h still high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_40))
            # 15m uptrend & still high, 1d low
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_30) | (aroonu_14_1d_gt_10))
            # 15m uptrend & still high, 1d down move
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_30) | (rsi_3_1d_gt_10))
            # 15m uptrend & still high, 1h high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_40) | (stochrsi_k_1h_gt_10))
            # 15m uptrend, 1h high, 4h down move
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_10) | (rsi_3_4h_gt_10))
            # 15m & 1d uptrend, 1h still high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_40) | (aroonu_14_1d_lt_30))
            # 15m uptrend, 1h still high, 1d high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_40) | (stochrsi_k_1d_gt_10))
            # 15m & 1h uptrend, 4h down move
            & ((aroonu_14_15m_lt_25) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_25))
            # 15m & 1h uptrend, 1h low
            & ((aroonu_14_15m_lt_25) | (aroonu_14_1h_lt_30) | (stochrsi_k_1h_gt_20))
            # 15m uptrend, 1h high, 1d up move
            & ((aroonu_14_15m_lt_25) | (stochrsi_k_1h_gt_10) | (rsi_3_1d_lt_35))
            # 15m & 1h uptrend, 1h still high
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_25) | (stochrsi_k_1h_gt_30))
            # 15m & 1h uptrend, 4h still high
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_30) | (stochrsi_k_4h_gt_30))
            # 15m uptrend, 4h low, 1d up move
            & ((aroonu_14_15m_lt_30) | (aroonu_14_4h_gt_0) | (rsi_3_1d_lt_35))
            # 15m & 4h uptrend, 4h high
            & ((aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_30) | (stochrsi_k_4h_gt_10))
            # 15m & 1h uptrend, 1h down move
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_25) | (roc_9_1h < 0))
            # 15m uptrend, 1h down move, 1d up move
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_30) | (rsi_3_1d_lt_35))
            # 15m uptrend, 1h up move, 1d oversold
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_lt_40) | (roc_9_1d_gt_neg_25))
            # 15m uptrend, 4h down move, 1d oversold
            & ((aroonu_14_15m_lt_30) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m & 4h uptrend, 4h down move
            & ((aroonu_14_15m_lt_30) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_30))
            # 15m uptrend, 4h up move
            & ((aroonu_14_15m_lt_30) | (rsi_3_4h_lt_50))
            # 15m uptrend & high, 1h low
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_15m_gt_10) | (aroonu_14_1h_gt_0))
            # 15m & 4h uptrend, 15m still high
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_15m_gt_30) | (aroonu_14_4h_lt_30))
            # the 15m making new highs with both stochastics topped out
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_15m_lt_70) | (stochrsi_k_4h_lt_80))
            # 15m uptrend, 1h low, 4h down move
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_1h_gt_20) | (rsi_3_4h_gt_10))
            # 15m uptrend, 1h still high, 1d low
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_1h_gt_30) | (stochrsi_k_1d_gt_20))
            # 15m uptrend, 1h low, 4h down move
            & ((aroonu_14_15m_lt_40) | (aroonu_14_1h_gt_0) | (rsi_3_4h_gt_5))
            # 15m uptrend, 1h down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_gt_20))
            # 15m uptrend, 4h down move, 1d high
            & ((aroonu_14_15m_lt_40) | (rsi_3_4h_gt_15) | (stochrsi_k_1d_gt_10))
            # 15m & 4h uptrend, 15m low
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_20))
            # 15m uptrend & low, 4h still high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_30))
            # 15m uptrend & still high, 4h high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_40) | (stochrsi_k_4h_gt_10))
            # 15m uptrend & still high, 4h down move
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_60) | (rsi_3_4h_gt_15))
            # 15m uptrend, 1h high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_10))
            # 15m uptrend, 4h high, 1d oversold
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_4h_gt_10) | (roc_9_1d_gt_neg_25))
            # 15m & 1h uptrend, 4h low
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_25) | (aroonu_14_4h_gt_0))
            # 15m & 4h uptrend, 1d high
            & ((aroonu_14_15m_lt_50) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_gt_10))
            # 15m uptrend, 1h & 1d down move
            & ((aroonu_14_15m_lt_50) | (rsi_3_1h_gt_30) | (rsi_3_1d_gt_20))
            # 15m uptrend & still high, 4h down move
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_30) | (rsi_3_4h_gt_30))
            # 15m uptrend & still high, 1h up move
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_40) | (rsi_3_1h_lt_40))
            # 15m uptrend & still not low enough, 4h down move
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_70) | (rsi_3_4h_gt_10))
            # 15m uptrend, 1h low
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_1h_gt_20))
            # 15m uptrend, 1h still high, 1d down move
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_1h_gt_50) | (rsi_3_1d_gt_15))
            # 15m uptrend, 1h still high, 4h high
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_1h_gt_60) | (stochrsi_k_4h_gt_10))
            # 15m & 1h uptrend
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_60))
            # 15m uptrend & still high, 1d down move
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_15m_gt_60) | (rsi_3_1d_gt_10))
            # 15m uptrend, 1h still high, 4h low
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_1h_gt_30) | (aroonu_14_4h_gt_0))
            # 15m uptrend, 1h & 4h still high
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_1h_gt_40) | (stochrsi_k_4h_gt_30))
            # 15m uptrend, 4h high, 1d low
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 15m uptrend, 4h & 1d low
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_0))
            # 15m uptrend, 1h low, 4h oversold
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_gt_0) | (roc_9_4h_gt_neg_10))
            # 15m & 1h uptrend, 4h low
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_20))
            # 15m uptrend & still high
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_15m_gt_30))
            # 15m uptrend & still high, 1h low
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_15m_gt_50) | (aroonu_14_1h_gt_20))
            # 15m uptrend, 1h down move
            & ((aroonu_14_15m_lt_75) | (rsi_3_1h_gt_25))
            # 15m uptrend, 4h down move
            & ((aroonu_14_15m_lt_75) | (rsi_3_4h_gt_5))
            # 15m uptrend, 4h & 1d low
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_10))
            # 15m uptrend, 1d up move
            & ((aroonu_14_15m_lt_80) | (rsi_3_1d_lt_35))
            # 15m uptrend, 1h still high
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_1h_gt_40))
            # 15m uptrend, 4h down move
            & ((aroonu_14_15m_lt_90) | (rsi_3_4h_gt_15))
            # 15m uptrend, 4h high
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_4h_gt_10))
            # no 15m downtrend, the daily money flow at the floor and the daily itself at its low
            & ((aroond_14_15m > 30.0) | (mfi_14_1d > 25.0) | (willr_14_1d > -95.0))
            # 15m downtrend already maxed out and its oscillator still high
            & ((aroond_14_15m_lt_80) | (uo_7_14_28_15m < 55.0))
            # 15m & 1d high, 1d uptrend
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1d_lt_30) | (stochrsi_k_1d_gt_10))
            # 15m high, 1d uptrend
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1d_lt_60))
            # 15m high, 1h low, 4h down move
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_gt_0) | (rsi_3_4h_gt_20))
            # 15m & 1h high, 1h low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_gt_10) | (stochrsi_k_1h_gt_10))
            # 15m high, 1h uptrend, 4h low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_25) | (aroonu_14_4h_gt_20))
            # 15m high, 1h uptrend, 1d down move
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_25) | (rsi_3_1d_gt_10))
            # 15m high, 1h uptrend, 1d low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_30) | (aroonu_14_1d_gt_10))
            # 15m high, 4h uptrend, 1d down move
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_4h_lt_20) | (rsi_3_1d_gt_15))
            # 15m high, 4h & 1d uptrend
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_30))
            # 15m high, 4h uptrend & still high
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_4h_lt_30) | (stochrsi_k_4h_gt_40))
            # 15m stochastic on the floor, the daily collapsed and no hourly downtrend
            & ((stochrsi_k_15m_gt_10) | (roc_9_1d_gt_neg_25) | (aroond_14_1h > 35.0))
            # 15m high, 1h down move, 1d low
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_10) | (aroonu_14_1d_gt_10))
            # 15m high, 1h down move, 4h still high
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_gt_30))
            # 15m high, 1h down move & uptrend
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_15) | (aroonu_14_1h_lt_20))
            # 15m high, 4h & 1d down move
            & ((stochrsi_k_15m_gt_10) | (rsi_3_4h_gt_20) | (rsi_3_1d_gt_10))
            # 15m high, 4h down move & uptrend
            & ((stochrsi_k_15m_gt_10) | (rsi_3_4h_gt_25) | (aroonu_14_4h_lt_20))
            # 15m & 1h high, 1d low
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_1h_gt_10) | (aroonu_14_1d_gt_10))
            # 15m high, 1h still high, 4h low
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_1h_gt_40) | (stochrsi_k_4h_gt_20))
            # 15m high, 4h still high, 1d uptrend
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_50) | (aroonu_14_1d_lt_50))
            # 15m & 1d low, 1d uptrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1d_gt_10) | (roc_9_1d_lt_0))
            # 15m & 1h low, 1d down move
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_0) | (rsi_3_1d_gt_30))
            # 15m & 1h low, 1h still high
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_0) | (stochrsi_k_1h_gt_30))
            # 15m low, 1h uptrend, 4h down move
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_25))
            # 15m low, 1h uptrend, 1d high
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_20) | (stochrsi_k_1d_gt_10))
            # 15m & 1d low, 1h uptrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_gt_10))
            # 15m & 4h low, 1h uptrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_gt_0))
            # 15m low, 4h uptrend, 1d still high
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_gt_30))
            # 15m low, 4h oversold, 1d uptrend
            & ((stochrsi_k_15m_gt_20) | (roc_9_4h_gt_neg_15) | (aroonu_14_1d_lt_30))
            # 15m low, 1h down move, 4h oversold
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1h_gt_10) | (roc_9_4h_gt_neg_25))
            # 15m & 1h low, 1h down move
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1h_gt_5) | (aroonu_14_1h_gt_10))
            # 15m low, 1h down move, 4h high
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1h_gt_5) | (stochrsi_k_4h_gt_10))
            # 15m & 4h low, 4h down move
            & ((stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_5) | (aroonu_14_4h_gt_0))
            # 15m & 1h low, 1d high
            & ((stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_20) | (stochrsi_k_1d_gt_10))
            # 15m low, 1h still high, 4h uptrend
            & ((stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_30) | (aroonu_14_4h_lt_20))
            # 15m low, 4h high, 1d oversold
            & ((stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_10) | (roc_9_1d_gt_neg_25))
            # 15m low, 4h still high, 1d down move
            & ((stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_40) | (rsi_3_1d_gt_15))
            # 15m & 1d low, 4h still high
            & ((stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_50) | (aroonu_14_1d_gt_0))
            # 15m still high, 1h low, 4h down move
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_1h_gt_0) | (rsi_3_4h_gt_5))
            # 15m still high, 4h uptrend, 1d oversold
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_4h_lt_20) | (roc_9_1d_gt_neg_15))
            # 15m still high, 4h uptrend, 1d low
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_gt_10))
            # 15m still high, 4h uptrend, 1d down move
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_4h_lt_30) | (rsi_3_1d_gt_15))
            # 15m still high, 4h uptrend & high
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_4h_lt_30) | (stochrsi_k_4h_gt_10))
            # 15m still high, 1h up move, 4h low
            & ((stochrsi_k_15m_gt_30) | (rsi_3_1h_lt_40) | (aroonu_14_4h_gt_0))
            # 15m still high, 4h down move, 1d uptrend
            & ((stochrsi_k_15m_gt_30) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_30))
            # 15m still high, 1h high, 1d uptrend
            & ((stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_10) | (aroonu_14_1d_lt_30))
            # 15m still high, 1h high, 4h low
            & ((stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_10) | (aroonu_14_4h_gt_10))
            # both stochastics on the floor while the daily has not sold off
            & ((stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_10) | (rsi_3_1d_lt_35))
            # 15m still high, 1d uptrend & high
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_1d_lt_50) | (stochrsi_k_1d_gt_10))
            # 15m still high, 1h low, 1d down move
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_1h_gt_0) | (rsi_3_1d_gt_15))
            # 15m still high, 1h low, 4h up move
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_1h_gt_10) | (rsi_3_4h_lt_40))
            # 15m still high, 4h uptrend, 1d up move
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_4h_lt_30) | (rsi_3_1d_lt_35))
            # 15m still high, 1d up move & low
            & ((stochrsi_k_15m_gt_40) | (rsi_3_1d_lt_35) | (stochrsi_k_1d_gt_20))
            # 15m still high, 1h & 4h down move
            & ((stochrsi_k_15m_gt_40) | (rsi_3_1h_gt_10) | (rsi_3_4h_gt_5))
            # 15m still high, 1h up move, 4h down move
            & ((stochrsi_k_15m_gt_40) | (rsi_3_1h_lt_40) | (rsi_3_4h_gt_25))
            # 15m still high, 1h up move
            & ((stochrsi_k_15m_gt_40) | (rsi_3_1h_lt_50))
            # 15m & 1d still high, 4h down move
            & ((stochrsi_k_15m_gt_40) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_gt_30))
            # 15m still high, 4h down move & uptrend
            & ((stochrsi_k_15m_gt_40) | (rsi_3_4h_gt_15) | (aroonu_14_4h_lt_40))
            # 15m still high, 4h up move & low
            & ((stochrsi_k_15m_gt_40) | (rsi_3_4h_lt_40) | (aroonu_14_4h_gt_0))
            # 15m & 1h still high, 1h uptrend
            & ((stochrsi_k_15m_gt_50) | (aroonu_14_1h_lt_40) | (stochrsi_k_1h_gt_30))
            # 15m still high, 1h down move, 1d uptrend
            & ((stochrsi_k_15m_gt_50) | (rsi_3_1h_gt_10) | (aroonu_14_1d_lt_50))
            # 15m & 1h still high, 1h up move
            & ((stochrsi_k_15m_gt_50) | (rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_50))
            # 15m still high, 1h up move, 4h low
            & ((stochrsi_k_15m_gt_50) | (rsi_3_1h_lt_50) | (aroonu_14_4h_gt_20))
            # 15m still high, 4h down move, 1d uptrend
            & ((stochrsi_k_15m_gt_50) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_30))
            # 15m still high, 4h down move, 1d uptrend
            & ((stochrsi_k_15m_gt_50) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_40))
            # 15m still high, 1h uptrend, 4h high
            & ((stochrsi_k_15m_gt_60) | (aroonu_14_1h_lt_30) | (stochrsi_k_4h_gt_10))
            # 15m still high, 4h uptrend & low
            & ((stochrsi_k_15m_gt_60) | (aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m still high, 1h up move, 4h high
            & ((stochrsi_k_15m_gt_60) | (rsi_3_1h_lt_50) | (stochrsi_k_4h_gt_10))
            # 15m still high, 1h high, 1d uptrend
            & ((stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_10) | (roc_9_1d_lt_0))
            # 15m still not high enough, 1h up move & still high
            & ((stochrsi_k_15m_gt_70) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_50))
            # 15m stochastic topped out, the 4h has not sold off and the base has no downtrend at all
            & ((stochrsi_k_15m_lt_30) | (rsi_3_4h_lt_40) | (aroond_14 > 5.0))
            # 15m topped out, no 4h trend behind it and 4h money flow already gone
            & ((stochrsi_k_15m_lt_80) | (adx_14_4h > 20.0) | (mfi_14_4h > 20.0))
            # 15m topped out while the 4h is in an uptrend and the 1d is not yet stretched
            & ((stochrsi_k_15m_lt_80) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_lt_40))
            # both stochastics topped out while 4h money flow is already gone
            & ((stochrsi_k_15m_lt_80) | (stochrsi_k_4h_lt_80) | (mfi_14_4h < 40.0))
            # 15m in the upper half of its range while the 4h stochastic is topped out
            & ((willr_14_15m < -50.0) | (stochrsi_k_4h_lt_70))
            # 15m already running up, the daily deeply down and the 4h making no new high
            & ((roc_9_15m < 1.5) | (roc_9_1d_gt_neg_15) | (aroonu_14_4h < 10.0))
            # 15m uptrend, 1d oversold
            & ((roc_9_15m < 1.5) | (roc_9_1d_gt_neg_25))
            # 15m turned up, the 4h making new highs and its money flow still there
            & ((roc_9_15m > -3.0) | (aroonu_14_4h_lt_30) | (mfi_14_4h < 50.0))
            # the hour flat, the daily running up and no 4h trend behind the short
            & ((rsi_3_1h_gt_10) | (roc_9_1d_lt_10) | (adx_14_4h > 20.0))
            # 1h down move, 4h oversold, 1d uptrend
            & ((rsi_3_1h_gt_10) | (roc_9_4h_gt_neg_10) | (aroonu_14_1d_lt_30))
            # the hour has not moved down, its stochastic already on the floor and the base making no new high
            & ((rsi_3_1h_gt_10) | (stochk_14_3_3_1h < 30.0) | (aroonu_14 < 10.0))
            # 1h & 1d down move, 4h low
            & ((rsi_3_1h_gt_10) | (stochrsi_k_4h_gt_20) | (rsi_3_1d_gt_5))
            # 1h down move, 1d low & uptrend
            & ((rsi_3_1h_gt_15) | (aroonu_14_1d_gt_20) | (roc_9_1d_lt_0))
            # 1h down move, 1d oversold
            & ((rsi_3_1h_gt_15) | (roc_9_1d_gt_neg_25))
            # 1h & 4h down move, 4h low
            & ((rsi_3_1h_gt_15) | (rsi_3_4h_gt_20) | (aroonu_14_4h_gt_0))
            # 1h down move & uptrend, 4h oversold
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_40) | (roc_9_4h_gt_neg_15))
            # 1h down move, 1h & 1d uptrend
            & ((rsi_3_1h_gt_25) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_30))
            # 1h & 4h down move, 1d uptrend
            & ((rsi_3_1h_gt_25) | (rsi_3_4h_gt_25) | (aroonu_14_1d_lt_30))
            # the hour has already fallen and is not topped out
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1h_lt_80))
            # 1h down move, 4h up move & low
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_lt_40) | (aroonu_14_4h_gt_0))
            # 1h & 1d down move, 1d uptrend
            & ((rsi_3_1h_gt_35) | (rsi_3_1d_gt_25) | (roc_9_1d_lt_0))
            # 1h & 4h down move, 1h uptrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_1h_lt_25) | (rsi_3_4h_gt_5))
            # 1h down move & uptrend, 1d high
            & ((rsi_3_1h_gt_5) | (aroonu_14_1h_lt_40) | (stochrsi_k_1d_gt_10))
            # 1h down move, 1h & 1d low
            & ((rsi_3_1h_gt_5) | (stochrsi_k_1h_gt_20) | (aroonu_14_1d_gt_10))
            # 1h up move, 1d uptrend
            & ((rsi_3_1h_lt_40) | (aroonu_14_1d_lt_50))
            # 1h up move, 1h & 1d uptrend
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_lt_30))
            # the hour already sold off, making new highs, with a long squeeze behind it
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_lt_25) | (sqz_cnt_24 < 20.0))
            # 1h & 4h up move, 1h uptrend
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_lt_30) | (rsi_3_4h_lt_40))
            # 1h up move & uptrend, 4h low
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_lt_30) | (stochrsi_k_4h_gt_20))
            # 1h up move & uptrend, 4h still high
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_lt_60) | (stochrsi_k_4h_gt_30))
            # 1h up move, 4h uptrend, 1d down move
            & ((rsi_3_1h_lt_40) | (aroonu_14_4h_lt_20) | (rsi_3_1d_gt_10))
            # 1h & 1d up move, 4h uptrend
            & ((rsi_3_1h_lt_40) | (aroonu_14_4h_lt_20) | (rsi_3_1d_lt_35))
            # 1h up move, 4h & 1d uptrend
            & ((rsi_3_1h_lt_40) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_40))
            # the hour already sold off, the daily out of money flow and the hourly cci jumping
            & ((rsi_3_1h_lt_40) | (mfi_14_1d > 20.0) | (cci_20_change_pct_1h < 20.0))
            # 1h up move, 1d overbought
            & ((rsi_3_1h_lt_40) | (roc_9_1d_gt_neg_70))
            # 1h up move, 1d down move & uptrend
            & ((rsi_3_1h_lt_40) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_30))
            # 1h up move, 4h & 1d down move
            & ((rsi_3_1h_lt_40) | (rsi_3_4h_gt_10) | (rsi_3_1d_gt_10))
            # 1h up move, 4h down move, 1d low
            & ((rsi_3_1h_lt_40) | (rsi_3_4h_gt_5) | (aroonu_14_1d_gt_10))
            # neither the hour nor the 4h has sold off and the hour is making no new high
            & ((rsi_3_1h_lt_40) | (rsi_3_4h_lt_40) | (aroonu_14_1h > 5.0))
            # 1h up move & low, 1d uptrend
            & ((rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_20) | (aroonu_14_1d_lt_40))
            # 1h up move & low, 4h uptrend
            & ((rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_20))
            # 1h up move & still high, 1d down move
            & ((rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_30) | (rsi_3_1d_gt_20))
            # 1h up move, 4h still high, 1d down move
            & ((rsi_3_1h_lt_40) | (stochrsi_k_4h_gt_30) | (rsi_3_1d_gt_10))
            # 1h up move, 1d uptrend
            & ((rsi_3_1h_lt_50) | (aroonu_14_1d_lt_30))
            # 1h up move, 1h & 1d low
            & ((rsi_3_1h_lt_50) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_10))
            # 1h up move, 1h & 4h low
            & ((rsi_3_1h_lt_50) | (aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_0))
            # 1h up move & uptrend, 4h still high
            & ((rsi_3_1h_lt_50) | (aroonu_14_1h_lt_50) | (stochrsi_k_4h_gt_40))
            # 1h up move, 4h & 1d low
            & ((rsi_3_1h_lt_50) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_gt_10))
            # 1h & 4h up move
            & ((rsi_3_1h_lt_50) | (rsi_3_4h_lt_50))
            # 1h down move, 1d high & oversold
            & ((rsi_3_1h_lt_55) | (stochrsi_k_1d_gt_10) | (roc_9_1d_gt_neg_10))
            # 1h up move & uptrend, 1d low
            & ((rsi_3_1h_lt_60) | (aroonu_14_1h_lt_30) | (aroonu_14_1d_gt_30))
            # 1h & 4h up move, 4h still high
            & ((rsi_3_1h_lt_60) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_30))
            # 1h up move & uptrend
            & ((rsi_3_1h_lt_70) | (aroonu_14_1h_lt_20))
            # hourly money flow still strong, the 4h flow not yet negative and the hour making no new high: the move is already over
            & ((mfi_14_1h < 40.0) | (cmf_20_4h < -0.1) | (aroonu_14_1h > 5.0))
            # hourly money flow holding, its stochastics off the floor and the other one topped out
            & ((mfi_14_1h < 45.0) | (stochk_14_3_3_1h > 15.0) | (stochrsi_k_1h_lt_30))
            # 1h & 4h low, 1d down move
            & ((aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_0) | (rsi_3_1d_gt_15))
            # 1h low, 4h & 1d uptrend
            & ((aroonu_14_1h_gt_0) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_30))
            # 1h low, 4h uptrend, 1d down move
            & ((aroonu_14_1h_gt_0) | (aroonu_14_4h_lt_30) | (rsi_3_1d_gt_15))
            # 1h & 4h low, 1d oversold
            & ((aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_0) | (roc_9_1d_gt_neg_25))
            # 1h & 4h low, 1d down move
            & ((aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_0) | (rsi_3_1d_gt_10))
            # 1h & 1d low, 4h up move
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_lt_40) | (aroonu_14_1d_gt_10))
            # 1h low, 4h up move, 1d uptrend
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_lt_40) | (aroonu_14_1d_lt_30))
            # 1h & 4h low, 1h high
            & ((aroonu_14_1h_gt_10) | (stochrsi_k_1h_gt_10) | (aroonu_14_4h_gt_0))
            # 1h low & still high, 1d high
            & ((aroonu_14_1h_gt_10) | (stochrsi_k_1h_gt_30) | (stochrsi_k_1d_gt_10))
            # 1h low, 4h down move, 1d uptrend
            & ((aroonu_14_1h_gt_20) | (rsi_3_4h_gt_15) | (aroonu_14_1d_lt_60))
            # 1h low, 4h up move
            & ((aroonu_14_1h_gt_20) | (rsi_3_4h_lt_50))
            # 1h & 1d uptrend, 1d high
            & ((aroonu_14_1h_lt_20) | (aroonu_14_1d_lt_60) | (stochrsi_k_1d_gt_10))
            # 1h & 1d uptrend, 4h low
            & ((aroonu_14_1h_lt_20) | (aroonu_14_4h_gt_0) | (roc_9_1d_lt_0))
            # 1h & 4h & 1d uptrend
            & ((aroonu_14_1h_lt_20) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_30))
            # 1h & 4h uptrend, 1d down move
            & ((aroonu_14_1h_lt_20) | (aroonu_14_4h_lt_30) | (rsi_3_1d_gt_10))
            # 1h uptrend, 4h down move, 1d up move
            & ((aroonu_14_1h_lt_20) | (rsi_3_4h_gt_15) | (rsi_3_1d_lt_35))
            # 1h & 1d uptrend, 1d still high
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_1d_gt_30) | (roc_9_1d_lt_0))
            # 1h & 1d uptrend, 4h high
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_lt_40))
            # 1h uptrend, 1d low & oversold
            & ((aroonu_14_1h_lt_25) | (aroonu_14_1d_gt_0) | (roc_9_1d_gt_neg_25))
            # 1h & 4h uptrend, 1d down move
            & ((aroonu_14_1h_lt_25) | (aroonu_14_4h_lt_30) | (rsi_3_1d_gt_15))
            # 1h uptrend, 4h up move & still high
            & ((aroonu_14_1h_lt_25) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_30))
            # 1h uptrend & high, 1d low
            & ((aroonu_14_1h_lt_25) | (stochrsi_k_1h_gt_10) | (stochrsi_k_1d_gt_20))
            # 1h & 1d uptrend, 1h low
            & ((aroonu_14_1h_lt_25) | (stochrsi_k_1h_gt_20) | (aroonu_14_1d_lt_30))
            # 1h & 1d uptrend
            & ((aroonu_14_1h_lt_30) | (aroonu_14_1d_lt_40))
            # 1h & 4h uptrend, 1d high
            & ((aroonu_14_1h_lt_30) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_gt_10))
            # 1h uptrend, 4h oversold
            & ((aroonu_14_1h_lt_30) | (roc_9_4h_gt_neg_20))
            # 1h & 4h uptrend, 1h low
            & ((aroonu_14_1h_lt_30) | (stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_30))
            # 1h uptrend & low, 4h down move
            & ((aroonu_14_1h_lt_30) | (stochrsi_k_1h_gt_20) | (rsi_3_4h_gt_10))
            # 1h & 1d uptrend, 1h still high
            & ((aroonu_14_1h_lt_30) | (stochrsi_k_1h_gt_30) | (aroonu_14_1d_lt_30))
            # 1h & 1d uptrend, 4h high
            & ((aroonu_14_1h_lt_30) | (stochrsi_k_4h_gt_10) | (aroonu_14_1d_lt_30))
            # 1h & 4h uptrend
            & ((aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_40))
            # 1h uptrend, 1d up move & low
            & ((aroonu_14_1h_lt_40) | (rsi_3_1d_lt_35) | (aroonu_14_1d_gt_10))
            # 1h uptrend, 4h up move, 1d low
            & ((aroonu_14_1h_lt_40) | (rsi_3_4h_lt_40) | (aroonu_14_1d_gt_10))
            # 1h & 4h uptrend, 1h high
            & ((aroonu_14_1h_lt_40) | (stochrsi_k_1h_gt_10) | (aroonu_14_4h_lt_20))
            # 1h uptrend & still high, 1d low
            & ((aroonu_14_1h_lt_50) | (stochrsi_k_1h_gt_30) | (aroonu_14_1d_gt_10))
            # 1h uptrend, 4h high
            & ((aroonu_14_1h_lt_50) | (stochrsi_k_4h_gt_10))
            # 1h & 1d uptrend
            & ((aroonu_14_1h_lt_60) | (aroonu_14_1d_lt_30))
            # 1h uptrend & still high, 1d low
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_40) | (aroonu_14_1d_gt_10))
            # 1h & 4h uptrend, 1h still high
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_60) | (aroonu_14_4h_lt_30))
            # 1h uptrend, 1d low
            & ((aroonu_14_1h_lt_70) | (aroonu_14_1d_gt_20))
            # no 1h downtrend, the 4h flat and money still coming in on the hour
            & ((aroond_14_1h > 65.0) | (rsi_3_4h_gt_5) | (cmf_20_1h < -0.1))
            # the hourly stochastic pinned at zero, 4h money flow gone and the daily range twice its usual width
            & ((stochrsi_k_1h > 5.0) | (mfi_14_4h > 30.0) | (range_pct_14_1d < 25.0))
            # 1h high, 1d uptrend
            & ((stochrsi_k_1h_gt_10) | (aroonu_14_1d_lt_60) | (roc_9_1d_lt_0))
            # 1h high, 4h uptrend, 1d low
            & ((stochrsi_k_1h_gt_10) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_gt_0))
            # the hour on the floor, the daily collapsed and the hourly oscillator low too
            & ((stochrsi_k_1h_gt_10) | (roc_9_1d_gt_neg_25) | (uo_7_14_28_1h < 50.0))
            # 1h high, 1d up move & oversold
            & ((stochrsi_k_1h_gt_10) | (rsi_3_1d_lt_35) | (roc_9_1d_gt_neg_20))
            # 1h & 1d high, 4h down move
            & ((stochrsi_k_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_gt_10))
            # 1h & 4h low, 4h down move
            & ((stochrsi_k_1h_gt_20) | (rsi_3_4h_gt_5) | (aroonu_14_4h_gt_0))
            # 1h low, 4h up move
            & ((stochrsi_k_1h_gt_20) | (rsi_3_4h_lt_40))
            # 1h still high, 1d low & uptrend
            & ((stochrsi_k_1h_gt_30) | (aroonu_14_1d_gt_10) | (roc_9_1d_lt_0))
            # 1h still high, 4h low & high
            & ((stochrsi_k_1h_gt_30) | (aroonu_14_4h_gt_20) | (stochrsi_k_4h_gt_10))
            # 1h still high, 4h high, 1d oversold
            & ((stochrsi_k_1h_gt_30) | (stochrsi_k_4h_gt_10) | (roc_9_1d_gt_neg_40))
            # 1h & 4h still high, 1d down move
            & ((stochrsi_k_1h_gt_30) | (stochrsi_k_4h_gt_30) | (rsi_3_1d_gt_10))
            # 1h still high, 4h up move, 1d high
            & ((stochrsi_k_1h_gt_40) | (rsi_3_4h_lt_40) | (stochrsi_k_1d_gt_10))
            # 1h still high, 4h up move
            & ((stochrsi_k_1h_gt_40) | (rsi_3_4h_lt_50))
            # 1h uptrend, 4h & 1d down move
            & ((roc_9_1h < -1) | (rsi_3_4h_gt_15) | (rsi_3_1d_gt_10))
            # 1h oversold, 4h low & high
            & ((roc_9_1h_gt_neg_10) | (aroonu_14_4h_gt_0) | (stochrsi_k_4h_gt_10))
            # 4h down move & low, 1d high
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_gt_0) | (stochrsi_k_1d_gt_10))
            # the 4h has not moved down, the day closed strongly up and no 4h trend behind the short
            & ((rsi_3_4h_gt_15) | (change_pct_1d < 5.0) | (adx_14_4h > 35.0))
            # 4h down move, 1d up move & oversold
            & ((rsi_3_4h_gt_15) | (rsi_3_1d_lt_35) | (roc_9_1d_gt_neg_15))
            # 4h & 1d down move, 1d uptrend
            & ((rsi_3_4h_gt_20) | (rsi_3_1d_gt_30) | (aroonu_14_1d_lt_30))
            # 4h down move & low, 1d uptrend
            & ((rsi_3_4h_gt_5) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_lt_30))
            # 4h down move & low, 1d oversold
            & ((rsi_3_4h_gt_5) | (aroonu_14_4h_gt_20) | (roc_9_1d_gt_neg_30))
            # 4h down move, 4h & 1d uptrend
            & ((rsi_3_4h_gt_5) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_50))
            # 4h & 1d down move, 1d low
            & ((rsi_3_4h_gt_5) | (rsi_3_1d_gt_15) | (aroonu_14_1d_gt_10))
            # 4h up move, 1d uptrend
            & ((rsi_3_4h_lt_40) | (aroonu_14_1d_lt_40))
            # 4h up move & uptrend, 1d oversold
            & ((rsi_3_4h_lt_40) | (aroonu_14_4h_lt_20) | (roc_9_1d_gt_neg_15))
            # 4h up move, 1d overbought
            & ((rsi_3_4h_lt_40) | (roc_9_1d_gt_neg_70))
            # 4h up move, 1d low
            & ((rsi_3_4h_lt_50) | (aroonu_14_1d_gt_10))
            # 4h up move, 1d still high
            & ((rsi_3_4h_lt_70) | (stochrsi_k_1d_gt_40))
            # 4h money flow holding, the daily out of it and the 4h not yet washed out
            & ((mfi_14_4h < 40.0) | (mfi_14_1d > 20.0) | (cci_20_4h > -225.0))
            # 4h money flow holding up while its rsi has collapsed
            & ((mfi_14_4h < 40.0) | (rsi_14_change_pct_4h > -15.0))
            # 4h low & oversold, 1d down move
            & ((aroonu_14_4h_gt_10) | (roc_9_4h_gt_neg_20) | (rsi_3_1d_gt_5))
            # 4h low, 1d up move & high
            & ((aroonu_14_4h_gt_10) | (rsi_3_1d_lt_35) | (stochrsi_k_1d_gt_10))
            # 4h uptrend, 1d down move & low
            & ((aroonu_14_4h_lt_20) | (rsi_3_1d_gt_5) | (aroonu_14_1d_gt_10))
            # 4h uptrend, 4h & 1d high
            & ((aroonu_14_4h_lt_20) | (stochrsi_k_4h_gt_10) | (stochrsi_k_1d_gt_10))
            # the 4h making new highs with a topped-out stochastic and no daily downtrend
            & ((aroonu_14_4h_lt_20) | (stochrsi_k_4h_lt_70) | (aroond_14_1d > 55.0))
            # 4h & 1d uptrend, 1d high
            & ((aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_gt_10))
            # 4h uptrend & high, 1d down move
            & ((aroonu_14_4h_lt_30) | (stochrsi_k_4h_gt_10) | (rsi_3_1d_gt_25))
            # 4h & 1d uptrend, 1d low
            & ((aroonu_14_4h_lt_40) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_gt_20))
            # 4h uptrend, 1d down move
            & ((aroonu_14_4h_lt_40) | (rsi_3_1d_gt_10))
            # 4h still high, 5m momentum not yet turned, 5m money flow high
            & ((stochrsi_k_4h > 5) | (rsi_14_change_pct > -12) | (mfi_14 < 65))
            # 4h still high, 1h stoch off the floor, 1h money flow low
            & ((stochrsi_k_4h > 5) | (stochk_14_3_3_1h > 15) | (mfi_14_1h < 40))
            # 4h & 1d high, 1d uptrend
            & ((stochrsi_k_4h_gt_10) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_gt_10))
            # 4h high, 1d uptrend
            & ((stochrsi_k_4h_gt_10) | (aroonu_14_1d_lt_70))
            # 4h high, 1d up move & oversold
            & ((stochrsi_k_4h_gt_10) | (rsi_3_1d_lt_35) | (roc_9_1d_gt_neg_20))
            # 4h low, 1d uptrend & high
            & ((stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_50) | (stochrsi_k_1d_gt_10))
            # 4h still high, 1d uptrend & oversold
            & ((stochrsi_k_4h_gt_40) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_10))
            # the 4h stochastic high, the daily aroon-up floored and daily money still coming in
            & ((stochrsi_k_4h_lt_50) | (aroonu_14_1d_gt_10) | (cmf_20_1d < 0.1))
            # 4h stoch high, 1d aroon-down maxed, 5m no new high, 15m already washed
            & ((stochk_14_3_3_4h < 40) | (aroond_14_1d > 55) | (aroonu_14_lt_25) | (stochrsi_k_15m < 65))
            # money still flowing in on the hour while the 4h trend is already strong
            & ((cmf_20_1h_lt_0_10) | (adx_14_4h < 40.0))
            # 1d down move & uptrend
            & ((rsi_3_1d_gt_25) | (roc_9_1d_lt_20))
            # the daily oversold on both rsi and money flow while its aroon-up is still up there
            & ((rsi_14_1d > 30.0) | (mfi_14_1d > 30.0) | (aroonu_14_1d < 25.0))
            # the daily fully exhausted on both aroon and stochastic while its money flow has not turned
            & ((aroonu_14_1d > 5.0) | (stochrsi_k_1d > 5.0) | (cmf_20_1d < -0.05))
            # the 12-candle ceiling already maxed, the 15m washed out and 4h money flow still present
            & ((quad_s93_max_12 < 95.0) | (rsi_14_15m > 30.0) | (mfi_14_4h < 40.0))
            # a long squeeze behind it, the 4h oscillator high and no daily downtrend
            & ((sqz_cnt_24 < 20.0) | (uo_7_14_28_4h < 55.0) | (aroond_14_1d > 55.0))
            # 15m & 4h collapse already spent, 5m neither new low nor new high
            & ((cci_20_change_pct_15m > -195) | (aroond_14 > 5) | (aroonu_14_lt_25) | (rsi_3_change_pct_4h > -40))
            # the 15m cci collapsing, the daily already sold off and 4h money flow still present
            & ((cci_20_change_pct_15m > -195.0) | (rsi_3_1d_gt_10) | (mfi_14_4h < 25.0))
            # the 15m rsi_3 has jumped, no 4h trend behind it and 4h money flow still there
            & ((rsi_3_change_pct_15m < 70.0) | (adx_14_4h > 20.0) | (mfi_14_4h < 55.0))
            # the 15m oscillator collapsing while both 4h stochastics are already at their floor
            & ((uo_7_14_28_change_pct_15m > -15.0) | (stochrsi_k_4h_lt_30) | (stochk_14_3_3_4h < 40.0))
            # 1h cci collapsing, 15m making lows, 1h oscillator high, 4h collapse already spent
            & ((cci_20_change_pct_1h < 20) | (aroond_14_15m > 30) | (uo_7_14_28_1h > 40) | (rsi_3_change_pct_4h > -40))
            # 1h collapse already spent, 15m & 1h making lows, 4h trend weak
            & ((cci_20_change_pct_1h > -35) | (aroond_14_1h > 35) | (aroond_14_15m > 30) | (adx_14_4h < 40))
          )

          # Logic
          short_entry_logic.append(
            # breakdown must be real: price already in the lower half of the range,
            # 15m momentum actually down (losses were top-of-range fake breakdowns)
            (willr_14 < -50.0)
            & (rsi_3_15m < 45.0)
            # downtrend regime + momentum side + bearish engulfing close
            & (close < ema_200)
            & (rsi_14 < 50.0)
            & (engulf_bear > 0.5)
            # the 4h has not made a fresh high: a continuation short, not a pullback in a rally
            & (aroonu_14_4h < 50.0)
            # the daily oscillator is not at its ceiling either
            & (stochrsi_k_1d < 50.0)
          )

        # Condition #666 - Swing-failure pattern (Short, experimental, RAW — mirror).
        if short_entry_condition_index == 666:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)

          # Logic
          # prior 48-candle high swept by the wick, candle closes back below it
          short_entry_logic.append(sfp_bear > 0.5)

        # Condition #667 - 1h inside-bar breakout (Short, experimental, RAW — mirror).
        if short_entry_condition_index == 667:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m down move, 1h up move, 1d uptrend
            ((rsi_3_gt_10) | (rsi_3_1h_lt_40) | (aroonu_14_1d_lt_60))
            # 5m down move, 1h up move, 4h low
            & ((rsi_3_gt_15) | (rsi_3_1h_lt_50) | (aroonu_14_4h_gt_0))
            # 5m down move, 15m uptrend & high
            & ((rsi_3_gt_3) | (aroonu_14_15m_lt_60) | (stochrsi_k_15m_gt_10))
            # 5m down move, 1d low & oversold
            & ((rsi_3_gt_3) | (aroonu_14_1d_gt_10) | (roc_9_1d_gt_neg_40))
            # 5m down move, 1h uptrend, 1d oversold
            & ((rsi_3_gt_3) | (aroonu_14_1h_lt_40) | (roc_9_1d_gt_neg_40))
            # 5m down move, 1h oversold, 4h low
            & ((rsi_3_gt_3) | (roc_9_1h_gt_neg_10) | (aroonu_14_4h_gt_10))
            # 5m & 15m down move, 1d oversold
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_25) | (roc_9_1d_gt_neg_40))
            # 5m & 15m down move, 1h low
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_25) | (stochrsi_k_1h_gt_20))
            # 5m & 1h down move, 15m low
            & ((rsi_3_gt_3) | (stochrsi_k_15m_gt_20) | (rsi_3_1h_gt_20))
            # 5m & 1d down move, 1h still high
            & ((rsi_3_gt_3) | (stochrsi_k_1h_gt_40) | (rsi_3_1d_gt_10))
            # 5m down move, 15m uptrend, 4h oversold
            & ((rsi_3_gt_5) | (aroonu_14_15m_lt_50) | (roc_9_4h_gt_neg_15))
            # 5m down move, 1h & 1d uptrend
            & ((rsi_3_gt_5) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_60))
            # 5m down move & oversold
            & ((rsi_3_gt_5) | (roc_9 > -15))
            # 5m up move, 15m down move
            & ((rsi_3_lt_40) | (rsi_3_15m_gt_25))
            # 5m uptrend, 15m on the floor, 4h up move, 1d downtrend & up move
            & (
              (aroonu_14_lt_25) | (roc_9_4h < -8.0) | (stochrsi_k_15m_gt_10) | (aroonu_14_1d_gt_0) | (roc_9_1d < -10.0)
            )
            # 5m uptrend, 15m washed out, 1h washed out, 4h down move, 1d up move
            & (
              (aroonu_14_lt_25)
              | (stochrsi_k_1h_gt_70)
              | (stochrsi_k_15m > 25.0)
              | (roc_9_1d < -15.0)
              | (rsi_3_4h_gt_50)
            )
            # 5m uptrend, 15m low, 4h up move
            & ((aroonu_14_lt_25) | (aroonu_14_15m_gt_20) | (rsi_3_4h_lt_70))
            # 5m uptrend & up move, 15m down move, 1h still high, 4h down move
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_20) | (rsi_3 < 15.0) | (stochrsi_k_1h_lt_30) | (rsi_3_4h_gt_50))
            # 5m uptrend, 1h still high, 4h up move
            & ((aroonu_14_lt_25) | (stochrsi_k_1h_gt_60) | (rsi_3_4h_lt_70))
            # 5m uptrend, 1d low & overbought
            & ((aroonu_14_lt_30) | (aroonu_14_1d_gt_10) | (roc_9_1d_gt_neg_70))
            # 5m uptrend, 4h oversold
            & ((aroonu_14_lt_30) | (roc_9_4h_gt_neg_40))
            # 5m & 4h uptrend, 15m still high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_60) | (aroonu_14_4h_lt_30))
            # 5m uptrend, 1h still high, 4h low
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_gt_60) | (aroonu_14_4h_gt_0))
            # 5m uptrend, 4h still high, 1d low
            & ((aroonu_14_lt_30) | (stochrsi_k_4h_gt_50) | (stochrsi_k_1d_gt_20))
            # 5m willr 480 low & up move, 1h CCI high, 1d down move
            & ((willr_480 > -85.0) | (cci_20_1h < -50.0) | (roc_9_1d_gt_neg_25) | (rsi_3 < 15.0))
            # 5m oversold, 1d uptrend
            & ((roc_9 > -15) | (aroonu_14_1d_lt_60))
            # 5m & 4h oversold
            & ((roc_9 > -15) | (roc_9_4h_gt_neg_30))
            # 15m down move, 4h down move, 1d downtrend & on the floor & up move
            & (
              (rsi_3_15m_gt_15) | (aroonu_14_1d_gt_10) | (stochrsi_k_1d > 5.0) | (roc_9_1d < -15.0) | (rsi_3_4h_gt_45)
            )
            # 15m down move & downtrend, 1h uptrend, 1d uptrend & still high
            & (
              (rsi_3_15m_gt_20)
              | (aroonu_14_1h_lt_60)
              | (aroonu_14_1d < 45.0)
              | (aroonu_14_15m_gt_0)
              | (stochrsi_k_1d < 15.0)
            )
            # 5m on the floor, 15m down move & downtrend, 1h up move, 1d down move
            & (
              (rsi_3_15m_gt_20) | (rsi_3_1h_lt_75) | (roc_9_1d_gt_neg_15) | (stochrsi_k > 5.0) | (aroonu_14_15m_gt_50)
            )
            # 15m momentum alive, 15m stochastic at the floor and daily money leaving
            & ((rsi_3_15m < 5) | (stochk_14_3_3_15m > 15) | (cmf_20_1d_gt_neg_0_20))
            # 15m down move, 1d uptrend & oversold
            & ((rsi_3_15m_gt_15) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_40))
            # 15m down move, 1h & 1d uptrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_60))
            # 15m down move, 15m & 1d low
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_gt_40) | (aroonu_14_1d_gt_30))
            # 5m up move & uptrend, 15m down move & uptrend, 4h down move
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_30) | (rsi_3 < 15.0) | (rsi_3_4h_gt_25) | (aroonu_14 < 10.0))
            # 15m down move & uptrend, 4h up move
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_60) | (rsi_3_4h_lt_60))
            # 15m & 1d down move, 15m uptrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_70) | (rsi_3_1d_gt_5))
            # 5m up move & still high, 15m down move, 4h downtrend & down move
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_gt_10) | (rsi_3 < 15.0) | (stochrsi_k_lt_30) | (rsi_3_4h_gt_50))
            # 15m down move & low, 1h uptrend
            & ((rsi_3_15m_gt_20) | (stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_30))
            # 15m down move & low, 1h oversold
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_gt_20) | (roc_9_1h_gt_neg_10))
            # 15m down move, 15m & 1d uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_40) | (roc_9_1d_lt_15))
            # 15m & 4h down move, 15m uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_70) | (rsi_3_4h_gt_10))
            # 15m down move & uptrend, 1h up move
            & ((rsi_3_15m_gt_30) | (aroonu_14_15m_lt_50) | (rsi_3_1h_lt_70))
            # 15m down move, 1h uptrend, 1d up move
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_90) | (rsi_3_1d_lt_35))
            # 15m & 1h down move, 1d oversold
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_gt_30) | (roc_9_1d_gt_neg_20))
            # 15m down move & low, 1h up move
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_gt_20) | (rsi_3_1h_lt_50))
            # 15m down move, 15m & 1h uptrend
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_90))
            # 15m down move & uptrend, 1h up move
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_70) | (rsi_3_1h_lt_40))
            # 15m down move & uptrend, 4h low
            & ((rsi_3_15m_gt_35) | (aroonu_14_15m_lt_80) | (aroonu_14_4h_gt_10))
            # 15m up move & low, 4h uptrend
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_gt_20) | (aroonu_14_4h_lt_20))
            # 15m up move, 1h & 4h uptrend
            & ((rsi_3_15m_lt_50) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_20))
            # 15m up move, 4h low, 1d still high
            & ((rsi_3_15m_lt_50) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_30))
            # 15m & 4h down move, 4h low
            & ((rsi_3_15m_lt_55) | (rsi_3_4h_gt_50) | (aroonu_14_4h_gt_20))
            # 5m still high, 15m up move, 1h down move
            & ((rsi_3_15m_lt_60) | (rsi_3_1h_gt_40) | (stochrsi_k < 45.0))
            # 5m downtrend, 15m downtrend & up move, 1d on the floor & up move
            & (
              (aroonu_14_15m_gt_50)
              | (stochrsi_k_1d_gt_10)
              | (rsi_3_15m < 40.0)
              | (roc_9_1d < -10.0)
              | (aroonu_14 > 25.0)
            )
            # 5m downtrend, 15m uptrend & overbought, 4h up move, 1d on the floor
            & (
              (aroonu_14_15m_lt_30)
              | (stochrsi_k_1d_gt_10)
              | (stochrsi_k_15m_lt_80)
              | (roc_9_4h < -10.0)
              | (aroonu_14 > 25.0)
            )
            # 15m uptrend & up move, 1h up move, 1d still high & uptrend
            & (
              (aroonu_14_15m_lt_50)
              | (roc_9_1h < -1.0)
              | (stochrsi_k_1d < 35.0)
              | (rsi_3_15m < 30.0)
              | (aroonu_14_1d < 5.0)
            )
            # 5m downtrend, 15m downtrend, 1h uptrend, 4h up move
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_75) | (roc_9_4h_lt_5) | (aroonu_14 > 15.0))
            # 15m low, 1h & 1d down move
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_gt_40) | (rsi_3_1d_gt_25))
            # 15m low, 1h up move & still high
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_40))
            # 15m low, 1h up move, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_60) | (roc_9_1d_lt_0))
            # 15m low & still high, 1d high
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_50) | (stochrsi_k_1d_gt_10))
            # 5m down move, 15m downtrend, 1h downtrend & up move
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_10) | (roc_9_1h < 5.0) | (rsi_3_gt_10))
            # 15m & 1h low
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_20) | (stochrsi_k_1h_gt_20))
            # 15m & 1d low, 1h down move
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_gt_35) | (aroonu_14_1d_gt_10))
            # 15m low, 1h & 1d uptrend
            & ((aroonu_14_15m_gt_30) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_30))
            # 15m low, 1h up move & still not low enough
            & ((aroonu_14_15m_gt_40) | (rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_80))
            # 15m & 1h & 1d low
            & ((aroonu_14_15m_gt_50) | (aroonu_14_1h_gt_20) | (aroonu_14_1d_gt_30))
            # 15m low, 4h still high, 1d high
            & ((aroonu_14_15m_gt_50) | (stochrsi_k_4h_gt_30) | (stochrsi_k_1d_gt_10))
            # 15m low, 4h still high, 1d down move
            & ((aroonu_14_15m_gt_50) | (stochrsi_k_4h_gt_60) | (rsi_3_1d_gt_10))
            # 15m uptrend, 4h oversold, 1d up move
            & ((aroonu_14_15m_lt_20) | (roc_9_4h_gt_neg_15) | (rsi_3_1d_lt_35))
            # 15m uptrend, 1h up move, 1d high
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_lt_40) | (stochrsi_k_1d_gt_10))
            # 15m uptrend, 1h & 1d oversold
            & ((aroonu_14_15m_lt_30) | (roc_9_1h_gt_neg_10) | (roc_9_1d_gt_neg_20))
            # 15m uptrend & low, 4h down move
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_10))
            # 15m uptrend, 1d high & oversold
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_1d_gt_10) | (roc_9_1d_gt_neg_10))
            # 15m uptrend, 1h still high, 4h up move
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_60) | (rsi_3_4h_lt_60))
            # 15m & 1h uptrend, 4h still high
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_60) | (stochrsi_k_4h_gt_40))
            # 15m uptrend, 1d down move & high
            & ((aroonu_14_15m_lt_50) | (rsi_3_1d_gt_10) | (stochrsi_k_1d_gt_10))
            # 15m uptrend, 15m & 4h low
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m uptrend & still high, 4h down move
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_30) | (rsi_3_4h_gt_30))
            # 15m uptrend & still high, 4h down move
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_50) | (rsi_3_4h_gt_10))
            # 15m & 1d uptrend, 1h low
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_1h_gt_20) | (aroonu_14_1d_lt_30))
            # 15m uptrend & up move, 1d uptrend & down move
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_30) | (rsi_3_15m < 20.0))
            # 15m & 1h uptrend, 4h low
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_20))
            # 15m uptrend, 1d up move & low
            & ((aroonu_14_15m_lt_60) | (rsi_3_1d_lt_35) | (stochrsi_k_1d_gt_20))
            # 5m up move, 15m uptrend, 4h down move
            & ((aroonu_14_15m_lt_60) | (rsi_3_4h_gt_15) | (rsi_3 < 25.0))
            # 15m & 1h uptrend, 1d low
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_80) | (aroonu_14_1d_gt_10))
            # 5m down move, 15m uptrend & washed out, 1h uptrend
            & ((aroonu_14_15m_lt_70) | (aroonu_14_1h_lt_90) | (stochrsi_k_15m_gt_30) | (rsi_3_gt_5))
            # 15m uptrend & washed out, 1h money coming in & down move
            & ((aroonu_14_15m_lt_70) | (mfi_14_1h < 50.0) | (rsi_3_1h_gt_45) | (stochrsi_k_15m_gt_30))
            # 15m uptrend & still high, 1h low
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_15m_gt_50) | (aroonu_14_1h_gt_10))
            # 15m uptrend, 4h & 1d high
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_4h_gt_10) | (stochrsi_k_1d_gt_10))
            # 15m uptrend, 4h washed out, 1d downtrend
            & ((aroonu_14_15m_lt_90) | (stochrsi_k_4h_gt_40) | (aroonu_14_1d_gt_20))
            # 15m no recent low, 15m money drained and 1h cycle turning up
            & ((aroond_14_15m > 30) | (mfi_14_15m > 30) | (cci_20_change_pct_1h < 20))
            # 5m still high, 15m washed out, 1h down move, 4h still high, 1d up move
            & (
              (stochrsi_k_15m_gt_60)
              | (rsi_3_1h_gt_25)
              | (stochrsi_k_4h < 65.0)
              | (stochrsi_k < 10.0)
              | (roc_9_1d < -20.0)
            )
            # 5m downtrend, 15m washed out, 1h washed out & downtrend, 1d downtrend
            & (
              (stochrsi_k_15m_gt_60)
              | (stochrsi_k_1h_gt_30)
              | (aroonu_14_1h_gt_0)
              | (aroonu_14 > 30.0)
              | (aroonu_14_1d > 40.0)
            )
            # 15m high, 1d uptrend & low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1d_lt_70) | (stochrsi_k_1d_gt_20))
            # 15m high, 1h down move, 4h uptrend
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_30) | (aroonu_14_4h_lt_30))
            # 15m high, 4h low, 1d uptrend
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_40))
            # 15m & 1h & 1d low
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_30) | (aroonu_14_1d_gt_10))
            # 15m & 1h low, 1h uptrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_30) | (stochrsi_k_1h_gt_20))
            # 15m low, 1h down move & uptrend
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1h_gt_35) | (aroonu_14_1h_lt_30))
            # 15m & 1d low, 1h up move
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1h_lt_60) | (aroonu_14_1d_gt_10))
            # 15m low, 1h still not low enough, 1d down move
            & ((stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_80) | (rsi_3_1d_gt_25))
            # 15m still high, 1d uptrend & high
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_1d_lt_70) | (stochrsi_k_1d_gt_10))
            # 15m still high, 1h uptrend, 4h oversold
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_1h_lt_20) | (roc_9_4h_gt_neg_10))
            # 15m & 1h still high, 1h up move
            & ((stochrsi_k_15m_gt_50) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_60))
            # 15m still high, 1h & 1d uptrend
            & ((stochrsi_k_15m_gt_60) | (aroonu_14_1h_lt_40) | (aroonu_14_1d_lt_30))
            # 15m still high, 4h down move, 1d low
            & ((stochrsi_k_15m_gt_60) | (rsi_3_4h_gt_30) | (aroonu_14_1d_gt_50))
            # 15m down move & up move, 4h down move, 1d up move & downtrend
            & ((roc_9_15m > -1.0) | (rsi_3_4h_gt_20) | (rsi_3_1d < 30.0) | (rsi_3_15m < 10.0) | (aroonu_14_1d > 15.0))
            # 15m UO high, 1h falling fast, 1d down move
            & ((uo_7_14_28_15m < 55.0) | (rsi_14_change_pct_1h > -5.0) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h still high, 1d downtrend & up move
            & (
              (rsi_3_1h_gt_30) | (aroonu_14_1d_gt_20) | (roc_9_1d < -15.0) | (stochrsi_k_4h_lt_10) | (rsi_3_1d < 10.0)
            )
            # 1h down move & uptrend, 4h up move & still high, 1d up move
            & (
              (rsi_3_1h_gt_35) | (roc_9_4h < -8.0) | (aroonu_14_1h < 65.0) | (roc_9_1d < -10.0) | (stochrsi_k_4h_lt_40)
            )
            # 5m up move, 15m uptrend, 1h down move, 1d on the floor
            & ((rsi_3_1h_gt_25) | (stochrsi_k_1d_gt_10) | (rsi_3 < 30.0) | (aroonu_14_15m < 15.0))
            # 5m up move, 15m still high, 1h down move, 4h up move, 1d up move
            & ((rsi_3_1h_gt_30) | (roc_9_4h < -8.0) | (rsi_3 < 15.0) | (rsi_3_1d < 15.0) | (stochrsi_k_15m < 10.0))
            # 1h up move & uptrend, 1d up move
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_lt_40) | (roc_9_1d_lt_10))
            # 1h up move, 4h still high, 1d uptrend
            & ((rsi_3_1h_lt_40) | (stochrsi_k_4h_gt_60) | (aroonu_14_1d_lt_30))
            # 1h up move & uptrend & still not low enough
            & ((rsi_3_1h_lt_50) | (aroonu_14_1h_lt_50) | (stochrsi_k_1h_gt_80))
            # 1h & 1d up move, 4h down move
            & ((rsi_3_1h_lt_50) | (rsi_3_4h_gt_20) | (rsi_3_1d_lt_35))
            # 1h & 4h up move, 4h still high
            & ((rsi_3_1h_lt_50) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_60))
            # 5m up move, 1h up move, 4h still high, 1d on the floor
            & ((rsi_3_1h_lt_50) | (stochrsi_k_1d_gt_10) | (rsi_3 < 20.0) | (stochrsi_k_4h < 75.0))
            # 5m still high, 1h up move & washed out, 4h uptrend
            & ((rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_75) | (aroonu_14_4h < 25.0) | (stochrsi_k < 25.0))
            # 1h RSI low & down move, 4h up move
            & ((rsi_14_1h > 45.0) | (rsi_3_4h_lt_40) | (rsi_3_1h_gt_10))
            # the 1h has already dumped while the 4h is not weak: a late break into a bounce
            & ((cmf_20_1h > -0.2) | (mfi_14_4h < 30.0))
            # 5m uptrend, 1h downtrend, 4h down move, 1d up move & downtrend
            & (
              (aroonu_14_1h_gt_10)
              | (roc_9_4h_gt_neg_10)
              | (rsi_3_1d < 15.0)
              | (aroonu_14 < 10.0)
              | (aroonu_14_1d > 45.0)
            )
            # 1h downtrend & washed out, 4h washed out, 1d up move & downtrend
            & (
              (aroonu_14_1h_gt_10)
              | (stochrsi_k_1h_gt_60)
              | (rsi_3_1d < 20.0)
              | (stochrsi_k_4h_gt_50)
              | (aroonu_14_1d > 40.0)
            )
            # 15m still high, 1h downtrend, 4h washed out & uptrend, 1d up move
            & (
              (aroonu_14_1h_gt_10)
              | (stochrsi_k_4h_gt_20)
              | (rsi_3_1d < 30.0)
              | (stochrsi_k_15m_lt_40)
              | (aroonu_14_4h < 10.0)
            )
            # 1h downtrend & still high, 4h down move & still high, 1d downtrend
            & (
              (aroonu_14_1h_gt_30)
              | (rsi_3_4h_gt_15)
              | (stochrsi_k_4h_lt_10)
              | (aroonu_14_1d > 40.0)
              | (stochrsi_k_1h < 5.0)
            )
            # 5m up move, 15m down move, 1h downtrend, 4h uptrend
            & ((aroonu_14_1h_gt_10) | (aroonu_14_4h_lt_20) | (rsi_3_15m_gt_10) | (rsi_3 < 15.0))
            # 1h & 1d low, 1d overbought
            & ((aroonu_14_1h_gt_20) | (aroonu_14_1d_gt_10) | (roc_9_1d_gt_neg_70))
            # 1h downtrend, 4h downtrend, 1d uptrend
            & ((aroonu_14_1h_gt_30) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_lt_80))
            # 1h & 1d uptrend, 4h low
            & ((aroonu_14_1h_lt_20) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_lt_60))
            # 1h & 1d uptrend, 1d down move
            & ((aroonu_14_1h_lt_20) | (rsi_3_1d_gt_15) | (aroonu_14_1d_lt_60))
            # 1h & 1d uptrend, 1d down move
            & ((aroonu_14_1h_lt_20) | (rsi_3_1d_gt_25) | (roc_9_1d_lt_0))
            # 1h uptrend, 4h high, 1d down move
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_10) | (rsi_3_1d_gt_5))
            # 1h & 1d uptrend, 4h low
            & ((aroonu_14_1h_lt_40) | (aroonu_14_4h_gt_0) | (aroonu_14_1d_lt_40))
            # 1h & 4h uptrend, 1h low
            & ((aroonu_14_1h_lt_50) | (stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_20))
            # 15m down move, 1h on the floor & up move, 1d downtrend & up move
            & (
              (stochrsi_k_1h_gt_10) | (aroonu_14_1d_gt_10) | (rsi_3_1h < 15.0) | (rsi_3_15m_gt_25) | (rsi_3_1d < 15.0)
            )
            # 15m still high & downtrend, 1h washed out, 1d downtrend & still high
            & (
              (stochrsi_k_1h_gt_20)
              | (aroonu_14_1d_gt_10)
              | (stochrsi_k_15m < 75.0)
              | (stochrsi_k_1d < 15.0)
              | (aroonu_14_15m_gt_0)
            )
            # 5m still high, 15m down move, 1h washed out, 4h up move, 1d uptrend
            & (
              (stochrsi_k_1h_gt_30)
              | (aroonu_14_1d_lt_30)
              | (stochrsi_k < 35.0)
              | (roc_9_4h < -5.0)
              | (rsi_3_15m_gt_40)
            )
            # 1h washed out & up move, 4h still high, 1d downtrend & up move
            & (
              (stochrsi_k_1h_gt_50)
              | (aroonu_14_1d_gt_10)
              | (roc_9_1d < -15.0)
              | (stochrsi_k_4h < 15.0)
              | (rsi_3_1h < 15.0)
            )
            # 15m washed out, 1h washed out, 4h downtrend & still high, 1d up move
            & (
              (stochrsi_k_1h_gt_50)
              | (aroonu_14_4h_gt_10)
              | (stochrsi_k_15m > 25.0)
              | (stochrsi_k_4h < 35.0)
              | (roc_9_1d < -20.0)
            )
            # 5m uptrend, 1h washed out, 4h up move & washed out, 1d still high
            & (
              (stochrsi_k_1h_gt_50)
              | (roc_9_4h < -8.0)
              | (stochrsi_k_1d < 35.0)
              | (aroonu_14 < 55.0)
              | (stochrsi_k_4h_gt_75)
            )
            # 5m up move, 15m uptrend, 1h washed out, 4h downtrend, 1d down move
            & (
              (stochrsi_k_1h_gt_60)
              | (aroonu_14_4h_gt_10)
              | (rsi_3 < 25.0)
              | (aroonu_14_15m_lt_25)
              | (roc_9_1d_gt_neg_10)
            )
            # 5m up move & downtrend, 1h WILLR high, 1d bot wick pct low & on the floor
            & (
              (willr_14_1h < -45.0)
              | (bot_wick_pct_1d > 1.0)
              | (rsi_3 < 15.0)
              | (stochrsi_k_1d > 5.0)
              | (aroonu_14 > 0.0)
            )
            # 15m downtrend & washed out, 1h up move, 1d uptrend & still high
            & (
              (roc_9_1h < -1.0)
              | (aroonu_14_1d_lt_30)
              | (aroonu_14_15m > 25.0)
              | (stochrsi_k_1d_lt_20)
              | (stochrsi_k_15m_gt_20)
            )
            # 5m up move & on the floor, 1h down move, 1d downtrend
            & ((roc_9_1h > -5.0) | (aroonu_14_1d_gt_10) | (rsi_3 < 20.0) | (stochrsi_k > 15.0))
            # 1h downtrend, 4h down move & overbought, 1d downtrend & up move
            & (
              (rsi_3_4h_gt_30)
              | (aroonu_14_1d_gt_10)
              | (stochrsi_k_4h_lt_80)
              | (roc_9_1d < -25.0)
              | (aroonu_14_1h > 25.0)
            )
            # 5m uptrend, 15m up move, 4h down move, 1d downtrend & up move
            & ((rsi_3_4h_gt_20) | (aroonu_14_1d_gt_20) | (rsi_3_1d < 30.0) | (rsi_3_15m < 10.0) | (aroonu_14 < 10.0))
            # 4h down move & oversold, 1d up move
            & ((rsi_3_4h_gt_30) | (roc_9_4h_gt_neg_15) | (rsi_3_1d_lt_35))
            # 5m washed out, 4h down move, 1d downtrend & up move
            & ((rsi_3_4h_gt_45) | (aroonu_14_1d_gt_30) | (rsi_3_1d < 30.0) | (roc_9_1d < -20.0) | (stochrsi_k > 25.0))
            # 1h down move, 4h up move, 1d downtrend
            & ((rsi_3_4h_lt_40) | (aroonu_14_1d_gt_50) | (rsi_3_1h_gt_10))
            # 4h up move & still high, 1d down move
            & ((rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_30) | (rsi_3_1d_gt_25))
            # 4h up move & uptrend, 1d low
            & ((rsi_3_4h_lt_60) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_gt_20))
            # 4h up move, 1d down move & oversold
            & ((rsi_3_4h_lt_60) | (rsi_3_1d_gt_10) | (roc_9_1d_gt_neg_30))
            # the 4h money flow is still healthy: no breakdown behind this break
            & (mfi_14_4h < 50.0)
            # 5m uptrend, 4h washed out, 1d down move & up move & uptrend
            & (
              (stochrsi_k_4h_gt_30)
              | (roc_9_1d_gt_neg_25)
              | (rsi_3_1d < 15.0)
              | (aroonu_14_1d < 25.0)
              | (aroonu_14 < 15.0)
            )
            # 15m washed out, 4h up move & down move, 1d washed out & up move
            & (
              (roc_9_4h < -8.0) | (stochrsi_k_1d_gt_30) | (roc_9_1d_lt_0) | (stochrsi_k_15m > 25.0) | (rsi_3_4h_gt_50)
            )
            # 1d strong down move, or 4h not at the ceiling
            & ((roc_9_1d < -10.0) | (stochrsi_k_4h < 90.0))
            # 5m quad s93 max 12 low & up move, 15m CCI high & downtrend, 4h up move
            & (
              (quad_s93_max_12 > 70.0)
              | (cci_20_15m < 0.0)
              | (rsi_3 < 15.0)
              | (roc_9_4h < -5.0)
              | (aroonu_14_15m_gt_50)
            )
            # 5m stochastic high, 15m money flowing in and daily no recent low
            & ((stoch_14_3 < 20) | (cmf_20_15m_lt_0_10) | (aroond_14_1d > 55))
            # 5m still high, 15m rising fast, 4h uptrend & up move, 1d daily change low
            & (
              (rsi_14_change_pct_15m < -3.0)
              | (change_pct_1d_gt_neg_5)
              | (stochrsi_k_lt_30)
              | (aroonu_14_4h < 15.0)
              | (roc_9_4h < -10.0)
            )
            # 5m still high & down move, 15m rising fast, 4h rising fast
            & (
              (rsi_14_change_pct_15m < -6.0)
              | (stochrsi_k_change_pct_4h < 125.0)
              | (stochrsi_k < 55.0)
              | (rsi_3 > 35.0)
            )
            # 15m cycle falling, 4h no recent low and daily money flowing in
            & ((cci_20_change_pct_15m > -195) | (aroond_14_4h > 50) | (mfi_14_1d < 45))
          )

          # Logic
          short_entry_logic.append(
            (close < ema_200)
            # 15m not low, 1h not narrow, 1h not oversold, 1d deep down move
            & ((stochk_14_3_3_15m < 40.0) | (bbb_20_2_0_1h < 7.0) | (willr_14_1h < -70.0) | (roc_9_1d_gt_neg_20))
            # don't short a breakdown when the daily cycle already sits low (bounce zone)
            & (stochrsi_k_1d < 45.0)
            # the 4h has to be in on it: no recent 4h high behind the break
            & (aroonu_14_4h_lt_40)
            # last completed 1h candle was an inside bar; this 5m candle CROSSES below the mother low
            & (ib_ready > 0.5)
            & (np_shift(close, 1) >= ib_mother_l)
            & (close < ib_mother_l)
          )

        # Condition #669 - Dump hunter (Short, experimental, RAW — crash ignition, mirror of 171).
        if short_entry_condition_index == 669:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m down move & washed out, 15m downtrend & still high, 4h still high
            (
              (rsi_3_gt_15)
              | (aroonu_14_15m_gt_10)
              | (stochrsi_k_4h < 55.0)
              | (stochrsi_k_15m_lt_20)
              | (stochrsi_k > 20.0)
            )
            # 5m, 1h and 4h all spent
            & ((rsi_3_gt_10) | (stochrsi_k_1h_gt_10) | (rsi_3_4h_gt_5))
            # 5m down move, 1h up move, 4h uptrend, 1d down move
            & ((rsi_3_gt_15) | (roc_9_1d_gt_neg_10) | (aroonu_14_4h_lt_40) | (rsi_3_1h < 10.0) | (rsi_3_1d_gt_65))
            # 5m & 1d down move, 4h uptrend
            & ((rsi_3_gt_3) | (aroonu_14_4h_lt_20) | (rsi_3_1d_gt_10))
            # 5m down move, 4h uptrend, 1d high
            & ((rsi_3_gt_3) | (aroonu_14_4h_lt_30) | (stochrsi_k_1d_gt_10))
            # 5m & 15m down move, 1h uptrend
            & ((rsi_3_gt_3) | (rsi_3_15m_gt_5) | (aroonu_14_1h_lt_25))
            # 5m & 1h & 1d down move
            & ((rsi_3_gt_3) | (rsi_3_1h_gt_10) | (rsi_3_1d_gt_10))
            # 5m down move, 4h up move & still high
            & ((rsi_3_gt_3) | (rsi_3_4h_lt_50) | (stochrsi_k_4h_gt_50))
            # 5m down move, 1h still high, 4h low
            & ((rsi_3_gt_3) | (stochrsi_k_1h_gt_30) | (aroonu_14_4h_gt_20))
            # 5m down move, 4h & 1d low
            & ((rsi_3_gt_3) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_10))
            # 5m & 1d down move, 4h low
            & ((rsi_3_gt_3) | (stochrsi_k_4h_gt_20) | (rsi_3_1d_gt_10))
            # 5m down move, 4h uptrend & still high
            & ((rsi_3_gt_5) | (aroonu_14_4h_lt_30) | (stochrsi_k_4h_gt_30))
            # 5m & 1h down move, 4h still high
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_gt_30))
            # 5m down move, 1h high, 4h low
            & ((rsi_3_gt_5) | (stochrsi_k_1h_gt_10) | (stochrsi_k_4h_gt_20))
            # 5m down move, 4h high & oversold
            & ((rsi_3_gt_5) | (stochrsi_k_4h_gt_10) | (roc_9_4h_gt_neg_10))
            # 5m uptrend, 15m low, 1d oversold
            & ((aroonu_14_lt_25) | (aroonu_14_15m_gt_20) | (roc_9_1d_gt_neg_20))
            # 5m & 15m uptrend, 1h down move
            & ((aroonu_14_lt_25) | (aroonu_14_15m_lt_50) | (rsi_3_1h_gt_20))
            # 5m & 1d uptrend, 4h low
            & ((aroonu_14_lt_25) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_lt_40))
            # 5m & 4h uptrend, 4h high
            & ((aroonu_14_lt_25) | (aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_10))
            # 5m & 15m uptrend, 15m down move
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_10) | (aroonu_14_15m_lt_40))
            # 5m & 1d uptrend, 1h down move
            & ((aroonu_14_lt_25) | (rsi_3_1h_gt_20) | (aroonu_14_1d_lt_40))
            # 5m uptrend, 15m high, 1h low
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_10) | (aroonu_14_1h_gt_10))
            # 5m uptrend, 15m & 1h low
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_0))
            # 5m & 1h uptrend, 15m low
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_25))
            # 5m & 4h uptrend, 15m low
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_60))
            # 5m uptrend, 15m still high, 1h up move
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_40) | (rsi_3_1h_lt_60))
            # 5m & 4h uptrend, 15m low
            & ((aroonu_14_lt_30) | (aroonu_14_15m_gt_10) | (aroonu_14_4h_lt_60))
            # 5m uptrend, 15m low, 4h down move
            & ((aroonu_14_lt_30) | (aroonu_14_15m_gt_10) | (rsi_3_4h_gt_10))
            # 5m uptrend, 15m downtrend, 4h on the floor
            & ((aroonu_14_lt_30) | (aroonu_14_15m_gt_20) | (stochrsi_k_4h_gt_10))
            # 5m & 15m uptrend, 1d low
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_40) | (aroonu_14_1d_gt_20))
            # 5m & 1d uptrend, 1d still high
            & ((aroonu_14_lt_30) | (aroonu_14_1d_lt_60) | (stochrsi_k_1d_gt_60))
            # 5m & 1d uptrend, 1d still not high enough
            & ((aroonu_14_lt_30) | (aroonu_14_1d_lt_80) | (stochrsi_k_1d_gt_70))
            # 5m uptrend, 1h & 4h low
            & ((aroonu_14_lt_30) | (aroonu_14_1h_gt_0) | (stochrsi_k_4h_gt_20))
            # 5m & 1h uptrend, 4h low
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_20) | (aroonu_14_4h_gt_10))
            # 5m & 1h uptrend, 4h low
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_25) | (aroonu_14_4h_gt_20))
            # 5m & 1d uptrend, 4h low
            & ((aroonu_14_lt_30) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_lt_30))
            # 5m uptrend, 4h low, 1d up move
            & ((aroonu_14_lt_30) | (aroonu_14_4h_gt_20) | (rsi_3_1d_lt_35))
            # 5m & 4h uptrend, 1d low
            & ((aroonu_14_lt_30) | (aroonu_14_4h_lt_80) | (stochrsi_k_1d_gt_20))
            # 5m uptrend, 15m down move & high
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_10) | (stochrsi_k_15m_gt_10))
            # 5m uptrend, 15m down move & still high, 4h uptrend
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_15) | (aroonu_14_4h_lt_40) | (stochrsi_k_15m < 45.0))
            # 5m uptrend, 15m down move, 4h up move
            & ((aroonu_14_lt_30) | (rsi_3_15m_gt_20) | (rsi_3_4h_lt_40))
            # 5m uptrend, 1h up move, 1d downtrend
            & ((aroonu_14_lt_30) | (rsi_3_1h_lt_40) | (aroonu_14_1d_gt_10))
            # 5m & 1h uptrend, 1h up move
            & ((aroonu_14_lt_30) | (rsi_3_1h_lt_55) | (aroonu_14_1h_lt_25))
            # 5m uptrend, 4h up move & still high
            & ((aroonu_14_lt_30) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_50))
            # 5m uptrend, 4h up move & low
            & ((aroonu_14_lt_30) | (rsi_3_4h_lt_50) | (aroonu_14_4h_gt_50))
            # 5m uptrend, 15m high, 4h still not low enough
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_80))
            # 5m uptrend, 15m & 4h low
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_20) | (aroonu_14_4h_gt_10))
            # 5m & 4h uptrend, 15m low
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_40))
            # 5m uptrend, 15m still high, 1h low
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_30) | (aroonu_14_1h_gt_0))
            # 5m & 1d uptrend, 15m still high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_40) | (aroonu_14_1d_lt_60))
            # 5m & 4h uptrend, 15m still high
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_40) | (aroonu_14_4h_lt_50))
            # 5m uptrend, 15m still high, 4h low
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_40) | (stochrsi_k_4h_gt_20))
            # 5m & 4h uptrend, 1h high
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_gt_10) | (aroonu_14_4h_lt_90))
            # 5m uptrend, 1h high, 1d low
            & ((aroonu_14_lt_30) | (stochrsi_k_1h_gt_10) | (stochrsi_k_1d_gt_20))
            # 5m uptrend, 4h & 1d low
            & ((aroonu_14_lt_30) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_20))
            # 5m uptrend, 4h low, 1d still high
            & ((aroonu_14_lt_30) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_40))
            # 5m uptrend, 4h still high, 1d low
            & ((aroonu_14_lt_30) | (stochrsi_k_4h_gt_40) | (stochrsi_k_1d_gt_20))
            # 5m the last 24h is flat, 15m not oversold and 15m momentum alive
            & ((roc_288 < 8) | (rsi_14_15m_lt_30) | (rsi_3_15m < 5))
            # 15m down move, 4h uptrend & washed out, 1d down move & downtrend
            & (
              (rsi_3_15m_gt_20)
              | (aroonu_14_4h_lt_20)
              | (rsi_3_1d_gt_45)
              | (aroonu_14_1d > 15.0)
              | (stochrsi_k_4h_gt_70)
            )
            # 15m down move & still high, 1h washed out, 4h uptrend, 1d down move
            & (
              (rsi_3_15m_gt_25)
              | (aroonu_14_4h_lt_20)
              | (rsi_3_1d_gt_40)
              | (stochrsi_k_1h_gt_40)
              | (stochrsi_k_15m < 10.0)
            )
            # 15m down move & low, 1d uptrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_gt_10) | (aroonu_14_1d_lt_70))
            # 15m down move, 15m & 1h uptrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_20))
            # 15m down move & still high, 1h uptrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_30) | (stochrsi_k_15m < 35.0))
            # 15m down move, 4h & 1d uptrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_4h_lt_20) | (aroonu_14_1d_lt_70))
            # 15m & 1d down move, 1d still high
            & ((rsi_3_15m_gt_10) | (rsi_3_1d_gt_40) | (stochrsi_k_1d_gt_30))
            # 15m & 1h down move, 1d oversold
            & ((rsi_3_15m_gt_10) | (rsi_3_1h_gt_5) | (roc_9_1d_gt_neg_20))
            # 15m & 4h down move, 1d high
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_5) | (stochrsi_k_1d_gt_10))
            # 15m down move & uptrend, 4h low
            & ((rsi_3_15m_gt_15) | (aroonu_14_15m_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m down move, 1h & 4h uptrend
            & ((rsi_3_15m_gt_15) | (aroonu_14_1h_lt_25) | (aroonu_14_4h_lt_20))
            # 15m down move, 4h uptrend, 1d high
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_40) | (stochrsi_k_1d_gt_10))
            # 15m down move, 4h uptrend, 1d low
            & ((rsi_3_15m_gt_15) | (aroonu_14_4h_lt_80) | (stochrsi_k_1d_gt_20))
            # 15m & 4h down move, 1d oversold
            & ((rsi_3_15m_gt_15) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_15))
            # 15m down move & still high, 1d uptrend
            & ((rsi_3_15m_gt_15) | (stochrsi_k_15m_lt_50) | (aroonu_14_1d_lt_60))
            # 15m down move, 1h still high, 4h uptrend
            & ((rsi_3_15m_gt_15) | (stochrsi_k_1h_lt_70) | (aroonu_14_4h_lt_30))
            # 15m & 4h down move, 15m uptrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_lt_20) | (rsi_3_4h_gt_15))
            # 15m down move, 1h & 4h uptrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_20) | (aroonu_14_4h_lt_30))
            # 15m & 4h down move, 1h uptrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_1h_lt_25) | (rsi_3_4h_gt_30))
            # 15m down move, 1h up move, 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m & 1d down move, 4h high
            & ((rsi_3_15m_gt_20) | (stochrsi_k_4h_gt_10) | (rsi_3_1d_gt_10))
            # 15m & 4h down move, 15m uptrend
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_30) | (rsi_3_4h_gt_25))
            # 15m down move & uptrend, 4h up move
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_40) | (rsi_3_4h_lt_50))
            # 15m down move & uptrend, 1h still high
            & ((rsi_3_15m_gt_25) | (aroonu_14_15m_lt_80) | (stochrsi_k_1h_gt_50))
            # 15m down move, 1d down move
            & ((rsi_3_15m_gt_3) | (roc_9_1d_gt_neg_70))
            # 15m & 4h down move, 1h up move
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_lt_65) | (rsi_3_4h_gt_30))
            # 15m & 1h down move, 15m low
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_gt_10) | (rsi_3_1h_gt_30))
            # 15m & 1h down move, 15m uptrend
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_30) | (rsi_3_1h_gt_30))
            # 15m down move & uptrend, 1h still high
            & ((rsi_3_15m_gt_5) | (aroonu_14_15m_lt_30) | (stochrsi_k_1h_gt_40))
            # 15m down move, 1h low, 4h up move
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_gt_0) | (rsi_3_4h_lt_40))
            # 15m and 1d spent, 1h still trending up
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_20) | (rsi_3_1d_gt_10))
            # 15m down move, 1h uptrend, 4h low
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_20))
            # 15m down move, 1h & 1d uptrend
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_25) | (aroonu_14_1d_lt_30))
            # 15m down move, 4h uptrend, 1d oversold
            & ((rsi_3_15m_gt_5) | (aroonu_14_4h_lt_20) | (roc_9_1d_gt_neg_20))
            # 15m up move & low, 1h down move
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_gt_20) | (rsi_3_1h_gt_15))
            # 15m up move & low, 1d down move
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_gt_30) | (rsi_3_1d_gt_40))
            # 15m up move, 4h low & still high
            & ((rsi_3_15m_lt_50) | (aroonu_14_4h_gt_30) | (stochrsi_k_4h_gt_60))
            # 15m up move, 15m & 1d low
            & ((rsi_3_15m_lt_55) | (aroonu_14_15m_gt_60) | (aroonu_14_1d_gt_20))
            # 15m up move, 1h low, 4h still high
            & ((rsi_3_15m_lt_55) | (aroonu_14_1h_gt_20) | (stochrsi_k_4h_gt_60))
            # 15m money drained, 1h momentum snapping up, daily momentum collapsing and daily stochastic at the floor
            & ((mfi_14_15m > 30) | (rsi_3_change_pct_1h < -20) | (rsi_3_change_pct_1d > -20) | (stochk_14_3_3_1d > 30))
            # 15m downtrend & down move & still high, 1h up move, 1d down move
            & (
              (aroonu_14_15m_gt_10) | (rsi_3_1d_gt_25) | (rsi_3_15m_gt_20) | (stochrsi_k_15m < 10.0) | (rsi_3_1h < 5.0)
            )
            # 15m downtrend & still high, 1h down move, 4h uptrend, 1d downtrend
            & (
              (aroonu_14_15m_gt_10)
              | (rsi_3_1h_gt_15)
              | (aroonu_14_4h < 15.0)
              | (aroonu_14_1d > 15.0)
              | (stochrsi_k_15m < 25.0)
            )
            # 15m downtrend, 1h up move, 4h down move & still high, 1d up move
            & (
              (aroonu_14_15m_gt_10) | (rsi_3_4h_gt_35) | (stochrsi_k_4h < 45.0) | (rsi_3_1d < 15.0) | (rsi_3_1h < 5.0)
            )
            # 15m downtrend, 1h washed out & up move, 1d washed out & up move
            & (
              (aroonu_14_15m_gt_10)
              | (stochrsi_k_1h_gt_30)
              | (rsi_3_1h < 10.0)
              | (stochrsi_k_1d_gt_30)
              | (rsi_3_1d < 15.0)
            )
            # 15m downtrend, 1h uptrend, 4h uptrend, 1d down move & downtrend
            & (
              (aroonu_14_15m_gt_20)
              | (rsi_3_1d_gt_25)
              | (aroonu_14_4h < 15.0)
              | (aroonu_14_1d > 15.0)
              | (aroonu_14_1h < 5.0)
            )
            # 15m & 1h low, 1h down move
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_10) | (rsi_3_1h_gt_20))
            # 15m low, 1h & 4h uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_lt_20) | (aroonu_14_4h_lt_60))
            # 15m & 4h low, 4h uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_4h_gt_10) | (roc_9_4h_lt_5))
            # 15m low, 4h uptrend, 1d down move
            & ((aroonu_14_15m_gt_10) | (aroonu_14_4h_lt_30) | (rsi_3_1d_gt_20))
            # 15m & 1d low, 4h uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_4h_lt_70) | (stochrsi_k_1d_gt_20))
            # 15m & 4h low, 1h up move
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_40) | (aroonu_14_4h_gt_30))
            # 15m low, 1h up move, 4h still high
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_50) | (stochrsi_k_4h_gt_40))
            # 15m low & high, 4h up move
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_10) | (rsi_3_4h_lt_70))
            # 15m low, 4h high
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_15m_gt_20) | (stochrsi_k_4h_gt_10))
            # 15m low, 1h high, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_1h_gt_10) | (aroonu_14_1d_lt_60))
            # 15m low, 1h high, 4h uptrend
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_1h_gt_10) | (aroonu_14_4h_lt_80))
            # 15m & 4h low, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_80))
            # 15m & 1h low, 4h up move
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_0) | (rsi_3_4h_lt_40))
            # 15m low, 1h uptrend, 4h up move
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_25) | (rsi_3_4h_lt_70))
            # 15m & 4h low, 1d uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_lt_80))
            # 15m low, 1h down move, 4h still high
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_gt_15) | (stochrsi_k_4h_gt_60))
            # 15m low, 1h down move, 4h uptrend
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_gt_20) | (aroonu_14_4h_lt_70))
            # 15m & 1h low, 1h up move
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_70) | (aroonu_14_1h_gt_0))
            # 15m low, 4h up move & still high
            & ((aroonu_14_15m_gt_30) | (rsi_3_4h_lt_50) | (stochrsi_k_4h_gt_40))
            # 15m & 1d low, 1h up move
            & ((aroonu_14_15m_gt_40) | (rsi_3_1h_lt_40) | (stochrsi_k_1d_gt_20))
            # 15m & 4h uptrend, 1h low
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_lt_70))
            # 15m & 4h uptrend, 1d low
            & ((aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_gt_20))
            # 15m uptrend, 1h down move, 4h low
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_gt_15) | (aroonu_14_4h_gt_10))
            # 15m uptrend & high, 4h down move
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_10) | (rsi_3_4h_gt_10))
            # 15m uptrend & high, 4h low
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m uptrend & still high, 1d low
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_30) | (aroonu_14_1d_gt_20))
            # 15m uptrend, 1h high, 1d low
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_10) | (aroonu_14_1d_gt_30))
            # 15m uptrend, 1h still high, 4h high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_40) | (stochrsi_k_4h_gt_10))
            # 15m uptrend, 1h uptrend, 4h washed out
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_25) | (stochrsi_k_4h_gt_20))
            # 15m & 4h uptrend, 4h high
            & ((aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_50) | (stochrsi_k_4h_gt_10))
            # 15m & 4h uptrend, 1d still high
            & ((aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_90) | (stochrsi_k_1d_gt_60))
            # 15m & 1h uptrend, 1h up move
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_lt_40) | (aroonu_14_1h_lt_20))
            # 15m & 1d uptrend, 4h up move
            & ((aroonu_14_15m_lt_30) | (rsi_3_4h_lt_50) | (aroonu_14_1d_lt_60))
            # 15m & 1h uptrend, 15m high
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_25))
            # 15m uptrend & high, 4h low
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_15m_gt_10) | (aroonu_14_4h_gt_30))
            # 15m uptrend, 1h low, 4h still high
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_50))
            # 15m uptrend, 1h still high, 4h low
            & ((aroonu_14_15m_lt_30) | (stochrsi_k_1h_gt_40) | (stochrsi_k_4h_gt_20))
            # 15m uptrend, 1h & 4h low
            & ((aroonu_14_15m_lt_40) | (aroonu_14_1h_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m & 1h & 4h uptrend
            & ((aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_25) | (aroonu_14_4h_lt_20))
            # 15m & 1h uptrend, 4h still high
            & ((aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_30) | (stochrsi_k_4h_gt_40))
            # 5m uptrend & down move, 15m uptrend, 1h washed out, 4h up move
            & ((aroonu_14_15m_lt_40) | (roc_9_4h < 0.0) | (stochrsi_k_1h_gt_30) | (aroonu_14 < 15.0) | (rsi_3_gt_10))
            # 15m uptrend, 1h up move, 4h down move
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_lt_40) | (rsi_3_4h_gt_5))
            # 15m uptrend, 4h up move & still high
            & ((aroonu_14_15m_lt_40) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_50))
            # 15m & 4h uptrend, 4h up move
            & ((aroonu_14_15m_lt_40) | (rsi_3_4h_lt_50) | (aroonu_14_4h_lt_20))
            # 15m uptrend, 4h up move, 1d low
            & ((aroonu_14_15m_lt_40) | (rsi_3_4h_lt_70) | (aroonu_14_1d_gt_30))
            # 15m uptrend & high, 1d low
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_10) | (stochrsi_k_1d_gt_20))
            # 15m uptrend & high, 4h still high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_40))
            # 15m & 4h uptrend, 15m low
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_40))
            # 15m uptrend & low, 4h down move
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_20))
            # 15m uptrend & still high, 1d low
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_40) | (aroonu_14_1d_gt_10))
            # 15m uptrend & still high, 4h low
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_40) | (stochrsi_k_4h_gt_20))
            # 15m uptrend, 1h on the floor, 4h downtrend
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_10) | (aroonu_14_4h_gt_50))
            # 15m & 1d uptrend, 1h still high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_40) | (aroonu_14_1d_lt_60))
            # 15m uptrend, 4h & 1d low
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_20))
            # 15m uptrend, 4h down move, 1d up move
            & ((aroonu_14_15m_lt_50) | (rsi_3_4h_gt_15) | (rsi_3_1d_lt_35))
            # 15m uptrend & still high, 1h low
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_40) | (stochrsi_k_1h_gt_20))
            # 15m uptrend, 1h uptrend, 4h up move
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_20) | (rsi_3_4h_lt_40))
            # 15m & 1h uptrend, 1d low
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_20) | (stochrsi_k_1d_gt_20))
            # 15m & 1h uptrend, 1h low
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_20) | (stochrsi_k_1h_gt_20))
            # 15m & 1d uptrend, 15m high
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_15m_gt_10) | (aroonu_14_1d_lt_80))
            # 15m uptrend & still high, 1d low
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_15m_gt_40) | (aroonu_14_1d_gt_30))
            # 15m uptrend, 1h still high, 1d low
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_1h_gt_60) | (aroonu_14_1d_gt_20))
            # 15m uptrend, 15m & 4h still high
            & ((aroonu_14_15m_lt_70) | (stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_40))
            # 15m uptrend intact while 15m is low
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_gt_20))
            # 15m uptrend, 1h still high, 4h low
            & ((aroonu_14_15m_lt_80) | (stochrsi_k_1h_gt_60) | (aroonu_14_4h_gt_20))
            # 15m uptrend, 4h up move & still not low enough
            & ((aroonu_14_15m_lt_90) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_80))
            # 15m & 1d high, 1d uptrend
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1d_lt_30) | (stochrsi_k_1d_gt_10))
            # 15m high, 1h & 4h low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_gt_10))
            # 15m high, 1h low, 4h uptrend
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_gt_0) | (aroonu_14_4h_lt_40))
            # 15m high, 1h & 4h low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_gt_0) | (stochrsi_k_4h_gt_20))
            # 15m high, 1h uptrend, 1d low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_gt_20))
            # 15m high, 1h & 4h uptrend
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_1h_lt_25) | (aroonu_14_4h_lt_30))
            # 15m high, 4h low, 1d uptrend
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_4h_gt_30) | (aroonu_14_1d_lt_40))
            # 15m high, 4h low, 1d up move
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_4h_gt_30) | (rsi_3_1d_lt_80))
            # 15m high, 4h uptrend, 1d low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_gt_10))
            # 15m high, 4h uptrend, 1d low
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_gt_20))
            # 15m on the floor, 4h uptrend & washed out
            & ((stochrsi_k_15m_gt_10) | (aroonu_14_4h_lt_80) | (stochrsi_k_4h_gt_40))
            # 15m high, 1h down move, 1d up move
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_5) | (rsi_3_1d_lt_35))
            # 15m high, 1h up move, 4h still high
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_lt_40) | (stochrsi_k_4h_gt_50))
            # 15m high, 4h up move & still high
            & ((stochrsi_k_15m_gt_10) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_40))
            # 15m high, 4h up move & still high
            & ((stochrsi_k_15m_gt_10) | (rsi_3_4h_lt_50) | (stochrsi_k_4h_gt_50))
            # 15m high, 1d low & uptrend
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_1d_gt_20) | (roc_9_1d_lt_10))
            # 15m on the floor, 4h on the floor
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_10))
            # 15m high, 4h low, 1d uptrend
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_40))
            # 15m high, 4h low, 1d oversold
            & ((stochrsi_k_15m_gt_10) | (stochrsi_k_4h_gt_20) | (roc_9_1d_gt_neg_15))
            # 15m & 1d low, 1h uptrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_20) | (stochrsi_k_1d_gt_20))
            # 15m low, 4h uptrend & still high
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_30))
            # 15m low, 4h down move, 1d oversold
            & ((stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_15) | (roc_9_1d_gt_neg_20))
            # 15m & 1h & 4h low
            & ((stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m still high, 1d uptrend & low
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_gt_20))
            # 15m washed out, 1h still high, 1d down move
            & ((stochrsi_k_15m_gt_30) | (roc_9_1d_gt_neg_40) | (stochrsi_k_1h < 35.0))
            # 15m still high, 1d down move & uptrend
            & ((stochrsi_k_15m_gt_30) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_60))
            # 15m still high, 1h up move & low
            & ((stochrsi_k_15m_gt_30) | (rsi_3_1h_lt_40) | (aroonu_14_1h_gt_0))
            # 15m still high, 1h high, 4h low
            & ((stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m still high, 4h uptrend & low
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m still high, 1h up move, 4h low
            & ((stochrsi_k_15m_gt_40) | (rsi_3_1h_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m still high, 1h up move, 4h down move
            & ((stochrsi_k_15m_gt_40) | (rsi_3_1h_lt_50) | (rsi_3_4h_gt_30))
            # 15m & 1h still high, 4h low
            & ((stochrsi_k_15m_gt_40) | (stochrsi_k_1h_gt_30) | (aroonu_14_4h_gt_10))
            # 15m still high, 1h low, 1d uptrend
            & ((stochrsi_k_15m_gt_50) | (stochrsi_k_1h_gt_20) | (aroonu_14_1d_lt_60))
            # 15m overbought, 1h down move, 4h still high
            & ((stochrsi_k_15m_lt_80) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_lt_40))
            # 15m down move & washed out, 4h uptrend, 1d downtrend & down move
            & (
              (roc_9_15m > -1.0)
              | (aroonu_14_1d_gt_20)
              | (aroonu_14_4h < 15.0)
              | (rsi_3_1d_gt_50)
              | (stochrsi_k_15m_gt_40)
            )
            # 15m down move & still high, 1h washed out, 4h uptrend, 1d down move
            & (
              (roc_9_15m > -1.0)
              | (rsi_3_1d_gt_35)
              | (aroonu_14_4h < 15.0)
              | (stochrsi_k_15m < 10.0)
              | (stochrsi_k_1h > 45.0)
            )
            # 15m down move & still high, 1h down move & still high, 4h uptrend
            & (
              (roc_9_15m > -1.0)
              | (rsi_3_1h_gt_20)
              | (aroonu_14_4h < 15.0)
              | (stochrsi_k_1h < 10.0)
              | (stochrsi_k_15m < 10.0)
            )
            # 15m down move, 1h downtrend, 4h up move & down move, 1d down move
            & ((roc_9_15m > -1.0) | (aroonu_14_1h_gt_20) | (roc_9_4h < 0.0) | (rsi_3_1d_gt_35) | (rsi_3_4h_gt_35))
            # 1h down move & low, 1d uptrend
            & ((rsi_3_1h_gt_10) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_lt_40))
            # 1h down move, 4h up move, 1d high
            & ((rsi_3_1h_gt_10) | (rsi_3_4h_lt_40) | (stochrsi_k_1d_gt_10))
            # 1h down move, 4h low, 1d oversold
            & ((rsi_3_1h_gt_10) | (stochrsi_k_4h_gt_20) | (roc_9_1d_gt_neg_20))
            # 5m up move, 1h down move, 1d AROOND low
            & ((rsi_3_1h_gt_15) | (aroond_14_1d > 10.0) | (rsi_3 < 15.0))
            # 1h & 4h down move, 1d high
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_25) | (stochrsi_k_1d_gt_10))
            # 15m down move, 1h down move & on the floor, 4h up move & down move
            & ((rsi_3_1h_gt_20) | (stochrsi_k_1h_gt_10) | (roc_9_4h < 0.0) | (rsi_3_15m_gt_10) | (rsi_3_4h_gt_30))
            # 1h down move, 4h & 1d high
            & ((rsi_3_1h_gt_20) | (stochrsi_k_4h_gt_10) | (stochrsi_k_1d_gt_10))
            # 1h down move, 4h high & oversold
            & ((rsi_3_1h_gt_25) | (stochrsi_k_4h_gt_10) | (roc_9_4h_gt_neg_10))
            # 1h & 1d down move, 4h uptrend
            & ((rsi_3_1h_gt_5) | (aroonu_14_4h_lt_50) | (rsi_3_1d_gt_40))
            # 1h up move & uptrend, 4h down move
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_30))
            # 1h up move & uptrend, 1d still high
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_lt_20) | (stochrsi_k_1d_gt_40))
            # 1h up move, 4h still high, 1d low
            & ((rsi_3_1h_lt_40) | (stochrsi_k_4h_gt_30) | (aroonu_14_1d_gt_20))
            # 1h up move, 1d uptrend & still not high enough
            & ((rsi_3_1h_lt_50) | (aroonu_14_1d_lt_60) | (stochrsi_k_1d_gt_70))
            # 1h up move, 4h & 1d still high
            & ((rsi_3_1h_lt_50) | (stochrsi_k_4h_gt_40) | (stochrsi_k_1d_gt_40))
            # 1h up move & low, 4h still high
            & ((rsi_3_1h_lt_55) | (aroonu_14_1h_gt_10) | (stochrsi_k_4h_gt_50))
            # 1h & 1d up move, 1h still high
            & ((rsi_3_1h_lt_55) | (stochrsi_k_1h_gt_40) | (rsi_3_1d_lt_90))
            # 1h up move, 4h & 1d uptrend
            & ((rsi_3_1h_lt_60) | (aroonu_14_4h_lt_70) | (roc_9_1d_lt_35))
            # 5m uptrend, 1h downtrend & up move, 1d down move & up move
            & (
              (aroonu_14_1h_gt_10) | (roc_9_1d_gt_neg_20) | (aroonu_14 < 10.0) | (rsi_3_1h < 20.0) | (rsi_3_1d < 15.0)
            )
            # 1h low, 4h uptrend & high
            & ((aroonu_14_1h_gt_0) | (aroonu_14_4h_lt_30) | (stochrsi_k_4h_gt_10))
            # 1h & 4h low, 4h uptrend
            & ((aroonu_14_1h_gt_0) | (aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_20))
            # 1h low, 1d down move & oversold
            & ((aroonu_14_1h_gt_0) | (roc_9_1d_gt_neg_15) | (rsi_3_1d_gt_20))
            # 1h low, 4h down move & uptrend
            & ((aroonu_14_1h_gt_0) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_40))
            # 1h & 1d low, 4h up move
            & ((aroonu_14_1h_gt_0) | (rsi_3_4h_lt_40) | (aroonu_14_1d_gt_20))
            # 1h downtrend, 1d extended
            & ((aroonu_14_1h_gt_10) | (roc_9_1d_lt_100))
            # 1h & 4h low, 4h up move
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_20))
            # 1h low & high, 1d uptrend
            & ((aroonu_14_1h_gt_10) | (stochrsi_k_1h_gt_10) | (aroonu_14_1d_lt_60))
            # 1h low & high, 4h down move
            & ((aroonu_14_1h_gt_10) | (stochrsi_k_1h_gt_10) | (rsi_3_4h_gt_10))
            # 1h & 4h low, 1d uptrend
            & ((aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_20) | (roc_9_1d_lt_10))
            # 1h low, 4h & 1d uptrend
            & ((aroonu_14_1h_gt_20) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_lt_60))
            # 1h & 1d uptrend, 1d low
            & ((aroonu_14_1h_lt_20) | (aroonu_14_1d_gt_20) | (roc_9_1d_lt_10))
            # 1h & 4h uptrend, 1d low
            & ((aroonu_14_1h_lt_20) | (aroonu_14_4h_lt_30) | (stochrsi_k_1d_gt_20))
            # 1h uptrend & high, 4h low
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_1h_gt_10) | (stochrsi_k_4h_gt_20))
            # 1h uptrend, 4h & 1d low
            & ((aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_20))
            # 1h uptrend, 1d down move
            & ((aroonu_14_1h_lt_30) | (rsi_3_1d_gt_5))
            # 1h still not low enough
            & (aroonu_14_1h_lt_40)
            # 5m downtrend, 1h washed out & up move, 4h washed out, 1d down move
            & (
              (stochrsi_k_1h_gt_20)
              | (roc_9_1d_gt_neg_15)
              | (rsi_3_1h < 10.0)
              | (aroonu_14 > 25.0)
              | (stochrsi_k_4h_gt_75)
            )
            # 5m still high, 1h washed out, 4h washed out & uptrend, 1d downtrend
            & (
              (stochrsi_k_1h_gt_20)
              | (stochrsi_k_4h_gt_40)
              | (aroonu_14_1d_gt_0)
              | (aroonu_14_4h < 15.0)
              | (stochrsi_k_lt_20)
            )
            # 1h high, 4h low, 1d uptrend
            & ((stochrsi_k_1h_gt_10) | (aroonu_14_4h_gt_10) | (roc_9_1d_lt_10))
            # 1h low, 4h leg spent, 1d washed out
            & ((stochrsi_k_1h_gt_10) | (roc_9_4h_gt_neg_10) | (rsi_3_1d_gt_10))
            # 5m up move, 1h on the floor, 1d down move & uptrend
            & ((stochrsi_k_1h_gt_10) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_30) | (rsi_3 < 10.0))
            # 1h high, 4h up move, 1d uptrend
            & ((stochrsi_k_1h_gt_10) | (rsi_3_4h_lt_40) | (aroonu_14_1d_lt_40))
            # 1h high, 4h up move & low
            & ((stochrsi_k_1h_gt_10) | (rsi_3_4h_lt_40) | (aroonu_14_4h_gt_10))
            # 1h on the floor, 4h up move, 1d still high
            & ((stochrsi_k_1h_gt_10) | (rsi_3_4h_lt_50) | (stochrsi_k_1d_lt_60))
            # 1h high, 4h up move & uptrend
            & ((stochrsi_k_1h_gt_10) | (rsi_3_4h_lt_60) | (aroonu_14_4h_lt_90))
            # 1h still high, 4h up move & low
            & ((stochrsi_k_1h_gt_30) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_20))
            # 4h down move & uptrend & still high
            & ((rsi_3_4h_gt_15) | (aroonu_14_4h_lt_60) | (stochrsi_k_4h_lt_60))
            # 4h up move, 1d uptrend & oversold
            & ((rsi_3_4h_lt_40) | (aroonu_14_1d_lt_60) | (roc_9_1d_gt_neg_10))
            # 4h up move, 1d down move & overbought
            & ((rsi_3_4h_lt_40) | (rsi_3_1d_gt_55) | (stochrsi_k_1d_lt_90))
            # 4h up move, 1d still high & uptrend
            & ((rsi_3_4h_lt_40) | (stochrsi_k_1d_gt_40) | (roc_9_1d_lt_10))
            # 4h up move & still high, 1d down move
            & ((rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_60) | (rsi_3_1d_gt_10))
            # 4h up move & still not low enough, 1d still not high enough
            & ((rsi_3_4h_lt_60) | (stochrsi_k_4h_gt_80) | (stochrsi_k_1d_gt_70))
            # 1h washed out, 4h uptrend & washed out, 1d downtrend & down move
            & (
              (aroonu_14_4h_lt_20)
              | (aroonu_14_1d_gt_10)
              | (rsi_3_1d_gt_50)
              | (stochrsi_k_4h_gt_70)
              | (stochrsi_k_1h > 45.0)
            )
            # 1h up move, 4h uptrend & down move & still high, 1d down move
            & (
              (aroonu_14_4h_lt_40)
              | (roc_9_1d_gt_neg_10)
              | (rsi_3_1h < 10.0)
              | (rsi_3_4h_gt_40)
              | (stochrsi_k_4h_lt_30)
            )
            # 4h low, 1d up move & oversold
            & ((aroonu_14_4h_gt_10) | (rsi_3_1d_lt_35) | (roc_9_1d_gt_neg_15))
            # 4h low, 1d uptrend
            & ((aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_30))
            # 4h low & still high, 1d down move
            & ((aroonu_14_4h_gt_10) | (stochrsi_k_4h_gt_30) | (rsi_3_1d_gt_30))
            # 4h & 1d uptrend, 1d down move
            & ((aroonu_14_4h_lt_20) | (rsi_3_1d_gt_10) | (aroonu_14_1d_lt_30))
            # 4h uptrend & low, 1d down move
            & ((aroonu_14_4h_lt_30) | (stochrsi_k_4h_gt_20) | (rsi_3_1d_gt_20))
            # 4h & 1d uptrend, 1d still high
            & ((aroonu_14_4h_lt_40) | (aroonu_14_1d_lt_60) | (stochrsi_k_1d_gt_60))
            # 4h uptrend & still high, 1d low
            & ((aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_30) | (aroonu_14_1d_gt_20))
            # 4h & 1d uptrend, 1d low
            & ((aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_30) | (stochrsi_k_1d_gt_20))
            # 4h high, 1d uptrend & still high
            & ((stochrsi_k_4h_gt_10) | (aroonu_14_1d_lt_30) | (stochrsi_k_1d_gt_40))
            # 4h low, 1d uptrend & oversold
            & ((stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_15))
            # 4h & 1d low, 1d uptrend
            & ((stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_30) | (stochrsi_k_1d_gt_20))
            # 4h low, 1d uptrend & still high
            & ((stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_gt_30))
            # 4h & 1d low, 1d up move
            & ((stochrsi_k_4h_gt_20) | (rsi_3_1d_lt_35) | (stochrsi_k_1d_gt_20))
            # 1h momentum snapping up, 4h cycle falling and 4h momentum collapsing
            & ((rsi_3_change_pct_1h < 80) | (cci_20_change_pct_4h > 0.0) | (rsi_3_change_pct_4h > -40))
          )

          # Logic
          short_entry_logic.append(
            # calm base: not already crashed over the rolling 24h (ride the ignition, don't chase)
            (roc_288 > -10.0)
            # ...but the daily trend has to be down: a dump hunter continues a decline, and in a
            # rising market the same ignition is a shakeout (it bled -5,105 across the bull windows)
            & (roc_9_1d < -5.0)
            # ...on explosive volume. 3.0 is load-bearing: at 2.0 the tag takes 95 more trades and
            # loses ~92% of its profit (measured 2026-08-13)
            & (vol_rel > 3.0)
            # ignition: red candle with a real body (a doji-sized "breakdown" has no follow-through:
            # bodies under 0.3% are net negative) CROSSING below the prior 48-candle low...
            & (close < (open_rate * 0.997))
            & (close < dh_prev_min)
            & (np_shift(close, 1) >= dh_prev_min)
          )

        # Condition #670 - Marubozu momentum (Short, experimental, RAW — mirror).
        if short_entry_condition_index == 670:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m down move, 15m uptrend & still high, 1h washed out, 1d uptrend
            (
              (rsi_3_gt_15)
              | (stochrsi_k_1h_gt_40)
              | (aroonu_14_15m < 55.0)
              | (aroonu_14_1d_lt_30)
              | (stochrsi_k_15m < 55.0)
            )
            # 5m & 4h down move, 15m low
            & ((rsi_3_gt_10) | (aroonu_14_15m_gt_20) | (rsi_3_4h_gt_10))
            # 5m down move, 15m uptrend, 1h still high
            & ((rsi_3_gt_10) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_gt_50))
            # 5m down move, 1h & 1d low
            & ((rsi_3_gt_10) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_20))
            # 5m down move, 1h uptrend & low
            & ((rsi_3_gt_10) | (aroonu_14_1h_lt_40) | (stochrsi_k_1h_gt_20))
            # 5m down move, 15m low, 1h uptrend
            & ((rsi_3_gt_10) | (stochrsi_k_15m_gt_20) | (aroonu_14_1h_lt_60))
            # 5m & 1h down move, 15m up move
            & ((rsi_3_gt_15) | (rsi_3_15m_lt_50) | (rsi_3_1h_gt_25))
            # 5m & 1h down move, 1d low
            & ((rsi_3_gt_15) | (rsi_3_1h_gt_30) | (stochrsi_k_1d_gt_20))
            # 5m & 1h down move, 1h uptrend
            & ((rsi_3_gt_15) | (rsi_3_1h_gt_35) | (aroonu_14_1h_lt_60))
            # 5m & 1d down move, 1h up move
            & ((rsi_3_gt_15) | (rsi_3_1h_lt_40) | (rsi_3_1d_gt_30))
            # 5m down move, 15m low
            & ((rsi_3_gt_3) | (aroonu_14_15m_gt_10))
            # 5m down move, 1h down move, 4h down move
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_25) | (roc_9_4h_gt_neg_15))
            # 5m & 1h down move, 1h low
            & ((rsi_3_gt_5) | (rsi_3_1h_gt_40) | (aroonu_14_1h_gt_20))
            # 5m & 1d down move, 15m low
            & ((rsi_3_gt_5) | (stochrsi_k_15m_gt_20) | (rsi_3_1d_gt_30))
            # 5m up move, 15m uptrend & still high
            & ((rsi_3_lt_40) | (aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_60))
            # 5m up move, 15m uptrend, 1h high
            & ((rsi_3_lt_40) | (aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_10))
            # 5m up move, 1h uptrend & high
            & ((rsi_3_lt_40) | (aroonu_14_1h_lt_50) | (stochrsi_k_1h_gt_10))
            # 5m RSI high & down move, 1h still high, 4h up move, 1d uptrend
            & ((rsi_14 < 40.0) | (rsi_3_4h_lt_50) | (aroonu_14_1d_lt_40) | (stochrsi_k_1h < 55.0) | (rsi_3 > 20.0))
            # 5m RSI high, 15m down move, 4h up move, 1d still high
            & ((rsi_14 < 40.0) | (stochrsi_k_1d_lt_60) | (rsi_3_15m_gt_25) | (rsi_3_4h_lt_40))
            # 5m RSI high & downtrend & up move, 4h UO high
            & ((rsi_14 < 40.0) | (uo_7_14_28_4h < 55.0) | (aroonu_14 > 0.0) | (rsi_3 < 35.0))
            # 5m money coming in, 15m down move, 1h still high, 4h up move, 1d still high
            & ((cmf_20 < -0.1) | (rsi_3_15m_gt_25) | (stochrsi_k_1d_lt_60) | (rsi_3_4h_lt_40) | (stochrsi_k_1h < 35.0))
            # 5m uptrend, 15m downtrend & still high, 1h still high, 4h washed out
            & (
              (aroonu_14_lt_30)
              | (aroonu_14_15m_gt_40)
              | (stochrsi_k_1h < 55.0)
              | (stochrsi_k_4h > 35.0)
              | (stochrsi_k_15m_lt_50)
            )
            # 5m uptrend & still high, 15m downtrend, 1h downtrend, 4h up move
            & (
              (aroonu_14_lt_30)
              | (aroonu_14_1h_gt_10)
              | (roc_9_4h < 0.0)
              | (stochrsi_k < 55.0)
              | (aroonu_14_15m > 25.0)
            )
            # 5m & 1h uptrend, 15m low
            & ((aroonu_14_lt_25) | (aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_20))
            # 5m uptrend & up move, 1h downtrend, 4h up move, 1d downtrend
            & ((aroonu_14_lt_25) | (aroonu_14_1d_gt_10) | (roc_9_4h < 0.0) | (aroonu_14_1h_gt_10) | (rsi_3 < 20.0))
            # 5m & 1h uptrend, 4h still high
            & ((aroonu_14_lt_25) | (aroonu_14_1h_lt_60) | (stochrsi_k_4h_gt_40))
            # 5m uptrend, 15m down move, 4h down move, 1d up move & on the floor
            & ((aroonu_14_lt_25) | (roc_9_15m > -3.0) | (roc_9_1d < -15.0) | (stochrsi_k_1d > 15.0) | (rsi_3_4h_gt_30))
            # 5m uptrend, 15m down move & uptrend, 1h down move, 4h up move
            & ((aroonu_14_lt_25) | (rsi_3_15m_gt_25) | (aroonu_14_15m_lt_75) | (roc_9_4h < 0.0) | (rsi_3_1h_gt_65))
            # 5m & 1d uptrend, 1h up move
            & ((aroonu_14_lt_25) | (rsi_3_1h_lt_60) | (aroonu_14_1d_lt_70))
            # 5m uptrend, 4h up move & still high
            & ((aroonu_14_lt_25) | (rsi_3_4h_lt_50) | (stochrsi_k_4h_gt_40))
            # 5m uptrend, 15m & 1h low
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_20))
            # 5m & 1d uptrend, 15m still high
            & ((aroonu_14_lt_25) | (stochrsi_k_15m_gt_50) | (aroonu_14_1d_lt_40))
            # 5m & 4h uptrend, 15m low
            & ((aroonu_14_lt_30) | (aroonu_14_15m_gt_10) | (aroonu_14_4h_lt_30))
            # 5m & 1h uptrend, 15m low
            & ((aroonu_14_lt_30) | (aroonu_14_15m_gt_10) | (roc_9_1h < -1))
            # 5m uptrend, 15m low, 4h oversold
            & ((aroonu_14_lt_30) | (aroonu_14_15m_gt_10) | (roc_9_4h_gt_neg_10))
            # 5m uptrend, 15m low, 1h down move
            & ((aroonu_14_lt_30) | (aroonu_14_15m_gt_10) | (rsi_3_1h_gt_20))
            # 5m uptrend, 15m low, 4h up move
            & ((aroonu_14_lt_30) | (aroonu_14_15m_gt_20) | (rsi_3_4h_lt_60))
            # 5m uptrend, 15m low & still high
            & ((aroonu_14_lt_30) | (aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_50))
            # 5m & 15m uptrend, 15m still high
            & ((aroonu_14_lt_30) | (aroonu_14_15m_lt_60) | (stochrsi_k_15m_gt_40))
            # 5m & 1h uptrend, 1h low
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_20) | (stochrsi_k_1h_gt_20))
            # 5m & 1h uptrend, 4h low
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_30) | (stochrsi_k_4h_gt_20))
            # 5m & 1h uptrend, 4h up move
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_40) | (rsi_3_4h_lt_70))
            # 5m & 1h uptrend, 1h still high
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_60))
            # 5m & 1h uptrend, 4h up move
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_70) | (rsi_3_4h_lt_50))
            # 5m & 1h uptrend
            & ((aroonu_14_lt_30) | (aroonu_14_1h_lt_90))
            # 5m & 1h uptrend, 4h high
            & ((aroonu_14_lt_30) | (roc_9_1h < 0) | (stochrsi_k_4h_gt_10))
            # 5m uptrend & up move, 15m up move, 1d still high & up move
            & ((aroonu_14_lt_30) | (rsi_3_15m_lt_60) | (stochrsi_k_1d < 55.0) | (rsi_3_1d_lt_35) | (rsi_3 < 20.0))
            # 5m uptrend, 1h down move, 4h low
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_15) | (aroonu_14_4h_gt_10))
            # 5m uptrend, 1h down move, 1d still high
            & ((aroonu_14_lt_30) | (rsi_3_1h_gt_15) | (stochrsi_k_1d_gt_30))
            # 5m uptrend, 15m low, 1h up move
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_20) | (rsi_3_1h_lt_40))
            # 5m uptrend, 15m still high, 1h down move
            & ((aroonu_14_lt_30) | (stochrsi_k_15m_gt_60) | (rsi_3_1h_gt_20))
            # 5m stochrsik, 1d stochrsik, 1h aroond, 1h roc
            & ((stochrsi_k < 55) | (stochrsi_k_1d < 35) | (aroond_14_1h < 90) | (roc_9_1h < -1))
            # 5m still high, 15m down move & downtrend, 1h downtrend, 1d up move
            & (
              (rsi_3_15m_gt_10)
              | (aroonu_14_15m_gt_50)
              | (stochrsi_k < 60.0)
              | (aroonu_14_1h_gt_10)
              | (rsi_3_1d < 30.0)
            )
            # 15m down move & uptrend & still high, 4h up move & downtrend
            & (
              (rsi_3_15m_gt_25)
              | (aroonu_14_15m_lt_75)
              | (roc_9_4h < 0.0)
              | (aroonu_14_4h_gt_10)
              | (stochrsi_k_15m < 25.0)
            )
            # 15m down move & uptrend & washed out, 4h on the floor, 1d up move
            & (
              (rsi_3_15m_gt_30)
              | (stochrsi_k_4h_gt_10)
              | (rsi_3_1d < 30.0)
              | (aroonu_14_15m_lt_40)
              | (stochrsi_k_15m_gt_50)
            )
            # 5m still high & uptrend, 15m down move & uptrend, 1h uptrend
            & (
              (rsi_3_15m_gt_50)
              | (aroonu_14_15m_lt_40)
              | (stochrsi_k < 65.0)
              | (aroonu_14_1h < 65.0)
              | (aroonu_14 < 5.0)
            )
            # 15m up move & downtrend & still high, 4h still high, 1d up move
            & (
              (rsi_3_15m_lt_50)
              | (aroonu_14_15m_gt_10)
              | (rsi_3_1d < 25.0)
              | (stochrsi_k_15m_lt_70)
              | (stochrsi_k_4h_lt_30)
            )
            # 5m still high, 15m up move, 1h downtrend, 4h up move, 1d down move
            & (
              (rsi_3_15m_lt_55) | (roc_9_1d_gt_neg_10) | (rsi_3_4h < 25.0) | (aroonu_14_1h_gt_40) | (stochrsi_k < 45.0)
            )
            # 5m up move, 15m down move & uptrend, 1h uptrend
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_50) | (aroonu_14_15m_lt_75) | (rsi_3 < 5.0))
            # 15m down move, 1h uptrend, 1d low
            & ((rsi_3_15m_gt_10) | (aroonu_14_1h_lt_90) | (aroonu_14_1d_gt_30))
            # 15m down move, 4h uptrend
            & ((rsi_3_15m_gt_10) | (roc_9_4h_lt_20))
            # 15m down move & uptrend, 1h RSI high
            & ((rsi_3_15m_gt_10) | (rsi_14_1h_lt_50) | (aroonu_14_15m_lt_75))
            # 15m & 4h down move
            & ((rsi_3_15m_gt_10) | (rsi_3_4h_gt_3))
            # 15m down move, 1d overbought
            & ((rsi_3_15m_gt_15) | (roc_9_1d_gt_neg_70))
            # 15m down move & low, 1d uptrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_15m_gt_30) | (aroonu_14_1d_lt_70))
            # 15m & 1d down move, 4h uptrend
            & ((rsi_3_15m_gt_20) | (aroonu_14_4h_lt_20) | (rsi_3_1d_gt_20))
            # 15m & 1d down move, 1d low
            & ((rsi_3_15m_gt_20) | (rsi_3_1d_gt_10) | (aroonu_14_1d_gt_10))
            # 15m down move, 1h up move, 4h low
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_lt_40) | (aroonu_14_4h_gt_30))
            # 15m down move, 1h up move
            & ((rsi_3_15m_gt_20) | (rsi_3_1h_lt_80))
            # 5m up move, 15m down move, 4h uptrend & on the floor & up move
            & ((rsi_3_15m_gt_25) | (aroonu_14_4h_lt_20) | (stochrsi_k_4h > 5.0) | (roc_9_4h < -10.0) | (rsi_3 < 5.0))
            # 15m down move, 1h up move, 1d oversold
            & ((rsi_3_15m_gt_25) | (rsi_3_1h_lt_40) | (roc_9_1d_gt_neg_10))
            # 5m uptrend, 15m down move, 4h up move, 1d uptrend
            & ((rsi_3_15m_gt_25) | (rsi_3_4h_lt_40) | (aroonu_14_1d < 65.0) | (aroonu_14_lt_25))
            # 15m down move, 4h oversold
            & ((rsi_3_15m_gt_3) | (roc_9_4h_gt_neg_10))
            # 15m down move, 1d low & oversold
            & ((rsi_3_15m_gt_30) | (aroonu_14_1d_gt_10) | (roc_9_1d_gt_neg_30))
            # 15m down move, 1h low, 4h uptrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_gt_30) | (aroonu_14_4h_lt_80))
            # 15m down move, 1h uptrend & still high
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_70) | (stochrsi_k_1h_gt_50))
            # 15m down move, 4h low, 1d up move
            & ((rsi_3_15m_gt_30) | (aroonu_14_4h_gt_10) | (rsi_3_1d_lt_35))
            # 5m still high, 15m down move, 1h up move, 4h washed out, 1d up move
            & ((rsi_3_15m_gt_30) | (roc_9_1h < -5.0) | (stochrsi_k_4h_gt_30) | (stochrsi_k_lt_30) | (roc_9_1d < -20.0))
            # 15m down move, 1h up move, 4h low
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_lt_40) | (aroonu_14_4h_gt_10))
            # 15m down move, 1h up move, 4h still high
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_lt_40) | (stochrsi_k_4h_gt_30))
            # 15m down move, 4h still high, 1d uptrend
            & ((rsi_3_15m_gt_30) | (stochrsi_k_4h_gt_40) | (roc_9_1d_lt_0))
            # 5m still high, 15m down move & uptrend, 1d downtrend
            & ((rsi_3_15m_gt_35) | (aroonu_14_1d_gt_10) | (stochrsi_k < 70.0) | (aroonu_14_15m < 45.0))
            # 15m down move & uptrend, 4h up move
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_60) | (rsi_3_4h_lt_60))
            # 15m down move & uptrend, 1h low
            & ((rsi_3_15m_gt_40) | (aroonu_14_15m_lt_60) | (stochrsi_k_1h_gt_20))
            # 15m & 4h down move, 1h uptrend
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_lt_40) | (rsi_3_4h_gt_10))
            # 15m down move, 1h uptrend, 4h low
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m down move, 1h uptrend & low
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_lt_50) | (stochrsi_k_1h_gt_20))
            # 15m & 4h down move, 1h uptrend
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_lt_60) | (rsi_3_4h_gt_30))
            # 5m up move, 15m down move & up move
            & ((rsi_3_15m_gt_40) | (roc_9_15m < 1.5) | (rsi_3 < 35.0))
            # 15m down move, 1h up move, 1d oversold
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_lt_40) | (roc_9_1d_gt_neg_30))
            # 15m down move, 4h still high, 1d up move
            & ((rsi_3_15m_gt_40) | (stochrsi_k_4h_gt_30) | (rsi_3_1d_lt_35))
            # 5m downtrend, 15m down move, 1h uptrend, 4h down move
            & ((rsi_3_15m_gt_5) | (aroonu_14_1h_lt_50) | (rsi_3_4h_gt_20) | (aroonu_14 > 0.0))
            # 15m down move, 4h uptrend, 1d low
            & ((rsi_3_15m_gt_5) | (aroonu_14_4h_lt_40) | (stochrsi_k_1d_gt_20))
            # 15m down move, 1h RSI high, 4h down move
            & ((rsi_3_15m_gt_5) | (rsi_14_1h_lt_40) | (rsi_3_4h_gt_20))
            # 15m & 4h down move
            & ((rsi_3_15m_gt_5) | (rsi_3_4h_gt_15))
            # 15m up move & downtrend, 1h overbought, 1d uptrend
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_gt_40) | (stochrsi_k_1h < 85.0) | (aroonu_14_1d < 5.0))
            # 15m & 1h up move, 15m low
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_gt_60) | (rsi_3_1h_lt_60))
            # 15m up move, 15m & 1h uptrend
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_60))
            # 15m up move & uptrend, 4h low
            & ((rsi_3_15m_lt_50) | (aroonu_14_15m_lt_20) | (stochrsi_k_4h_gt_20))
            # 5m washed out, 15m up move, 1h up move, 1d uptrend
            & ((rsi_3_15m_lt_50) | (aroonu_14_1d_lt_30) | (stochrsi_k > 20.0) | (roc_9_1h < 0.0))
            # 15m up move, 1h uptrend, 1d low
            & ((rsi_3_15m_lt_50) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_gt_10))
            # 15m up move, 1h uptrend, 1d high
            & ((rsi_3_15m_lt_50) | (aroonu_14_1h_lt_50) | (stochrsi_k_1d_gt_10))
            # 15m up move, 1h uptrend, 4h low
            & ((rsi_3_15m_lt_50) | (aroonu_14_1h_lt_60) | (stochrsi_k_4h_gt_20))
            # 15m up move, 4h & 1d low
            & ((rsi_3_15m_lt_50) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 5m up move, 15m up move, 4h up move, 1d up move
            & ((rsi_3_15m_lt_50) | (rsi_3_1d_lt_35) | (rsi_3_4h_lt_75) | (rsi_3 < 15.0))
            # 15m & 4h up move, 1h down move
            & ((rsi_3_15m_lt_50) | (rsi_3_1h_gt_25) | (rsi_3_4h_lt_40))
            # 15m & 1h up move, 1d low
            & ((rsi_3_15m_lt_50) | (rsi_3_1h_lt_70) | (aroonu_14_1d_gt_20))
            # 15m & 4h up move, 1d still high
            & ((rsi_3_15m_lt_50) | (rsi_3_4h_lt_60) | (stochrsi_k_1d_gt_50))
            # 15m up move, 15m & 4h low
            & ((rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_20) | (aroonu_14_4h_gt_30))
            # 15m & 1h up move, 15m still high
            & ((rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_40) | (rsi_3_1h_lt_50))
            # 15m up move & still high, 4h down move
            & ((rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_40) | (rsi_3_4h_gt_20))
            # 15m up move & still high, 4h high
            & ((rsi_3_15m_lt_50) | (stochrsi_k_15m_gt_40) | (stochrsi_k_4h_gt_10))
            # 15m down move, 1h up move
            & ((rsi_3_15m_lt_55) | (rsi_3_1h_lt_80))
            # 5m down move & still high, 15m up move, 1h downtrend
            & ((rsi_3_15m_lt_60) | (aroonu_14_1h_gt_10) | (rsi_3_gt_10) | (stochrsi_k < 55.0))
            # 15m up move, 1d strong downtrend
            & ((rsi_3_15m_lt_60) | (roc_9_1d_lt_70))
            # 15m up move & downtrend, 1h up move & still high
            & ((rsi_3_15m_lt_60) | (roc_9_1h < 0.0) | (stochrsi_k_1h < 75.0) | (aroonu_14_15m_gt_60))
            # 15m & 4h up move, 4h uptrend
            & ((rsi_3_15m_lt_60) | (rsi_3_4h_lt_40) | (aroonu_14_4h_lt_30))
            # 15m & 4h up move
            & ((rsi_3_15m_lt_60) | (rsi_3_4h_lt_50))
            # 15m up move & still high, 1h low
            & ((rsi_3_15m_lt_60) | (stochrsi_k_15m_gt_60) | (aroonu_14_1h_gt_30))
            # 5m washed out, 15m up move, 4h UO high & washed out
            & ((rsi_3_15m_lt_60) | (uo_7_14_28_4h < 55.0) | (stochrsi_k_4h_gt_50) | (stochrsi_k > 30.0))
            # 15m up move & uptrend, 1h down move
            & ((rsi_3_15m_lt_70) | (aroonu_14_15m_lt_50) | (rsi_3_1h_gt_30))
            # 15m up move, 1h uptrend & low
            & ((rsi_3_15m_lt_70) | (aroonu_14_1h_lt_20) | (stochrsi_k_1h_gt_20))
            # 15m up move, 1h uptrend, 1d still high
            & ((rsi_3_15m_lt_70) | (aroonu_14_1h_lt_50) | (stochrsi_k_1d_lt_30))
            # 15m up move, 4h uptrend, 1d still high
            & ((rsi_3_15m_lt_70) | (aroonu_14_4h_lt_30) | (stochrsi_k_1d_gt_50))
            # 15m up move, 1h money coming in, 1d up move
            & ((rsi_3_15m_lt_70) | (mfi_14_1h < 45.0) | (roc_9_1d < 5.0))
            # 15m & 1h up move, 1d still high
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_lt_60) | (stochrsi_k_1d_gt_40))
            # 15m down move, 1h up move
            & ((rsi_3_15m_lt_75) | (rsi_3_1h_lt_70))
            # 15m up move & low, 4h uptrend
            & ((rsi_3_15m_lt_80) | (aroonu_14_15m_gt_20) | (aroonu_14_4h_lt_30))
            # 15m down move, 1h up move
            & ((rsi_3_15m_lt_85) | (rsi_3_1h_lt_60))
            # 15m mfi, 4h rsi, 4h cmf, 1d roc
            & ((mfi_14_15m > 30) | (rsi_3_change_pct_4h > -40) | (cmf_20_4h > -0.15) | (roc_9_1d_gt_neg_20))
            # 15m downtrend, 1h downtrend, 1d uptrend & still high & down move
            & (
              (aroonu_14_15m_gt_10)
              | (aroonu_14_1d_lt_40)
              | (stochrsi_k_1d_lt_50)
              | (rsi_3_1d_gt_20)
              | (aroonu_14_1h_gt_0)
            )
            # 15m uptrend & washed out, 4h down move, 1d up move & downtrend
            & (
              (aroonu_14_15m_lt_25)
              | (rsi_3_4h_gt_20)
              | (rsi_3_1d < 40.0)
              | (aroonu_14_1d > 15.0)
              | (stochrsi_k_15m > 65.0)
            )
            # 5m uptrend, 15m uptrend & washed out, 1h uptrend, 4h washed out
            & (
              (aroonu_14_15m_lt_30)
              | (stochrsi_k_4h_gt_20)
              | (aroonu_14_1h < 15.0)
              | (aroonu_14 < 15.0)
              | (stochrsi_k_15m_gt_80)
            )
            # 5m still high, 15m uptrend, 4h on the floor & uptrend, 1d down move
            & (
              (aroonu_14_15m_lt_50)
              | (stochrsi_k_4h_gt_10)
              | (stochrsi_k < 45.0)
              | (aroonu_14_4h < 5.0)
              | (rsi_3_1d_gt_40)
            )
            # 15m uptrend & washed out, 1h up move & down move, 4h washed out
            & (
              (aroonu_14_15m_lt_75)
              | (stochrsi_k_4h_gt_20)
              | (roc_9_1h < 0.0)
              | (stochrsi_k_15m_gt_80)
              | (rsi_3_1h_gt_65)
            )
            # 15m & 1h low, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_20) | (aroonu_14_1d_lt_70))
            # 5m uptrend, 15m downtrend & down move, 1h downtrend, 4h up move
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_20) | (rsi_3_15m_gt_30) | (aroonu_14_lt_25) | (rsi_3_4h < 5.0))
            # 15m & 1h low, 4h uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_1h_gt_40) | (aroonu_14_4h_lt_90))
            # 15m low, 4h & 1d uptrend
            & ((aroonu_14_15m_gt_10) | (aroonu_14_4h_lt_80) | (aroonu_14_1d_lt_40))
            # 15m low, 1d overbought
            & ((aroonu_14_15m_gt_10) | (roc_9_1d_gt_neg_80))
            # 15m low, 4h & 1d uptrend
            & ((aroonu_14_15m_gt_10) | (roc_9_4h < -5) | (aroonu_14_1d_lt_40))
            # 15m low, 1d up move & still high
            & ((aroonu_14_15m_gt_10) | (rsi_3_1d_lt_35) | (stochrsi_k_1d_gt_30))
            # 15m low, 1h up move, 1d down move
            & ((aroonu_14_15m_gt_10) | (rsi_3_1h_lt_40) | (rsi_3_1d_gt_10))
            # 15m low, 4h up move, 1d uptrend
            & ((aroonu_14_15m_gt_10) | (rsi_3_4h_lt_40) | (aroonu_14_1d_lt_70))
            # 15m low, 4h up move, 1d oversold
            & ((aroonu_14_15m_gt_10) | (rsi_3_4h_lt_60) | (roc_9_1d_gt_neg_25))
            # 15m & 1h low, 4h uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_gt_20) | (aroonu_14_4h_lt_60))
            # 15m low, 1h & 1d uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_60) | (aroonu_14_1d_lt_50))
            # 15m & 4h low, 1h uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1h_lt_80) | (aroonu_14_4h_gt_10))
            # 15m low, 4h uptrend, 1d high
            & ((aroonu_14_15m_gt_20) | (aroonu_14_4h_lt_60) | (stochrsi_k_1d_gt_10))
            # 15m & 1d low, 1d up move
            & ((aroonu_14_15m_gt_20) | (rsi_3_1d_lt_35) | (aroonu_14_1d_gt_10))
            # 15m & 1d low, 1d up move
            & ((aroonu_14_15m_gt_20) | (rsi_3_1d_lt_35) | (stochrsi_k_1d_gt_20))
            # 15m low, 1h up move, 4h uptrend
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_40) | (aroonu_14_4h_lt_20))
            # 15m low, 1h up move & still high
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_60))
            # 15m & 4h low, 1h up move
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_60) | (aroonu_14_4h_gt_10))
            # 15m low, 1h still high, 1d uptrend
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_1h_gt_40) | (aroonu_14_1d_lt_30))
            # 15m & 1h low, 1d uptrend
            & ((aroonu_14_15m_gt_30) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_lt_70))
            # 15m low, 1h up move, 4h still high
            & ((aroonu_14_15m_gt_30) | (rsi_3_1h_lt_50) | (stochrsi_k_4h_gt_40))
            # 15m & 1h low, 1d uptrend
            & ((aroonu_14_15m_gt_30) | (stochrsi_k_1h_gt_20) | (aroonu_14_1d_lt_70))
            # 15m low, 1h uptrend & still high
            & ((aroonu_14_15m_gt_40) | (aroonu_14_1h_lt_90) | (stochrsi_k_1h_gt_50))
            # 15m & 4h low, 4h uptrend
            & ((aroonu_14_15m_gt_40) | (aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_20))
            # 15m low, 1h down move, 1d uptrend
            & ((aroonu_14_15m_gt_40) | (rsi_3_1h_gt_20) | (aroonu_14_1d_lt_50))
            # 15m low, 1h & 1d uptrend
            & ((aroonu_14_15m_gt_60) | (aroonu_14_1h_lt_40) | (roc_9_1d_lt_0))
            # 15m & 1h & 4h uptrend
            & ((aroonu_14_15m_lt_20) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_lt_60))
            # 15m & 4h uptrend, 1d high
            & ((aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_gt_10))
            # 15m & 4h & 1d uptrend
            & ((aroonu_14_15m_lt_20) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_lt_60))
            # 15m uptrend, 4h up move, 1d high
            & ((aroonu_14_15m_lt_20) | (rsi_3_4h_lt_40) | (stochrsi_k_1d_gt_10))
            # 15m uptrend & low, 4h down move
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_30))
            # 15m uptrend & low, 1h high
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_15m_gt_20) | (stochrsi_k_1h_gt_10))
            # 15m & 4h uptrend, 1h low
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_90))
            # 15m & 1h & 4h uptrend
            & ((aroonu_14_15m_lt_30) | (aroonu_14_1h_lt_60) | (roc_9_4h_lt_5))
            # 15m & 4h uptrend, 4h still high
            & ((aroonu_14_15m_lt_30) | (aroonu_14_4h_lt_50) | (stochrsi_k_4h_gt_40))
            # 5m down move, 15m uptrend & down move, 4h uptrend, 1d up move
            & ((aroonu_14_15m_lt_30) | (roc_9_15m > -1.0) | (rsi_3_1d < 55.0) | (rsi_3_gt_10) | (aroonu_14_4h < 15.0))
            # 15m uptrend, 1h down move, 1d up move
            & ((aroonu_14_15m_lt_30) | (rsi_3_1h_gt_20) | (rsi_3_1d_lt_35))
            # 15m & 1h & 4h uptrend
            & ((aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_20) | (aroonu_14_4h_lt_80))
            # 15m & 1h uptrend, 1h still high
            & ((aroonu_14_15m_lt_40) | (aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_50))
            # 15m & 4h & 1d uptrend
            & ((aroonu_14_15m_lt_40) | (aroonu_14_4h_lt_50) | (aroonu_14_1d_lt_30))
            # 5m up move, 15m uptrend & down move, 4h roc 2 high, 1d uptrend
            & ((aroonu_14_15m_lt_40) | (roc_2_4h < -4.0) | (rsi_3_15m_gt_5) | (aroonu_14_1d < 55.0) | (rsi_3 < 10.0))
            # 15m uptrend & down move & up move, 1d still high
            & ((aroonu_14_15m_lt_40) | (roc_9_15m > -3.0) | (stochrsi_k_1d_lt_50) | (rsi_3_15m < 35.0))
            # 15m uptrend, 1h up move & still high
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_40))
            # 15m uptrend, 1h up move, 4h low
            & ((aroonu_14_15m_lt_40) | (rsi_3_1h_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m & 1d uptrend, 4h up move
            & ((aroonu_14_15m_lt_40) | (rsi_3_4h_lt_40) | (aroonu_14_1d_lt_40))
            # 15m uptrend, 15m & 1h low
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_10))
            # 15m & 1d uptrend, 1h still high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_30) | (aroonu_14_1d_lt_40))
            # 15m uptrend, 1h still high, 1d down move
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_30) | (rsi_3_1d_gt_20))
            # 15m uptrend, 1h still high, 1d high
            & ((aroonu_14_15m_lt_40) | (stochrsi_k_1h_gt_30) | (stochrsi_k_1d_gt_10))
            # 5m still high, 15m uptrend, 1h still high, 1d WILLR high
            & ((aroonu_14_15m_lt_40) | (willr_14_1d < -90.0) | (stochrsi_k < 65.0) | (stochrsi_k_1h < 75.0))
            # 5m still high & down move, 15m uptrend, 1h uptrend, 4h down move
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_40) | (stochrsi_k < 25.0) | (rsi_3_4h_gt_45) | (rsi_3 > 25.0))
            # 15m & 1h uptrend, 4h low
            & ((aroonu_14_15m_lt_50) | (aroonu_14_1h_lt_60) | (aroonu_14_4h_gt_10))
            # 15m uptrend, 4h & 1d low
            & ((aroonu_14_15m_lt_50) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 15m & 1d uptrend, 1h still high
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_1h_gt_40) | (aroonu_14_1d_lt_60))
            # 5m up move, 15m uptrend, 1h down move, 1d downtrend
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1d_gt_30) | (rsi_3_1h_gt_10) | (rsi_3 < 20.0))
            # 15m & 1h uptrend, 4h low
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_40) | (aroonu_14_4h_gt_10))
            # 15m & 1h uptrend, 1d down move
            & ((aroonu_14_15m_lt_60) | (aroonu_14_1h_lt_40) | (rsi_3_1d_gt_10))
            # 15m uptrend, 4h low
            & ((aroonu_14_15m_lt_60) | (aroonu_14_4h_gt_20) | (stochrsi_k_4h_gt_20))
            # 15m & 4h uptrend
            & ((aroonu_14_15m_lt_60) | (roc_9_4h_lt_5))
            # 15m uptrend, 1h down move, 4h still high, 1d still high
            & ((aroonu_14_15m_lt_60) | (rsi_3_1h_gt_35) | (stochrsi_k_1d < 75.0) | (stochrsi_k_4h_lt_20))
            # 15m uptrend, 1h up move, 4h low
            & ((aroonu_14_15m_lt_60) | (rsi_3_1h_lt_50) | (aroonu_14_4h_gt_30))
            # 15m uptrend & still high, 4h low
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_15m_gt_40) | (stochrsi_k_4h_gt_20))
            # 15m uptrend & still high, 4h down move
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_15m_gt_50) | (rsi_3_4h_gt_10))
            # 15m & 4h uptrend, 1h still high
            & ((aroonu_14_15m_lt_60) | (stochrsi_k_1h_gt_30) | (aroonu_14_4h_lt_50))
            # 5m downtrend, 15m uptrend, 1h uptrend, 1d downtrend
            & ((aroonu_14_15m_lt_75) | (aroonu_14_1d_gt_10) | (aroonu_14 > 10.0) | (aroonu_14_1h_lt_40))
            # 5m up move & downtrend, 15m uptrend, 4h down move, 1d down move
            & ((aroonu_14_15m_lt_75) | (rsi_3_1d_gt_25) | (rsi_3 < 25.0) | (aroonu_14 > 30.0) | (rsi_3_4h_gt_35))
            # 15m & 4h uptrend
            & ((aroonu_14_15m_lt_80) | (aroonu_14_4h_lt_75))
            # 5m down move, 15m uptrend, 1h down move, 1d up move
            & ((aroonu_14_15m_lt_80) | (rsi_3_1h_gt_40) | (rsi_3_1d < 40.0) | (rsi_3 > 20.0))
            # 15m & 4h uptrend, 1h low
            & ((aroonu_14_15m_lt_90) | (aroonu_14_1h_gt_30) | (aroonu_14_4h_lt_60))
            # 15m uptrend, 1h down move
            & ((aroonu_14_15m_lt_90) | (rsi_3_1h_gt_3))
            # 5m on the floor, 15m AROOND low & washed out, 1h downtrend, 4h money coming in
            & (
              (aroond_14_15m > 30.0)
              | (mfi_14_4h < 40.0)
              | (aroonu_14_1h > 15.0)
              | (stochrsi_k > 10.0)
              | (stochrsi_k_15m > 55.0)
            )
            # 5m still high & down move, 15m on the floor, 4h washed out & up move
            & (
              (stochrsi_k_15m_gt_10)
              | (stochrsi_k_4h_gt_70)
              | (stochrsi_k < 60.0)
              | (roc_9_4h < -10.0)
              | (rsi_3 > 35.0)
            )
            # 15m high, 1h down move, 4h still high
            & ((stochrsi_k_15m_gt_10) | (rsi_3_1h_gt_25) | (stochrsi_k_4h_gt_60))
            # 15m & 1h low, 4h oversold
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_10) | (roc_9_4h_gt_neg_10))
            # 15m & 1h low, 1d up move
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_30) | (rsi_3_1d_lt_35))
            # 15m & 1d low, 4h uptrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_20) | (aroonu_14_1d_gt_10))
            # 15m low, 4h uptrend & still high
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_50) | (stochrsi_k_4h_gt_60))
            # 15m low, 4h uptrend
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_4h_lt_90) | (roc_9_4h_lt_10))
            # 15m low, 1d down move & oversold
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1d_gt_10) | (roc_9_1d_gt_neg_30))
            # 15m low, 1h down move, 4h still high
            & ((stochrsi_k_15m_gt_20) | (rsi_3_1h_gt_20) | (stochrsi_k_4h_gt_60))
            # 15m low, 4h down move & uptrend
            & ((stochrsi_k_15m_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_20))
            # 15m still high, 1h low, 4h down move
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_1h_gt_10) | (rsi_3_4h_gt_10))
            # 15m still high, 1h low, 4h uptrend
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_1h_gt_40) | (aroonu_14_4h_lt_30))
            # 15m still high, 1h uptrend & high
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_1h_lt_50) | (stochrsi_k_1h_gt_10))
            # 15m still high, 4h uptrend, 1d low
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_4h_lt_40) | (aroonu_14_1d_gt_10))
            # 15m still high, 1h up move, 4h low
            & ((stochrsi_k_15m_gt_40) | (rsi_3_1h_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m still high, 4h up move & low
            & ((stochrsi_k_15m_gt_40) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_20))
            # 15m still high, 4h uptrend & oversold
            & ((stochrsi_k_15m_gt_50) | (aroonu_14_4h_lt_30) | (roc_9_4h_gt_neg_15))
            # 15m & 4h still high, 4h uptrend
            & ((stochrsi_k_15m_gt_60) | (aroonu_14_4h_lt_50) | (stochrsi_k_4h_gt_30))
            # 15m still high, 1h up move & low
            & ((stochrsi_k_15m_gt_60) | (rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_20))
            # 15m & 4h still high, 1d uptrend
            & ((stochrsi_k_15m_gt_60) | (stochrsi_k_4h_gt_40) | (roc_9_1d_lt_10))
            # 5m downtrend, 15m stochk 14 3 3 high, 4h AROOND low, 1d uptrend & down move
            & (
              (stochk_14_3_3_15m < 55.0)
              | (aroond_14_4h > 50.0)
              | (aroonu_14 > 30.0)
              | (aroonu_14_1d < 15.0)
              | (rsi_3_1d_gt_40)
            )
            # 15m down move & uptrend, 1h still high, 4h on the floor, 1d up move
            & (
              (roc_9_15m > -1.0)
              | (stochrsi_k_4h_gt_10)
              | (aroonu_14_15m < 45.0)
              | (rsi_3_1d < 20.0)
              | (stochrsi_k_1h_lt_20)
            )
            # 5m up move, 15m up move, 1h money coming in
            & ((roc_9_15m < 1.5) | (mfi_14_1h < 45.0) | (rsi_3 < 35.0))
            # 15m uptrend, 1h up move, 4h high
            & ((roc_9_15m < 1.5) | (rsi_3_1h_lt_65) | (stochrsi_k_4h_gt_10))
            # 15m oversold, 4h & 1d high
            & ((roc_9_15m > -1) | (stochrsi_k_4h_gt_10) | (stochrsi_k_1d_lt_60))
            # 5m down move, 15m down move, 1d downtrend & down move & up move
            & ((roc_9_15m > -1.0) | (aroonu_14_1d_gt_10) | (rsi_3_gt_5) | (rsi_3_1d_gt_10) | (roc_9_1d < -10.0))
            # 5m up move, 1h up move & downtrend, 4h on the floor, 1d uptrend
            & (
              (rsi_3_1h_lt_40) | (aroonu_14_1h_gt_10) | (rsi_3 < 25.0) | (stochrsi_k_4h > 5.0) | (aroonu_14_1d < 25.0)
            )
            # 5m washed out, 15m up move, 1h up move & falling fast
            & (
              (rsi_3_1h_lt_40)
              | (rsi_14_change_pct_1h > -5.0)
              | (rsi_3_15m < 40.0)
              | (roc_9_1h < 0.0)
              | (stochrsi_k > 30.0)
            )
            # 1h down move, 4h low, 1d uptrend
            & ((rsi_3_1h_gt_15) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_40))
            # 5m down move, 1h down move, 1d uptrend
            & ((rsi_3_1h_gt_20) | (aroonu_14_1d_lt_80) | (rsi_3_gt_5))
            # 1h down move & uptrend, 4h low
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_50) | (aroonu_14_4h_gt_30))
            # 1h down move & downtrend, 4h downtrend & down move, 1d up move
            & ((rsi_3_1h_gt_20) | (rsi_3_1d_lt_35) | (aroonu_14_1h_gt_10) | (aroonu_14_4h > 40.0) | (rsi_3_4h_gt_30))
            # 5m still high, 15m still high, 1h down move, 4h up move
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_lt_50) | (stochrsi_k_15m < 65.0) | (stochrsi_k < 15.0))
            # 1h down move, 4h up move, 1d low
            & ((rsi_3_1h_gt_40) | (rsi_3_4h_lt_70) | (aroonu_14_1d_gt_30))
            # 1h up move, 1h & 1d low
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_gt_10) | (aroonu_14_1d_gt_10))
            # 1h up move & uptrend, 4h down move
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_20))
            # 1h up move & uptrend, 4h low
            & ((rsi_3_1h_lt_40) | (aroonu_14_1h_lt_20) | (stochrsi_k_4h_gt_20))
            # 1h up move, 4h uptrend & still high
            & ((rsi_3_1h_lt_40) | (aroonu_14_4h_lt_50) | (stochrsi_k_4h_gt_40))
            # 1h up move & low, 1d high
            & ((rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_20) | (stochrsi_k_1d_gt_10))
            # 1h up move & still high, 1d uptrend
            & ((rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_50) | (aroonu_14_1d_lt_30))
            # 1h up move, 1h & 1d still high
            & ((rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_50) | (stochrsi_k_1d_gt_30))
            # 1h down move, 4h uptrend
            & ((rsi_3_1h_lt_55) | (aroonu_14_4h_lt_90))
            # 1h up move & still high, 4h down move
            & ((rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_30) | (rsi_3_4h_gt_20))
            # 1h up move & still high
            & ((rsi_3_1h_lt_70) | (stochrsi_k_1h_gt_30))
            # 5m still high, 1h downtrend & washed out, 4h up move, 1d up move
            & (
              (aroonu_14_1h_gt_10)
              | (rsi_3_1d_lt_35)
              | (stochrsi_k < 55.0)
              | (rsi_3_4h < 20.0)
              | (stochrsi_k_1h > 35.0)
            )
            # 5m washed out, 1h downtrend & washed out, 4h still high & downtrend
            & (
              (aroonu_14_1h_gt_10)
              | (stochrsi_k_1h_gt_20)
              | (stochrsi_k_4h < 55.0)
              | (stochrsi_k > 70.0)
              | (aroonu_14_4h_gt_50)
            )
            # 1h & 4h & 1d low
            & ((aroonu_14_1h_gt_10) | (aroonu_14_4h_gt_10) | (aroonu_14_1d_gt_10))
            # 1h low, 4h up move & still high
            & ((aroonu_14_1h_gt_10) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_60))
            # 5m washed out & up move, 1h downtrend & down move, 1d washed out
            & ((aroonu_14_1h_gt_10) | (stochrsi_k_1d_gt_20) | (rsi_3_1h_gt_15) | (stochrsi_k > 30.0) | (rsi_3 < 10.0))
            # 1h low & high, 4h up move
            & ((aroonu_14_1h_gt_10) | (stochrsi_k_1h_gt_10) | (rsi_3_4h_lt_40))
            # 1h low, 1d uptrend
            & ((aroonu_14_1h_gt_20) | (aroonu_14_1d_lt_50) | (roc_9_1d_lt_0))
            # 5m downtrend, 15m down move, 1h downtrend, 1d up move & overbought
            & ((aroonu_14_1h_gt_20) | (roc_9_1d_lt_0) | (rsi_3_15m_gt_30) | (aroonu_14 > 10.0) | (stochrsi_k_1d_lt_80))
            # 1h low, 4h up move & still high
            & ((aroonu_14_1h_gt_30) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_50))
            # 5m up move, 1h downtrend, 4h uptrend
            & ((aroonu_14_1h_gt_40) | (aroonu_14_4h_lt_90) | (rsi_3 < 35.0))
            # 1h low, 4h up move & still high
            & ((aroonu_14_1h_gt_40) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_40))
            # 1h low, 4h up move & still high
            & ((aroonu_14_1h_gt_40) | (rsi_3_4h_lt_50) | (stochrsi_k_4h_gt_60))
            # 1h & 4h uptrend, 1d high
            & ((aroonu_14_1h_lt_20) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_gt_10))
            # 1h uptrend, 4h low
            & ((aroonu_14_1h_lt_40) | (aroonu_14_4h_gt_20) | (stochrsi_k_4h_gt_20))
            # 1h & 4h uptrend, 4h still high
            & ((aroonu_14_1h_lt_40) | (aroonu_14_4h_lt_50) | (stochrsi_k_4h_gt_60))
            # 1h & 4h uptrend, 4h down move
            & ((aroonu_14_1h_lt_40) | (rsi_3_4h_gt_30) | (aroonu_14_4h_lt_40))
            # 1h uptrend & still high, 4h low
            & ((aroonu_14_1h_lt_50) | (stochrsi_k_1h_gt_40) | (stochrsi_k_4h_gt_20))
            # 1h uptrend, 1d down move
            & ((aroonu_14_1h_lt_60) | (rsi_3_1d_gt_10))
            # 1h uptrend & low
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_20))
            # 1h uptrend, 1h & 4h still high
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_30) | (stochrsi_k_4h_gt_40))
            # 1h uptrend, 1h & 1d still high
            & ((aroonu_14_1h_lt_60) | (stochrsi_k_1h_gt_40) | (stochrsi_k_1d_gt_40))
            # 5m up move, 1h uptrend, 1d AROOND low & still high
            & ((aroonu_14_1h_lt_80) | (aroond_14_1d > 5.0) | (stochrsi_k_1d_lt_70) | (rsi_3 < 5.0))
            # 5m up move, 1h uptrend, 1d uptrend & still high
            & ((aroonu_14_1h_lt_80) | (aroonu_14_1d_lt_60) | (stochrsi_k_1d_lt_70) | (rsi_3 < 20.0))
            # 1h uptrend, 4h still high, 1d low
            & ((aroonu_14_1h_lt_80) | (stochrsi_k_4h_gt_60) | (stochrsi_k_1d_gt_20))
            # 1h uptrend, 4h low, 1d oversold
            & ((aroonu_14_1h_lt_90) | (aroonu_14_4h_gt_10) | (roc_9_1d_gt_neg_15))
            # 1h aroond, 4h stochrsik, 1h cci, 5m stoch
            & ((aroond_14_1h > 35) | (stochrsi_k_change_pct_4h < 5) | (cci_20_change_pct_1h < 20) | (stoch_9_3 < 20))
            # 1h washed out & down move, 4h downtrend, 1d downtrend & up move
            & (
              (stochrsi_k_1h_gt_50)
              | (aroonu_14_1d_gt_10)
              | (rsi_3_1h_gt_10)
              | (aroonu_14_4h > 25.0)
              | (rsi_3_1d < 15.0)
            )
            # 1h stochrsik, 5m stoch, 1d aroonu, 1d top
            & ((stochrsi_k_1h > 25) | (stoch_9_3 < 20) | (aroonu_14_1d_gt_10) | (top_wick_pct_1d_lt_8))
            # 1h high, 1d overbought
            & ((stochrsi_k_1h_gt_10) | (roc_9_1d_gt_neg_50))
            # 1h & 1d high, 4h down move
            & ((stochrsi_k_1h_gt_10) | (rsi_3_4h_gt_10) | (stochrsi_k_1d_gt_10))
            # 1h high, 4h up move & uptrend
            & ((stochrsi_k_1h_gt_10) | (rsi_3_4h_lt_40) | (aroonu_14_4h_lt_90))
            # 5m downtrend, 15m overbought, 1h washed out, 1d up move
            & ((stochrsi_k_1h_gt_20) | (rsi_3_1d_lt_35) | (stochrsi_k_15m < 95.0) | (aroonu_14 > 60.0))
            # 1h still high, 1d low & high
            & ((stochrsi_k_1h_gt_30) | (aroonu_14_1d_gt_10) | (stochrsi_k_1d_gt_10))
            # 1h & 4h still high, 4h up move
            & ((stochrsi_k_1h_gt_30) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_40))
            # 1h still high, 4h & 1d uptrend
            & ((stochrsi_k_1h_gt_40) | (aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_40))
            # 1h still high, 1d uptrend & oversold
            & ((stochrsi_k_1h_gt_50) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_30))
            # 15m downtrend, 1h stochk 14 3 3 high, 4h WILLR low & down move, 1d still high
            & (
              (stochk_14_3_3_1h < 30.0)
              | (willr_14_4h > -80.0)
              | (stochrsi_k_1d_lt_50)
              | (rsi_3_4h_gt_25)
              | (aroonu_14_15m > 65.0)
            )
            # 5m uptrend, 15m washed out, 1h up move, 1d downtrend & up move
            & (
              (roc_9_1h < -1.0)
              | (aroonu_14_1d_gt_10)
              | (aroonu_14 < 60.0)
              | (roc_9_1d < -10.0)
              | (stochrsi_k_15m_gt_90)
            )
            # 5m uptrend, 15m downtrend, 1h up move, 4h on the floor, 1d downtrend
            & (
              (roc_9_1h < -1.0)
              | (aroonu_14_1d_gt_10)
              | (stochrsi_k_4h > 5.0)
              | (aroonu_14_15m > 25.0)
              | (aroonu_14 < 5.0)
            )
            # 5m still high, 1h up move & overbought, 4h on the floor & downtrend
            & (
              (roc_9_1h < -1.0)
              | (stochrsi_k_4h_gt_10)
              | (stochrsi_k < 45.0)
              | (stochrsi_k_1h_lt_80)
              | (aroonu_14_4h > 15.0)
            )
            # 1h uptrend, 4h down move
            & ((roc_9_1h < 0) | (rsi_3_4h_gt_10))
            # 15m washed out, 4h down move & uptrend, 1d up move & downtrend
            & (
              (rsi_3_4h_gt_15)
              | (roc_9_1d_lt_0)
              | (aroonu_14_1d_gt_10)
              | (stochrsi_k_15m_gt_70)
              | (aroonu_14_4h < 10.0)
            )
            # 15m washed out, 4h down move & up move, 1d downtrend & up move
            & (
              (rsi_3_4h_gt_20)
              | (aroonu_14_1d_gt_10)
              | (roc_9_1d < -10.0)
              | (stochrsi_k_15m > 75.0)
              | (roc_9_4h < -10.0)
            )
            # 4h down move & low, 1d up move
            & ((rsi_3_4h_gt_10) | (aroonu_14_4h_gt_20) | (rsi_3_1d_lt_35))
            # 4h down move & uptrend, 1d high
            & ((rsi_3_4h_gt_20) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_gt_10))
            # 15m downtrend, 1h up move, 4h down move & up move, 1d up move
            & ((rsi_3_4h_gt_25) | (rsi_3_1d_lt_35) | (roc_9_4h < 0.0) | (rsi_3_1h < 35.0) | (aroonu_14_15m_gt_30))
            # 4h down move, 1d uptrend & oversold
            & ((rsi_3_4h_gt_30) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_30))
            # 4h up move, 1d low & high
            & ((rsi_3_4h_lt_40) | (aroonu_14_1d_gt_10) | (stochrsi_k_1d_gt_10))
            # 4h up move & uptrend, 1d low
            & ((rsi_3_4h_lt_40) | (aroonu_14_4h_lt_50) | (stochrsi_k_1d_gt_20))
            # 4h up move & uptrend, 1d high
            & ((rsi_3_4h_lt_50) | (aroonu_14_4h_lt_20) | (stochrsi_k_1d_gt_10))
            # 4h up move & still high, 1d low
            & ((rsi_3_4h_lt_50) | (stochrsi_k_4h_gt_40) | (stochrsi_k_1d_gt_20))
            # 4h up move, 1d uptrend & still high
            & ((rsi_3_4h_lt_60) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_gt_30))
            # 4h up move & uptrend, 1d down move
            & ((rsi_3_4h_lt_60) | (aroonu_14_4h_lt_20) | (rsi_3_1d_gt_30))
            # 4h down move, 1d uptrend
            & ((rsi_3_4h_lt_75) | (aroonu_14_1d_lt_75))
            # 1h still high & down move, 4h downtrend, 1d AROOND low & downtrend
            & (
              (aroonu_14_4h_gt_10)
              | (aroond_14_1d > 50.0)
              | (stochrsi_k_1h < 65.0)
              | (aroonu_14_1d_gt_0)
              | (rsi_3_1h_gt_65)
            )
            # 1h downtrend & down move, 4h downtrend & up move, 1d down move
            & (
              (aroonu_14_4h_gt_10) | (roc_9_1d_gt_neg_20) | (rsi_3_4h_lt_50) | (aroonu_14_1h > 25.0) | (rsi_3_1h_gt_35)
            )
            # 15m downtrend, 1h downtrend, 4h downtrend & up move, 1d up move
            & (
              (aroonu_14_4h_gt_10) | (rsi_3_1d_lt_35) | (aroonu_14_1h_gt_0) | (aroonu_14_15m_gt_40) | (rsi_3_4h < 10.0)
            )
            # 5m washed out, 1h down move, 4h downtrend, 1d stochk 14 3 3 high & on the floor
            & (
              (aroonu_14_4h_gt_10)
              | (stochk_14_3_3_1d < 20.0)
              | (stochrsi_k_1d > 5.0)
              | (rsi_3_1h_gt_35)
              | (stochrsi_k > 50.0)
            )
            # 15m downtrend, 4h downtrend & down move & still high, 1d up move
            & (
              (aroonu_14_4h_gt_30)
              | (rsi_3_1d_lt_35)
              | (rsi_3_4h_gt_30)
              | (stochrsi_k_4h_lt_40)
              | (aroonu_14_15m > 25.0)
            )
            # 5m still high, 1h overbought, 4h uptrend, 1d down move
            & ((aroonu_14_4h_lt_20) | (rsi_3_1d_gt_40) | (stochrsi_k_1h_lt_90) | (stochrsi_k < 60.0))
            # 4h & 1d uptrend, 1d oversold
            & ((aroonu_14_4h_lt_30) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_20))
            # 4h uptrend, 1d overbought
            & ((aroonu_14_4h_lt_40) | (roc_9_1d_gt_neg_60))
            # 4h uptrend & still high, 1d high
            & ((aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_50) | (stochrsi_k_1d_gt_10))
            # 4h uptrend, 4h & 1d low
            & ((aroonu_14_4h_lt_50) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_10))
            # 4h uptrend & still high, 1d low
            & ((aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_60) | (stochrsi_k_1d_gt_20))
            # 4h uptrend, 1d down move
            & ((aroonu_14_4h_lt_75) | (rsi_3_1d_gt_15))
            # 4h aroond, 15m aroonu, 1d aroonu, 1h cmf
            & ((aroond_14_4h > 50) | (aroonu_14_15m_gt_20) | (aroonu_14_1d_gt_10) | (cmf_20_1h_gt_neg_0_10))
            # 4h washed out & -DI low & up move, 1d down move & downtrend
            & (
              (stochrsi_k_4h_gt_30)
              | (minus_di_14_4h > 25.0)
              | (roc_9_1d > -5.0)
              | (rsi_3_4h < 20.0)
              | (aroonu_14_1d_gt_30)
            )
            # 5m downtrend, 15m on the floor, 1h washed out, 4h washed out, 1d up move
            & (
              (stochrsi_k_4h_gt_30)
              | (rsi_3_1d_lt_35)
              | (stochrsi_k_15m > 5.0)
              | (stochrsi_k_1h_gt_40)
              | (aroonu_14 > 0.0)
            )
            # 15m on the floor & uptrend, 4h washed out & up move, 1d downtrend
            & (
              (stochrsi_k_4h_gt_50)
              | (aroonu_14_1d_gt_10)
              | (stochrsi_k_15m > 5.0)
              | (aroonu_14_15m_lt_40)
              | (rsi_3_4h < 25.0)
            )
            # 15m on the floor, 1h uptrend & up move, 4h washed out, 1d downtrend
            & (
              (stochrsi_k_4h_gt_80)
              | (aroonu_14_1d_gt_10)
              | (aroonu_14_1h_lt_90)
              | (stochrsi_k_15m_gt_10)
              | (roc_9_1h < 0.0)
            )
            # 4h stochrsik, 1d roc, 15m aroonu, 1h stochk
            & ((stochrsi_k_4h < 55) | (roc_9_1d < -10) | (aroonu_14_15m_lt_40) | (stochk_14_3_3_1h > 15))
            # 5m uptrend & down move, 1h down move, 4h on the floor, 1d uptrend
            & ((stochrsi_k_4h_gt_10) | (aroonu_14_1d_lt_30) | (rsi_3_1h_gt_5) | (aroonu_14 < 75.0) | (rsi_3 > 35.0))
            # 4h washed out & up move, 1d downtrend & down move
            & ((stochrsi_k_4h_gt_60) | (aroonu_14_1d_gt_10) | (roc_9_4h < 0.0) | (rsi_3_1d_gt_20))
            # 5m down move, 4h washed out & up move, 1d down move
            & ((stochrsi_k_4h_gt_70) | (roc_9_4h_lt_5) | (rsi_3_1d_gt_40) | (rsi_3 > 20.0))
            # 1h uptrend, 4h -DI low & washed out, 1d downtrend & down move
            & (
              (minus_di_14_4h > 25.0)
              | (aroonu_14_1d_gt_10)
              | (rsi_3_1d_gt_20)
              | (stochrsi_k_4h_gt_60)
              | (aroonu_14_1h < 10.0)
            )
            # 15m washed out, 4h downtrend, 1d down move & still high & downtrend
            & (
              (rsi_3_1d_gt_25)
              | (stochrsi_k_1d_lt_70)
              | (aroonu_14_4h > 15.0)
              | (stochrsi_k_15m_gt_80)
              | (aroonu_14_1d > 40.0)
            )
            # 1d money out & still low & top_wick_pct low
            & ((cmf_20_1d_gt_neg_0_25) | (mfi_14_1d > 20) | (top_wick_pct_1d > 1))
            # 1d mfi, 15m aroond, 4h aroond, 15m rsi
            & ((mfi_14_1d > 20) | (aroond_14_15m > 30) | (aroond_14_4h > 50) | (rsi_14_change_pct_15m < 3))
            # 15m still high, 1h uptrend & down move, 1d downtrend & down move
            & (
              (aroonu_14_1d_gt_10)
              | (roc_9_1d_gt_neg_10)
              | (aroonu_14_1h_lt_75)
              | (rsi_3_1h_gt_20)
              | (stochrsi_k_15m < 10.0)
            )
            # 5m uptrend, 15m down move, 1h on the floor, 1d downtrend & down move
            & (
              (aroonu_14_1d_gt_10)
              | (roc_9_1d_gt_neg_15)
              | (rsi_3_15m_gt_5)
              | (stochrsi_k_1h_gt_10)
              | (aroonu_14 < 10.0)
            )
            # 5m up move, 1h overbought, 1d downtrend & washed out
            & ((aroonu_14_1d_gt_10) | (stochrsi_k_1d_gt_30) | (stochrsi_k_1h_lt_90) | (rsi_3 < 35.0))
            # 4h overbought, 1d uptrend & down move
            & ((aroonu_14_1d_lt_60) | (roc_9_1d_gt_neg_20) | (stochrsi_k_4h_lt_90))
            # 5m squeeze count high, 15m down move & uptrend, 4h down move
            & ((sqz_cnt_24 < 20.0) | (rsi_3_15m_gt_50) | (aroonu_14_15m_lt_90) | (rsi_3_4h_gt_10))
            # 5m vol_rel high, 15m uo_7_14_28 high
            & ((vol_rel < 4) | (uo_7_14_28_15m < 55))
            # 15m daily change high, 1h UO high, 4h down move & up move, 1d up move
            & (
              (change_pct_15m < -0.5)
              | (uo_7_14_28_1h < 46.0)
              | (rsi_3_4h_gt_10)
              | (roc_9_4h < -5.0)
              | (roc_9_1d < -10.0)
            )
            # 5m down move, 15m falling fast, 1h money coming in, 1d on the floor & up move
            & (
              (obv_change_pct_15m > 0.0)
              | (mfi_14_1h < 40.0)
              | (stochrsi_k_1d > 5.0)
              | (roc_9_1d < -10.0)
              | (rsi_3_gt_5)
            )
            # 15m rsi, 1h cci, 15m aroonu, 1d aroond
            & ((rsi_3_change_pct_15m < 70) | (cci_20_1h < -50) | (aroonu_14_15m_gt_20) | (aroond_14_1d > 55))
            # 4h rsi, 15m rsi, 15m cci
            & (
              (rsi_3_change_pct_4h < 65)
              | (rsi_3_change_pct_15m < 70)
              | (rsi_14_change_pct_15m < 3)
              | (cci_20_change_pct_15m < 0.0)
            )
          )

          # Logic
          short_entry_logic.append(
            (close < ema_200)
            & (rsi_14 < 50.0)
            # 4h trend must agree — a full red candle inside a 4h uptrend is a pullback's low
            & (ema_12_4h < ema_200_4h)
            # full-body red candle: body >90% of range and a meaningful size
            & (mrb_bear > 0.5)
            # only below the daily 200 EMA: in a bull market the ignition is a dip being bought
            & (close < ema_200_1d)
            # not after a 24h crash: a full red candle there is the capitulation low
            & (roc_288 > -15.0)
          )

        # Condition #671 - Shooting-star pin-bar (Short, experimental, RAW — mirror at a top).
        if short_entry_condition_index == 671:
          # Protections
          short_entry_logic.append(num_empty_288 <= allowed_empty_candles_288)
          short_entry_logic.append(protections_short_global == True)
          short_entry_logic.append(
            # 5m up move & downtrend, 15m RSI low & downtrend
            ((rsi_3 < 85.0) | (rsi_14_15m > 60.0) | (aroonu_14 > 15.0) | (aroonu_14_15m_gt_0))
            # 5m up move, 15m uptrend, 1d down move
            & ((rsi_3_lt_90) | (aroonu_14_15m_lt_20) | (rsi_3_1d_gt_20))
            # 5m & 1h up move, 15m uptrend
            & ((rsi_3_lt_90) | (aroonu_14_15m_lt_75) | (rsi_3_1h_lt_60))
            # 5m up move, 1d uptrend & oversold
            & ((rsi_3_lt_90) | (aroonu_14_1d_lt_30) | (roc_9_1d_gt_neg_10))
            # 5m up move, 15m down move & high
            & ((rsi_3_lt_90) | (rsi_3_15m_gt_50) | (stochrsi_k_15m_gt_10))
            # 5m up move, 15m down move & uptrend
            & ((rsi_3_lt_90) | (rsi_3_15m_gt_55) | (aroonu_14_15m_lt_20))
            # 5m & 15m up move, 1d down move
            & ((rsi_3_lt_90) | (rsi_3_15m_lt_60) | (rsi_3_1d_gt_10))
            # 5m up move, 1h still high, 1d low
            & ((rsi_3_lt_90) | (stochrsi_k_1h_gt_60) | (aroonu_14_1d_gt_20))
            # 5m up move & still not low enough, 15m low
            & ((rsi_3_lt_90) | (stochrsi_k_gt_80) | (aroonu_14_15m_gt_20))
            # 5m & 15m up move, 15m low
            & ((rsi_3_lt_95) | (rsi_3_15m_lt_70) | (aroonu_14_15m_gt_50))
            # 5m & 15m & 4h up move
            & ((rsi_3_lt_95) | (rsi_3_15m_lt_70) | (rsi_3_4h_lt_40))
            # 5m RSI low, 15m CCI high, 4h still high
            & ((rsi_14 > 60.0) | (cci_20_15m < 120.0) | (stochrsi_k_4h_lt_70))
            # 5m & 4h low, 1h uptrend
            & ((aroonu_14_gt_75) | (roc_9_1h_lt_10) | (aroonu_14_4h_gt_20))
            # 5m & 1d low, 15m up move
            & ((aroonu_14_gt_75) | (rsi_3_15m_lt_60) | (aroonu_14_1d_gt_10))
            # 5m low, 15m up move, 1d down move
            & ((aroonu_14_gt_75) | (rsi_3_15m_lt_80) | (rsi_3_1d_gt_10))
            # 5m & 1h low, 1h up move
            & ((aroonu_14_gt_75) | (rsi_3_1h_lt_50) | (aroonu_14_1h_gt_20))
            # 5m & 4h low, 1h up move
            & ((aroonu_14_gt_75) | (rsi_3_1h_lt_80) | (aroonu_14_4h_gt_20))
            # 5m low, 4h down move, 1d oversold
            & ((aroonu_14_gt_75) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_25))
            # 5m low, 4h up move & uptrend
            & ((aroonu_14_gt_75) | (rsi_3_4h_lt_40) | (aroonu_14_4h_lt_40))
            # 5m low, 15m still not low enough, 1h up move
            & ((aroonu_14_gt_75) | (stochrsi_k_15m_gt_80) | (rsi_3_1h_lt_80))
            # 5m & 1d low, 1h still high
            & ((aroonu_14_gt_75) | (stochrsi_k_1h_gt_40) | (aroonu_14_1d_gt_10))
            # 5m still not low enough, 15m low, 4h up move
            & ((stochrsi_k_gt_80) | (aroonu_14_15m_gt_20) | (rsi_3_4h_lt_40))
            # 5m still not low enough, 1h uptrend, 4h down move
            & ((stochrsi_k_gt_80) | (aroonu_14_1h_lt_75) | (rsi_3_4h_gt_40))
            # 5m & 1h still not low enough, 1h uptrend
            & ((stochrsi_k_gt_80) | (aroonu_14_1h_lt_75) | (stochrsi_k_1h_gt_80))
            # 5m still not low enough, 4h uptrend, 1d oversold
            & ((stochrsi_k_gt_80) | (aroonu_14_4h_lt_40) | (roc_9_1d_gt_neg_25))
            # 5m still not low enough, 4h oversold, 1d uptrend
            & ((stochrsi_k_gt_80) | (roc_9_4h_gt_neg_10) | (roc_9_1d_lt_0))
            # 5m still not low enough, 15m up move & still high
            & ((stochrsi_k_gt_80) | (rsi_3_15m_lt_60) | (stochrsi_k_15m_gt_60))
            # 5m still not low enough, 15m up move, 1h still high
            & ((stochrsi_k_gt_80) | (rsi_3_15m_lt_70) | (stochrsi_k_1h_gt_60))
            # 5m still not low enough, 15m & 1h up move
            & ((stochrsi_k_gt_80) | (rsi_3_15m_lt_90) | (rsi_3_1h_lt_60))
            # 5m still not low enough, 1h up move, 1d uptrend
            & ((stochrsi_k_gt_80) | (rsi_3_1h_lt_50) | (roc_9_1d_lt_0))
            # 5m still not low enough, 1h up move & low
            & ((stochrsi_k_gt_80) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_20))
            # 5m & 1h still not low enough, 1h up move
            & ((stochrsi_k_gt_80) | (rsi_3_1h_lt_70) | (stochrsi_k_1h_gt_80))
            # 5m still not low enough, 15m still high, 1h low
            & ((stochrsi_k_gt_80) | (stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_20))
            # 5m still not low enough, 1h still high, 1d down move
            & ((stochrsi_k_gt_80) | (stochrsi_k_1h_gt_40) | (rsi_3_1d_gt_20))
            # ikili omurga
            & ((roc_288 > -10.0) | (rsi_14_4h < 50.0))
            # 15m & 4h down move, 1h uptrend
            & ((rsi_3_15m_gt_30) | (aroonu_14_1h_lt_20) | (rsi_3_4h_gt_20))
            # 15m down move, 1h up move & low
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_lt_40) | (aroonu_14_1h_gt_20))
            # 15m & 4h down move, 1h up move
            & ((rsi_3_15m_gt_30) | (rsi_3_1h_lt_40) | (rsi_3_4h_gt_30))
            # 15m down move, 15m & 1d low
            & ((rsi_3_15m_gt_30) | (stochrsi_k_15m_gt_20) | (aroonu_14_1d_gt_10))
            # 15m & 1d down move, 1h low
            & ((rsi_3_15m_gt_40) | (aroonu_14_1h_gt_20) | (rsi_3_1d_gt_20))
            # 15m down move, 4h uptrend, 1d oversold
            & ((rsi_3_15m_gt_40) | (aroonu_14_4h_lt_40) | (roc_9_1d_gt_neg_15))
            # 15m & 1h down move, 1d low
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_20) | (aroonu_14_1d_gt_30))
            # 15m & 1h down move, 1d oversold
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_20) | (roc_9_1d_gt_neg_20))
            # 15m & 1h down move, 1d low
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_gt_30) | (stochrsi_k_1d_gt_20))
            # 15m down move, 1h up move & low
            & ((rsi_3_15m_gt_40) | (rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_20))
            # 15m & 1d down move, 1h low
            & ((rsi_3_15m_gt_40) | (stochrsi_k_1h_gt_20) | (rsi_3_1d_gt_20))
            # 15m & 1h down move
            & ((rsi_3_15m_gt_5) | (rsi_3_1h_gt_10))
            # 15m down move & low, 4h uptrend
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_gt_20) | (aroonu_14_4h_lt_80))
            # 15m down move, 15m & 1d low
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_gt_50) | (stochrsi_k_1d_gt_20))
            # 15m down move & uptrend, 1d oversold
            & ((rsi_3_15m_gt_50) | (aroonu_14_15m_lt_75) | (roc_9_1d_gt_neg_25))
            # 15m down move, 1h uptrend, 1d low
            & ((rsi_3_15m_gt_50) | (aroonu_14_1h_lt_25) | (aroonu_14_1d_gt_20))
            # 15m & 4h down move, 1d oversold
            & ((rsi_3_15m_gt_50) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_20))
            # 15m down move & low, 4h up move
            & ((rsi_3_15m_gt_55) | (aroonu_14_15m_gt_20) | (rsi_3_4h_lt_60))
            # 15m down move, 1d uptrend & still not low enough
            & ((rsi_3_15m_gt_55) | (aroonu_14_1d_lt_70) | (stochrsi_k_1d_gt_70))
            # 15m down move, 1h up move & still high
            & ((rsi_3_15m_gt_55) | (rsi_3_1h_lt_70) | (stochrsi_k_1h_gt_60))
            # 15m up move & low, 4h uptrend
            & ((rsi_3_15m_lt_60) | (aroonu_14_15m_gt_20) | (roc_9_4h_lt_15))
            # 15m up move & low & still high
            & ((rsi_3_15m_lt_60) | (aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_30))
            # 15m up move, 1h down move, 4h low
            & ((rsi_3_15m_lt_60) | (rsi_3_1h_gt_10) | (aroonu_14_4h_gt_20))
            # 15m up move, 1h down move, 1d low
            & ((rsi_3_15m_lt_60) | (rsi_3_1h_gt_40) | (stochrsi_k_1d_gt_20))
            # 15m up move, 4h down move & uptrend
            & ((rsi_3_15m_lt_60) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_80))
            # 15m up move & still high, 4h uptrend
            & ((rsi_3_15m_lt_60) | (stochrsi_k_15m_gt_30) | (aroonu_14_4h_lt_80))
            # 15m up move & still high, 4h low
            & ((rsi_3_15m_lt_60) | (stochrsi_k_15m_gt_30) | (stochrsi_k_4h_gt_20))
            # 15m up move & still high, 1h uptrend
            & ((rsi_3_15m_lt_60) | (stochrsi_k_15m_gt_50) | (aroonu_14_1h_lt_75))
            # 15m & 1h up move, 15m still not high enough
            & ((rsi_3_15m_lt_60) | (stochrsi_k_15m_gt_70) | (rsi_3_1h_lt_90))
            # 15m up move & low, 1d uptrend
            & ((rsi_3_15m_lt_70) | (aroonu_14_15m_gt_50) | (aroonu_14_1d_lt_60))
            # 15m up move & low, 1d oversold
            & ((rsi_3_15m_lt_70) | (aroonu_14_15m_gt_60) | (roc_9_1d_gt_neg_30))
            # 15m up move, 1h down move, 4h low
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_gt_10) | (stochrsi_k_4h_gt_20))
            # 15m up move, 1h down move, 1d uptrend
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_gt_20) | (aroonu_14_1d_lt_30))
            # 15m up move, 1h & 1d down move
            & ((rsi_3_15m_lt_70) | (rsi_3_1h_gt_30) | (rsi_3_1d_gt_20))
            # 15m up move, 4h down move, 1d uptrend
            & ((rsi_3_15m_lt_70) | (rsi_3_4h_gt_30) | (aroonu_14_1d_lt_50))
            # 15m up move & still high, 4h still not low enough
            & ((rsi_3_15m_lt_70) | (stochrsi_k_15m_gt_40) | (stochrsi_k_4h_gt_80))
            # 15m & 1h up move, 15m still high
            & ((rsi_3_15m_lt_70) | (stochrsi_k_15m_gt_50) | (rsi_3_1h_lt_40))
            # 15m up move & still not low enough, 1d high
            & ((rsi_3_15m_lt_70) | (stochrsi_k_15m_gt_70) | (stochrsi_k_1d_gt_10))
            # 15m up move, 4h still high, 1d down move
            & ((rsi_3_15m_lt_70) | (stochrsi_k_4h_gt_60) | (rsi_3_1d_gt_10))
            # 15m up move, 1h money coming in, 1d uptrend
            & ((rsi_3_15m_lt_75) | (mfi_14_1h < 80.0) | (aroonu_14_1d_lt_30))
            # 15m down move, 1h oversold
            & ((rsi_3_15m_lt_75) | (roc_9_1h_gt_neg_10))
            # 15m up move & uptrend, 1h down move
            & ((rsi_3_15m_lt_80) | (aroonu_14_15m_lt_20) | (rsi_3_1h_gt_20))
            # 15m & 4h up move, 1h low
            & ((rsi_3_15m_lt_80) | (aroonu_14_1h_gt_40) | (rsi_3_4h_lt_60))
            # 15m up move, 1h & 1d uptrend
            & ((rsi_3_15m_lt_80) | (aroonu_14_1h_lt_20) | (aroonu_14_1d_lt_70))
            # 15m up move, 4h & 1d uptrend
            & ((rsi_3_15m_lt_80) | (aroonu_14_4h_lt_60) | (aroonu_14_1d_lt_30))
            # 15m up move, 4h uptrend, 1d down move
            & ((rsi_3_15m_lt_80) | (aroonu_14_4h_lt_80) | (rsi_3_1d_gt_40))
            # 15m up move, 1h down move, 4h low
            & ((rsi_3_15m_lt_80) | (rsi_3_1h_gt_30) | (aroonu_14_4h_gt_20))
            # 15m & 1h up move, 1h low
            & ((rsi_3_15m_lt_80) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_20))
            # 15m & 1h & 4h up move
            & ((rsi_3_15m_lt_80) | (rsi_3_1h_lt_90) | (rsi_3_4h_lt_70))
            # 15m & 4h up move, 1d uptrend
            & ((rsi_3_15m_lt_80) | (rsi_3_4h_lt_60) | (aroonu_14_1d_lt_90))
            # 15m up move & still high, 1h down move
            & ((rsi_3_15m_lt_80) | (stochrsi_k_15m_gt_40) | (rsi_3_1h_gt_30))
            # 15m & 4h up move, 15m still not high enough
            & ((rsi_3_15m_lt_80) | (stochrsi_k_15m_gt_70) | (rsi_3_4h_lt_90))
            # 15m up move & still not low enough, 1d oversold
            & ((rsi_3_15m_lt_80) | (stochrsi_k_15m_gt_90) | (roc_9_1d_gt_neg_40))
            # 15m up move, 1h still high, 1d down move
            & ((rsi_3_15m_lt_80) | (stochrsi_k_1h_gt_40) | (rsi_3_1d_gt_30))
            # 5m overbought, 15m up move, 1d uptrend & down move
            & ((rsi_3_15m_lt_85) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_30) | (stochrsi_k < 95.0))
            # 5m up move, 15m up move, 1h rising fast, 1d down move
            & ((rsi_3_15m_lt_85) | (rsi_3_change_pct_1h < 65.0) | (roc_9_1d_gt_neg_30) | (rsi_3 < 65.0))
            # 15m up move & uptrend, 1h down move
            & ((rsi_3_15m_lt_90) | (aroonu_14_15m_lt_75) | (rsi_3_1h_gt_30))
            # 15m up move, 1d uptrend & low
            & ((rsi_3_15m_lt_90) | (aroonu_14_1d_lt_30) | (stochrsi_k_1d_gt_20))
            # 15m up move, 4h uptrend, 1d oversold
            & ((rsi_3_15m_lt_90) | (aroonu_14_4h_lt_80) | (roc_9_1d_gt_neg_10))
            # 15m up move, 1h down move & uptrend
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_gt_50) | (aroonu_14_1h_lt_75))
            # 15m & 1h up move, 1d uptrend
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_70) | (aroonu_14_1d_lt_60))
            # 15m & 1h up move, 4h low
            & ((rsi_3_15m_lt_90) | (rsi_3_1h_lt_80) | (aroonu_14_4h_gt_30))
            # 15m up move & still not low enough, 4h low
            & ((rsi_3_15m_lt_90) | (stochrsi_k_15m_gt_70) | (stochrsi_k_4h_gt_20))
            # 15m up move, 1h still high, 1d down move
            & ((rsi_3_15m_lt_90) | (stochrsi_k_1h_gt_40) | (rsi_3_1d_gt_40))
            # 15m up move, 1h & 4h still high
            & ((rsi_3_15m_lt_90) | (stochrsi_k_1h_gt_40) | (stochrsi_k_4h_gt_40))
            # 5m up move, 15m downtrend, 1h up move, 4h washed out
            & ((aroonu_14_15m_gt_10) | (stochrsi_k_4h_gt_20) | (roc_9_1h < 0.0) | (rsi_3 < 85.0))
            # 15m & 1d low, 1d oversold
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1d_gt_10) | (roc_9_1d_gt_neg_30))
            # 15m low, 1d uptrend & oversold
            & ((aroonu_14_15m_gt_20) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_10))
            # 15m low, 4h uptrend, 1d down move
            & ((aroonu_14_15m_gt_20) | (aroonu_14_4h_lt_40) | (rsi_3_1d_gt_30))
            # 15m & 4h low, 4h uptrend
            & ((aroonu_14_15m_gt_20) | (aroonu_14_4h_lt_50) | (stochrsi_k_4h_gt_20))
            # 15m & 1h low, 1h up move
            & ((aroonu_14_15m_gt_20) | (rsi_3_1h_lt_60) | (aroonu_14_1h_gt_20))
            # 15m low, 4h up move & still high
            & ((aroonu_14_15m_gt_20) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_40))
            # 15m low, 4h up move, 1d uptrend
            & ((aroonu_14_15m_gt_20) | (rsi_3_4h_lt_60) | (aroonu_14_1d_lt_50))
            # 15m low & still high, 1d uptrend
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_50) | (roc_9_1d_lt_0))
            # 15m low & still high, 1h up move
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_50) | (rsi_3_1h_lt_40))
            # 15m low & still high, 4h up move
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_50) | (rsi_3_4h_lt_40))
            # 15m & 1h low, 15m still high
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_50) | (stochrsi_k_1h_gt_20))
            # 15m low & still not low enough, 1d high
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_15m_gt_80) | (stochrsi_k_1d_gt_10))
            # 15m & 1h & 1d low
            & ((aroonu_14_15m_gt_20) | (stochrsi_k_1h_gt_20) | (stochrsi_k_1d_gt_20))
            # 15m low, 1d uptrend & still high
            & ((aroonu_14_15m_gt_50) | (aroonu_14_1d_lt_70) | (stochrsi_k_1d_gt_60))
            # 15m & 4h & 1d low
            & ((aroonu_14_15m_gt_50) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_gt_10))
            # 15m & 4h low, 4h uptrend
            & ((aroonu_14_15m_gt_50) | (aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_20))
            # 15m & 4h low, 1h up move
            & ((aroonu_14_15m_gt_60) | (rsi_3_1h_lt_70) | (aroonu_14_4h_gt_50))
            # 15m uptrend, 1h up move & still high
            & ((aroonu_14_15m_lt_20) | (rsi_3_1h_lt_50) | (stochrsi_k_1h_gt_40))
            # 15m uptrend, 1h still high, 4h up move
            & ((aroonu_14_15m_lt_20) | (stochrsi_k_1h_gt_40) | (rsi_3_4h_lt_60))
            # 15m uptrend, 1h still high, 4h up move
            & ((aroonu_14_15m_lt_25) | (stochrsi_k_1h_gt_40) | (rsi_3_4h_lt_50))
            # 15m uptrend, 1h still high, 1d low
            & ((aroonu_14_15m_lt_25) | (stochrsi_k_1h_gt_40) | (stochrsi_k_1d_gt_20))
            # 15m & 4h uptrend, 4h down move
            & ((aroonu_14_15m_lt_50) | (rsi_3_4h_gt_20) | (aroonu_14_4h_lt_80))
            # 15m & 1d uptrend, 15m still high
            & ((aroonu_14_15m_lt_50) | (stochrsi_k_15m_gt_30) | (aroonu_14_1d_lt_90))
            # 15m & 1d uptrend, 1d down move
            & ((aroonu_14_15m_lt_75) | (rsi_3_1d_gt_10) | (aroonu_14_1d_lt_60))
            # 15m uptrend, 1h & 4h down move
            & ((aroonu_14_15m_lt_75) | (rsi_3_1h_gt_40) | (rsi_3_4h_gt_10))
            # 15m & 1d uptrend, 1h up move
            & ((aroonu_14_15m_lt_75) | (rsi_3_1h_lt_70) | (aroonu_14_1d_lt_60))
            # 15m uptrend, 4h down move, 1d high
            & ((aroonu_14_15m_lt_75) | (rsi_3_4h_gt_20) | (stochrsi_k_1d_gt_10))
            # 15m uptrend, 15m & 1h still high
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_gt_50) | (stochrsi_k_1h_gt_40))
            # 15m & 4h uptrend, 15m still not low enough
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_gt_70) | (aroonu_14_4h_lt_40))
            # 15m & 4h uptrend, 15m still not low enough
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_15m_gt_80) | (roc_9_4h_lt_5))
            # 15m uptrend, 1h still high, 4h up move
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_1h_gt_60) | (rsi_3_4h_lt_60))
            # 15m & 4h uptrend, 4h still high
            & ((aroonu_14_15m_lt_75) | (stochrsi_k_4h_gt_60) | (roc_9_4h_lt_5))
            # 5m uptrend, 15m uptrend, 1h down move, 4h up move
            & ((aroonu_14_15m_lt_90) | (roc_9_4h_lt_5) | (rsi_3_1h_gt_40) | (aroonu_14 < 80.0))
            # 15m & 1h & 1d low
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_20) | (stochrsi_k_1d_gt_20))
            # 15m & 1h low, 4h up move
            & ((stochrsi_k_15m_gt_20) | (aroonu_14_1h_gt_60) | (rsi_3_4h_lt_70))
            # 15m still high, 1h uptrend, 1d low
            & ((stochrsi_k_15m_gt_30) | (aroonu_14_1h_lt_50) | (aroonu_14_1d_gt_10))
            # 15m still high, 1h up move, 4h still not low enough
            & ((stochrsi_k_15m_gt_30) | (rsi_3_1h_lt_40) | (stochrsi_k_4h_gt_80))
            # 15m still high, 1h & 1d low
            & ((stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_20) | (aroonu_14_1d_gt_50))
            # 15m still high, 1h low, 4h down move
            & ((stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_20) | (rsi_3_4h_gt_30))
            # 15m still high, 1h still not low enough, 1d low
            & ((stochrsi_k_15m_gt_30) | (stochrsi_k_1h_gt_80) | (stochrsi_k_1d_gt_20))
            # 15m still high, 1h uptrend, 4h down move
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_1h_lt_50) | (rsi_3_4h_gt_20))
            # 15m still high, 4h uptrend, 1d low
            & ((stochrsi_k_15m_gt_40) | (aroonu_14_4h_lt_30) | (stochrsi_k_1d_gt_20))
            # 15m still high, 4h uptrend, 1d low
            & ((stochrsi_k_15m_gt_40) | (roc_9_4h_lt_10) | (aroonu_14_1d_gt_20))
            # 15m still high, 1d down move & low
            & ((stochrsi_k_15m_gt_40) | (rsi_3_1d_gt_20) | (aroonu_14_1d_gt_10))
            # 15m still high, 1h down move, 1d low
            & ((stochrsi_k_15m_gt_40) | (rsi_3_1h_gt_30) | (stochrsi_k_1d_gt_20))
            # 15m still high, 4h down move, 1d low
            & ((stochrsi_k_15m_gt_40) | (rsi_3_4h_gt_40) | (stochrsi_k_1d_gt_20))
            # 15m still high, 4h up move & low
            & ((stochrsi_k_15m_gt_40) | (rsi_3_4h_lt_70) | (aroonu_14_4h_gt_30))
            # 15m & 1h still high, 1d down move
            & ((stochrsi_k_15m_gt_40) | (stochrsi_k_1h_gt_40) | (rsi_3_1d_gt_30))
            # 15m & 1h still high, 1d low
            & ((stochrsi_k_15m_gt_40) | (stochrsi_k_1h_gt_60) | (aroonu_14_1d_gt_10))
            # 15m still high, 1d uptrend & oversold
            & ((stochrsi_k_15m_gt_50) | (aroonu_14_1d_lt_40) | (roc_9_1d_gt_neg_15))
            # 15m still high, 1d uptrend & oversold
            & ((stochrsi_k_15m_gt_50) | (aroonu_14_1d_lt_60) | (roc_9_1d_gt_neg_10))
            # 15m & 1d still high, 1d uptrend
            & ((stochrsi_k_15m_gt_50) | (stochrsi_k_1d_gt_40) | (roc_9_1d_lt_0))
            # 15m still high, 1d still not low enough & uptrend
            & ((stochrsi_k_15m_gt_50) | (stochrsi_k_1d_gt_70) | (roc_9_1d_lt_10))
            # 15m & 1h still high, 1d low
            & ((stochrsi_k_15m_gt_50) | (stochrsi_k_1h_gt_50) | (aroonu_14_1d_gt_10))
            # 15m still high, 1h up move, 4h down move
            & ((stochrsi_k_15m_gt_60) | (rsi_3_1h_lt_40) | (rsi_3_4h_gt_40))
            # 15m still high, 1h up move & low
            & ((stochrsi_k_15m_gt_60) | (rsi_3_1h_lt_50) | (aroonu_14_1h_gt_20))
            # 15m still high, 1h up move, 1d oversold
            & ((stochrsi_k_15m_gt_60) | (rsi_3_1h_lt_70) | (roc_9_1d_gt_neg_25))
            # 15m still high, 1h up move, 1d uptrend
            & ((stochrsi_k_15m_gt_60) | (rsi_3_1h_lt_70) | (roc_9_1d_lt_0))
            # 15m still high, 4h up move, 1d low
            & ((stochrsi_k_15m_gt_60) | (rsi_3_4h_lt_70) | (aroonu_14_1d_gt_10))
            # 15m & 1d still high, 1d uptrend
            & ((stochrsi_k_15m_gt_60) | (stochrsi_k_1d_gt_30) | (roc_9_1d_lt_0))
            # 15m still high, 1h low, 1d oversold
            & ((stochrsi_k_15m_gt_60) | (stochrsi_k_1h_gt_20) | (roc_9_1d_gt_neg_15))
            # 15m still not low enough, 1h up move, 4h down move
            & ((stochrsi_k_15m_gt_70) | (rsi_3_1h_lt_40) | (rsi_3_4h_gt_30))
            # 15m still not low enough, 1h up move, 4h uptrend
            & ((stochrsi_k_15m_gt_70) | (rsi_3_1h_lt_70) | (aroonu_14_4h_lt_60))
            # 15m still not low enough, 1h up move, 4h low
            & ((stochrsi_k_15m_gt_80) | (rsi_3_1h_lt_50) | (stochrsi_k_4h_gt_20))
            # 15m still not low enough, 1h & 4h up move
            & ((stochrsi_k_15m_gt_80) | (rsi_3_1h_lt_80) | (rsi_3_4h_lt_70))
            # 15m still not low enough, 4h down move, 1d oversold
            & ((stochrsi_k_15m_gt_80) | (rsi_3_4h_gt_10) | (roc_9_1d_gt_neg_25))
            # 15m still not low enough, 4h up move, 1d low
            & ((stochrsi_k_15m_gt_80) | (rsi_3_4h_lt_40) | (stochrsi_k_1d_gt_20))
            # 15m still not low enough, 1h & 1d low
            & ((stochrsi_k_15m_gt_80) | (stochrsi_k_1h_gt_20) | (stochrsi_k_1d_gt_20))
            # 15m still not low enough, 1h uptrend, 4h low
            & ((stochrsi_k_15m_gt_90) | (aroonu_14_1h_lt_50) | (stochrsi_k_4h_gt_20))
            # 1h down move, 4h & 1d low
            & ((rsi_3_1h_gt_10) | (stochrsi_k_4h_gt_20) | (aroonu_14_1d_gt_30))
            # 1h & 1d down move, 4h low
            & ((rsi_3_1h_gt_10) | (stochrsi_k_4h_gt_20) | (rsi_3_1d_gt_40))
            # 1h down move & uptrend, 1d oversold
            & ((rsi_3_1h_gt_20) | (aroonu_14_1h_lt_25) | (roc_9_1d_gt_neg_10))
            # 1h & 4h down move, 4h low
            & ((rsi_3_1h_gt_20) | (rsi_3_4h_gt_10) | (aroonu_14_4h_gt_20))
            # 1h down move, 1d low & oversold
            & ((rsi_3_1h_gt_30) | (aroonu_14_1d_gt_10) | (roc_9_1d_gt_neg_30))
            # 1h down move, 4h & 1d up move
            & ((rsi_3_1h_gt_30) | (rsi_3_4h_lt_40) | (rsi_3_1d_lt_80))
            # 1h down move & uptrend, 4h low
            & ((rsi_3_1h_gt_60) | (aroonu_14_1h_lt_50) | (stochrsi_k_4h_gt_20))
            # 1h up move & still high, 1d oversold
            & ((rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_30) | (roc_9_1d_gt_neg_25))
            # 1h up move & still high, 1d uptrend
            & ((rsi_3_1h_lt_40) | (stochrsi_k_1h_gt_40) | (aroonu_14_1d_lt_30))
            # 1h up move, 4h still high, 1d uptrend
            & ((rsi_3_1h_lt_40) | (stochrsi_k_4h_gt_60) | (aroonu_14_1d_lt_60))
            # 1h up move, 1d down move & uptrend
            & ((rsi_3_1h_lt_50) | (rsi_3_1d_gt_40) | (roc_9_1d_lt_10))
            # 1h up move, 4h low, 1d still high
            & ((rsi_3_1h_lt_50) | (stochrsi_k_4h_gt_20) | (stochrsi_k_1d_gt_40))
            # 1h up move & still not high enough, 4h low
            & ((rsi_3_1h_lt_60) | (stochrsi_k_1h_gt_70) | (aroonu_14_4h_gt_20))
            # 1h up move & low, 1d oversold
            & ((rsi_3_1h_lt_70) | (aroonu_14_1h_gt_20) | (roc_9_1d_gt_neg_20))
            # 1h up move, 1h & 1d low
            & ((rsi_3_1h_lt_70) | (aroonu_14_1h_gt_20) | (stochrsi_k_1d_gt_20))
            # 1h up move, 4h & 1d down move
            & ((rsi_3_1h_lt_70) | (rsi_3_4h_gt_40) | (rsi_3_1d_gt_20))
            # 1h up move, 4h down move & low
            & ((rsi_3_1h_lt_70) | (rsi_3_4h_gt_50) | (aroonu_14_4h_gt_20))
            # 1h up move, 1h & 4h low
            & ((rsi_3_1h_lt_80) | (aroonu_14_1h_gt_40) | (stochrsi_k_4h_gt_20))
            # 1h & 4h up move, 1d uptrend
            & ((rsi_3_1h_lt_80) | (rsi_3_4h_lt_70) | (roc_9_1d_lt_0))
            # 1h up move & still not low enough, 4h low
            & ((rsi_3_1h_lt_80) | (stochrsi_k_1h_gt_80) | (aroonu_14_4h_gt_30))
            # 1h up move & still not low enough, 1d down move
            & ((rsi_3_1h_lt_80) | (stochrsi_k_1h_gt_80) | (rsi_3_1d_gt_40))
            # 1h up move, 4h low, 1d uptrend
            & ((rsi_3_1h_lt_90) | (aroonu_14_4h_gt_30) | (aroonu_14_1d_lt_30))
            # 1h & 4h up move, 4h still high
            & ((rsi_3_1h_lt_90) | (rsi_3_4h_lt_70) | (stochrsi_k_4h_gt_40))
            # 1h & 4h low, 1d oversold
            & ((aroonu_14_1h_gt_20) | (aroonu_14_4h_gt_20) | (roc_9_1d_gt_neg_20))
            # 1h low, 4h uptrend, 1d up move
            & ((aroonu_14_1h_gt_20) | (aroonu_14_4h_lt_80) | (rsi_3_1d_lt_35))
            # 1h low, 4h uptrend
            & ((aroonu_14_1h_gt_20) | (stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_50))
            # 1h low, 4h up move, 1d down move
            & ((aroonu_14_1h_gt_40) | (rsi_3_4h_lt_50) | (rsi_3_1d_gt_50))
            # 1h low, 1d uptrend & oversold
            & ((aroonu_14_1h_gt_60) | (aroonu_14_1d_lt_60) | (roc_9_1d_gt_neg_10))
            # 1h & 1d low, 4h up move
            & ((aroonu_14_1h_gt_60) | (rsi_3_4h_lt_50) | (stochrsi_k_1d_gt_20))
            # 1h uptrend, 4h down move & oversold
            & ((aroonu_14_1h_lt_20) | (rsi_3_4h_gt_30) | (roc_9_4h_gt_neg_20))
            # 1h & 4h & 1d uptrend
            & ((aroonu_14_1h_lt_50) | (aroonu_14_4h_lt_20) | (roc_9_1d_lt_20))
            # 1h uptrend, 4h down move, 1d still high
            & ((aroonu_14_1h_lt_50) | (rsi_3_4h_gt_40) | (stochrsi_k_1d_gt_40))
            # 1h uptrend & still not low enough, 1d low
            & ((aroonu_14_1h_lt_50) | (stochrsi_k_1h_gt_80) | (stochrsi_k_1d_gt_20))
            # 1h uptrend, 4h down move, 1d low
            & ((aroonu_14_1h_lt_75) | (rsi_3_4h_gt_40) | (aroonu_14_1d_gt_30))
            # 1h uptrend, 4h down move & low
            & ((aroonu_14_1h_lt_75) | (rsi_3_4h_gt_50) | (aroonu_14_4h_gt_20))
            # 1h & 4h uptrend, 1h still not low enough
            & ((aroonu_14_1h_lt_75) | (stochrsi_k_1h_gt_80) | (aroonu_14_4h_lt_50))
            # 1h uptrend & still not low enough, 4h up move
            & ((aroonu_14_1h_lt_75) | (stochrsi_k_1h_gt_80) | (rsi_3_4h_lt_70))
            # 1h & 1d low, 4h uptrend
            & ((stochrsi_k_1h_gt_20) | (aroonu_14_4h_lt_30) | (stochrsi_k_1d_gt_20))
            # 1h & 4h low, 4h down move
            & ((stochrsi_k_1h_gt_20) | (rsi_3_4h_gt_20) | (aroonu_14_4h_gt_20))
            # 1h low, 4h up move & still high
            & ((stochrsi_k_1h_gt_20) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_40))
            # 1h still high, 4h & 1d low
            & ((stochrsi_k_1h_gt_40) | (aroonu_14_4h_gt_20) | (aroonu_14_1d_gt_20))
            # 1h still high, 4h & 1d low
            & ((stochrsi_k_1h_gt_40) | (aroonu_14_4h_gt_20) | (stochrsi_k_1d_gt_20))
            # 1h still high, 1d down move & low
            & ((stochrsi_k_1h_gt_60) | (rsi_3_1d_gt_10) | (aroonu_14_1d_gt_10))
            # 1h still high, 4h up move & low
            & ((stochrsi_k_1h_gt_60) | (rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_20))
            # 1h still not low enough, 4h up move & still high
            & ((stochrsi_k_1h_gt_80) | (rsi_3_4h_lt_70) | (stochrsi_k_4h_gt_60))
            # 4h up move, 4h & 1d uptrend
            & ((rsi_3_4h_lt_40) | (aroonu_14_4h_lt_40) | (aroonu_14_1d_lt_40))
            # 4h up move & low, 1d uptrend
            & ((rsi_3_4h_lt_40) | (stochrsi_k_4h_gt_20) | (roc_9_1d_lt_0))
            # 4h up move & still high, 1d low
            & ((rsi_3_4h_lt_60) | (stochrsi_k_4h_gt_40) | (stochrsi_k_1d_gt_20))
            # 4h & 1d up move, 4h still high
            & ((rsi_3_4h_lt_70) | (stochrsi_k_4h_gt_40) | (rsi_3_1d_lt_35))
            # 5m down move & washed out, 4h up move, 1d uptrend
            & ((rsi_3_4h_lt_75) | (aroonu_14_1d_lt_50) | (rsi_3 > 65.0) | (stochrsi_k > 70.0))
            # 4h & 1d uptrend, 4h oversold
            & ((aroonu_14_4h_lt_40) | (roc_9_4h_gt_neg_10) | (roc_9_1d_lt_0))
            # 4h uptrend & still high, 1d down move
            & ((aroonu_14_4h_lt_40) | (stochrsi_k_4h_gt_40) | (rsi_3_1d_gt_20))
            # 4h uptrend, 1d down move & low
            & ((aroonu_14_4h_lt_60) | (rsi_3_1d_gt_30) | (aroonu_14_1d_gt_10))
            # 4h uptrend & low, 1d oversold
            & ((aroonu_14_4h_lt_60) | (stochrsi_k_4h_gt_20) | (roc_9_1d_gt_neg_10))
            # 4h & 1d low, 1d uptrend
            & ((stochrsi_k_4h_gt_20) | (aroonu_14_1d_lt_40) | (stochrsi_k_1d_gt_20))
            # 4h low, 1d down move & uptrend
            & ((stochrsi_k_4h_gt_20) | (rsi_3_1d_gt_20) | (aroonu_14_1d_lt_60))
            # 4h still high, 1d uptrend & oversold
            & ((stochrsi_k_4h_gt_40) | (aroonu_14_1d_lt_70) | (roc_9_1d_gt_neg_25))
            # 1h cci collapsing, 15m cci not yet extreme, 4h no new high, 1h money still flowing in
            & ((cci_20_change_pct_1h > -35) | (cci_20_15m < 120) | (aroonu_14_4h > 25) | (cmf_20_1h > -0.05))
          )

          # Logic
          short_entry_logic.append(
            # top context: near the 4h high, 5m hot
            (close > (close_max_48 * 0.97))
            & (rsi_3 > 60.0)
            # the fact: long upper rejection wick, tiny lower wick
            & (pb_star > 0.5)
            # ...and it does not close at a new 4h closing high: that is strength, not rejection
            & (close < close_max_48)
            # 4h trend must agree — a rejection inside a 4h uptrend gets taken out
            & (ema_12_4h < ema_200_4h)
            # only below the daily 200 EMA: in a bull market the top keeps breaking
            & (close < ema_200_1d)
            # not after a 24h crash: a wick there is the relief bounce off the low
            & (roc_288 > -15.0)
          )

        short_entry_logic.append(df["volume"] > 0)
        item_short_entry = _and_entry_conditions(short_entry_logic)
        _append_entry_tag(entry_tags, item_short_entry, f"{short_entry_condition_index} ")
        short_entry_conditions.append(item_short_entry)
        df.loc[:, "enter_short"] = item_short_entry.astype(int)

        ###############################################################################################

        # SHORT ENTRY CONDITIONS ENDS HERE

        ###############################################################################################

    if short_entry_conditions:
      df.loc[:, "enter_short"] = _or_entry_conditions(short_entry_conditions).astype(int)

    df.loc[:, "enter_tag"] = entry_tags
    if debug:
      tok = time.perf_counter()
      log.debug("populate_entry_trend took a total of: %.4f seconds.", tok - tik)
    return df

  ###############################################################################################

  # COMMON FUNCTIONS FOR BOTH LONG AND SHORT SIDE ENDS HERE

  ###############################################################################################

  #  /$$        /$$$$$$  /$$   /$$  /$$$$$$         /$$$$$$  /$$$$$$ /$$$$$$$  /$$$$$$$$
  # | $$       /$$__  $$| $$$ | $$ /$$__  $$       /$$__  $$|_  $$_/| $$__  $$| $$_____/
  # | $$      | $$  \ $$| $$$$| $$| $$  \__/      | $$  \__/  | $$  | $$  \ $$| $$
  # | $$      | $$  | $$| $$ $$ $$| $$ /$$$$      |  $$$$$$   | $$  | $$  | $$| $$$$$
  # | $$      | $$  | $$| $$  $$$$| $$|_  $$       \____  $$  | $$  | $$  | $$| $$__/
  # | $$      | $$  | $$| $$\  $$$| $$  \ $$       /$$  \ $$  | $$  | $$  | $$| $$
  # | $$$$$$$$|  $$$$$$/| $$ \  $$|  $$$$$$/      |  $$$$$$/ /$$$$$$| $$$$$$$/| $$$$$$$$
  # |________/ \______/ |__/  \__/ \______/        \______/ |______/|_______/ |________/

  # Long Side Functions for handling long orders
  # ---------------------------------------------------------------------------------------------

  ###############################################################################################

  # LONG EXIT FUNCTIONS STARTS HERE

  ###############################################################################################

  #
  #  /$$        /$$$$$$  /$$   /$$  /$$$$$$        /$$$$$$$$ /$$   /$$ /$$$$$$ /$$$$$$$$
  # | $$       /$$__  $$| $$$ | $$ /$$__  $$      | $$_____/| $$  / $$|_  $$_/|__  $$__/
  # | $$      | $$  \ $$| $$$$| $$| $$  \__/      | $$      |  $$/ $$/  | $$     | $$
  # | $$      | $$  | $$| $$ $$ $$| $$ /$$$$      | $$$$$    \  $$$$/   | $$     | $$
  # | $$      | $$  | $$| $$  $$$$| $$|_  $$      | $$__/     >$$  $$   | $$     | $$
  # | $$      | $$  | $$| $$\  $$$| $$  \ $$      | $$       /$$/\  $$  | $$     | $$
  # | $$$$$$$$|  $$$$$$/| $$ \  $$|  $$$$$$/      | $$$$$$$$| $$  \ $$ /$$$$$$   | $$
  # |________/ \______/ |__/  \__/ \______/       |________/|__/  |__/|______/   |__/
  #

  # Long Exit Normal
  # ---------------------------------------------------------------------------------------------
  def long_exit_normal(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_orders,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.long_normal_mode_name

    sell = False

    # if the profit is negative skip checking these
    if profit_init_ratio > 0.0:
      # Original sell signals
      sell, signal_name = self.long_exit_signals(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

      # Main sell signals
      if not sell:
        sell, signal_name = self.long_exit_main(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

      # Williams %R based sells
      if not sell:
        sell, signal_name = self.long_exit_williams_r(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

      # Downtrend/descending based sells
      if not sell:
        sell, signal_name = self.long_exit_dec(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

    # Stoplosses
    if not sell:
      sell, signal_name = self.long_exit_stoploss(
        mode_name,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None

    # Profit Target Signal
    # Check if pair exist on target_profit_cache
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    if target_data is not None:
      previous_rate = target_data["rate"]
      previous_profit = target_data["profit"]
      previous_sell_reason = target_data["sell_reason"]
      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )
      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"
      if previous_sell_reason == f"exit_{mode_name}_stoploss_u_e":
        if profit_ratio > (previous_profit + 0.005):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )
          if mark_pair:
            set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
      elif (profit_init_ratio > (previous_profit + 0.001)) and (
        previous_sell_reason != f"exit_{mode_name}_stoploss_doom"
      ):
        # Update the target, raise it.
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      previous_profit = None
      previous_sell_reason = ""
      target_data = profit_target_get(pair) if profit_target_get is not None else None
      if target_data is not None:
        previous_profit = target_data["profit"]
        previous_sell_reason = target_data["sell_reason"]
      if signal_name in [
        f"exit_{mode_name}_stoploss_doom",
        f"exit_{mode_name}_stoploss_u_e",
      ] and (
        previous_sell_reason
        not in [
          f"exit_{mode_name}_stoploss_doom",
          f"exit_{mode_name}_stoploss_u_e",
        ]
      ):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
      elif (previous_profit is None) or (previous_profit < profit_init_ratio):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
    else:
      if profit_init_ratio >= 0.005:
        previous_profit = None
        target_data = profit_target_get(pair) if profit_target_get is not None else None
        if target_data is not None:
          previous_profit = target_data["profit"]
        if (previous_profit is None) or (previous_profit < profit_init_ratio):
          mark_signal = f"exit_profit_{mode_name}_max"
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    if signal_name not in [
      f"exit_profit_{mode_name}_max",
      f"exit_{mode_name}_stoploss_doom",
      f"exit_{mode_name}_stoploss_u_e",
    ]:
      if sell and (signal_name is not None):
        return True, f"{signal_name}"

    #  Here ends exit signal conditions for long_exit_normal

    return False, None

  # Long Exit Pump
  # ---------------------------------------------------------------------------------------------
  def long_exit_pump(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_orders,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.long_pump_mode_name

    sell = False
    signal_name = None

    stoploss_doom = f"exit_{mode_name}_stoploss_doom"
    stoploss_ue = f"exit_{mode_name}_stoploss_u_e"
    max_signal = f"exit_profit_{mode_name}_max"

    candle_args = (
      last_candle,
      previous_candle_1,
    )

    common_args = (
      mode_name,
      profit_init_ratio,
      max_profit,
      max_loss,
      *candle_args,
      trade,
      current_time,
      enter_tags,
    )

    # Profit-based exits
    if profit_init_ratio > 0.0:
      exit_checks = (
        self.long_exit_signals,
        self.long_exit_main,
        self.long_exit_williams_r,
        self.long_exit_dec,
      )

      for exit_check in exit_checks:
        sell, signal_name = exit_check(*common_args)

        if sell:
          break

    # Stoploss exits
    if not sell:
      sell, signal_name = self.long_exit_stoploss(
        mode_name,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        *candle_args,
        trade,
        current_time,
        enter_tags,
      )

    # Cached target profit data
    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    previous_profit = target_data["profit"] if target_data else None
    previous_sell_reason = target_data["sell_reason"] if target_data else ""

    # Profit target logic
    if target_data:
      previous_rate = target_data["rate"]

      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )

      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"

      if previous_sell_reason == stoploss_ue:
        if profit_ratio > (previous_profit + 0.005):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )

          if mark_pair:
            set_profit_target(
              pair,
              mark_signal,
              current_rate,
              profit_ratio,
              current_time,
            )

      elif profit_init_ratio > (previous_profit + 0.001) and previous_sell_reason != stoploss_doom:
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_init_ratio,
            current_time,
          )

    # Sell triggered
    if sell and signal_name is not None:
      if signal_name in (stoploss_doom, stoploss_ue):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_ratio,
            current_time,
          )

        else:
          return True, signal_name

      elif previous_profit is None or previous_profit < profit_init_ratio:
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_init_ratio,
            current_time,
          )

        else:
          return True, signal_name

    # Update cached max profit
    elif profit_init_ratio >= 0.005:
      if previous_profit is None or previous_profit < profit_init_ratio:
        set_profit_target(
          pair,
          max_signal,
          current_rate,
          profit_init_ratio,
          current_time,
        )

    # Final sell validation
    if sell and signal_name is not None and signal_name not in (max_signal, stoploss_doom, stoploss_ue):
      return True, signal_name

    return False, None

  # Long Exit Quick
  # ---------------------------------------------------------------------------------------------
  def long_exit_quick(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_orders,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.long_quick_mode_name

    sell = False
    signal_name = None

    stoploss_doom = f"exit_{mode_name}_stoploss_doom"
    stoploss_ue = f"exit_{mode_name}_stoploss_u_e"
    profit_max_signal = f"exit_profit_{mode_name}_max"

    candle_args = (
      last_candle,
      previous_candle_1,
    )

    common_args = (
      mode_name,
      profit_init_ratio,
      max_profit,
      max_loss,
      *candle_args,
      trade,
      current_time,
      enter_tags,
    )

    # -------------------------------------------------------------------------
    # Profit-based exit signals
    # -------------------------------------------------------------------------
    if profit_init_ratio > 0.0:
      exit_checks = (
        self.long_exit_signals,
        self.long_exit_main,
        self.long_exit_williams_r,
        self.long_exit_dec,
      )

      for exit_check in exit_checks:
        sell, signal_name = exit_check(*common_args)

        if sell:
          break

    # -------------------------------------------------------------------------
    # Stoploss
    # -------------------------------------------------------------------------
    if not sell:
      sell, signal_name = self.long_exit_stoploss(
        mode_name,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        *candle_args,
        trade,
        current_time,
        enter_tags,
      )

    # -------------------------------------------------------------------------
    # Extra quick exit logic
    # -------------------------------------------------------------------------
    if not sell and 0.02 < profit_init_ratio <= 0.09:
      rsi_14 = last_candle["RSI_14"]
      mfi_14 = last_candle["MFI_14"]
      willr_14 = last_candle["WILLR_14"]
      rsi_3 = last_candle["RSI_3"]
      rsi_3_15m = last_candle["RSI_3_15m"]

      quick_conditions = (
        (rsi_14 > 78.0, "q_1"),
        (mfi_14 > 84.0, "q_2"),
        (willr_14 >= -0.1, "q_3"),
        (
          rsi_14 >= 72.0 and rsi_3 > 90.0 and rsi_3_15m > 90.0,
          "q_4",
        ),
        (rsi_3_15m > 96.0, "q_5"),
        (rsi_3 > 85.0 and rsi_3_15m > 85.0, "q_6"),
        (rsi_3 > 90.0 and rsi_3_15m > 80.0, "q_7"),
        (rsi_3 > 92.0 and rsi_3_15m > 75.0, "q_8"),
        (rsi_3 > 94.0 and rsi_3_15m > 70.0, "q_9"),
        (rsi_3 > 99.0, "q_10"),
      )

      for condition, suffix in quick_conditions:
        if condition:
          sell = True
          signal_name = f"exit_{mode_name}_{suffix}"
          break

    # -------------------------------------------------------------------------
    # Cached target data
    # -------------------------------------------------------------------------
    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    previous_profit = target_data["profit"] if target_data else None
    previous_sell_reason = target_data["sell_reason"] if target_data else ""

    # -------------------------------------------------------------------------
    # Profit target logic
    # -------------------------------------------------------------------------
    if target_data:
      previous_rate = target_data["rate"]

      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )

      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"

      if previous_sell_reason == stoploss_ue:
        if profit_ratio > (previous_profit + 0.001):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )

          if mark_pair:
            set_profit_target(
              pair,
              mark_signal,
              current_rate,
              profit_ratio,
              current_time,
            )

      elif profit_init_ratio > (previous_profit + 0.001) and previous_sell_reason != stoploss_doom:
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_init_ratio,
            current_time,
          )

    # -------------------------------------------------------------------------
    # Sell triggered logic
    # -------------------------------------------------------------------------
    if sell and signal_name is not None:
      if signal_name in (stoploss_doom, stoploss_ue) and previous_sell_reason not in (
        stoploss_doom,
        f"exit_{mode_name}_stoploss_u_e",
      ):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_ratio,
            current_time,
          )

        else:
          return True, signal_name

      elif previous_profit is None or previous_profit < profit_init_ratio:
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_init_ratio,
            current_time,
          )

        else:
          return True, signal_name

    # -------------------------------------------------------------------------
    # Update max cached profit
    # -------------------------------------------------------------------------
    elif profit_init_ratio >= 0.005:
      if previous_profit is None or previous_profit < profit_init_ratio:
        set_profit_target(
          pair,
          profit_max_signal,
          current_rate,
          profit_init_ratio,
          current_time,
        )

    # -------------------------------------------------------------------------
    # Final sell validation
    # -------------------------------------------------------------------------
    if (
      sell
      and signal_name is not None
      and signal_name
      not in (
        profit_max_signal,
        stoploss_doom,
        stoploss_ue,
      )
    ):
      return True, signal_name

    return False, None

  # Long Exit Rebuy
  # ---------------------------------------------------------------------------------------------
  def long_exit_rebuy(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    is_futures_mode = self.is_futures_mode

    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.long_rebuy_mode_name
    stoploss_doom = f"exit_{mode_name}_stoploss_doom"
    stoploss_u_e = f"exit_{mode_name}_stoploss_u_e"
    profit_max = f"exit_profit_{mode_name}_max"

    sell = False
    signal_name = None

    signal_args = (
      mode_name,
      profit_current_stake_ratio,
      max_profit,
      max_loss,
      last_candle,
      previous_candle_1,
      trade,
      current_time,
      enter_tags,
    )

    # Original sell signals
    for exit_func in (
      self.long_exit_signals,
      self.long_exit_main,
      self.long_exit_williams_r,
      self.long_exit_dec,
    ):
      sell, signal_name = exit_func(*signal_args)

      if sell:
        break

    # Stoplosses
    if not sell:
      leverage = trade.leverage
      entry_cost = filled_entries[0].safe_filled * filled_entries[0].safe_price

      is_system_v3, is_system_v3_1, is_system_v3_2 = self.get_system_version_flags(trade)
      is_system_v4 = self.is_system_v4(trade)

      if is_system_v4:
        threshold = (
          self.system_v4_stop_threshold_futures_rebuy if is_futures_mode else self.system_v4_stop_threshold_spot_rebuy
        )

        if self.system_v4_stops_enable and profit_stake < -(entry_cost * threshold / leverage):
          sell, signal_name = True, stoploss_doom

      elif is_system_v3_2:
        threshold = (
          self.system_v3_2_stop_threshold_futures_rebuy
          if is_futures_mode
          else self.system_v3_2_stop_threshold_spot_rebuy
        )

        if self.system_v3_2_stops_enable and profit_stake < -(entry_cost * threshold / leverage):
          sell, signal_name = True, stoploss_doom

      elif is_system_v3_1:
        threshold = (
          self.system_v3_1_stop_threshold_futures_rebuy
          if is_futures_mode
          else self.system_v3_1_stop_threshold_spot_rebuy
        )

        if profit_stake < -(entry_cost * threshold / leverage):
          sell, signal_name = True, stoploss_doom

      elif is_system_v3:
        threshold = (
          self.system_v3_stop_threshold_futures_rebuy if is_futures_mode else self.system_v3_stop_threshold_spot_rebuy
        )

        if profit_stake < -(entry_cost * threshold / leverage):
          sell, signal_name = True, stoploss_doom

      else:
        threshold = self.stop_threshold_futures_rebuy if is_futures_mode else self.stop_threshold_spot_rebuy

        if profit_stake < -(entry_cost * threshold / leverage) and (
          trade.open_date_utc.replace(tzinfo=None) >= datetime(2024, 9, 13) or self.is_backtest_mode()
        ):
          sell, signal_name = True, stoploss_doom

    # Profit Target Signal
    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    previous_profit = target_data["profit"] if target_data else None
    previous_sell_reason = target_data["sell_reason"] if target_data else ""

    if target_data:
      previous_rate = target_data["rate"]
      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )

      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"

      if previous_sell_reason == stoploss_u_e:
        if profit_ratio > (previous_profit + 0.001):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )

          if mark_pair:
            set_profit_target(
              pair,
              mark_signal,
              current_rate,
              profit_ratio,
              current_time,
            )

      elif profit_init_ratio > (previous_profit + 0.001) and previous_sell_reason != stoploss_doom:
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_init_ratio,
            current_time,
          )

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      if signal_name in (stoploss_doom, stoploss_u_e):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_ratio,
            current_time,
          )
        else:
          return True, signal_name

      elif (previous_profit is None) or (previous_profit < profit_init_ratio):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_init_ratio,
            current_time,
          )
        else:
          return True, signal_name

    else:
      if profit_init_ratio >= 0.005:
        if (previous_profit is None) or (previous_profit < profit_init_ratio):
          set_profit_target(
            pair,
            profit_max,
            current_rate,
            profit_init_ratio,
            current_time,
          )

    if signal_name not in (
      profit_max,
      stoploss_doom,
      stoploss_u_e,
    ):
      if sell and signal_name is not None:
        return True, signal_name

    if (
      enter_tags == ["65"]
      and (current_time - trade.open_date_utc).total_seconds() >= 90 * 60
      and profit_init_ratio >= 0.0125
    ):
      return True, "exit_long_rebuy_e_r"

    # Here ends exit signal conditions for long_exit_rebuy
    return False, None

  # Long Exit High Profit
  # ---------------------------------------------------------------------------------------------
  def long_exit_high_profit(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_orders,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.long_high_profit_mode_name

    stoploss_doom = f"exit_{mode_name}_stoploss_doom"
    stoploss_u_e = f"exit_{mode_name}_stoploss_u_e"
    profit_max = f"exit_profit_{mode_name}_max"

    sell = False
    signal_name = None

    signal_args = (
      mode_name,
      profit_init_ratio,
      max_profit,
      max_loss,
      last_candle,
      previous_candle_1,
      trade,
      current_time,
      enter_tags,
    )

    # Original/Main/Williams sells
    for exit_func in (
      self.long_exit_signals,
      self.long_exit_main,
      self.long_exit_williams_r,
    ):
      sell, signal_name = exit_func(*signal_args)

      if sell:
        break

    # Stoplosses
    if not sell:
      sell, signal_name = self.long_exit_stoploss(
        mode_name,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Profit Target Signal
    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    previous_profit = target_data["profit"] if target_data else None
    previous_sell_reason = target_data["sell_reason"] if target_data else ""

    if target_data:
      previous_rate = target_data["rate"]
      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )

      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"

      if previous_sell_reason == stoploss_u_e:
        if profit_ratio > (previous_profit + 0.001):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )

          if mark_pair:
            set_profit_target(
              pair,
              mark_signal,
              current_rate,
              profit_ratio,
              current_time,
            )

      elif profit_init_ratio > (previous_profit + 0.001) and previous_sell_reason != stoploss_doom:
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_init_ratio,
            current_time,
          )

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      if signal_name in (stoploss_doom, stoploss_u_e):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_ratio,
            current_time,
          )
        else:
          return True, signal_name

      elif (previous_profit is None) or (previous_profit < profit_init_ratio):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_init_ratio,
            current_time,
          )
        else:
          return True, signal_name

    else:
      if profit_init_ratio >= 0.03:
        if (previous_profit is None) or (previous_profit < profit_init_ratio):
          set_profit_target(
            pair,
            profit_max,
            current_rate,
            profit_init_ratio,
            current_time,
          )

    if signal_name not in [
      profit_max,
      # stoploss_doom,
      # stoploss_u_e,
    ]:
      if sell and signal_name is not None:
        return True, signal_name

    # Here ends exit signal conditions for long_exit_high_profit
    return False, None

  # Long Exit Rapid
  # ---------------------------------------------------------------------------------------------
  def long_exit_rapid(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    is_futures_mode = self.is_futures_mode
    stops_enable = self.stops_enable

    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    is_backtest = self.is_backtest_mode()
    is_system_v3, is_system_v3_1, is_system_v3_2 = self.get_system_version_flags(trade)
    is_system_v4 = self.is_system_v4(trade)

    mode = self.long_rapid_mode_name
    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None
    pair_cache = profit_target_get(pair) if profit_target_get is not None else None
    previous_profit = pair_cache["profit"] if pair_cache else None
    previous_sell_reason = pair_cache["sell_reason"] if pair_cache else ""

    sell = False
    signal_name = None

    common_args = (
      mode,
      profit_init_ratio,
      max_profit,
      max_loss,
      last_candle,
      previous_candle_1,
      trade,
      current_time,
      enter_tags,
    )

    # if the profit is negative skip checking these
    if profit_init_ratio > 0.0:
      for exit_func in (
        self.long_exit_signals,
        self.long_exit_main,
        self.long_exit_williams_r,
        self.long_exit_dec,
      ):
        sell, signal_name = exit_func(*common_args)
        if sell:
          break

    # Extra exit logic
    if not sell:
      in_range = 0.09 >= profit_init_ratio > 0.005

      if in_range:
        rsi14 = last_candle["RSI_14"]
        mfi14 = last_candle["MFI_14"]
        willr14 = last_candle["WILLR_14"]
        rsi3 = last_candle["RSI_3"]
        rsi3_15m = last_candle["RSI_3_15m"]

        rapid_conditions = (
          (rsi14 > 78.0, f"exit_{mode}_rpd_1"),
          (mfi14 > 84.0, f"exit_{mode}_rpd_2"),
          (willr14 >= -0.1, f"exit_{mode}_rpd_3"),
          (
            rsi14 >= 72.0 and rsi3 > 90.0 and rsi3_15m > 90.0,
            f"exit_{mode}_rpd_4",
          ),
          (rsi3_15m > 96.0, f"exit_{mode}_rpd_5"),
          (rsi3 > 85.0 and rsi3_15m > 85.0, f"exit_{mode}_rpd_6"),
          (rsi3 > 90.0 and rsi3_15m > 80.0, f"exit_{mode}_rpd_7"),
          (rsi3 > 92.0 and rsi3_15m > 75.0, f"exit_{mode}_rpd_8"),
          (rsi3 > 94.0 and rsi3_15m > 70.0, f"exit_{mode}_rpd_9"),
          (rsi3 > 99.0, f"exit_{mode}_rpd_10"),
        )

        for condition, signal in rapid_conditions:
          if condition:
            sell, signal_name = True, signal
            break

      if not sell:
        entry_cost = filled_entries[0].safe_filled * filled_entries[0].safe_price
        leverage = trade.leverage
        stop_threshold = None
        stop_enabled = False

        if is_system_v4:
          stop_enabled = self.system_v4_stops_enable
          stop_threshold = (
            self.system_v4_stop_threshold_rapid_futures
            if is_futures_mode
            else self.system_v4_stop_threshold_rapid_spot
          )
        elif is_system_v3_2:
          stop_enabled = self.system_v3_2_stops_enable
          stop_threshold = (
            self.system_v3_2_stop_threshold_rapid_futures
            if is_futures_mode
            else self.system_v3_2_stop_threshold_rapid_spot
          )
        elif is_system_v3_1:
          stop_enabled = stops_enable
          stop_threshold = (
            self.system_v3_1_stop_threshold_rapid_futures
            if is_futures_mode
            else self.system_v3_1_stop_threshold_rapid_spot
          )
        elif is_system_v3:
          stop_enabled = stops_enable
          stop_threshold = (
            self.system_v3_stop_threshold_rapid_futures
            if is_futures_mode
            else self.system_v3_stop_threshold_rapid_spot
          )
        else:
          stop_enabled = stops_enable
          stop_threshold = self.stop_threshold_rapid_futures if is_futures_mode else self.stop_threshold_rapid_spot

        if stop_enabled:
          stoploss_value = -(entry_cost * stop_threshold / leverage)

          if is_system_v3 or is_system_v3_1 or is_system_v3_2:
            if profit_stake < stoploss_value:
              sell, signal_name = True, f"exit_{mode}_stoploss_doom"
          elif profit_stake < stoploss_value and (
            is_backtest or trade.open_date_utc.replace(tzinfo=None) >= datetime(2024, 9, 13)
          ):
            sell, signal_name = True, f"exit_{mode}_stoploss_doom"

    # Profit Target Signal
    if pair_cache:
      previous_rate = pair_cache["rate"]
      previous_time_profit_reached = datetime.fromisoformat(pair_cache["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )

      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"

      if previous_sell_reason == f"exit_{mode}_stoploss_u_e":
        if profit_ratio > (previous_profit + 0.001):
          mark_pair, mark_signal = mark_profit_target(
            mode,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )

          if mark_pair:
            set_profit_target(
              pair,
              mark_signal,
              current_rate,
              profit_ratio,
              current_time,
            )

      elif profit_init_ratio > (previous_profit + 0.001) and previous_sell_reason != f"exit_{mode}_stoploss_doom":
        mark_pair, mark_signal = mark_profit_target(
          mode,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_init_ratio,
            current_time,
          )

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      protected_signals = {
        f"exit_{mode}_stoploss_doom",
        f"exit_{mode}_stoploss_u_e",
      }

      blocked_previous_signals = {
        f"exit_{mode}_stoploss_doom",
        f"exit_{mode}_stoploss_u_e",
      }

      if signal_name in protected_signals and previous_sell_reason not in blocked_previous_signals:
        mark_pair, mark_signal = mark_profit_target(
          mode,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_ratio,
            current_time,
          )
        else:
          return True, signal_name

      elif previous_profit is None or previous_profit < profit_init_ratio:
        mark_pair, mark_signal = mark_profit_target(
          mode,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_init_ratio,
            current_time,
          )
        else:
          return True, signal_name

    elif profit_init_ratio >= 0.005:
      if previous_profit is None or previous_profit < profit_init_ratio:
        set_profit_target(
          pair,
          f"exit_profit_{mode}_max",
          current_rate,
          profit_init_ratio,
          current_time,
        )

    ignored_signals = {
      f"exit_profit_{mode}_max",
      f"exit_{mode}_stoploss_doom",
      f"exit_{mode}_stoploss_u_e",
    }

    if sell and signal_name is not None and signal_name not in ignored_signals:
      return True, signal_name

    # Here ends exit signal conditions for long_exit_rapid
    return False, None

  # Long Exit Grind
  # ---------------------------------------------------------------------------------------------
  def long_exit_grind(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    if profit_init_ratio > 0.25:
      return True, f"exit_{self.long_grind_mode_name}_g"

    # Here ends exit signal conditions for long_exit_grind
    return False, None

  # Long Exit Btc
  # ---------------------------------------------------------------------------------------------
  def long_exit_btc(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    if profit_init_ratio > 0.25:
      return True, f"exit_{self.long_btc_mode_name}_g"

    # Here ends exit signal conditions for long_exit_btc
    return False, None

  # Long Exit Top Coins
  # ---------------------------------------------------------------------------------------------
  def long_exit_top_coins(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_orders,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode = self.long_top_coins_mode_name

    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None
    pair_cache = profit_target_get(pair) if profit_target_get is not None else None
    previous_profit = pair_cache["profit"] if pair_cache else None
    previous_sell_reason = pair_cache["sell_reason"] if pair_cache else ""

    sell = False
    signal_name = None

    common_args = (
      mode,
      profit_init_ratio,
      max_profit,
      max_loss,
      last_candle,
      previous_candle_1,
      trade,
      current_time,
      enter_tags,
    )

    # Original/Main/Williams/DEC sell signals
    for exit_func in (
      self.long_exit_signals,
      self.long_exit_main,
      self.long_exit_williams_r,
      self.long_exit_dec,
    ):
      sell, signal_name = exit_func(*common_args)

      if sell:
        break

    # Stoplosses
    if not sell:
      sell, signal_name = self.long_exit_stoploss(
        mode,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Profit Target Signal
    if pair_cache:
      previous_rate = pair_cache["rate"]
      previous_time_profit_reached = datetime.fromisoformat(pair_cache["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )

      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"

      if previous_sell_reason == f"exit_{mode}_stoploss_u_e":
        if profit_ratio > (previous_profit + 0.005):
          mark_pair, mark_signal = mark_profit_target(
            mode,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )

          if mark_pair:
            set_profit_target(
              pair,
              mark_signal,
              current_rate,
              profit_ratio,
              current_time,
            )

      elif profit_init_ratio > (previous_profit + 0.001) and previous_sell_reason != f"exit_{mode}_stoploss_doom":
        mark_pair, mark_signal = mark_profit_target(
          mode,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            profit_init_ratio,
            current_time,
          )

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      protected_signals = {
        f"exit_{mode}_stoploss_doom",
        f"exit_{mode}_stoploss_u_e",
      }

      blocked_previous_signals = {
        f"exit_{mode}_stoploss_doom",
        f"exit_{mode}_stoploss_u_e",
      }

      target_profit = profit_ratio if signal_name in protected_signals else profit_init_ratio

      should_mark = (signal_name in protected_signals and previous_sell_reason not in blocked_previous_signals) or (
        signal_name not in protected_signals and (previous_profit is None or previous_profit < profit_init_ratio)
      )

      if should_mark:
        mark_pair, mark_signal = mark_profit_target(
          mode,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          target_profit,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(
            pair,
            mark_signal,
            current_rate,
            target_profit,
            current_time,
          )
        else:
          return True, signal_name

    elif profit_init_ratio >= 0.005:
      if previous_profit is None or previous_profit < profit_init_ratio:
        set_profit_target(
          pair,
          f"exit_profit_{mode}_max",
          current_rate,
          profit_init_ratio,
          current_time,
        )

    ignored_signals = {
      f"exit_profit_{mode}_max",
      f"exit_{mode}_stoploss_doom",
      f"exit_{mode}_stoploss_u_e",
    }

    if sell and signal_name is not None and signal_name not in ignored_signals:
      return True, signal_name

    # Here ends exit signal conditions for long_exit_top_coins
    return False, None

  # Long Exit Scalp
  # ---------------------------------------------------------------------------------------------
  def long_exit_scalp(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    is_futures_mode = self.is_futures_mode

    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode = self.long_scalp_mode_name

    is_system_v3, is_system_v3_1, is_system_v3_2 = self.get_system_version_flags(trade)
    is_system_v4 = self.is_system_v4(trade)

    sell = False
    signal_name = None

    signal_args = (
      profit_init_ratio,
      max_profit,
      max_loss,
      last_candle,
      previous_candle_1,
      trade,
      current_time,
      enter_tags,
    )

    # Original sell signals
    sell, signal_name = self.long_exit_signals(mode, *signal_args)

    # Main sell signals
    if not sell:
      sell, signal_name = self.long_exit_main(mode, *signal_args)

    # Williams %R based sells
    if not sell:
      sell, signal_name = self.long_exit_williams_r(mode, *signal_args)

    # Downtrend/descending based sells
    if not sell:
      sell, signal_name = self.long_exit_dec(mode, *signal_args)

    # Extra exit logic
    if not sell:
      entry_cost = filled_entries[0].safe_filled * filled_entries[0].safe_price
      leverage = trade.leverage

      if is_system_v4:
        threshold = (
          self.system_v4_stop_threshold_scalp_futures if is_futures_mode else self.system_v4_stop_threshold_scalp_spot
        )

        stoploss_hit = self.system_v4_stops_enable and profit_stake < -(entry_cost * threshold / leverage)

      elif is_system_v3_2:
        threshold = (
          self.system_v3_2_stop_threshold_scalp_futures
          if is_futures_mode
          else self.system_v3_2_stop_threshold_scalp_spot
        )

        stoploss_hit = self.system_v3_2_stops_enable and profit_stake < -(entry_cost * threshold / leverage)

      elif is_system_v3_1:
        threshold = (
          self.system_v3_1_stop_threshold_scalp_futures
          if is_futures_mode
          else self.system_v3_1_stop_threshold_scalp_spot
        )

        stoploss_hit = profit_stake < -(entry_cost * threshold / leverage)

      elif is_system_v3:
        threshold = (
          self.system_v3_stop_threshold_scalp_futures if is_futures_mode else self.system_v3_stop_threshold_scalp_spot
        )

        stoploss_hit = profit_stake < -(entry_cost * threshold / leverage)

      else:
        threshold = self.stop_threshold_scalp_futures if is_futures_mode else self.stop_threshold_scalp_spot

        stoploss_hit = profit_stake < -(entry_cost * threshold)

      if stoploss_hit:
        sell, signal_name = True, f"exit_{mode}_stoploss_doom"

    # Profit Target Signal
    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None
    pair_data = profit_target_get(pair) if profit_target_get is not None else None
    previous_profit = pair_data["profit"] if pair_data else None
    previous_sell_reason = pair_data["sell_reason"] if pair_data else ""

    if pair_data:
      previous_rate = pair_data["rate"]
      previous_time_profit_reached = datetime.fromisoformat(pair_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )

      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"

      if previous_sell_reason == f"exit_{mode}_stoploss_u_e":
        if profit_ratio > (previous_profit + 0.005):
          mark_pair, mark_signal = mark_profit_target(
            mode,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )

          if mark_pair:
            set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)

      elif profit_init_ratio > (previous_profit + 0.001) and previous_sell_reason != f"exit_{mode}_stoploss_doom":
        # Update the target, raise it.
        mark_pair, mark_signal = mark_profit_target(
          mode,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      if signal_name in {
        f"exit_{mode}_stoploss_doom",
        f"exit_{mode}_stoploss_u_e",
      }:
        mark_pair, mark_signal = mark_profit_target(
          mode,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"

      elif (previous_profit is None) or (previous_profit < profit_init_ratio):
        mark_pair, mark_signal = mark_profit_target(
          mode,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )

        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"

    else:
      if profit_init_ratio >= 0.005:
        if (previous_profit is None) or (previous_profit < profit_init_ratio):
          mark_signal = f"exit_profit_{mode}_max"
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    if signal_name not in {
      f"exit_profit_{mode}_max",
      f"exit_{mode}_stoploss_doom",
      f"exit_{mode}_stoploss_u_e",
    }:
      if sell and (signal_name is not None):
        return True, f"{signal_name}"

    # Here ends exit signal conditions for long_exit_scalp

    return False, None

  # Long Exit Signals
  # ---------------------------------------------------------------------------------------------
  def long_exit_signals(
    self,
    mode_name: str,
    current_profit: float,
    max_profit: float,
    max_loss: float,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    buy_tag,
  ) -> tuple:
    last_rsi_14 = last_candle["RSI_14"]
    last_close = last_candle["close"]
    last_ema_200 = last_candle["EMA_200"]
    last_ema_50 = last_candle["EMA_50"]
    last_rsi_14_1h = last_candle["RSI_14_1h"]
    last_bbu_20 = last_candle["BBU_20_2.0"]
    last_bbu_20_1h = last_candle["BBU_20_2.0_1h"]
    bb_above_count = last_candle["BB_ABOVE_COUNT"]
    current_profit_gt_0_01 = current_profit > 0.01

    # Sell signal 1
    if (last_rsi_14 > 84.0) and (last_close > last_bbu_20) and (bb_above_count >= 5):
      if last_close > last_ema_200:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_1_1_1"
      else:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_1_2_1"

    # Sell signal 2
    elif (last_rsi_14 > 86.0) and (last_close > last_bbu_20) and (bb_above_count >= 3):
      if last_close > last_ema_200:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_2_1_1"
      else:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_2_2_1"

    # Sell signal 3
    elif last_rsi_14 > 88.0:
      if last_close > last_ema_200:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_3_1_1"
      else:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_3_2_1"

    # Sell signal 4
    elif (last_rsi_14 > 84.0) and (last_rsi_14_1h > 80.0):
      if last_close > last_ema_200:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_4_1_1"
      else:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_4_2_1"

    # Sell signal 6
    elif (last_close < last_ema_200) and (last_close > last_ema_50) and (last_rsi_14 > 79.0):
      if current_profit_gt_0_01:
        return True, f"exit_{mode_name}_6_1"

    # # Sell signal 7
    # elif (last_candle["RSI_14_1h"] > 79.0) and (last_candle["crossed_below_EMA_12_26"]):
    #   if last_candle["close"] > last_candle["EMA_200"]:
    #     if current_profit_gt_0_01:
    #       return True, f"exit_{mode_name}_7_1_1"
    #   else:
    #     if current_profit_gt_0_01:
    #       return True, f"exit_{mode_name}_7_2_1"

    # Sell signal 8
    elif last_close > last_bbu_20_1h * 1.14:
      if last_close > last_ema_200:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_8_1_1"
      else:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_8_2_1"

    #  Here ends exit signal conditions for long_exit_signals

    return False, None

  # Long Exit Main
  # ---------------------------------------------------------------------------------------------
  def long_exit_main(
    self,
    mode_name: str,
    current_profit: float,
    max_profit: float,
    max_loss: float,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    buy_tag,
  ) -> tuple:
    last_close = last_candle["close"]
    last_ema_200 = last_candle["EMA_200"]
    last_rsi_14 = last_candle["RSI_14"]

    if last_close > last_ema_200:
      if 0.01 > current_profit >= 0.001:
        if last_rsi_14 < 10.0:
          return True, f"exit_{mode_name}_o_0"
      elif 0.02 > current_profit >= 0.01:
        if last_rsi_14 < 26.0:
          return True, f"exit_{mode_name}_o_1"
      elif 0.03 > current_profit >= 0.02:
        if last_rsi_14 < 30.0:
          return True, f"exit_{mode_name}_o_2"
      elif 0.04 > current_profit >= 0.03:
        if last_rsi_14 < 32.0:
          return True, f"exit_{mode_name}_o_3"
      elif 0.05 > current_profit >= 0.04:
        if last_rsi_14 < 34.0:
          return True, f"exit_{mode_name}_o_4"
      elif 0.06 > current_profit >= 0.05:
        if last_rsi_14 < 36.0:
          return True, f"exit_{mode_name}_o_5"
      elif 0.07 > current_profit >= 0.06:
        if last_rsi_14 < 38.0:
          return True, f"exit_{mode_name}_o_6"
      elif 0.08 > current_profit >= 0.07:
        if last_rsi_14 < 40.0:
          return True, f"exit_{mode_name}_o_7"
      elif 0.09 > current_profit >= 0.08:
        if last_rsi_14 < 42.0:
          return True, f"exit_{mode_name}_o_8"
      elif 0.1 > current_profit >= 0.09:
        if last_rsi_14 < 44.0:
          return True, f"exit_{mode_name}_o_9"
      elif 0.12 > current_profit >= 0.1:
        if last_rsi_14 < 46.0:
          return True, f"exit_{mode_name}_o_10"
      elif 0.2 > current_profit >= 0.12:
        if last_rsi_14 < 44.0:
          return True, f"exit_{mode_name}_o_11"
      elif current_profit >= 0.2:
        if last_rsi_14 < 42.0:
          return True, f"exit_{mode_name}_o_12"
    elif last_close < last_ema_200:
      if 0.01 > current_profit >= 0.001:
        if last_rsi_14 < 12.0:
          return True, f"exit_{mode_name}_u_0"
      elif 0.02 > current_profit >= 0.01:
        if last_rsi_14 < 30.0:
          return True, f"exit_{mode_name}_u_1"
      elif 0.03 > current_profit >= 0.02:
        if last_rsi_14 < 32.0:
          return True, f"exit_{mode_name}_u_2"
      elif 0.04 > current_profit >= 0.03:
        if last_rsi_14 < 34.0:
          return True, f"exit_{mode_name}_u_3"
      elif 0.05 > current_profit >= 0.04:
        if last_rsi_14 < 36.0:
          return True, f"exit_{mode_name}_u_4"
      elif 0.06 > current_profit >= 0.05:
        if last_rsi_14 < 38.0:
          return True, f"exit_{mode_name}_u_5"
      elif 0.07 > current_profit >= 0.06:
        if last_rsi_14 < 40.0:
          return True, f"exit_{mode_name}_u_6"
      elif 0.08 > current_profit >= 0.07:
        if last_rsi_14 < 42.0:
          return True, f"exit_{mode_name}_u_7"
      elif 0.09 > current_profit >= 0.08:
        if last_rsi_14 < 44.0:
          return True, f"exit_{mode_name}_u_8"
      elif 0.1 > current_profit >= 0.09:
        if last_rsi_14 < 46.0:
          return True, f"exit_{mode_name}_u_9"
      elif 0.12 > current_profit >= 0.1:
        if last_rsi_14 < 48.0:
          return True, f"exit_{mode_name}_u_10"
      elif 0.2 > current_profit >= 0.12:
        if last_rsi_14 < 46.0:
          return True, f"exit_{mode_name}_u_11"
      elif current_profit >= 0.2:
        if last_rsi_14 < 44.0:
          return True, f"exit_{mode_name}_u_12"

    #  Here ends exit signal conditions for long_exit_main

    return False, None

  # Long Exit Williams R
  # ---------------------------------------------------------------------------------------------
  def long_exit_williams_r(
    self,
    mode_name: str,
    current_profit: float,
    max_profit: float,
    max_loss: float,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    buy_tag,
  ) -> tuple:
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_willr_480 = last_candle["WILLR_480"]
    last_aroonu_14_4h = last_candle["AROONU_14_4h"]

    if 0.01 > current_profit >= 0.001:
      if (last_stochrsi_k > 95.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 95.0):
        return True, f"exit_{mode_name}_w_0_1"
    elif 0.02 > current_profit >= 0.01:
      if (last_stochrsi_k > 95.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 95.0):
        return True, f"exit_{mode_name}_w_1_1"
    elif 0.03 > current_profit >= 0.02:
      if (last_stochrsi_k > 95.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 95.0):
        return True, f"exit_{mode_name}_w_2_1"
    elif 0.04 > current_profit >= 0.03:
      if (last_stochrsi_k > 95.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 95.0):
        return True, f"exit_{mode_name}_w_3_1"
    elif 0.05 > current_profit >= 0.04:
      if (last_stochrsi_k > 90.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 90.0):
        return True, f"exit_{mode_name}_w_4_1"
    elif 0.06 > current_profit >= 0.05:
      if (last_stochrsi_k > 90.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 90.0):
        return True, f"exit_{mode_name}_w_5_1"
    elif 0.07 > current_profit >= 0.06:
      if (last_stochrsi_k > 90.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 90.0):
        return True, f"exit_{mode_name}_w_6_1"
    elif 0.08 > current_profit >= 0.07:
      if (last_stochrsi_k > 90.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 90.0):
        return True, f"exit_{mode_name}_w_7_1"
    elif 0.09 > current_profit >= 0.08:
      if (last_stochrsi_k > 90.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 90.0):
        return True, f"exit_{mode_name}_w_8_1"
    elif 0.1 > current_profit >= 0.09:
      if (last_stochrsi_k > 90.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 90.0):
        return True, f"exit_{mode_name}_w_9_1"
    elif 0.12 > current_profit >= 0.1:
      if (last_stochrsi_k > 90.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 90.0):
        return True, f"exit_{mode_name}_w_10_1"
    elif 0.2 > current_profit >= 0.12:
      if (last_stochrsi_k > 90.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 90.0):
        return True, f"exit_{mode_name}_w_11_1"
    elif current_profit >= 0.2:
      if (last_stochrsi_k > 90.0) and (last_willr_480 > -1.0) and (last_aroonu_14_4h > 90.0):
        return True, f"exit_{mode_name}_w_12_1"

    #  Here ends exit signal conditions for long_exit_williams_r

    return False, None

  # Long Exit Dec
  # ---------------------------------------------------------------------------------------------
  def long_exit_dec(
    self,
    mode_name: str,
    current_profit: float,
    max_profit: float,
    max_loss: float,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    buy_tag,
  ) -> tuple:
    last_sma_200_dec = last_candle["SMA_200_dec_24"]
    last_rsi_14 = last_candle["RSI_14"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_aroonu_14 = last_candle["AROONU_14"]
    last_sma_200_dec_1h = last_candle["SMA_200_dec_12_1h"]
    last_sma_200_dec_4h = last_candle["SMA_200_dec_6_4h"]
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_rsi_3_4h = last_candle["RSI_3_4h"]

    if 0.01 > current_profit >= 0.001:
      if (
        last_sma_200_dec
        and last_sma_200_dec_1h
        and last_sma_200_dec_4h
        and (last_rsi_14 > 82.0)
        and (last_stochrsi_k > 95.0)
        and (last_aroonu_14 > 95.0)
      ):
        return True, f"exit_{mode_name}_d_0_1"
      if (
        (last_rsi_3 > 98.0)
        and (last_stochrsi_k > 98.0)
        and (last_rsi_3_4h < 30.0)
        and (last_rsi_3_1h < 20.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_0_2"
    elif 0.02 > current_profit >= 0.01:
      if (
        last_sma_200_dec
        and last_sma_200_dec_1h
        and last_sma_200_dec_4h
        and (last_rsi_14 > 80.0)
        and (last_stochrsi_k > 95.0)
        and (last_aroonu_14 > 95.0)
      ):
        return True, f"exit_{mode_name}_d_1_1"
      if (
        (last_rsi_3 > 98.0)
        and (last_stochrsi_k > 98.0)
        and (last_rsi_3_4h < 30.0)
        and (last_rsi_3_1h < 20.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_1_2"
    elif 0.03 > current_profit >= 0.02:
      if (
        last_sma_200_dec
        and last_sma_200_dec_1h
        and last_sma_200_dec_4h
        and (last_rsi_14 > 78.0)
        and (last_stochrsi_k > 95.0)
        and (last_aroonu_14 > 95.0)
      ):
        return True, f"exit_{mode_name}_d_2_1"
      if (
        (last_rsi_3 > 98.0)
        and (last_stochrsi_k > 98.0)
        and (last_rsi_3_4h < 30.0)
        and (last_rsi_3_1h < 20.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_2_2"
    elif 0.04 > current_profit >= 0.03:
      if last_sma_200_dec and (last_rsi_14 > 76.0) and (last_stochrsi_k > 95.0) and (last_aroonu_14 > 90.0):
        return True, f"exit_{mode_name}_d_3_1"
      if (
        (last_rsi_3 > 95.0)
        and (last_stochrsi_k > 90.0)
        and (last_rsi_3_4h < 30.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_3_2"
    elif 0.05 > current_profit >= 0.04:
      if last_sma_200_dec and (last_rsi_14 > 74.0) and (last_stochrsi_k > 92.0) and (last_aroonu_14 > 90.0):
        return True, f"exit_{mode_name}_d_4_1"
      if (
        (last_rsi_3 > 95.0)
        and (last_stochrsi_k > 90.0)
        and (last_rsi_3_4h < 30.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_4_2"
    elif 0.06 > current_profit >= 0.05:
      if last_sma_200_dec and (last_stochrsi_k > 95.0) and (last_aroonu_14 > 90.0):
        return True, f"exit_{mode_name}_d_5_1"
      if (
        (last_rsi_3 > 95.0)
        and (last_stochrsi_k > 90.0)
        and (last_rsi_3_4h < 30.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_5_2"
    elif 0.07 > current_profit >= 0.06:
      if last_sma_200_dec or ((last_stochrsi_k > 95.0) and (last_aroonu_14 > 90.0)):
        return True, f"exit_{mode_name}_d_6_1"
      if (
        (last_rsi_3 > 95.0)
        and (last_stochrsi_k > 90.0)
        and (last_rsi_3_4h < 30.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_6_2"
    elif 0.08 > current_profit >= 0.07:
      if last_sma_200_dec or ((last_stochrsi_k > 95.0) and (last_aroonu_14 > 90.0)):
        return True, f"exit_{mode_name}_d_7_1"
      if (
        (last_rsi_3 > 95.0)
        and (last_stochrsi_k > 90.0)
        and (last_rsi_3_4h < 30.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_7_2"
    elif 0.09 > current_profit >= 0.08:
      if last_sma_200_dec or ((last_stochrsi_k > 95.0) and (last_aroonu_14 > 90.0)):
        return True, f"exit_{mode_name}_d_8_1"
      if (
        (last_rsi_3 > 95.0)
        and (last_stochrsi_k > 90.0)
        and (last_rsi_3_4h < 30.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_8_2"
    elif 0.1 > current_profit >= 0.09:
      if last_sma_200_dec or ((last_stochrsi_k > 95.0) and (last_aroonu_14 > 90.0)):
        return True, f"exit_{mode_name}_d_9_1"
      if (
        (last_rsi_3 > 95.0)
        and (last_stochrsi_k > 90.0)
        and (last_rsi_3_4h < 30.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_9_2"
    elif 0.12 > current_profit >= 0.1:
      if last_sma_200_dec or ((last_stochrsi_k > 95.0) and (last_aroonu_14 > 90.0)):
        return True, f"exit_{mode_name}_d_10_1"
      if (
        (last_rsi_3 > 95.0)
        and (last_stochrsi_k > 90.0)
        and (last_rsi_3_4h < 30.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_10_2"
    elif 0.2 > current_profit >= 0.12:
      if last_sma_200_dec or ((last_stochrsi_k > 95.0) and (last_aroonu_14 > 90.0)):
        return True, f"exit_{mode_name}_d_11_1"
      if (
        (last_rsi_3 > 95.0)
        and (last_stochrsi_k > 90.0)
        and (last_rsi_3_4h < 30.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_11_2"
    elif current_profit >= 0.2:
      if last_sma_200_dec or ((last_stochrsi_k > 95.0) and (last_aroonu_14 > 90.0)):
        return True, f"exit_{mode_name}_d_12_1"
      if (
        (last_rsi_3 > 95.0)
        and (last_stochrsi_k > 90.0)
        and (last_rsi_3_4h < 30.0)
        and last_sma_200_dec
        and last_sma_200_dec_1h
      ):
        return True, f"exit_{mode_name}_d_12_2"

    #  Here ends exit signal conditions for long_exit_dec

    return False, None

  # Long Exit Stop Loss
  # ---------------------------------------------------------------------------------------------
  def long_exit_stoploss(
    self,
    mode_name: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_orders,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    buy_tag,
  ) -> tuple:
    is_futures_mode = self.is_futures_mode
    doom_stops_enable = self.doom_stops_enable
    trade_leverage = trade.leverage
    stoploss_doom = f"exit_{mode_name}_stoploss_doom"
    stoploss_u_e = f"exit_{mode_name}_stoploss_u_e"

    is_backtest = self.is_backtest_mode()
    trade_open_date = None if is_backtest else trade.open_date_utc.replace(tzinfo=None)
    is_system_v3, is_system_v3_1, is_system_v3_2 = self.get_system_version_flags(trade)
    is_system_v4 = self.is_system_v4(trade)
    if not self.stops_enable:
      return False, None

    entry_cost = filled_entries[0].safe_filled * filled_entries[0].safe_price
    if is_system_v4:
      # Stoploss doom
      if self.system_v4_stops_enable and (
        profit_stake
        < -(
          entry_cost
          * (
            self.system_v4_stop_threshold_doom_futures if is_futures_mode else self.system_v4_stop_threshold_doom_spot
          )
          / trade_leverage
        )
      ):
        return True, stoploss_doom
    elif is_system_v3_2:
      # Stoploss doom
      if self.system_v3_2_stops_enable and (
        profit_stake
        < -(
          entry_cost
          * (
            self.system_v3_2_stop_threshold_doom_futures
            if is_futures_mode
            else self.system_v3_2_stop_threshold_doom_spot
          )
          / trade_leverage
        )
      ):
        return True, stoploss_doom
    elif is_system_v3_1:
      # Stoploss doom
      if doom_stops_enable and (
        profit_stake
        < -(
          entry_cost
          * (
            self.system_v3_1_stop_threshold_doom_futures
            if is_futures_mode
            else self.system_v3_1_stop_threshold_doom_spot
          )
          / trade_leverage
        )
      ):
        return True, stoploss_doom
    elif is_system_v3:
      # Stoploss doom
      if doom_stops_enable and (
        profit_stake
        < -(
          entry_cost
          * (
            self.system_v3_stop_threshold_doom_futures if is_futures_mode else self.system_v3_stop_threshold_doom_spot
          )
          / trade_leverage
        )
      ):
        return True, stoploss_doom
    else:
      # Stoploss doom
      if (
        doom_stops_enable
        and (
          profit_stake
          < -(entry_cost * (self.stop_threshold_doom_futures if is_futures_mode else self.stop_threshold_doom_spot))
        )
        and (
          self.has_valid_entry_conditions(trade, current_rate, last_candle, previous_candle_1, filled_orders) == False
        )
        # temporary
        and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
      ):
        return True, stoploss_doom

    last_close = last_candle["close"]
    last_ema_200 = last_candle["EMA_200"]
    last_rsi_14 = last_candle["RSI_14"]
    last_cmf_20 = last_candle["CMF_20"]
    last_rsi_14_1h = last_candle["RSI_14_1h"]
    previous_rsi_14 = previous_candle_1["RSI_14"]

    # Stoploss u_e
    if (
      self.u_e_stops_enable
      and (
        profit_stake
        < -(
          entry_cost * (self.stop_threshold_futures if is_futures_mode else self.stop_threshold_spot)
          # / trade.leverage
        )
      )
      and (last_close < last_ema_200)
      and (last_cmf_20 < -0.0)
      and (((last_ema_200 - last_close) / last_close) < 0.010)
      and (last_rsi_14 > previous_rsi_14)
      and (last_rsi_14 > (last_rsi_14_1h + 24.0))
      # and (current_time - timedelta(minutes=720) > trade.open_date_utc)
      # temporary
      and (is_backtest or trade_open_date >= datetime(2025, 4, 3))
    ):
      return True, stoploss_u_e

    #  Here ends exit signal conditions for long_exit_stoploss

    return False, None

  ###############################################################################################

  # LONG EXIT FUNCTIONS ENDS HERE

  ###############################################################################################

  # LONG GRIND FUNCTIONS STARTS HERE

  ###############################################################################################

  #
  #  /$$       /$$$$$$ /$$   /$$ /$$$$$$         /$$$$$$ /$$$$$$$ /$$$$$$/$$   /$$/$$$$$$$
  # | $$      /$$__  $| $$$ | $$/$$__  $$       /$$__  $| $$__  $|_  $$_| $$$ | $| $$__  $$
  # | $$     | $$  \ $| $$$$| $| $$  \__/      | $$  \__| $$  \ $$ | $$ | $$$$| $| $$  \ $$
  # | $$     | $$  | $| $$ $$ $| $$ /$$$$      | $$ /$$$| $$$$$$$/ | $$ | $$ $$ $| $$  | $$
  # | $$     | $$  | $| $$  $$$| $$|_  $$      | $$|_  $| $$__  $$ | $$ | $$  $$$| $$  | $$
  # | $$     | $$  | $| $$\  $$| $$  \ $$      | $$  \ $| $$  \ $$ | $$ | $$\  $$| $$  | $$
  # | $$$$$$$|  $$$$$$| $$ \  $|  $$$$$$/      |  $$$$$$| $$  | $$/$$$$$| $$ \  $| $$$$$$$/
  # |________/\______/|__/  \__/\______/        \______/|__/  |__|______|__/  \__|_______/
  #

  # Long Grinding Adjust Trade Position v2
  # ---------------------------------------------------------------------------------------------
  def long_grind_adjust_trade_position_v2(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ):
    dp = self.dp
    send_msg = self.dp.send_msg
    notification_msg = self.notification_msg
    scale_stakes_for_min_stake = self.scale_stakes_for_min_stake
    long_grind_exit_v2 = self.long_grind_exit_v2
    stake_currency = self.config["stake_currency"]
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_stake_amount = trade.stake_amount
    trade_fee_open = trade.fee_open
    trade_fee_close = trade.fee_close

    is_backtest = self.is_backtest_mode()
    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    is_futures = self.is_futures_mode
    trade_leverage = trade.leverage
    trade_get_custom_data = trade.get_custom_data
    trade_set_custom_data = trade.set_custom_data
    trade_is_short = trade.is_short
    derisk_enable = self.derisk_enable
    long_rebuy_mode_tags = self.long_rebuy_mode_tags
    long_grind_mode_tags = self.long_grind_mode_tags

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)
    if len(df) < 2:
      return None
    last_candle = df.iloc[-1]
    previous_candle = df.iloc[-2]

    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_exits = trade.nr_of_successful_exits

    if dp.runmode.value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = self.config["exit_pricing"]["price_side"]
        if trade_is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    first_filled_order = filled_orders[0]
    last_filled_order = filled_orders[-1]
    first_filled_entry = filled_entries[0]
    last_filled_entry = filled_entries[-1]

    current_stake_amount = trade_amount * exit_rate
    slice_amount = first_filled_entry.safe_filled * first_filled_entry.safe_price
    slice_profit = (exit_rate - last_filled_order.safe_price) / last_filled_order.safe_price
    slice_profit_entry = (exit_rate - last_filled_entry.safe_price) / last_filled_entry.safe_price
    slice_profit_exit = (
      ((exit_rate - filled_exits[-1].safe_price) / filled_exits[-1].safe_price) if count_of_exits > 0 else 0.0
    )

    is_rebuy_mode = all(c in long_rebuy_mode_tags for c in enter_tags) or (
      any(c in long_rebuy_mode_tags for c in enter_tags)
      and all(c in (long_rebuy_mode_tags + long_grind_mode_tags) for c in enter_tags)
    )

    has_order_tags = hasattr(first_filled_order, "ft_order_tag")

    fee_open_rate = trade_fee_open if self.custom_fee_open_rate is None else self.custom_fee_open_rate
    fee_close_rate = trade_fee_close if self.custom_fee_close_rate is None else self.custom_fee_close_rate
    stake_scale_leverage = trade_leverage if is_futures else 1.0
    derisk_flag_timeout = None

    def get_derisk_flag_timeout():
      nonlocal derisk_flag_timeout
      if derisk_flag_timeout is None:
        derisk_flag_timeout = current_time - timedelta(hours=96)

      return derisk_flag_timeout

    grind_1_max_sub_grinds = 0
    grind_1_stakes = scale_stakes_for_min_stake(
      self.grinding_v2_grind_1_stakes_futures if is_futures else self.grinding_v2_grind_1_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_1_sub_thresholds = (
      self.grinding_v2_grind_1_thresholds_futures if is_futures else self.grinding_v2_grind_1_thresholds_spot
    )
    grind_1_max_sub_grinds = len(grind_1_stakes)
    grind_1_derisk_grinds = (
      self.grinding_v2_grind_1_derisk_futures if is_futures else self.grinding_v2_grind_1_derisk_spot
    )
    grind_1_profit_threshold = (
      self.grinding_v2_grind_1_profit_threshold_futures
      if is_futures
      else self.grinding_v2_grind_1_profit_threshold_spot
    )

    grind_2_max_sub_grinds = 0
    grind_2_stakes = scale_stakes_for_min_stake(
      self.grinding_v2_grind_2_stakes_futures if is_futures else self.grinding_v2_grind_2_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_2_sub_thresholds = (
      self.grinding_v2_grind_2_thresholds_futures if is_futures else self.grinding_v2_grind_2_thresholds_spot
    )
    grind_2_max_sub_grinds = len(grind_2_stakes)
    grind_2_derisk_grinds = (
      self.grinding_v2_grind_2_derisk_futures if is_futures else self.grinding_v2_grind_2_derisk_spot
    )
    grind_2_profit_threshold = (
      self.grinding_v2_grind_2_profit_threshold_futures
      if is_futures
      else self.grinding_v2_grind_2_profit_threshold_spot
    )

    grind_3_max_sub_grinds = 0
    grind_3_stakes = scale_stakes_for_min_stake(
      self.grinding_v2_grind_3_stakes_futures if is_futures else self.grinding_v2_grind_3_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_3_sub_thresholds = (
      self.grinding_v2_grind_3_thresholds_futures if is_futures else self.grinding_v2_grind_3_thresholds_spot
    )
    grind_3_max_sub_grinds = len(grind_3_stakes)
    grind_3_derisk_grinds = (
      self.grinding_v2_grind_3_derisk_futures if is_futures else self.grinding_v2_grind_3_derisk_spot
    )
    grind_3_profit_threshold = (
      self.grinding_v2_grind_3_profit_threshold_futures
      if is_futures
      else self.grinding_v2_grind_3_profit_threshold_spot
    )

    grind_4_max_sub_grinds = 0
    grind_4_stakes = scale_stakes_for_min_stake(
      self.grinding_v2_grind_4_stakes_futures if is_futures else self.grinding_v2_grind_4_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_4_sub_thresholds = (
      self.grinding_v2_grind_4_thresholds_futures if is_futures else self.grinding_v2_grind_4_thresholds_spot
    )
    grind_4_max_sub_grinds = len(grind_4_stakes)
    grind_4_derisk_grinds = (
      self.grinding_v2_grind_4_derisk_futures if is_futures else self.grinding_v2_grind_4_derisk_spot
    )
    grind_4_profit_threshold = (
      self.grinding_v2_grind_4_profit_threshold_futures
      if is_futures
      else self.grinding_v2_grind_4_profit_threshold_spot
    )

    grind_5_max_sub_grinds = 0
    grind_5_stakes = scale_stakes_for_min_stake(
      self.grinding_v2_grind_5_stakes_futures if is_futures else self.grinding_v2_grind_5_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_5_sub_thresholds = (
      self.grinding_v2_grind_5_thresholds_futures if is_futures else self.grinding_v2_grind_5_thresholds_spot
    )
    grind_5_max_sub_grinds = len(grind_5_stakes)
    grind_5_derisk_grinds = (
      self.grinding_v2_grind_5_derisk_futures if is_futures else self.grinding_v2_grind_5_derisk_spot
    )
    grind_5_profit_threshold = (
      self.grinding_v2_grind_5_profit_threshold_futures
      if is_futures
      else self.grinding_v2_grind_5_profit_threshold_spot
    )

    is_derisk_1 = False
    is_derisk_1_found = False  # derisk_level_1 de-risk exit
    derisk_1_order = None
    is_derisk_2 = False
    is_derisk_2_found = False  # derisk_level_2 de-risk exit
    derisk_2_order = None
    is_derisk_3 = False
    is_derisk_3_found = False  # derisk_level_3 de-risk exit
    derisk_3_order = None
    buyback_1_sub_grind_count = 0
    buyback_1_total_amount = 0.0
    buyback_1_total_cost = 0.0
    buyback_1_current_open_rate = 0.0
    buyback_1_current_grind_stake = 0.0
    buyback_1_current_grind_stake_profit = 0.0
    buyback_1_is_exit_found = False
    buyback_1_found = False
    buyback_1_buy_orders = []
    buyback_1_orders = []
    buyback_1_distance_ratio = 0.0
    buyback_1_exit_order = None
    buyback_1_exit_distance_ratio = 0.0
    buyback_2_sub_grind_count = 0
    buyback_2_total_amount = 0.0
    buyback_2_total_cost = 0.0
    buyback_2_current_open_rate = 0.0
    buyback_2_current_grind_stake = 0.0
    buyback_2_current_grind_stake_profit = 0.0
    buyback_2_is_exit_found = False
    buyback_2_found = False
    buyback_2_buy_orders = []
    buyback_2_orders = []
    buyback_2_distance_ratio = 0.0
    buyback_2_exit_order = None
    buyback_2_exit_distance_ratio = 0.0
    buyback_3_sub_grind_count = 0
    buyback_3_total_amount = 0.0
    buyback_3_total_cost = 0.0
    buyback_3_current_open_rate = 0.0
    buyback_3_current_grind_stake = 0.0
    buyback_3_current_grind_stake_profit = 0.0
    buyback_3_is_exit_found = False
    buyback_3_found = False
    buyback_3_buy_orders = []
    buyback_3_orders = []
    buyback_3_distance_ratio = 0.0
    buyback_3_exit_order = None
    buyback_3_exit_distance_ratio = 0.0
    grind_1_sub_grind_count = 0
    grind_1_total_amount = 0.0
    grind_1_total_cost = 0.0
    grind_1_current_open_rate = 0.0
    grind_1_current_grind_stake = 0.0
    grind_1_current_grind_stake_profit = 0.0
    grind_1_is_exit_found = False
    grind_1_found = False
    grind_1_buy_orders = []
    grind_1_orders = []
    grind_1_distance_ratio = 0.0
    grind_1_exit_order = None
    grind_1_exit_distance_ratio = 0.0
    grind_2_sub_grind_count = 0
    grind_2_total_amount = 0.0
    grind_2_total_cost = 0.0
    grind_2_current_open_rate = 0.0
    grind_2_current_grind_stake = 0.0
    grind_2_current_grind_stake_profit = 0.0
    grind_2_is_exit_found = False
    grind_2_found = False
    grind_2_buy_orders = []
    grind_2_orders = []
    grind_2_distance_ratio = 0.0
    grind_2_exit_order = None
    grind_2_exit_distance_ratio = 0.0
    grind_3_sub_grind_count = 0
    grind_3_total_amount = 0.0
    grind_3_total_cost = 0.0
    grind_3_current_open_rate = 0.0
    grind_3_current_grind_stake = 0.0
    grind_3_current_grind_stake_profit = 0.0
    grind_3_is_exit_found = False
    grind_3_found = False
    grind_3_buy_orders = []
    grind_3_orders = []
    grind_3_distance_ratio = 0.0
    grind_3_exit_order = None
    grind_3_exit_distance_ratio = 0.0
    grind_4_sub_grind_count = 0
    grind_4_total_amount = 0.0
    grind_4_total_cost = 0.0
    grind_4_current_open_rate = 0.0
    grind_4_current_grind_stake = 0.0
    grind_4_current_grind_stake_profit = 0.0
    grind_4_is_exit_found = False
    grind_4_found = False
    grind_4_buy_orders = []
    grind_4_orders = []
    grind_4_distance_ratio = 0.0
    grind_4_exit_order = None
    grind_4_exit_distance_ratio = 0.0
    grind_5_sub_grind_count = 0
    grind_5_total_amount = 0.0
    grind_5_total_cost = 0.0
    grind_5_current_open_rate = 0.0
    grind_5_current_grind_stake = 0.0
    grind_5_current_grind_stake_profit = 0.0
    grind_5_is_exit_found = False
    grind_5_found = False
    grind_5_buy_orders = []
    grind_5_orders = []
    grind_5_distance_ratio = 0.0
    grind_5_exit_order = None
    grind_5_exit_distance_ratio = 0.0
    for order in reversed(filled_orders):
      if (order.ft_order_side == "buy") and (order is not first_filled_order):
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag
        if not buyback_1_is_exit_found and order_tag == "buyback_1_entry":
          buyback_1_sub_grind_count += 1
          buyback_1_total_amount += order.safe_filled
          buyback_1_total_cost += order.safe_filled * order.safe_price
          buyback_1_buy_orders.append(order.id)
          buyback_1_orders.append(order)
          if not buyback_1_found:
            buyback_1_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            buyback_1_found = True
        elif not buyback_2_is_exit_found and order_tag == "buyback_2_entry":
          buyback_2_sub_grind_count += 1
          buyback_2_total_amount += order.safe_filled
          buyback_2_total_cost += order.safe_filled * order.safe_price
          buyback_2_buy_orders.append(order.id)
          buyback_2_orders.append(order)
          if not buyback_2_found:
            buyback_2_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            buyback_2_found = True
        elif not buyback_3_is_exit_found and order_tag == "buyback_3_entry":
          buyback_3_sub_grind_count += 1
          buyback_3_total_amount += order.safe_filled
          buyback_3_total_cost += order.safe_filled * order.safe_price
          buyback_3_buy_orders.append(order.id)
          buyback_3_orders.append(order)
          if not buyback_3_found:
            buyback_3_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            buyback_3_found = True
        elif not grind_1_is_exit_found and order_tag == "grind_1_entry":
          grind_1_sub_grind_count += 1
          grind_1_total_amount += order.safe_filled
          grind_1_total_cost += order.safe_filled * order.safe_price
          grind_1_buy_orders.append(order.id)
          grind_1_orders.append(order)
          if not grind_1_found:
            grind_1_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_1_found = True
        elif not grind_2_is_exit_found and order_tag == "grind_2_entry":
          grind_2_sub_grind_count += 1
          grind_2_total_amount += order.safe_filled
          grind_2_total_cost += order.safe_filled * order.safe_price
          grind_2_buy_orders.append(order.id)
          grind_2_orders.append(order)
          if not grind_2_found:
            grind_2_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_2_found = True
        elif not grind_3_is_exit_found and order_tag == "grind_3_entry":
          grind_3_sub_grind_count += 1
          grind_3_total_amount += order.safe_filled
          grind_3_total_cost += order.safe_filled * order.safe_price
          grind_3_buy_orders.append(order.id)
          grind_3_orders.append(order)
          if not grind_3_found:
            grind_3_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_3_found = True
        elif not grind_4_is_exit_found and order_tag == "grind_4_entry":
          grind_4_sub_grind_count += 1
          grind_4_total_amount += order.safe_filled
          grind_4_total_cost += order.safe_filled * order.safe_price
          grind_4_buy_orders.append(order.id)
          grind_4_orders.append(order)
          if not grind_4_found:
            grind_4_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_4_found = True
        elif not grind_5_is_exit_found and order_tag == "grind_5_entry":
          grind_5_sub_grind_count += 1
          grind_5_total_amount += order.safe_filled
          grind_5_total_cost += order.safe_filled * order.safe_price
          grind_5_buy_orders.append(order.id)
          grind_5_orders.append(order)
          if not grind_5_found:
            grind_5_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_5_found = True
      elif order.ft_order_side == "sell":
        if order is filled_exits[-1] and (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
          # break
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag.partition(" ")[0]
        if order_tag in ["derisk_level_1", "d"]:
          if not is_derisk_1_found:
            is_derisk_1_found = True
            is_derisk_1 = True
            derisk_1_order = order
        elif order_tag == "derisk_level_2":
          if not is_derisk_2_found:
            is_derisk_2_found = True
            is_derisk_2 = True
            derisk_2_order = order
        elif order_tag == "derisk_level_3":
          if not is_derisk_3_found:
            is_derisk_3_found = True
            is_derisk_3 = True
            derisk_3_order = order
        elif not buyback_1_is_exit_found and order_tag in ["buyback_1_exit", "buyback_1_derisk"]:
          buyback_1_is_exit_found = True
          buyback_1_exit_order = order
        elif not buyback_2_is_exit_found and order_tag in ["buyback_2_exit", "buyback_2_derisk"]:
          buyback_2_is_exit_found = True
          buyback_2_exit_order = order
        elif not buyback_3_is_exit_found and order_tag in ["buyback_3_exit", "buyback_3_derisk"]:
          buyback_3_is_exit_found = True
          buyback_3_exit_order = order
        elif not grind_1_is_exit_found and order_tag in ["grind_1_exit", "grind_1_derisk"]:
          grind_1_is_exit_found = True
          grind_1_exit_order = order
        elif not grind_2_is_exit_found and order_tag in ["grind_2_exit", "grind_2_derisk"]:
          grind_2_is_exit_found = True
          grind_2_exit_order = order
        elif not grind_3_is_exit_found and order_tag in ["grind_3_exit", "grind_3_derisk"]:
          grind_3_is_exit_found = True
          grind_3_exit_order = order
        elif not grind_4_is_exit_found and order_tag in ["grind_4_exit", "grind_4_derisk"]:
          grind_4_is_exit_found = True
          grind_4_exit_order = order
        elif not grind_5_is_exit_found and order_tag in ["grind_5_exit", "grind_5_derisk"]:
          grind_5_is_exit_found = True
          grind_5_exit_order = order
        elif order_tag == "derisk_global":
          if not buyback_1_is_exit_found:
            buyback_1_is_exit_found = True
            buyback_1_exit_order = order
          if not buyback_2_is_exit_found:
            buyback_2_is_exit_found = True
            buyback_2_exit_order = order
          if not buyback_3_is_exit_found:
            buyback_3_is_exit_found = True
            buyback_3_exit_order = order
          if not grind_1_is_exit_found:
            grind_1_is_exit_found = True
            grind_1_exit_order = order
          if not grind_2_is_exit_found:
            grind_2_is_exit_found = True
            grind_2_exit_order = order
          if not grind_3_is_exit_found:
            grind_3_is_exit_found = True
            grind_3_exit_order = order
          if not grind_4_is_exit_found:
            grind_4_is_exit_found = True
            grind_4_exit_order = order
          if not grind_5_is_exit_found:
            grind_5_is_exit_found = True
            grind_5_exit_order = order

    if buyback_1_sub_grind_count > 0:
      buyback_1_current_open_rate = buyback_1_total_cost / buyback_1_total_amount
      buyback_1_current_grind_stake = buyback_1_total_amount * exit_rate * (1 - trade_fee_close)
      buyback_1_current_grind_stake_profit = buyback_1_current_grind_stake - buyback_1_total_cost
    if buyback_2_sub_grind_count > 0:
      buyback_2_current_open_rate = buyback_2_total_cost / buyback_2_total_amount
      buyback_2_current_grind_stake = buyback_2_total_amount * exit_rate * (1 - trade_fee_close)
      buyback_2_current_grind_stake_profit = buyback_2_current_grind_stake - buyback_2_total_cost
    if buyback_3_sub_grind_count > 0:
      buyback_3_current_open_rate = buyback_3_total_cost / buyback_3_total_amount
      buyback_3_current_grind_stake = buyback_3_total_amount * exit_rate * (1 - trade_fee_close)
      buyback_3_current_grind_stake_profit = buyback_3_current_grind_stake - buyback_3_total_cost
    if grind_1_sub_grind_count > 0:
      grind_1_current_open_rate = grind_1_total_cost / grind_1_total_amount
      grind_1_current_grind_stake = grind_1_total_amount * exit_rate * (1 - trade_fee_close)
      grind_1_current_grind_stake_profit = grind_1_current_grind_stake - grind_1_total_cost
    if grind_2_sub_grind_count > 0:
      grind_2_current_open_rate = grind_2_total_cost / grind_2_total_amount
      grind_2_current_grind_stake = grind_2_total_amount * exit_rate * (1 - trade_fee_close)
      grind_2_current_grind_stake_profit = grind_2_current_grind_stake - grind_2_total_cost
    if grind_3_sub_grind_count > 0:
      grind_3_current_open_rate = grind_3_total_cost / grind_3_total_amount
      grind_3_current_grind_stake = grind_3_total_amount * exit_rate * (1 - trade_fee_close)
      grind_3_current_grind_stake_profit = grind_3_current_grind_stake - grind_3_total_cost
    if grind_4_sub_grind_count > 0:
      grind_4_current_open_rate = grind_4_total_cost / grind_4_total_amount
      grind_4_current_grind_stake = grind_4_total_amount * exit_rate * (1 - trade_fee_close)
      grind_4_current_grind_stake_profit = grind_4_current_grind_stake - grind_4_total_cost
    if grind_5_sub_grind_count > 0:
      grind_5_current_open_rate = grind_5_total_cost / grind_5_total_amount
      grind_5_current_grind_stake = grind_5_total_amount * exit_rate * (1 - trade_fee_close)
      grind_5_current_grind_stake_profit = grind_5_current_grind_stake - grind_5_total_cost

    if grind_1_is_exit_found:
      grind_1_exit_distance_ratio = (exit_rate - grind_1_exit_order.safe_price) / grind_1_exit_order.safe_price
    if grind_2_is_exit_found:
      grind_2_exit_distance_ratio = (exit_rate - grind_2_exit_order.safe_price) / grind_2_exit_order.safe_price
    if grind_3_is_exit_found:
      grind_3_exit_distance_ratio = (exit_rate - grind_3_exit_order.safe_price) / grind_3_exit_order.safe_price
    if grind_4_is_exit_found:
      grind_4_exit_distance_ratio = (exit_rate - grind_4_exit_order.safe_price) / grind_4_exit_order.safe_price
    if buyback_1_is_exit_found:
      buyback_1_exit_distance_ratio = (exit_rate - buyback_1_exit_order.safe_price) / buyback_1_exit_order.safe_price
    elif is_derisk_1_found:
      buyback_1_exit_distance_ratio = (exit_rate - derisk_1_order.safe_price) / derisk_1_order.safe_price
    if buyback_2_is_exit_found:
      buyback_2_exit_distance_ratio = (exit_rate - buyback_2_exit_order.safe_price) / buyback_2_exit_order.safe_price
    elif is_derisk_2_found:
      buyback_2_exit_distance_ratio = (exit_rate - derisk_2_order.safe_price) / derisk_2_order.safe_price
    if buyback_3_is_exit_found:
      buyback_3_exit_distance_ratio = (exit_rate - buyback_3_exit_order.safe_price) / buyback_3_exit_order.safe_price
    elif is_derisk_3_found:
      buyback_3_exit_distance_ratio = (exit_rate - derisk_3_order.safe_price) / derisk_3_order.safe_price

    # all buybacks & grinds
    current_open_grind_stake_profit = (
      buyback_1_current_grind_stake_profit
      + buyback_2_current_grind_stake_profit
      + buyback_3_current_grind_stake_profit
      + grind_1_current_grind_stake_profit
      + grind_2_current_grind_stake_profit
      + grind_3_current_grind_stake_profit
      + grind_4_current_grind_stake_profit
      + grind_5_current_grind_stake_profit
    )
    num_open_grinds_and_buybacks = (
      buyback_1_sub_grind_count
      + buyback_2_sub_grind_count
      + buyback_3_sub_grind_count
      + grind_1_sub_grind_count
      + grind_2_sub_grind_count
      + grind_3_sub_grind_count
      + grind_4_sub_grind_count
      + grind_5_sub_grind_count
    )

    # Rebuy mode, the first entry is lower than normal slot stake
    if is_rebuy_mode:
      slice_amount /= self.rebuy_mode_stake_multiplier
    # not reached the max allowed stake for all grinds
    is_not_trade_max_stake = (current_stake_amount < (slice_amount * self.grinding_v2_max_stake)) and (
      num_open_grinds_and_buybacks < self.grinding_v2_max_grinds_and_buybacks
    )
    slice_profit_lt_neg_0_06 = slice_profit < -0.06

    is_long_extra_checks_entry = (
      (current_time - timedelta(minutes=5) > last_filled_entry.order_filled_utc)
      and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or slice_profit_lt_neg_0_06)
      and (
        (current_stake_amount < ((first_filled_entry.safe_filled * first_filled_entry.safe_price) * 0.50))
        or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
        or slice_profit_lt_neg_0_06
      )
    )
    is_long_buyback_entry = self.long_buyback_entry_v2(last_candle, previous_candle, slice_profit, True)
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_3_15m = last_candle["RSI_3_15m"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_aroonu_14 = last_candle["AROONU_14"]
    last_aroonu_14_15m = last_candle["AROONU_14_15m"]
    is_long_grind_entry = (
      self.long_grind_entry_v3(
        last_candle,
        previous_candle,
        num_open_grinds_and_buybacks,
        slice_profit,
        slice_profit_entry,
        slice_profit_exit,
        True,
      )
      or (
        (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
        and (num_open_grinds_and_buybacks == 0)
        and (
          (last_rsi_3 > 10.0)
          and (last_rsi_3_15m > 20.0)
          and (last_rsi_3_1h > 20.0)
          and (last_rsi_3_1h > 20.0)
          and (last_aroonu_14 < 50.0)
          and (last_aroonu_14_15m < 50.0)
        )
      )
      or (
        is_futures
        and trade.liquidation_price is not None
        and (
          (trade_is_short and current_rate > trade.liquidation_price * 0.90)
          or (not trade_is_short and current_rate < trade.liquidation_price * 1.10)
        )
        and (slice_profit < -0.03)
        and (last_rsi_3 > 10.0)
        and (last_rsi_3_15m > 20.0)
        # and (last_candle["RSI_3_1h"] > 20.0)
        # and (last_candle["RSI_3_1h"] > 20.0)
        and (last_aroonu_14 < 50.0)
        and (last_aroonu_14_15m < 50.0)
      )
    )

    # De-risk level 1

    # flag it
    if (
      derisk_enable
      and self.grinding_v2_derisk_level_1_enable
      and (not is_derisk_1_found)
      and not is_rebuy_mode
      and (trade_get_custom_data(key="grinding_v2_derisk_level_1_flag") is not True)
      and (
        profit_stake
        < (
          slice_amount
          * (self.grinding_v2_derisk_level_1_futures[0] if is_futures else self.grinding_v2_derisk_level_1_spot[0])
        )
        / trade_leverage
      )
    ):
      trade_set_custom_data(key="grinding_v2_derisk_level_1_flag", value=True)
      trade_set_custom_data(key="grinding_v2_derisk_level_1_profit", value=profit_stake)
      trade_set_custom_data(key="grinding_v2_derisk_level_1_time", value=current_time.isoformat())

    flag_is_derisk_level_1 = False
    if (
      derisk_enable
      and self.grinding_v2_derisk_level_1_enable
      and (not is_derisk_1_found)
      and not is_rebuy_mode
      and (trade_get_custom_data(key="grinding_v2_derisk_level_1_flag") is True)
    ):
      flag_profit = trade_get_custom_data(key="grinding_v2_derisk_level_1_profit")
      flag_time = datetime.fromisoformat(trade_get_custom_data(key="grinding_v2_derisk_level_1_time"))
      if get_derisk_flag_timeout() > flag_time:
        if profit_stake > flag_profit:
          trade_set_custom_data(key="grinding_v2_derisk_level_1_flag", value=False)
        else:
          flag_is_derisk_level_1 = True

    if (
      derisk_enable
      and self.grinding_v2_derisk_level_1_enable
      and (not is_derisk_1_found)
      and not is_rebuy_mode
      and (
        flag_is_derisk_level_1
        or (
          profit_stake
          < (
            slice_amount
            * (self.grinding_v2_derisk_level_1_futures[1] if is_futures else self.grinding_v2_derisk_level_1_spot[1])
          )
          / trade_leverage
        )
      )
    ):
      sell_amount = (
        (
          first_filled_entry.safe_filled
          * (
            self.grinding_v2_derisk_level_1_stake_futures if is_futures else self.grinding_v2_derisk_level_1_stake_spot
          )
        )
        * exit_rate
        / trade_leverage
      )
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="Level 1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk Level 1 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_1"

    # De-risk level 2

    # flag it
    if (
      derisk_enable
      and self.grinding_v2_derisk_level_2_enable
      and (not is_derisk_2_found)
      and not is_rebuy_mode
      and (trade_get_custom_data(key="grinding_v2_derisk_level_2_flag") is not True)
      and (
        profit_stake
        < (
          slice_amount
          * (self.grinding_v2_derisk_level_2_futures[0] if is_futures else self.grinding_v2_derisk_level_2_spot[0])
        )
        / trade_leverage
      )
    ):
      trade_set_custom_data(key="grinding_v2_derisk_level_2_flag", value=True)
      trade_set_custom_data(key="grinding_v2_derisk_level_2_profit", value=profit_stake)
      trade_set_custom_data(key="grinding_v2_derisk_level_2_time", value=current_time.isoformat())

    flag_is_derisk_level_2 = False
    if (
      derisk_enable
      and self.grinding_v2_derisk_level_2_enable
      and (not is_derisk_2_found)
      and not is_rebuy_mode
      and (trade_get_custom_data(key="grinding_v2_derisk_level_2_flag") is True)
    ):
      flag_profit = trade_get_custom_data(key="grinding_v2_derisk_level_2_profit")
      flag_time = datetime.fromisoformat(trade_get_custom_data(key="grinding_v2_derisk_level_2_time"))
      if get_derisk_flag_timeout() > flag_time:
        if profit_stake > flag_profit:
          trade_set_custom_data(key="grinding_v2_derisk_level_2_flag", value=False)
        else:
          flag_is_derisk_level_2 = True

    if (
      derisk_enable
      and self.grinding_v2_derisk_level_2_enable
      and (not is_derisk_2_found)
      and not is_rebuy_mode
      and (
        flag_is_derisk_level_2
        or (
          profit_stake
          < (
            slice_amount
            * (self.grinding_v2_derisk_level_2_futures[1] if is_futures else self.grinding_v2_derisk_level_2_spot[1])
          )
          / trade_leverage
        )
      )
    ):
      sell_amount = (
        (
          first_filled_entry.safe_filled
          * (
            self.grinding_v2_derisk_level_2_stake_futures if is_futures else self.grinding_v2_derisk_level_2_stake_spot
          )
        )
        * exit_rate
        / trade_leverage
      )
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="Level 2",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk Level 2 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_2"

    # De-risk level 3

    # flag it
    if (
      derisk_enable
      and self.grinding_v2_derisk_level_3_enable
      and (not is_derisk_3_found)
      and not is_rebuy_mode
      and (trade_get_custom_data(key="grinding_v2_derisk_level_3_flag") is not True)
      and (
        profit_stake
        < (
          slice_amount
          * (self.grinding_v2_derisk_level_3_futures[0] if is_futures else self.grinding_v2_derisk_level_3_spot[0])
        )
        / trade_leverage
      )
    ):
      trade_set_custom_data(key="grinding_v2_derisk_level_3_flag", value=True)
      trade_set_custom_data(key="grinding_v2_derisk_level_3_profit", value=profit_stake)
      trade_set_custom_data(key="grinding_v2_derisk_level_3_time", value=current_time.isoformat())

    flag_is_derisk_level_3 = False
    if (
      derisk_enable
      and self.grinding_v2_derisk_level_3_enable
      and (not is_derisk_3_found)
      and not is_rebuy_mode
      and (trade_get_custom_data(key="grinding_v2_derisk_level_3_flag") is True)
    ):
      flag_profit = trade_get_custom_data(key="grinding_v2_derisk_level_3_profit")
      flag_time = datetime.fromisoformat(trade_get_custom_data(key="grinding_v2_derisk_level_3_time"))
      if get_derisk_flag_timeout() > flag_time:
        if profit_stake > flag_profit:
          trade_set_custom_data(key="grinding_v2_derisk_level_3_flag", value=False)
        else:
          flag_is_derisk_level_3 = True

    if (
      derisk_enable
      and self.grinding_v2_derisk_level_3_enable
      and (not is_derisk_3_found)
      and not is_rebuy_mode
      and (
        flag_is_derisk_level_3
        or (
          profit_stake
          < (
            slice_amount
            * (self.grinding_v2_derisk_level_3_futures[1] if is_futures else self.grinding_v2_derisk_level_3_spot[1])
          )
          / trade_leverage
        )
      )
    ):
      sell_amount = (
        (
          first_filled_entry.safe_filled
          * (
            self.grinding_v2_derisk_level_3_stake_futures if is_futures else self.grinding_v2_derisk_level_3_stake_spot
          )
        )
        * exit_rate
        / trade_leverage
      )
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="Level 3",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk Level 3 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_3"

    # De-risk global
    if (
      self.grinding_v2_derisk_global_enable
      and is_derisk_1_found
      and (
        current_open_grind_stake_profit
        < (
          slice_amount
          * (self.grinding_v2_derisk_global_futures if is_futures else self.grinding_v2_derisk_global_spot)
        )
        / trade_leverage
      )
    ):
      sell_amount = trade_amount * exit_rate / trade_leverage - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="Global",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk Global [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_global"

    # Grinding 1

    if (
      (self.grinding_v2_grind_1_enable)
      and (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
      and is_long_grind_entry
      and is_long_extra_checks_entry
      and (grind_1_sub_grind_count < grind_1_max_sub_grinds)
      and (grind_1_sub_grind_count == 0 or (grind_1_distance_ratio < grind_1_sub_thresholds[grind_1_sub_grind_count]))
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_1_stakes[grind_1_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_1_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_1_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "grind_1_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_1_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
      if (grind_profit > (grind_1_profit_threshold + fee_open_rate + fee_close_rate)) and long_grind_exit_v2(
        last_candle, previous_candle, slice_profit, True
      ):
        sell_amount = grind_1_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="grind_1_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_1_total_amount,
            )
          )
          log.info(
            f"Grinding exit (grind_1_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "grind_1_exit"
          for grind_entry_id in grind_1_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_grind_1_use_derisk
    #   and (grind_1_sub_grind_count > 0)
    #   and (((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate) < grind_1_derisk_grinds)
    #   and (grind_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_grind_1_use_derisk
      and (grind_1_sub_grind_count > 0)
      and (grind_1_current_grind_stake_profit < (slice_amount * grind_1_derisk_grinds))
      and (is_backtest or grind_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = grind_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_1_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate)
            if grind_1_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_1_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
            coin_amount=grind_1_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_1_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "grind_1_derisk"
        for grind_entry_id in grind_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 2

    if (
      (self.grinding_v2_grind_2_enable)
      # and (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
      and is_long_grind_entry
      and is_long_extra_checks_entry
      and (grind_2_sub_grind_count < grind_2_max_sub_grinds)
      and (grind_2_sub_grind_count == 0 or (grind_2_distance_ratio < grind_2_sub_thresholds[grind_2_sub_grind_count]))
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_2_stakes[grind_2_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_2_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_2_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "grind_2_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_2_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
      if (grind_profit > (grind_2_profit_threshold + fee_open_rate + fee_close_rate)) and long_grind_exit_v2(
        last_candle, previous_candle, slice_profit, True
      ):
        sell_amount = grind_2_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="grind_2_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_2_total_amount,
            )
          )
          log.info(
            f"Grinding exit (grind_2_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "grind_2_exit"
          for grind_entry_id in grind_2_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_grind_2_use_derisk
    #   and (grind_2_sub_grind_count > 0)
    #   and (((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate) < grind_2_derisk_grinds)
    #   and (grind_2_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_grind_2_use_derisk
      and (grind_2_sub_grind_count > 0)
      and (grind_2_current_grind_stake_profit < (slice_amount * grind_2_derisk_grinds))
      and (is_backtest or grind_2_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = grind_2_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_2_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate)
            if grind_2_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_2_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_2_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
            coin_amount=grind_2_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_2_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_2_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "grind_2_derisk"
        for grind_entry_id in grind_2_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 3

    if (
      (self.grinding_v2_grind_3_enable)
      # and (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
      and is_long_grind_entry
      and is_long_extra_checks_entry
      and (grind_3_sub_grind_count < grind_3_max_sub_grinds)
      and (grind_3_sub_grind_count == 0 or (grind_3_distance_ratio < grind_3_sub_thresholds[grind_3_sub_grind_count]))
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_3_stakes[grind_3_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_3_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_3_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "grind_3_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_3_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
      if (grind_profit > (grind_3_profit_threshold + fee_open_rate + fee_close_rate)) and long_grind_exit_v2(
        last_candle, previous_candle, slice_profit, True
      ):
        sell_amount = grind_3_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="grind_3_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_3_total_amount,
            )
          )
          log.info(
            f"Grinding exit (grind_3_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "grind_3_exit"
          for grind_entry_id in grind_3_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_grind_3_use_derisk
    #   and (grind_3_sub_grind_count > 0)
    #   and (((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate) < grind_3_derisk_grinds)
    #   and (grind_3_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_grind_3_use_derisk
      and (grind_3_sub_grind_count > 0)
      and (grind_3_current_grind_stake_profit < (slice_amount * grind_3_derisk_grinds))
      and (is_backtest or grind_3_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = grind_3_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_3_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate)
            if grind_3_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_3_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_3_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
            coin_amount=grind_3_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_3_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_3_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "grind_3_derisk"
        for grind_entry_id in grind_3_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 4

    if (
      (self.grinding_v2_grind_4_enable)
      # and (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
      and (
        is_long_grind_entry
        # or (
        #   is_derisk_1_found
        #   # only queue 4 grinds open
        #   and (num_open_grinds_and_buybacks == grind_4_sub_grind_count)
        #   and (last_candle["protections_long_global"] == True)
        #   and (
        #     (slice_profit < -0.04)
        #     and (last_candle["RSI_3"] > 10.0)
        #     and (last_candle["RSI_3_15m"] > 20.0)
        #     and (last_candle["AROONU_14"] < 50.0)
        #     and (last_candle["AROONU_14_15m"] < 50.0)
        #   )
        # )
        # or (
        #   (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
        #   and (num_open_grinds_and_buybacks == 0)
        #   and (
        #     (last_candle["RSI_3"] > 10.0)
        #     and (last_candle["RSI_3_15m"] > 20.0)
        #     and (last_candle["RSI_3_1h"] > 20.0)
        #     and (last_candle["RSI_3_1h"] > 20.0)
        #     and (last_candle["AROONU_14"] < 50.0)
        #     and (last_candle["AROONU_14_15m"] < 50.0)
        #   )
        # )
      )
      and is_long_extra_checks_entry
      and (grind_4_sub_grind_count < grind_4_max_sub_grinds)
      and (grind_4_sub_grind_count == 0 or (grind_4_distance_ratio < grind_4_sub_thresholds[grind_4_sub_grind_count]))
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_4_stakes[grind_4_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_4_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_4_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "grind_4_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_4_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
      if (grind_profit > (grind_4_profit_threshold + fee_open_rate + fee_close_rate)) and long_grind_exit_v2(
        last_candle, previous_candle, slice_profit, True
      ):
        sell_amount = grind_4_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="grind_4_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_4_total_amount,
            )
          )
          log.info(
            f"Grinding exit (grind_4_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "grind_4_exit"
          for grind_entry_id in grind_4_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_grind_4_use_derisk
    #   and (grind_4_sub_grind_count > 0)
    #   and (((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate) < grind_4_derisk_grinds)
    #   and (grind_4_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_grind_4_use_derisk
      and (grind_4_sub_grind_count > 0)
      and (grind_4_current_grind_stake_profit < (slice_amount * grind_4_derisk_grinds))
      and (is_backtest or grind_4_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = grind_4_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_4_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate)
            if grind_4_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_4_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_4_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
            coin_amount=grind_4_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_4_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_4_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "grind_4_derisk"
        for grind_entry_id in grind_4_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 5

    if (
      (self.grinding_v2_grind_5_enable)
      and (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
      and (
        is_long_grind_entry
        or (
          is_derisk_1_found
          and (slice_profit_entry < -0.10)
          and (slice_profit_exit < -0.04)
          and (last_candle["protections_long_global"] == True)
          # and (
          #   (slice_profit < -0.04)
          #   and (last_candle["RSI_3"] > 10.0)
          #   and (last_candle["RSI_3_15m"] > 20.0)
          #   and (last_candle["AROONU_14"] < 50.0)
          #   and (last_candle["AROONU_14_15m"] < 50.0)
          # )
        )
      )
      and is_long_extra_checks_entry
      and (grind_5_sub_grind_count < grind_5_max_sub_grinds)
      and (grind_5_sub_grind_count == 0 or (grind_5_distance_ratio < grind_5_sub_thresholds[grind_5_sub_grind_count]))
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_5_stakes[grind_5_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_5_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_5_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "grind_5_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_5_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
      if (grind_profit > (grind_5_profit_threshold + fee_open_rate + fee_close_rate)) and long_grind_exit_v2(
        last_candle, previous_candle, slice_profit, True
      ):
        sell_amount = grind_5_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="grind_5_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_5_total_amount,
            )
          )
          log.info(
            f"Grinding exit (grind_5_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "grind_5_exit"
          for grind_entry_id in grind_5_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_grind_5_use_derisk
    #   and (grind_5_sub_grind_count > 0)
    #   and (((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate) < grind_5_derisk_grinds)
    #   and (grind_5_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_grind_5_use_derisk
      and (grind_5_sub_grind_count > 0)
      and (grind_5_current_grind_stake_profit < (slice_amount * grind_5_derisk_grinds))
      and (is_backtest or grind_5_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = grind_5_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_5_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate)
            if grind_5_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_5_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_5_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
            coin_amount=grind_5_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_5_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_5_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "grind_5_derisk"
        for grind_entry_id in grind_5_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Buyback 1

    if (
      self.grinding_v2_buyback_1_enable
      and is_derisk_1_found
      and is_long_buyback_entry
      and is_long_extra_checks_entry
      and (buyback_1_current_open_rate == 0)
      and (
        buyback_1_exit_distance_ratio
        < (
          self.grinding_v2_buyback_1_distance_ratio_futures
          if is_futures
          else self.grinding_v2_buyback_1_distance_ratio_spot
        )
      )
      and is_not_trade_max_stake
    ):
      buy_amount = (
        slice_amount
        * (self.grinding_v2_buyback_1_stake_futures if is_futures else self.grinding_v2_buyback_1_stake_spot)
        / trade_leverage
      )
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "buyback-entry",
          tag="buyback_1_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Buyback entry (buyback_1_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "buyback_1_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if buyback_1_sub_grind_count > 0:
      grind_profit = (exit_rate - buyback_1_current_open_rate) / buyback_1_current_open_rate
      if (
        grind_profit
        > (
          (
            self.grinding_v2_buyback_1_profit_threshold_futures
            if is_futures
            else self.grinding_v2_buyback_1_profit_threshold_spot
          )
          + fee_open_rate
          + fee_close_rate
        )
      ) and long_grind_exit_v2(last_candle, previous_candle, slice_profit, True):
        sell_amount = buyback_1_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "buyback-exit",
              tag="buyback_1_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=buyback_1_total_amount,
            )
          )
          log.info(
            f"Buyback exit (buyback_1_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "buyback_1_exit"
          for grind_entry_id in buyback_1_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_buyback_1_use_derisk
    #   and (buyback_1_sub_grind_count > 0)
    #   and (
    #     ((exit_rate - buyback_1_current_open_rate) / buyback_1_current_open_rate)
    #     < (
    #       self.grinding_v2_buyback_1_derisk_futures if self.is_futures_mode else self.grinding_v2_buyback_1_derisk_spot
    #     )
    #   )
    #   and (buyback_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_buyback_1_use_derisk
      and (buyback_1_sub_grind_count > 0)
      and (
        buyback_1_current_grind_stake_profit
        < (
          slice_amount
          * (self.grinding_v2_buyback_1_derisk_futures if is_futures else self.grinding_v2_buyback_1_derisk_spot)
        )
      )
      and (is_backtest or buyback_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = buyback_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if buyback_1_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - buyback_1_current_open_rate) / buyback_1_current_open_rate)
            if buyback_1_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "buyback-derisk",
            tag="buyback_1_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=buyback_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
            coin_amount=buyback_1_total_amount,
          )
        )
        log.info(
          f"Buyback de-risk (buyback_1_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({buyback_1_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "buyback_1_derisk"
        for grind_entry_id in buyback_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # # Buyback 2

    if (
      self.grinding_v2_buyback_2_enable
      and is_derisk_2_found
      and is_long_buyback_entry
      and is_long_extra_checks_entry
      and (buyback_2_current_open_rate == 0)
      and (
        buyback_2_exit_distance_ratio
        < (
          self.grinding_v2_buyback_2_distance_ratio_futures
          if is_futures
          else self.grinding_v2_buyback_2_distance_ratio_spot
        )
      )
      and is_not_trade_max_stake
    ):
      buy_amount = (
        slice_amount
        * (self.grinding_v2_buyback_2_stake_futures if is_futures else self.grinding_v2_buyback_2_stake_spot)
        / trade_leverage
      )
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "buyback-entry",
          tag="buyback_2_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Buyback entry (buyback_2_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "buyback_2_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if buyback_2_sub_grind_count > 0:
      grind_profit = (exit_rate - buyback_2_current_open_rate) / buyback_2_current_open_rate
      if (
        grind_profit
        > (
          (
            self.grinding_v2_buyback_2_profit_threshold_futures
            if is_futures
            else self.grinding_v2_buyback_2_profit_threshold_spot
          )
          + fee_open_rate
          + fee_close_rate
        )
      ) and long_grind_exit_v2(last_candle, previous_candle, slice_profit, True):
        sell_amount = buyback_2_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "buyback-exit",
              tag="buyback_2_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=buyback_2_total_amount,
            )
          )
          log.info(
            f"Buyback exit (buyback_2_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_2_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "buyback_2_exit"
          for grind_entry_id in buyback_2_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_buyback_2_use_derisk
    #   and (buyback_2_sub_grind_count > 0)
    #   and (
    #     ((exit_rate - buyback_2_current_open_rate) / buyback_2_current_open_rate)
    #     < (
    #       self.grinding_v2_buyback_2_derisk_futures if self.is_futures_mode else self.grinding_v2_buyback_2_derisk_spot
    #     )
    #   )
    #   and (buyback_2_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_buyback_2_use_derisk
      and (buyback_2_sub_grind_count > 0)
      and (
        buyback_2_current_grind_stake_profit
        < (
          slice_amount
          * (self.grinding_v2_buyback_2_derisk_futures if is_futures else self.grinding_v2_buyback_2_derisk_spot)
        )
      )
      and (is_backtest or buyback_2_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = buyback_2_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if buyback_2_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - buyback_2_current_open_rate) / buyback_2_current_open_rate)
            if buyback_2_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "buyback-derisk",
            tag="buyback_2_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=buyback_2_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
            coin_amount=buyback_2_total_amount,
          )
        )
        log.info(
          f"Buyback de-risk (buyback_2_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_2_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({buyback_2_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "buyback_2_derisk"
        for grind_entry_id in buyback_2_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # # Buyback 3

    if (
      self.grinding_v2_buyback_3_enable
      and is_derisk_3_found
      and is_long_buyback_entry
      and is_long_extra_checks_entry
      and (buyback_3_current_open_rate == 0)
      and (
        buyback_3_exit_distance_ratio
        < (
          self.grinding_v2_buyback_3_distance_ratio_futures
          if is_futures
          else self.grinding_v2_buyback_3_distance_ratio_spot
        )
      )
      and is_not_trade_max_stake
    ):
      buy_amount = (
        slice_amount
        * (self.grinding_v2_buyback_3_stake_futures if is_futures else self.grinding_v2_buyback_3_stake_spot)
        / trade_leverage
      )
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "buyback-entry",
          tag="buyback_3_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Buyback entry (buyback_3_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "buyback_3_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if buyback_3_sub_grind_count > 0:
      grind_profit = (exit_rate - buyback_3_current_open_rate) / buyback_3_current_open_rate
      if (
        grind_profit
        > (
          (
            self.grinding_v2_buyback_3_profit_threshold_futures
            if is_futures
            else self.grinding_v2_buyback_3_profit_threshold_spot
          )
          + fee_open_rate
          + fee_close_rate
        )
      ) and long_grind_exit_v2(last_candle, previous_candle, slice_profit, True):
        sell_amount = buyback_3_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "buyback-exit",
              tag="buyback_3_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=buyback_3_total_amount,
            )
          )
          log.info(
            f"Buyback exit (buyback_3_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_3_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "buyback_3_exit"
          for grind_entry_id in buyback_3_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_buyback_3_use_derisk
    #   and (buyback_3_sub_grind_count > 0)
    #   and (
    #     ((exit_rate - buyback_3_current_open_rate) / buyback_3_current_open_rate)
    #     < (
    #       self.grinding_v2_buyback_3_derisk_futures if self.is_futures_mode else self.grinding_v2_buyback_3_derisk_spot
    #     )
    #   )
    #   and (buyback_3_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_buyback_3_use_derisk
      and (buyback_3_sub_grind_count > 0)
      and (
        buyback_3_current_grind_stake_profit
        < (
          slice_amount
          * (self.grinding_v2_buyback_3_derisk_futures if is_futures else self.grinding_v2_buyback_3_derisk_spot)
        )
      )
      and (is_backtest or buyback_3_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = buyback_3_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if buyback_3_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - buyback_3_current_open_rate) / buyback_3_current_open_rate)
            if buyback_3_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "buyback-derisk",
            tag="buyback_3_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=buyback_3_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
            coin_amount=buyback_3_total_amount,
          )
        )
        log.info(
          f"Buyback de-risk (buyback_3_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_3_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({buyback_3_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "buyback_3_derisk"
        for grind_entry_id in buyback_3_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    return None

  def long_buyback_entry_v2(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    previous_ema_26 = previous_candle["EMA_26"]
    previous_ema_12 = previous_candle["EMA_12"]

    last_rsi_3_1d = last_candle["RSI_3_1d"]
    last_roc_9_1h = last_candle["ROC_9_1h"]
    last_roc_9_4h = last_candle["ROC_9_4h"]
    last_close_max_48 = last_candle["close_max_48"]
    last_high_max_6_1h = last_candle["high_max_6_1h"]
    last_high_max_12_1h = last_candle["high_max_12_1h"]
    last_open = last_candle["open"]

    last_ema_12 = last_candle["EMA_12"]
    last_ema_26 = last_candle["EMA_26"]
    last_roc_9_1d = last_candle["ROC_9_1d"]
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_rsi_3_4h = last_candle["RSI_3_4h"]

    last_close = last_candle["close"]
    last_rsi_14 = last_candle["RSI_14"]
    last_rsi_3_15m = last_candle["RSI_3_15m"]
    last_roc_2_1h = last_candle["ROC_2_1h"]
    last_roc_2_4h = last_candle["ROC_2_4h"]
    last_protections_long_global = last_candle["protections_long_global"]
    last_enter_long = last_candle["enter_long"]
    last_aroonu_14 = last_candle["AROONU_14"]
    last_aroonu_14_15m = last_candle["AROONU_14_15m"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_stochrsi_k_15m = last_candle["STOCHRSIk_14_14_3_3_15m"]
    last_stochrsi_k_1h = last_candle["STOCHRSIk_14_14_3_3_1h"]
    last_stochrsi_k_4h = last_candle["STOCHRSIk_14_14_3_3_4h"]
    last_roc_2_1d = last_candle["ROC_2_1d"]
    last_ema_16 = last_candle["EMA_16"]
    last_bbl_20 = last_candle["BBL_20_2.0"]

    # Reused long buyback entry v2 thresholds
    last_rsi_14_lt_36 = last_rsi_14 < 36.0
    last_roc_2_4h_gt_neg_5 = last_roc_2_4h > -5.0
    last_roc_2_1h_gt_neg_5 = last_roc_2_1h > -5.0
    last_rsi_3_4h_gt_10 = last_rsi_3_4h > 10.0
    last_rsi_3_1h_gt_10 = last_rsi_3_1h > 10.0
    last_rsi_3_1d_gt_10 = last_rsi_3_1d > 10.0
    last_rsi_3_15m_gt_10 = last_rsi_3_15m > 10.0
    last_roc_9_4h_gt_neg_5 = last_roc_9_4h > -5.0
    last_roc_9_1h_gt_neg_5 = last_roc_9_1h > -5.0
    last_roc_9_1d_gt_neg_5 = last_roc_9_1d > -5.0
    if (last_protections_long_global == True) and (
      (last_enter_long == True)
      or (
        (last_rsi_14_lt_36)
        and (last_rsi_3 > 20.0)
        and (last_rsi_3_15m > 20.0)
        # and (last_candle["RSI_3_1h"] > 20.0)
        # and (last_candle["RSI_3_4h"] > 20.0)
        and (last_aroonu_14 < 25.0)
        and (last_roc_2_1h_gt_neg_5)
        and (last_roc_2_4h_gt_neg_5)
        # and (last_candle["ROC_9_4h"] > -20.0)
        # and (last_candle["ROC_9_4h"] < 40.0)
        # and (last_candle["ROC_9_1d"] > -20.0)
        # and (last_candle["ROC_9_1d"] < 50.0)
        and (last_stochrsi_k < 20.0)
        and (last_stochrsi_k_15m < 20.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_1h"] < 30.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_4h"] < 30.0)
        and (last_close > (last_close_max_48 * 0.90))
        and (last_close > (last_high_max_6_1h * 0.85))
        and (last_close > (last_high_max_12_1h * 0.80))
        # and (last_candle["close"] < (last_candle["low_min_24_4h"] * 1.20))
        and (last_close < (last_ema_16 * 0.980))
      )
      or (
        (last_rsi_14_lt_36)
        and (last_rsi_3 > 5.0)
        and (last_rsi_3_15m > 15.0)
        and (last_rsi_3_1h > 15.0)
        and (last_rsi_3_4h > 15.0)
        and (last_roc_2_1h_gt_neg_5)
        and (last_roc_2_4h_gt_neg_5)
        # and (last_candle["ROC_2_1d"] > -10.0)
        # and (last_candle["ROC_9_1h"] > -10.0)
        # and (last_candle["ROC_9_4h"] > -10.0)
        and (last_roc_9_1d_gt_neg_5)
        and (last_ema_26 > last_ema_12)
        and ((last_ema_26 - last_ema_12) > (last_open * 0.020))
        and ((previous_ema_26 - previous_ema_12) > (last_open / 100.0))
      )
      or (
        (last_rsi_14_lt_36)
        and (last_rsi_3 > 10.0)
        and (last_rsi_3_15m_gt_10)
        and (last_rsi_3_1h_gt_10)
        and (last_rsi_3_4h_gt_10)
        and (last_rsi_3_1d_gt_10)
        and (last_roc_2_1h_gt_neg_5)
        and (last_roc_2_4h_gt_neg_5)
        and (last_roc_2_1d > -5.0)
        and (last_roc_9_1h_gt_neg_5)
        and (last_roc_9_4h_gt_neg_5)
        and (last_roc_9_1d > -10.0)
        # and (last_candle["ROC_9_4h"] < 40.0)
        # and (last_candle["ROC_9_1d"] < 50.0)
        and (last_aroonu_14_15m < 25.0)
        and (last_close > (last_close_max_48 * 0.90))
        and (last_close > (last_high_max_6_1h * 0.85))
        and (last_close > (last_high_max_12_1h * 0.80))
        # and (last_candle["close"] < (last_candle["low_min_24_4h"] * 1.20))
        and (last_close < (last_ema_12 * 0.980))
      )
      or (
        (last_rsi_14_lt_36)
        and (last_rsi_3_15m_gt_10)
        and (last_rsi_3_1h_gt_10)
        and (last_rsi_3_4h_gt_10)
        and (last_rsi_3_1d_gt_10)
        and (last_roc_2_1h_gt_neg_5)
        and (last_roc_2_4h_gt_neg_5)
        # and (last_candle["ROC_2_1d"] > -5.0)
        and (last_roc_9_1h_gt_neg_5)
        and (last_roc_9_4h_gt_neg_5)
        and (last_roc_9_1d_gt_neg_5)
        and (last_stochrsi_k_1h < 80.0)
        and (last_stochrsi_k_4h < 70.0)
        # and (last_candle["close"] > (last_candle["close_max_48"] * 0.90))
        # and (last_candle["close"] > (last_candle["high_max_6_1h"] * 0.85))
        # and (last_candle["close"] > (last_candle["high_max_12_1h"] * 0.80))
        and (last_close < (last_ema_26 * 0.960))
        and (last_close < (last_bbl_20 * 0.999))
      )
    ):
      return True

    return False

  def long_grind_entry_v2(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    previous_ema_26 = previous_candle["EMA_26"]
    previous_ema_12 = previous_candle["EMA_12"]
    last_bbl_20_2_0 = last_candle["BBL_20_2.0"]
    last_aroonu_14_15m = last_candle["AROONU_14_15m"]
    last_rsi_14_1h = last_candle["RSI_14_1h"]
    last_low_min_24_4h = last_candle["low_min_24_4h"]
    last_low_min_12_4h = last_candle["low_min_12_4h"]

    last_ema_12 = last_candle["EMA_12"]
    last_ema_26 = last_candle["EMA_26"]
    last_stochrsik_14_14_3_3 = last_candle["STOCHRSIk_14_14_3_3"]
    last_close_max_48 = last_candle["close_max_48"]
    last_open = last_candle["open"]
    last_aroonu_14 = last_candle["AROONU_14"]
    last_roc_2_1d = last_candle["ROC_2_1d"]
    last_roc_9_1d = last_candle["ROC_9_1d"]
    last_rsi_3_1d = last_candle["RSI_3_1d"]
    last_high_max_12_1h = last_candle["high_max_12_1h"]
    last_high_max_6_1h = last_candle["high_max_6_1h"]

    last_close = last_candle["close"]
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_3_15m = last_candle["RSI_3_15m"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_rsi_3_4h = last_candle["RSI_3_4h"]
    last_rsi_14 = last_candle["RSI_14"]
    last_roc_2_1h = last_candle["ROC_2_1h"]
    last_roc_2_4h = last_candle["ROC_2_4h"]
    last_roc_9_1h = last_candle["ROC_9_1h"]
    last_roc_9_4h = last_candle["ROC_9_4h"]
    last_protections_long_global = last_candle["protections_long_global"]
    last_enter_long = last_candle["enter_long"]
    last_stochrsi_k_15m = last_candle["STOCHRSIk_14_14_3_3_15m"]
    last_stochrsi_k_1h = last_candle["STOCHRSIk_14_14_3_3_1h"]
    last_stochrsi_k_4h = last_candle["STOCHRSIk_14_14_3_3_4h"]
    last_willr_14 = last_candle["WILLR_14"]
    last_ema_16 = last_candle["EMA_16"]

    # Reused long grind entry v2 thresholds
    last_rsi_3_gt_5 = last_rsi_3 > 5.0
    last_rsi_3_4h_gt_10 = last_rsi_3_4h > 10.0
    last_rsi_3_1h_gt_10 = last_rsi_3_1h > 10.0
    last_rsi_3_15m_gt_10 = last_rsi_3_15m > 10.0
    last_rsi_3_gt_10 = last_rsi_3 > 10.0
    last_rsi_14_lt_36 = last_rsi_14 < 36.0
    last_aroonu_14_lt_25 = last_aroonu_14 < 25.0
    last_stochrsik_14_14_3_3_lt_20 = last_stochrsik_14_14_3_3 < 20.0
    last_rsi_3_1d_gt_10 = last_rsi_3_1d > 10.0
    last_roc_9_4h_gt_neg_10 = last_roc_9_4h > -10.0
    last_roc_9_1h_gt_neg_10 = last_roc_9_1h > -10.0
    last_roc_2_4h_gt_neg_10 = last_roc_2_4h > -10.0
    last_roc_2_1h_gt_neg_10 = last_roc_2_1h > -10.0
    last_rsi_3_15m_gt_15 = last_rsi_3_15m > 15.0
    last_roc_2_4h_gt_neg_5 = last_roc_2_4h > -5.0
    last_roc_2_1h_gt_neg_5 = last_roc_2_1h > -5.0
    last_roc_2_1d_gt_neg_10 = last_roc_2_1d > -10.0
    last_rsi_3_4h_gt_15 = last_rsi_3_4h > 15.0
    last_rsi_3_1h_gt_15 = last_rsi_3_1h > 15.0
    last_rsi_3_15m_gt_5 = last_rsi_3_15m > 5.0
    last_roc_9_1d_gt_neg_30 = last_roc_9_1d > -30.0

    if (last_protections_long_global == True) and (
      (last_enter_long == True)
      or (
        (last_rsi_14 < 46.0)
        and (last_rsi_3_gt_10)
        and (last_rsi_3_15m_gt_15)
        and (last_rsi_3_1h_gt_15)
        and (last_rsi_3_4h_gt_15)
        and (last_roc_2_1h_gt_neg_10)
        and (last_roc_2_4h_gt_neg_10)
        and (last_roc_2_1d_gt_neg_10)
        and (last_roc_9_1h > -25.0)
        and (last_roc_9_4h > -25.0)
        and (last_roc_9_1d > -25.0)
        # and (last_candle["ROC_9_1d"] < 40.0)
        and (last_aroonu_14_lt_25)
        # and (last_candle["STOCHRSIk_14_14_3_3"] < 20.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_15m"] < 20.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_1h"] < 30.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_4h"] < 30.0)
        and (last_close > (last_close_max_48 * 0.90))
        and (last_close > (last_high_max_6_1h * 0.85))
        and (last_close > (last_high_max_12_1h * 0.80))
        and (last_close < (last_low_min_24_4h * 1.20))
        and (last_close < (last_ema_16 * 0.968))
      )
      or (
        (last_rsi_14_lt_36)
        and (last_rsi_3_gt_5)
        and (last_rsi_3_15m_gt_15)
        and (last_rsi_3_1h_gt_15)
        and (last_rsi_3_4h_gt_15)
        # and (last_candle["RSI_3_1d"] > 15.0)
        and (last_roc_2_1h_gt_neg_10)
        and (last_roc_2_4h_gt_neg_10)
        # and (last_candle["ROC_2_1d"] > -10.0)
        and (last_roc_9_1h_gt_neg_10)
        and (last_roc_9_4h_gt_neg_10)
        and (last_roc_9_1d_gt_neg_30)
        and (last_stochrsik_14_14_3_3 < 50.0)
        and (last_ema_26 > last_ema_12)
        and ((last_ema_26 - last_ema_12) > (last_open * 0.020))
        and ((previous_ema_26 - previous_ema_12) > (last_open / 100.0))
      )
      or (
        (last_rsi_14_lt_36)
        and (last_rsi_3_gt_10)
        and (last_rsi_3_15m_gt_10)
        and (last_rsi_3_1h_gt_10)
        and (last_rsi_3_4h_gt_10)
        and (last_rsi_3_1d_gt_10)
        and (last_roc_2_1h_gt_neg_5)
        and (last_roc_2_4h_gt_neg_5)
        and (last_roc_2_1d > -5.0)
        and (last_roc_9_1h_gt_neg_10)
        and (last_roc_9_4h_gt_neg_10)
        and (last_roc_9_1d > -10.0)
        # and (last_roc_9_4h < 40.0)
        # and (last_candle["ROC_9_1d"] < 50.0)
        and (last_aroonu_14_15m < 25.0)
        and (last_close > (last_close_max_48 * 0.90))
        and (last_close > (last_high_max_6_1h * 0.85))
        and (last_close > (last_high_max_12_1h * 0.80))
        # and (last_close < (last_candle["low_min_24_4h"] * 1.20))
        and (last_close < (last_ema_12 * 0.980))
      )
      or (
        (last_rsi_14_lt_36)
        and (last_rsi_3_gt_10)
        and (last_rsi_3_15m_gt_10)
        and (last_rsi_3_1h_gt_10)
        and (last_rsi_3_4h_gt_10)
        and (last_rsi_3_1d_gt_10)
        and (last_roc_2_1h_gt_neg_10)
        and (last_roc_2_4h_gt_neg_10)
        and (last_roc_2_1d_gt_neg_10)
        # and (last_roc_9_1h > -10.0)
        # and (last_roc_9_4h > -10.0)
        # and (last_candle["ROC_9_1d"] > -10.0)
        and (last_aroonu_14_lt_25)
        and (last_close > (last_close_max_48 * 0.90))
        and (last_close > (last_high_max_6_1h * 0.85))
        and (last_close > (last_high_max_12_1h * 0.80))
        and (last_close < (last_ema_26 * 0.962))
        and (last_close < (last_bbl_20_2_0 * 0.999))
      )
      or (
        (last_rsi_14 < 35.0)
        and (last_rsi_3_gt_10)
        and (last_rsi_3_15m_gt_10)
        and (last_rsi_3_1h_gt_10)
        and (last_rsi_3_4h_gt_10)
        # and (last_candle["RSI_3_1d"] > 10.0)
        and (last_roc_2_1h_gt_neg_10)
        and (last_roc_2_4h_gt_neg_10)
        and (last_roc_2_1d_gt_neg_10)
        and (last_roc_9_1h_gt_neg_10)
        and (last_roc_9_4h_gt_neg_10)
        # and (last_candle["ROC_9_1d"] > -10.0)
        and (last_aroonu_14_lt_25)
        # and (last_candle["AROONU_14_15m"] < 25.0)
        # and (last_candle["STOCHRSIk_14_14_3_3"] < 20.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_15m"] < 20.0)
        # and (last_close > (last_candle["close_max_48"] * 0.90))
        # and (last_close > (last_candle["high_max_6_1h"] * 0.85))
        # and (last_close > (last_candle["high_max_12_1h"] * 0.80))
        and (last_close < (last_low_min_12_4h * 1.25))
        and (last_close < (last_candle["EMA_9"] * 0.968))
        and (last_close < (last_candle["EMA_20"] * 0.980))
      )
      or (
        (last_rsi_14 > 35.0)
        and (last_rsi_3_gt_10)
        and (last_rsi_3 < 40.0)
        # and (last_candle["RSI_4"] < 40.0)
        and (last_rsi_3_15m_gt_15)
        # and (last_rsi_3_1h > 20.0)
        # and (last_rsi_3_4h > 20.0)
        # and (last_candle["RSI_3_1d"] > 20.0)
        and (last_roc_2_1h_gt_neg_5)
        and (last_roc_2_4h_gt_neg_5)
        # and (last_candle["ROC_2_1d"] > -5.0)
        and (last_roc_9_1h_gt_neg_10)
        and (last_roc_9_4h_gt_neg_10)
        # and (last_candle["ROC_9_1d"] > -10.0)
        and (last_aroonu_14_lt_25)
        # and (last_candle["AROONU_14_15m"] < 25.0)
        # and (last_candle["STOCHRSIk_14_14_3_3"] < 20.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_15m"] < 20.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_1h"] < 50.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_4h"] < 50.0)
        # and (last_close > (last_candle["close_max_48"] * 0.90))
        # and (last_close > (last_candle["high_max_6_1h"] * 0.85))
        # and (last_close > (last_candle["high_max_12_1h"] * 0.80))
        and (last_candle["RSI_20"] < previous_candle["RSI_20"])
        and (last_close < (last_candle["SMA_16"] * 0.955))
        # and (last_close < (last_candle["EMA_20"] * 0.980))
      )
      or (
        (last_rsi_3_gt_5)
        and (last_rsi_3_15m_gt_10)
        and (last_rsi_3_1h_gt_10)
        and (last_rsi_3_4h_gt_10)
        and (last_roc_2_1h_gt_neg_5)
        and (last_roc_2_4h_gt_neg_5)
        and (last_roc_9_1h > -5.0)
        and (last_roc_9_4h > -5.0)
        and (last_willr_14 < -50.0)
        # and (last_candle["AROONU_14"] < 25.0)
        and (last_stochrsik_14_14_3_3_lt_20)
        and (last_candle["WILLR_84_1h"] < -70.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_1h"] < 40.0)
        and (last_close < (last_low_min_24_4h * 1.30))
        and (last_candle["BBB_20_2.0_1h"] > 12.0)
        and (last_close_max_48 >= (last_close * 1.10))
      )
      or (
        (last_rsi_3 < 30.0)
        and (last_rsi_3_gt_5)
        and (last_rsi_3_15m_gt_5)
        and (last_rsi_3_1h_gt_10)
        and (last_rsi_3_4h_gt_10)
        # and (last_roc_2_1h > -5.0)
        # and (last_roc_2_4h > -5.0)
        # and (last_roc_9_1h > -5.0)
        # and (last_roc_9_4h > -5.0)
        and (last_roc_9_1d_gt_neg_30)
        # and (last_candle["STOCHRSIk_14_14_3_3"] < 20.0)
        # and (last_close < (last_candle["low_min_24_4h"] * 1.50))
        and (last_ema_26 > last_ema_12)
        and ((last_ema_26 - last_ema_12) > (last_open * 0.034))
        and ((previous_ema_26 - previous_ema_12) > (last_open / 100.0))
      )
      or (
        (last_rsi_3_gt_5)
        and (last_rsi_3_15m > 25.0)
        and (last_rsi_3_1h > 30.0)
        and (last_close < (last_candle["high_max_24_4h"] * 0.90))
        and (last_close < (last_close_max_48 * 0.90))
        and (last_close > (last_candle["close_min_12"] * 1.08))
      )
      or (
        (last_rsi_3_gt_5)
        and (last_rsi_3_15m_gt_5)
        and (last_stochrsik_14_14_3_3_lt_20)
        and (last_rsi_14 < (last_rsi_14_1h - 45.0))
      )
      or (
        (last_rsi_3_gt_10)
        and (last_rsi_3_15m_gt_10)
        and (last_rsi_3_1h_gt_10)
        and (last_rsi_3_4h_gt_10)
        and (last_rsi_3_1d_gt_10)
        and (last_stochrsik_14_14_3_3_lt_20)
        and (last_close < (last_candle["SMA_30"] * 0.978))
        and (last_close < (last_bbl_20_2_0 * 0.999))
      )
      or (
        (last_rsi_14_lt_36)
        and (last_rsi_3_gt_5)
        and (last_rsi_3_15m_gt_10)
        and (last_rsi_3_1h_gt_10)
        and (last_rsi_3_4h_gt_10)
        and (last_rsi_3_1d_gt_10)
        and (last_stochrsik_14_14_3_3 < 30.0)
        and (last_close > (last_close_max_48 * 0.85))
        and (last_close > (last_high_max_6_1h * 0.80))
        and (last_close > (last_high_max_12_1h * 0.75))
        and (last_close < (last_low_min_12_4h * 1.25))
        and (last_ema_26 > last_ema_12)
        and ((last_ema_26 - last_ema_12) > (last_open * 0.018))
        and ((previous_ema_26 - previous_ema_12) > (last_open / 100.0))
      )
      or (
        (last_rsi_3_gt_5)
        and (previous_candle["SMA_9"] < previous_candle["SMA_21"])
        and (last_candle["SMA_9"] > last_candle["SMA_21"])
        and (last_close < (last_candle["EMA_100"] * 0.984))
        and (last_rsi_3_1h > 20.0)
        and (last_rsi_3_4h > 20.0)
      )
      or (
        (slice_profit < -0.12)
        and (last_rsi_3_gt_5)
        and (last_rsi_3_15m_gt_10)
        and (last_rsi_14 < 40.0)
        and (last_aroonu_14_lt_25)
        and (last_aroonu_14_15m < 30.0)
        and (last_stochrsik_14_14_3_3_lt_20)
        and (last_stochrsi_k_15m < 30.0)
        and (last_rsi_14_1h < 50.0)
        and (last_candle["RSI_14_4h"] < 50.0)
      )
      or (
        (last_rsi_14_lt_36)
        and (last_rsi_3_gt_5)
        and (last_rsi_3_1h_gt_10)
        and (last_rsi_3_4h_gt_10)
        and (last_close < (last_ema_12 * 0.999))
        and (last_close < (last_bbl_20_2_0 * 0.996))
      )
    ):
      return True

    return False

  def long_buyback_exit_v2(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_14 = last_candle["RSI_14"]
    last_willr_14 = last_candle["WILLR_14"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_close = last_candle["close"]
    last_bbu_20 = last_candle["BBU_20_2.0"]

    if (
      (last_rsi_3 > 99.0)
      or (last_rsi_14 > 70.0)
      or (last_willr_14 > -0.1)
      or (last_stochrsi_k > 95.0)
      or (last_close > (last_bbu_20 * 1.01))
      or ((last_rsi_3 > 90.0) and (last_rsi_14 < 50.0))
    ):
      return True

    return False

  def long_grind_exit_v2(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_14 = last_candle["RSI_14"]
    last_willr_14 = last_candle["WILLR_14"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_close = last_candle["close"]
    last_bbu_20 = last_candle["BBU_20_2.0"]

    if (
      (last_rsi_3 > 99.0)
      or (last_rsi_14 > 70.0)
      or (last_willr_14 > -0.1)
      or (last_stochrsi_k > 95.0)
      or (last_close > (last_bbu_20 * 1.01))
      or ((last_rsi_3 > 90.0) and (last_rsi_14 < 50.0))
      or (
        (last_rsi_3 > 80.0)
        and (last_candle["RSI_3_1h"] < 20.0)
        and (last_candle["RSI_3_4h"] < 20.0)
        and (last_candle["ROC_9_1d"] > -10.0)
        and (last_candle["BTC_RSI_14_4h"] < 35.0)
      )
    ):
      return True

    return False

  # Long Grinding Adjust Trade Position v3
  # ---------------------------------------------------------------------------------------------
  def long_grind_adjust_trade_position_v3(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ):
    dp = self.dp
    send_msg = self.dp.send_msg
    notification_msg = self.notification_msg
    config = self.config
    stake_currency = config["stake_currency"]
    is_futures_mode = self.is_futures_mode
    scale_stakes_for_min_stake = self.scale_stakes_for_min_stake
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_stake_amount = trade.stake_amount
    trade_leverage = trade.leverage
    trade_fee_open = trade.fee_open
    trade_fee_close = trade.fee_close

    is_backtest = self.is_backtest_mode()
    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)
    if len(df) < 2:
      return None
    last_candle = df.iloc[-1]
    previous_candle = df.iloc[-2]

    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_exits = trade.nr_of_successful_exits

    if dp.runmode.value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = config["exit_pricing"]["price_side"]
        if trade.is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    current_stake_amount = trade_amount * exit_rate
    slice_amount = filled_entries[0].safe_filled * filled_entries[0].safe_price
    slice_profit = (exit_rate - filled_orders[-1].safe_price) / filled_orders[-1].safe_price
    slice_profit_entry = (exit_rate - filled_entries[-1].safe_price) / filled_entries[-1].safe_price
    slice_profit_exit = (
      ((exit_rate - filled_exits[-1].safe_price) / filled_exits[-1].safe_price) if count_of_exits > 0 else 0.0
    )

    is_rebuy_mode = all(c in self.long_rebuy_mode_tags for c in enter_tags) or (
      any(c in self.long_rebuy_mode_tags for c in enter_tags)
      and all(c in (self.long_rebuy_mode_tags + self.long_grind_mode_tags) for c in enter_tags)
    )
    # Rebuy mode, the first entry is lower than normal slot stake
    if is_rebuy_mode:
      slice_amount /= self.system_v3_rebuy_mode_stake_multiplier

    is_system_v3, is_system_v3_1, is_system_v3_2 = self.get_system_version_flags(trade)

    has_order_tags = hasattr(filled_orders[0], "ft_order_tag")

    fee_open_rate = trade_fee_open if self.custom_fee_open_rate is None else self.custom_fee_open_rate
    fee_close_rate = trade_fee_close if self.custom_fee_close_rate is None else self.custom_fee_close_rate
    fee_rate = fee_open_rate + fee_close_rate
    stake_scale_leverage = trade_leverage if is_futures_mode else 1.0
    grind_entry_retry_time = current_time - timedelta(minutes=5)

    # =========================================================================
    # GRINDING CONFIGURATION
    # =========================================================================
    if is_futures_mode:
      grind_1_stakes = self.system_v3_grind_1_stakes_futures
      grind_1_sub_thresholds = self.system_v3_grind_1_thresholds_futures
      grind_1_derisk_grinds = self.system_v3_grind_1_derisk_futures
      grind_1_profit_threshold = self.system_v3_grind_1_profit_threshold_futures

      grind_2_stakes = self.system_v3_grind_2_stakes_futures
      grind_2_sub_thresholds = self.system_v3_grind_2_thresholds_futures
      grind_2_derisk_grinds = self.system_v3_grind_2_derisk_futures
      grind_2_profit_threshold = self.system_v3_grind_2_profit_threshold_futures

      grind_3_stakes = self.system_v3_grind_3_stakes_futures
      grind_3_sub_thresholds = self.system_v3_grind_3_thresholds_futures
      grind_3_derisk_grinds = self.system_v3_grind_3_derisk_futures
      grind_3_profit_threshold = self.system_v3_grind_3_profit_threshold_futures

      grind_4_stakes = self.system_v3_grind_4_stakes_futures
      grind_4_sub_thresholds = self.system_v3_grind_4_thresholds_futures
      grind_4_derisk_grinds = self.system_v3_grind_4_derisk_futures
      grind_4_profit_threshold = self.system_v3_grind_4_profit_threshold_futures

      grind_5_stakes = self.system_v3_grind_5_stakes_futures
      grind_5_sub_thresholds = self.system_v3_grind_5_thresholds_futures
      grind_5_derisk_grinds = self.system_v3_grind_5_derisk_futures
      grind_5_profit_threshold = self.system_v3_grind_5_profit_threshold_futures

      rebuy_stakes = self.system_v3_1_rebuy_stakes_futures
      rebuy_sub_thresholds = self.system_v3_1_rebuy_thresholds_futures
    else:
      grind_1_stakes = self.system_v3_grind_1_stakes_spot
      grind_1_sub_thresholds = self.system_v3_grind_1_thresholds_spot
      grind_1_derisk_grinds = self.system_v3_grind_1_derisk_spot
      grind_1_profit_threshold = self.system_v3_grind_1_profit_threshold_spot

      grind_2_stakes = self.system_v3_grind_2_stakes_spot
      grind_2_sub_thresholds = self.system_v3_grind_2_thresholds_spot
      grind_2_derisk_grinds = self.system_v3_grind_2_derisk_spot
      grind_2_profit_threshold = self.system_v3_grind_2_profit_threshold_spot

      grind_3_stakes = self.system_v3_grind_3_stakes_spot
      grind_3_sub_thresholds = self.system_v3_grind_3_thresholds_spot
      grind_3_derisk_grinds = self.system_v3_grind_3_derisk_spot
      grind_3_profit_threshold = self.system_v3_grind_3_profit_threshold_spot

      grind_4_stakes = self.system_v3_grind_4_stakes_spot
      grind_4_sub_thresholds = self.system_v3_grind_4_thresholds_spot
      grind_4_derisk_grinds = self.system_v3_grind_4_derisk_spot
      grind_4_profit_threshold = self.system_v3_grind_4_profit_threshold_spot

      grind_5_stakes = self.system_v3_grind_5_stakes_spot
      grind_5_sub_thresholds = self.system_v3_grind_5_thresholds_spot
      grind_5_derisk_grinds = self.system_v3_grind_5_derisk_spot
      grind_5_profit_threshold = self.system_v3_grind_5_profit_threshold_spot

      rebuy_stakes = self.system_v3_1_rebuy_stakes_spot
      rebuy_sub_thresholds = self.system_v3_1_rebuy_thresholds_spot

    grind_1_max_sub_grinds = 0
    grind_1_stakes = scale_stakes_for_min_stake(
      grind_1_stakes, slice_amount, min_stake, trade_leverage, trade_leverage
    )
    grind_1_max_sub_grinds = len(grind_1_stakes)

    grind_2_max_sub_grinds = 0
    grind_2_stakes = scale_stakes_for_min_stake(
      grind_2_stakes, slice_amount, min_stake, stake_scale_leverage, trade_leverage
    )
    grind_2_max_sub_grinds = len(grind_2_stakes)

    grind_3_max_sub_grinds = 0
    grind_3_stakes = scale_stakes_for_min_stake(
      grind_3_stakes, slice_amount, min_stake, stake_scale_leverage, trade_leverage
    )
    grind_3_max_sub_grinds = len(grind_3_stakes)

    grind_4_max_sub_grinds = 0
    grind_4_stakes = scale_stakes_for_min_stake(
      grind_4_stakes, slice_amount, min_stake, stake_scale_leverage, trade_leverage
    )
    grind_4_max_sub_grinds = len(grind_4_stakes)

    grind_5_max_sub_grinds = 0
    grind_5_stakes = scale_stakes_for_min_stake(
      grind_5_stakes, slice_amount, min_stake, stake_scale_leverage, trade_leverage
    )
    grind_5_max_sub_grinds = len(grind_5_stakes)

    rebuy_max_sub_grinds = len(rebuy_stakes)

    is_derisk_1 = False
    is_derisk_1_found = False  # derisk_level_1 de-risk exit
    derisk_1_order = None
    is_derisk_2 = False
    is_derisk_2_found = False  # derisk_level_2 de-risk exit
    derisk_2_order = None
    is_derisk_3 = False
    is_derisk_3_found = False  # derisk_level_3 de-risk exit
    derisk_3_order = None
    is_derisk_4 = False
    is_derisk_4_found = False  # derisk_level_4 de-risk exit
    derisk_4_order = None
    grind_1_sub_grind_count = 0
    grind_1_total_amount = 0.0
    grind_1_total_cost = 0.0
    grind_1_current_open_rate = 0.0
    grind_1_current_grind_stake = 0.0
    grind_1_current_grind_profit_stake = 0.0
    grind_1_current_grind_profit_rate = 0.0
    grind_1_is_exit_found = False
    grind_1_found = False
    grind_1_buy_orders = []
    grind_1_orders = []
    grind_1_distance_ratio = 0.0
    grind_1_exit_order = None
    grind_1_exit_distance_ratio = 0.0
    grind_2_sub_grind_count = 0
    grind_2_total_amount = 0.0
    grind_2_total_cost = 0.0
    grind_2_current_open_rate = 0.0
    grind_2_current_grind_stake = 0.0
    grind_2_current_grind_profit_stake = 0.0
    grind_2_current_grind_profit_rate = 0.0
    grind_2_is_exit_found = False
    grind_2_found = False
    grind_2_buy_orders = []
    grind_2_orders = []
    grind_2_distance_ratio = 0.0
    grind_2_exit_order = None
    grind_2_exit_distance_ratio = 0.0
    grind_3_sub_grind_count = 0
    grind_3_total_amount = 0.0
    grind_3_total_cost = 0.0
    grind_3_current_open_rate = 0.0
    grind_3_current_grind_stake = 0.0
    grind_3_current_grind_profit_stake = 0.0
    grind_3_current_grind_profit_rate = 0.0
    grind_3_is_exit_found = False
    grind_3_found = False
    grind_3_buy_orders = []
    grind_3_orders = []
    grind_3_distance_ratio = 0.0
    grind_3_exit_order = None
    grind_3_exit_distance_ratio = 0.0
    grind_4_sub_grind_count = 0
    grind_4_total_amount = 0.0
    grind_4_total_cost = 0.0
    grind_4_current_open_rate = 0.0
    grind_4_current_grind_stake = 0.0
    grind_4_current_grind_profit_stake = 0.0
    grind_4_current_grind_profit_rate = 0.0
    grind_4_is_exit_found = False
    grind_4_found = False
    grind_4_buy_orders = []
    grind_4_orders = []
    grind_4_distance_ratio = 0.0
    grind_4_exit_order = None
    grind_4_exit_distance_ratio = 0.0
    grind_5_sub_grind_count = 0
    grind_5_total_amount = 0.0
    grind_5_total_cost = 0.0
    grind_5_current_open_rate = 0.0
    grind_5_current_grind_stake = 0.0
    grind_5_current_grind_profit_stake = 0.0
    grind_5_current_grind_profit_rate = 0.0
    grind_5_is_exit_found = False
    grind_5_found = False
    grind_5_buy_orders = []
    grind_5_orders = []
    grind_5_distance_ratio = 0.0
    grind_5_exit_order = None
    grind_5_exit_distance_ratio = 0.0
    buyback_1_sub_grind_count = 0
    buyback_1_total_amount = 0.0
    buyback_1_total_cost = 0.0
    buyback_1_current_open_rate = 0.0
    buyback_1_current_grind_stake = 0.0
    buyback_1_current_grind_stake_profit = 0.0
    buyback_1_is_exit_found = False
    buyback_1_found = False
    buyback_1_buy_orders = []
    buyback_1_orders = []
    buyback_1_distance_ratio = 0.0
    buyback_1_exit_order = None
    buyback_1_exit_distance_ratio = 0.0
    rebuy_sub_grind_count = 0
    rebuy_total_amount = 0.0
    rebuy_total_cost = 0.0
    rebuy_current_open_rate = 0.0
    rebuy_current_grind_stake = 0.0
    rebuy_current_grind_stake_profit = 0.0
    rebuy_is_exit_found = False
    rebuy_found = False
    rebuy_buy_orders = []
    rebuy_orders = []
    rebuy_distance_ratio = 0.0
    rebuy_exit_order = None
    rebuy_exit_distance_ratio = 0.0
    for order in reversed(filled_orders):
      if (order.ft_order_side == "buy") and (order is not filled_orders[0]):
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag
        if not grind_1_is_exit_found and order_tag == "grind_1_entry":
          grind_1_sub_grind_count += 1
          grind_1_total_amount += order.safe_filled
          grind_1_total_cost += order.safe_filled * order.safe_price
          grind_1_buy_orders.append(order.id)
          grind_1_orders.append(order)
          if not grind_1_found:
            grind_1_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_1_found = True
        elif not grind_2_is_exit_found and order_tag == "grind_2_entry":
          grind_2_sub_grind_count += 1
          grind_2_total_amount += order.safe_filled
          grind_2_total_cost += order.safe_filled * order.safe_price
          grind_2_buy_orders.append(order.id)
          grind_2_orders.append(order)
          if not grind_2_found:
            grind_2_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_2_found = True
        elif not grind_3_is_exit_found and order_tag == "grind_3_entry":
          grind_3_sub_grind_count += 1
          grind_3_total_amount += order.safe_filled
          grind_3_total_cost += order.safe_filled * order.safe_price
          grind_3_buy_orders.append(order.id)
          grind_3_orders.append(order)
          if not grind_3_found:
            grind_3_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_3_found = True
        elif not grind_4_is_exit_found and order_tag == "grind_4_entry":
          grind_4_sub_grind_count += 1
          grind_4_total_amount += order.safe_filled
          grind_4_total_cost += order.safe_filled * order.safe_price
          grind_4_buy_orders.append(order.id)
          grind_4_orders.append(order)
          if not grind_4_found:
            grind_4_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_4_found = True
        elif not grind_5_is_exit_found and order_tag == "grind_5_entry":
          grind_5_sub_grind_count += 1
          grind_5_total_amount += order.safe_filled
          grind_5_total_cost += order.safe_filled * order.safe_price
          grind_5_buy_orders.append(order.id)
          grind_5_orders.append(order)
          if not grind_5_found:
            grind_5_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_5_found = True
        elif not buyback_1_is_exit_found and order_tag == "buyback_1_entry":
          buyback_1_sub_grind_count += 1
          buyback_1_total_amount += order.safe_filled
          buyback_1_total_cost += order.safe_filled * order.safe_price
          buyback_1_buy_orders.append(order.id)
          buyback_1_orders.append(order)
          if not buyback_1_found:
            buyback_1_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            buyback_1_found = True
        elif not rebuy_is_exit_found and order_tag == "rebuy_entry":
          rebuy_sub_grind_count += 1
          rebuy_total_amount += order.safe_filled
          rebuy_total_cost += order.safe_filled * order.safe_price
          rebuy_buy_orders.append(order.id)
          rebuy_orders.append(order)
          if not rebuy_found:
            rebuy_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            rebuy_found = True
      elif order.ft_order_side == "sell":
        if order is filled_exits[-1] and (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
          # break
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag.partition(" ")[0]
        if order_tag == "derisk_level_1":
          if not is_derisk_1_found:
            is_derisk_1_found = True
            is_derisk_1 = True
            derisk_1_order = order
        elif order_tag == "derisk_level_2":
          if not is_derisk_2_found:
            is_derisk_2_found = True
            is_derisk_2 = True
            derisk_2_order = order
        elif order_tag == "derisk_level_3":
          if not is_derisk_3_found:
            is_derisk_3_found = True
            is_derisk_3 = True
            derisk_3_order = order
        elif order_tag == "derisk_level_4":
          if not is_derisk_4_found:
            is_derisk_4_found = True
            is_derisk_4 = True
            derisk_4_order = order
        elif not grind_1_is_exit_found and order_tag in ["grind_1_exit", "grind_1_derisk"]:
          grind_1_is_exit_found = True
          grind_1_exit_order = order
        elif not grind_2_is_exit_found and order_tag in ["grind_2_exit", "grind_2_derisk"]:
          grind_2_is_exit_found = True
          grind_2_exit_order = order
        elif not grind_3_is_exit_found and order_tag in ["grind_3_exit", "grind_3_derisk"]:
          grind_3_is_exit_found = True
          grind_3_exit_order = order
        elif not grind_4_is_exit_found and order_tag in ["grind_4_exit", "grind_4_derisk"]:
          grind_4_is_exit_found = True
          grind_4_exit_order = order
        elif not grind_5_is_exit_found and order_tag in ["grind_5_exit", "grind_5_derisk"]:
          grind_5_is_exit_found = True
          grind_5_exit_order = order
        elif not buyback_1_is_exit_found and order_tag in ["buyback_1_exit", "buyback_1_derisk"]:
          buyback_1_is_exit_found = True
          buyback_1_exit_order = order
        elif not rebuy_is_exit_found and order_tag in ["rebuy_exit", "rebuy_derisk"]:
          rebuy_is_exit_found = True
          rebuy_exit_order = order
        elif order_tag == "derisk_global":
          if not grind_1_is_exit_found:
            grind_1_is_exit_found = True
            grind_1_exit_order = order
          if not grind_2_is_exit_found:
            grind_2_is_exit_found = True
            grind_2_exit_order = order
          if not grind_3_is_exit_found:
            grind_3_is_exit_found = True
            grind_3_exit_order = order
          if not grind_4_is_exit_found:
            grind_4_is_exit_found = True
            grind_4_exit_order = order
          if not grind_5_is_exit_found:
            grind_5_is_exit_found = True
            grind_5_exit_order = order
          if not buyback_1_is_exit_found:
            buyback_1_is_exit_found = True
            buyback_1_exit_order = order
          if not rebuy_is_exit_found:
            rebuy_is_exit_found = True
            rebuy_exit_order = order

    if grind_1_sub_grind_count > 0:
      grind_1_current_open_rate = grind_1_total_cost / grind_1_total_amount
      grind_1_current_grind_stake = grind_1_total_amount * exit_rate * (1 - trade_fee_close)
      grind_1_current_grind_profit_stake = grind_1_current_grind_stake - grind_1_total_cost
      grind_1_current_grind_profit_rate = (exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
    if grind_2_sub_grind_count > 0:
      grind_2_current_open_rate = grind_2_total_cost / grind_2_total_amount
      grind_2_current_grind_stake = grind_2_total_amount * exit_rate * (1 - trade_fee_close)
      grind_2_current_grind_profit_stake = grind_2_current_grind_stake - grind_2_total_cost
      grind_2_current_grind_profit_rate = (exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
    if grind_3_sub_grind_count > 0:
      grind_3_current_open_rate = grind_3_total_cost / grind_3_total_amount
      grind_3_current_grind_stake = grind_3_total_amount * exit_rate * (1 - trade_fee_close)
      grind_3_current_grind_profit_stake = grind_3_current_grind_stake - grind_3_total_cost
      grind_3_current_grind_profit_rate = (exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
    if grind_4_sub_grind_count > 0:
      grind_4_current_open_rate = grind_4_total_cost / grind_4_total_amount
      grind_4_current_grind_stake = grind_4_total_amount * exit_rate * (1 - trade_fee_close)
      grind_4_current_grind_profit_stake = grind_4_current_grind_stake - grind_4_total_cost
      grind_4_current_grind_profit_rate = (exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
    if grind_5_sub_grind_count > 0:
      grind_5_current_open_rate = grind_5_total_cost / grind_5_total_amount
      grind_5_current_grind_stake = grind_5_total_amount * exit_rate * (1 - trade_fee_close)
      grind_5_current_grind_profit_stake = grind_5_current_grind_stake - grind_5_total_cost
      grind_5_current_grind_profit_rate = (exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
    if rebuy_sub_grind_count > 0:
      rebuy_current_open_rate = rebuy_total_cost / rebuy_total_amount
      rebuy_current_grind_stake = rebuy_total_amount * exit_rate * (1 - trade_fee_close)
      rebuy_current_grind_stake_profit = rebuy_current_grind_stake - rebuy_total_cost
    if buyback_1_sub_grind_count > 0:
      buyback_1_current_open_rate = buyback_1_total_cost / buyback_1_total_amount
      buyback_1_current_grind_stake = buyback_1_total_amount * exit_rate * (1 - trade_fee_close)
      buyback_1_current_grind_stake_profit = buyback_1_current_grind_stake - buyback_1_total_cost

    if grind_1_is_exit_found:
      grind_1_exit_distance_ratio = (exit_rate - grind_1_exit_order.safe_price) / grind_1_exit_order.safe_price
    if grind_2_is_exit_found:
      grind_2_exit_distance_ratio = (exit_rate - grind_2_exit_order.safe_price) / grind_2_exit_order.safe_price
    if grind_3_is_exit_found:
      grind_3_exit_distance_ratio = (exit_rate - grind_3_exit_order.safe_price) / grind_3_exit_order.safe_price
    if grind_4_is_exit_found:
      grind_4_exit_distance_ratio = (exit_rate - grind_4_exit_order.safe_price) / grind_4_exit_order.safe_price
    if grind_5_is_exit_found:
      grind_5_exit_distance_ratio = (exit_rate - grind_5_exit_order.safe_price) / grind_5_exit_order.safe_price
    if buyback_1_is_exit_found:
      buyback_1_exit_distance_ratio = (exit_rate - buyback_1_exit_order.safe_price) / buyback_1_exit_order.safe_price
    elif is_derisk_4_found:
      buyback_1_exit_distance_ratio = (exit_rate - derisk_4_order.safe_price) / derisk_4_order.safe_price
    if rebuy_is_exit_found:
      rebuy_exit_distance_ratio = (exit_rate - rebuy_exit_order.safe_price) / rebuy_exit_order.safe_price

    # all buybacks & grinds
    current_open_grind_stake_profit = (
      grind_1_current_grind_profit_stake
      + grind_2_current_grind_profit_stake
      + grind_3_current_grind_profit_stake
      + grind_4_current_grind_profit_stake
      + grind_5_current_grind_profit_stake
      + buyback_1_current_grind_stake_profit
      + rebuy_current_grind_stake_profit
    )
    num_open_grinds_and_buybacks = (
      grind_1_sub_grind_count
      + grind_2_sub_grind_count
      + grind_3_sub_grind_count
      + grind_4_sub_grind_count
      + grind_5_sub_grind_count
      + buyback_1_sub_grind_count
      + rebuy_sub_grind_count
    )

    # not reached the max allowed stake for all grinds
    is_not_trade_max_stake_v3 = current_stake_amount < (slice_amount * self.system_v3_max_stake)
    is_not_trade_max_stake_v3_1 = current_stake_amount < (slice_amount * self.system_v3_1_max_stake)

    grind_1_cluster_max_profit_stake = trade.get_custom_data(key="grind_1_cluster_max_profit_stake") or 0.0
    grind_1_cluster_max_profit_rate = trade.get_custom_data(key="grind_1_cluster_max_profit_rate") or 0.0
    if grind_1_current_grind_profit_stake > grind_1_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_1_cluster_max_profit_stake", value=grind_1_current_grind_profit_stake)
    if grind_1_current_grind_profit_rate > grind_1_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_1_cluster_max_profit_rate", value=grind_1_current_grind_profit_rate)

    grind_2_cluster_max_profit_stake = trade.get_custom_data(key="grind_2_cluster_max_profit_stake") or 0.0
    grind_2_cluster_max_profit_rate = trade.get_custom_data(key="grind_2_cluster_max_profit_rate") or 0.0
    if grind_2_current_grind_profit_stake > grind_2_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_2_cluster_max_profit_stake", value=grind_2_current_grind_profit_stake)
    if grind_2_current_grind_profit_rate > grind_2_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_2_cluster_max_profit_rate", value=grind_2_current_grind_profit_rate)

    grind_3_cluster_max_profit_stake = trade.get_custom_data(key="grind_3_cluster_max_profit_stake") or 0.0
    grind_3_cluster_max_profit_rate = trade.get_custom_data(key="grind_3_cluster_max_profit_rate") or 0.0
    if grind_3_current_grind_profit_stake > grind_3_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_3_cluster_max_profit_stake", value=grind_3_current_grind_profit_stake)
    if grind_3_current_grind_profit_rate > grind_3_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_3_cluster_max_profit_rate", value=grind_3_current_grind_profit_rate)

    grind_4_cluster_max_profit_stake = trade.get_custom_data(key="grind_4_cluster_max_profit_stake") or 0.0
    grind_4_cluster_max_profit_rate = trade.get_custom_data(key="grind_4_cluster_max_profit_rate") or 0.0
    if grind_4_current_grind_profit_stake > grind_4_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_4_cluster_max_profit_stake", value=grind_4_current_grind_profit_stake)
    if grind_4_current_grind_profit_rate > grind_4_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_4_cluster_max_profit_rate", value=grind_4_current_grind_profit_rate)

    grind_5_cluster_max_profit_stake = trade.get_custom_data(key="grind_5_cluster_max_profit_stake") or 0.0
    grind_5_cluster_max_profit_rate = trade.get_custom_data(key="grind_5_cluster_max_profit_rate") or 0.0
    if grind_5_current_grind_profit_stake > grind_5_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_5_cluster_max_profit_stake", value=grind_5_current_grind_profit_stake)
    if grind_5_current_grind_profit_rate > grind_5_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_5_cluster_max_profit_rate", value=grind_5_current_grind_profit_rate)

    is_long_extra_checks_entry = (
      grind_entry_retry_time > filled_entries[-1].order_filled_utc
      # and ((current_time - timedelta(hours=6) > filled_orders[-1].order_filled_utc) or (slice_profit < -0.02))
      and (
        (current_time - timedelta(hours=6) > filled_orders[-1].order_filled_utc)
        or (slice_profit < -0.06)
        or (is_derisk_3)
      )
      # and (
      #   (current_stake_amount < (filled_entries[0].cost * 0.50))
      #   or (current_time - timedelta(hours=6) > filled_orders[-1].order_filled_utc)
      #   or (slice_profit < -0.06)
      # )
    )
    # is_long_extra_checks_entry = True
    is_long_grind_entry = self.long_grind_entry_v3(
      last_candle,
      previous_candle,
      num_open_grinds_and_buybacks,
      slice_profit,
      slice_profit_entry,
      slice_profit_exit,
      True,
    )
    is_long_buyback_entry = self.long_buyback_entry_v3(last_candle, previous_candle, slice_profit, True)
    is_long_rebuy_entry = self.long_rebuy_entry_v3(last_candle, previous_candle, slice_profit, True)
    stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
    send_notifications = not is_backtest
    # =========================================================================
    # DE-RISK CONFIGURATION
    # =========================================================================

    if is_system_v3:
      derisk_1_enable = self.system_v3_derisk_level_1_enable
      derisk_2_enable = self.system_v3_derisk_level_2_enable
      derisk_3_enable = self.system_v3_derisk_level_3_enable
      derisk_4_enable = False
      if is_futures_mode:
        derisk_1_threshold = self.system_v3_derisk_level_1_futures[1]
        derisk_1_stake = self.system_v3_derisk_level_1_stake_futures
        derisk_2_threshold = self.system_v3_derisk_level_2_futures[1]
        derisk_2_stake = self.system_v3_derisk_level_2_stake_futures
        derisk_3_threshold = self.system_v3_derisk_level_3_futures[1]
        derisk_3_stake = self.system_v3_derisk_level_3_stake_futures
      else:
        derisk_1_threshold = self.system_v3_derisk_level_1_spot[1]
        derisk_1_stake = self.system_v3_derisk_level_1_stake_spot
        derisk_2_threshold = self.system_v3_derisk_level_2_spot[1]
        derisk_2_stake = self.system_v3_derisk_level_2_stake_spot
        derisk_3_threshold = self.system_v3_derisk_level_3_spot[1]
        derisk_3_stake = self.system_v3_derisk_level_3_stake_spot
    elif is_system_v3_1:
      derisk_1_enable = False
      derisk_2_enable = False
      derisk_3_enable = False
      derisk_4_enable = False
    elif is_system_v3_2:
      derisk_1_enable = self.system_v3_2_derisk_level_1_enable
      derisk_2_enable = self.system_v3_2_derisk_level_2_enable
      derisk_3_enable = self.system_v3_2_derisk_level_3_enable
      derisk_4_enable = self.system_v3_2_derisk_level_4_enable
      if is_futures_mode:
        derisk_1_threshold = self.system_v3_2_derisk_level_1_futures[1]
        derisk_1_stake = self.system_v3_2_derisk_level_1_stake_futures
        derisk_2_threshold = self.system_v3_2_derisk_level_2_futures[1]
        derisk_2_stake = self.system_v3_2_derisk_level_2_stake_futures
        derisk_3_threshold = self.system_v3_2_derisk_level_3_futures[1]
        derisk_3_stake = self.system_v3_2_derisk_level_3_stake_futures
        derisk_4_threshold = self.system_v3_2_derisk_level_4_futures[1]
        derisk_4_stake = self.system_v3_2_derisk_level_4_stake_futures
      else:
        derisk_1_threshold = self.system_v3_2_derisk_level_1_spot[1]
        derisk_1_stake = self.system_v3_2_derisk_level_1_stake_spot
        derisk_2_threshold = self.system_v3_2_derisk_level_2_spot[1]
        derisk_2_stake = self.system_v3_2_derisk_level_2_stake_spot
        derisk_3_threshold = self.system_v3_2_derisk_level_3_spot[1]
        derisk_3_stake = self.system_v3_2_derisk_level_3_stake_spot
        derisk_4_threshold = self.system_v3_2_derisk_level_4_spot[1]
        derisk_4_stake = self.system_v3_2_derisk_level_4_stake_spot
    derisk_enable = self.derisk_enable
    # ---------------------------------------------------------------------
    # De-risk level 1
    # ---------------------------------------------------------------------
    if (
      derisk_enable
      and derisk_1_enable
      and not (is_derisk_1_found)
      and not is_rebuy_mode
      and profit_stake < slice_amount * derisk_1_threshold / trade_leverage
    ):
      sell_amount = filled_entries[0].safe_filled * derisk_1_stake * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if send_notifications:
          send_msg(
            notification_msg(
              "de-risk",
              tag="Level 1",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"De-risk Level 1 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_1"
    # ---------------------------------------------------------------------
    # De-risk level 2
    # ---------------------------------------------------------------------
    if (
      derisk_enable
      and derisk_2_enable
      and not is_derisk_2_found
      and not is_rebuy_mode
      and profit_stake < slice_amount * derisk_2_threshold / trade_leverage
    ):
      sell_amount = filled_entries[0].safe_filled * derisk_2_stake * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if send_notifications:
          send_msg(
            notification_msg(
              "de-risk",
              tag="Level 2",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"De-risk Level 2 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_2"
    # ---------------------------------------------------------------------
    # De-risk level 3
    # ---------------------------------------------------------------------
    if (
      derisk_enable
      and derisk_3_enable
      and not is_derisk_3_found
      and not is_rebuy_mode
      and profit_stake < slice_amount * derisk_3_threshold / trade_leverage
    ):
      sell_amount = filled_entries[0].safe_filled * derisk_3_stake * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if send_notifications:
          send_msg(
            notification_msg(
              "de-risk",
              tag="Level 3",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"De-risk Level 3 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_3"
    # ---------------------------------------------------------------------
    # De-risk level 4
    # ---------------------------------------------------------------------
    if (
      derisk_enable
      and derisk_4_enable
      and not is_derisk_4_found
      and not is_rebuy_mode
      and profit_stake < (slice_amount * derisk_4_threshold / trade_leverage)
    ):
      sell_amount = filled_entries[0].safe_filled * derisk_4_stake * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if send_notifications:
          send_msg(
            notification_msg(
              "de-risk",
              tag="Level 4",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"De-risk Level 4 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_4"

    # Grinding 1

    if (
      (self.system_v3_grind_1_enable)
      # and is_derisk_1_found
      and is_long_grind_entry
      and is_long_extra_checks_entry
      and (grind_1_sub_grind_count < grind_1_max_sub_grinds)
      and (grind_1_sub_grind_count == 0 or (grind_1_distance_ratio < grind_1_sub_thresholds[grind_1_sub_grind_count]))
      and is_not_trade_max_stake_v3
    ):
      buy_amount = slice_amount * grind_1_stakes[grind_1_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      if send_notifications:
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="grind_1_entry",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
      log.info(
        f"Grinding entry (grind_1_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
      )
      order_tag = "grind_1_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_1_sub_grind_count > 0:
      ft_exit_amount, tag = self.long_grind_exit_v3(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_1_exit",
        "grind_1_exit",
        fee_open_rate,
        fee_close_rate,
        grind_1_cluster_max_profit_stake,
        grind_1_cluster_max_profit_rate,
        grind_1_current_grind_profit_stake,
        grind_1_current_grind_profit_rate,
        grind_1_total_amount,
        grind_1_profit_threshold,
        grind_1_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v3_grind_1_use_derisk
      and (grind_1_sub_grind_count > 0)
      and (((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate) < grind_1_derisk_grinds)
    ):
      # if (
      #   self.system_v3_grind_1_use_derisk
      #   and (grind_1_sub_grind_count > 0)
      #   and (grind_1_current_grind_profit_stake < (slice_amount * grind_1_derisk_grinds))
      #   and (grind_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_1_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate)
            if grind_1_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_1_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_1_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_1_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_1_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_total_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_1_derisk"
        for grind_entry_id in grind_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 2

    if (
      (self.system_v3_grind_2_enable)
      # and is_derisk_1_found
      and is_long_grind_entry
      and is_long_extra_checks_entry
      and (grind_2_sub_grind_count < grind_2_max_sub_grinds)
      and (grind_2_sub_grind_count == 0 or (grind_2_distance_ratio < grind_2_sub_thresholds[grind_2_sub_grind_count]))
      and is_not_trade_max_stake_v3
    ):
      buy_amount = slice_amount * grind_2_stakes[grind_2_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      if send_notifications:
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="grind_2_entry",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
      log.info(
        f"Grinding entry (grind_2_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
      )
      order_tag = "grind_2_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_2_sub_grind_count > 0:
      ft_exit_amount, tag = self.long_grind_exit_v3(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_2_exit",
        "grind_2_exit",
        fee_open_rate,
        fee_close_rate,
        grind_2_cluster_max_profit_stake,
        grind_2_cluster_max_profit_rate,
        grind_2_current_grind_profit_stake,
        grind_2_current_grind_profit_rate,
        grind_2_total_amount,
        grind_2_profit_threshold,
        grind_2_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v3_grind_2_use_derisk
      and (grind_2_sub_grind_count > 0)
      and (((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate) < grind_2_derisk_grinds)
    ):
      # if (
      #   self.system_v3_grind_2_use_derisk
      #   and (grind_2_sub_grind_count > 0)
      #   and (grind_2_current_grind_profit_stake < (slice_amount * grind_2_derisk_grinds))
      #   and (grind_2_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_2_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_2_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate)
            if grind_2_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_2_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_2_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_2_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_2_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_2_total_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_2_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_2_derisk"
        for grind_entry_id in grind_2_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 3

    if (
      (self.system_v3_grind_3_enable)
      # and is_derisk_1_found
      and is_long_grind_entry
      and is_long_extra_checks_entry
      and (grind_3_sub_grind_count < grind_3_max_sub_grinds)
      and (grind_3_sub_grind_count == 0 or (grind_3_distance_ratio < grind_3_sub_thresholds[grind_3_sub_grind_count]))
      and is_not_trade_max_stake_v3
    ):
      buy_amount = slice_amount * grind_3_stakes[grind_3_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      if send_notifications:
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="grind_3_entry",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
      log.info(
        f"Grinding entry (grind_3_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
      )
      order_tag = "grind_3_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_3_sub_grind_count > 0:
      ft_exit_amount, tag = self.long_grind_exit_v3(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_3_exit",
        "grind_3_exit",
        fee_open_rate,
        fee_close_rate,
        grind_3_cluster_max_profit_stake,
        grind_3_cluster_max_profit_rate,
        grind_3_current_grind_profit_stake,
        grind_3_current_grind_profit_rate,
        grind_3_total_amount,
        grind_3_profit_threshold,
        grind_3_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v3_grind_3_use_derisk
      and (grind_3_sub_grind_count > 0)
      and (((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate) < grind_3_derisk_grinds)
    ):
      # if (
      #   self.system_v3_grind_3_use_derisk
      #   and (grind_3_sub_grind_count > 0)
      #   and (grind_3_current_grind_profit_stake < (slice_amount * grind_3_derisk_grinds))
      #   and (grind_3_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_3_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_3_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate)
            if grind_3_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_3_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_3_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_3_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_3_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_3_total_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_3_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_3_derisk"
        for grind_entry_id in grind_3_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 4

    if (
      (self.system_v3_grind_4_enable)
      # and is_derisk_1_found
      # and is_long_grind_entry
      and (
        is_long_grind_entry
        or (
          (slice_profit_entry < -0.06)
          and (last_candle["RSI_3"] > 5.0)
          and (last_candle["RSI_3_15m"] > 10.0)
          and (last_candle["RSI_14"] < 35.0)
          and (last_candle["close"] < (last_candle["EMA_20"] * 0.985))
        )
        or (
          (slice_profit_entry < -0.06)
          and (num_open_grinds_and_buybacks == 0)
          and (last_candle["RSI_14"] < 30.0)
          and (last_candle["close"] < (last_candle["EMA_20"] * 0.980))
        )
      )
      and is_long_extra_checks_entry
      and (grind_4_sub_grind_count < grind_4_max_sub_grinds)
      and (grind_4_sub_grind_count == 0 or (grind_4_distance_ratio < grind_4_sub_thresholds[grind_4_sub_grind_count]))
      and is_not_trade_max_stake_v3
    ):
      buy_amount = slice_amount * grind_4_stakes[grind_4_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      if send_notifications:
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="grind_4_entry",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
      log.info(
        f"Grinding entry (grind_4_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
      )
      order_tag = "grind_4_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_4_sub_grind_count > 0:
      ft_exit_amount, tag = self.long_grind_exit_v3(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_4_exit",
        "grind_4_exit",
        fee_open_rate,
        fee_close_rate,
        grind_4_cluster_max_profit_stake,
        grind_4_cluster_max_profit_rate,
        grind_4_current_grind_profit_stake,
        grind_4_current_grind_profit_rate,
        grind_4_total_amount,
        grind_4_profit_threshold,
        grind_4_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v3_grind_4_use_derisk
      and (grind_4_sub_grind_count > 0)
      and (((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate) < grind_4_derisk_grinds)
    ):
      # if (
      #   self.system_v3_grind_4_use_derisk
      #   and (grind_4_sub_grind_count > 0)
      #   and (grind_4_current_grind_profit_stake < (slice_amount * grind_4_derisk_grinds))
      #   and (grind_4_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_4_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_4_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate)
            if grind_4_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_4_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_4_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_4_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_4_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_4_total_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_4_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_4_derisk"
        for grind_entry_id in grind_4_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 5

    if (
      (self.system_v3_grind_5_enable)
      # and is_derisk_1_found
      # and is_long_grind_entry
      and (
        is_long_grind_entry
        or (
          (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
          and (slice_profit_entry < -0.06)
          and (last_candle["RSI_3"] > 10.0)
          and (last_candle["RSI_3_15m"] > 20.0)
          and (last_candle["AROONU_14"] < 50.0)
        )
        or (
          (self.is_futures_mode)
          and (slice_profit_entry < -0.15)
          and (trade.liquidation_price is not None)
          and (
            (trade.is_short and current_rate > trade.liquidation_price * 0.80)
            or (not trade.is_short and current_rate < trade.liquidation_price * 1.20)
          )
        )
      )
      and is_long_extra_checks_entry
      and (grind_5_sub_grind_count < grind_5_max_sub_grinds)
      and (grind_5_sub_grind_count == 0 or (grind_5_distance_ratio < grind_5_sub_thresholds[grind_5_sub_grind_count]))
      and is_not_trade_max_stake_v3
    ):
      buy_amount = slice_amount * grind_5_stakes[grind_5_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      if send_notifications:
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="grind_5_entry",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
      log.info(
        f"Grinding entry (grind_5_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
      )
      order_tag = "grind_5_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_5_sub_grind_count > 0:
      ft_exit_amount, tag = self.long_grind_exit_v3(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_5_exit",
        "grind_5_exit",
        fee_open_rate,
        fee_close_rate,
        grind_5_cluster_max_profit_stake,
        grind_5_cluster_max_profit_rate,
        grind_5_current_grind_profit_stake,
        grind_5_current_grind_profit_rate,
        grind_5_total_amount,
        grind_5_profit_threshold,
        grind_5_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v3_grind_5_use_derisk
      and (grind_5_sub_grind_count > 0)
      and (((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate) < grind_5_derisk_grinds)
    ):
      # if (
      #   self.system_v3_grind_5_use_derisk
      #   and (grind_5_sub_grind_count > 0)
      #   and (grind_5_current_grind_profit_stake < (slice_amount * grind_5_derisk_grinds))
      #   and (grind_5_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_5_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_5_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate)
            if grind_5_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_5_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_5_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_5_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_5_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_5_total_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_5_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_5_derisk"
        for grind_entry_id in grind_5_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Buyback 1

    if (
      self.system_v3_buyback_1_enable
      and is_system_v3_2
      and is_derisk_4_found
      and is_long_buyback_entry
      # and is_long_extra_checks_entry
      and (buyback_1_current_open_rate == 0)
      and (
        (
          buyback_1_exit_distance_ratio
          < (
            self.system_v3_buyback_1_distance_ratio_negative_futures
            if is_futures_mode
            else self.system_v3_buyback_1_distance_ratio_negative_spot
          )
        )
        or (
          buyback_1_exit_distance_ratio
          > (
            self.system_v3_buyback_1_distance_ratio_positive_futures
            if is_futures_mode
            else self.system_v3_buyback_1_distance_ratio_positive_spot
          )
        )
      )
      and is_not_trade_max_stake_v3
    ):
      buy_amount = (
        slice_amount
        * (self.system_v3_buyback_1_stake_futures if is_futures_mode else self.system_v3_buyback_1_stake_spot)
        / trade_leverage
      )
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      if send_notifications:
        send_msg(
          notification_msg(
            "buyback-entry",
            tag="buyback_1_entry",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
      log.info(
        f"Buyback entry (buyback_1_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "buyback_1_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    # if buyback_1_sub_grind_count > 0:
    #   grind_profit = (exit_rate - buyback_1_current_open_rate) / buyback_1_current_open_rate
    #   if (
    #     grind_profit
    #     > (
    #       (
    #         self.system_v3_buyback_1_profit_threshold_futures
    #         if self.is_futures_mode
    #         else self.system_v3_buyback_1_profit_threshold_spot
    #       )
    #       + fee_open_rate
    #       + fee_close_rate
    #     )
    #   ) and self.long_grind_exit_v2(last_candle, previous_candle, slice_profit, True):
    #     sell_amount = buyback_1_total_amount * exit_rate / trade.leverage
    #     if ((current_stake_amount / trade.leverage) - sell_amount) < (min_stake * 1.55):
    #       sell_amount = (trade.amount * exit_rate / trade.leverage) - (min_stake * 1.55)
    #     ft_sell_amount = sell_amount * trade.leverage * (trade.stake_amount / trade.amount) / exit_rate
    #     if sell_amount > min_stake and ft_sell_amount > min_stake:
    #       self.dp.send_msg(
    #         self.notification_msg(
    #           "buyback-exit",
    #           tag="buyback_1_exit",
    #           pair=trade.pair,
    #           rate=exit_rate,
    #           stake_amount=sell_amount,
    #           profit_stake=profit_stake,
    #           profit_ratio=profit_ratio,
    #           stake_currency=self.config["stake_currency"],
    #           grind_profit_stake=grind_profit * sell_amount * trade.leverage,
    #           grind_profit_pct=grind_profit,
    #           coin_amount=buyback_1_total_amount,
    #         )
    #       )
    #       log.info(
    #         f"Buyback exit (buyback_1_exit) [{current_time}] [{trade.pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade.leverage} {self.config['stake_currency']})"
    #       )
    #       order_tag = "buyback_1_exit"
    #       for grind_entry_id in buyback_1_buy_orders:
    #         order_tag += " " + str(grind_entry_id)
    #       if has_order_tags:
    #         return -ft_sell_amount, order_tag
    #       else:
    #         return -ft_sell_amount

    # if (
    #   self.grinding_v2_buyback_1_use_derisk
    #   and (buyback_1_sub_grind_count > 0)
    #   and (
    #     ((exit_rate - buyback_1_current_open_rate) / buyback_1_current_open_rate)
    #     < (
    #       self.grinding_v2_buyback_1_derisk_futures if self.is_futures_mode else self.grinding_v2_buyback_1_derisk_spot
    #     )
    #   )
    #   and (buyback_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.system_v3_buyback_1_use_derisk
      and (buyback_1_sub_grind_count > 0)
      and (
        buyback_1_current_grind_stake_profit
        < (
          slice_amount
          * (self.system_v3_buyback_1_derisk_futures if is_futures_mode else self.system_v3_buyback_1_derisk_spot)
        )
      )
    ):
      sell_amount = buyback_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if buyback_1_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - buyback_1_current_open_rate) / buyback_1_current_open_rate)
            if buyback_1_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "buyback-derisk",
              tag="buyback_1_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=buyback_1_current_grind_stake_profit,
              grind_profit_pct=grind_profit,
              coin_amount=buyback_1_total_amount,
            )
          )
        log.info(
          f"Buyback de-risk (buyback_1_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {buyback_1_total_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({buyback_1_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "buyback_1_derisk"
        for grind_entry_id in buyback_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Rebuy

    if (
      is_system_v3_1
      and is_long_rebuy_entry
      and (
        (0 <= rebuy_sub_grind_count < rebuy_max_sub_grinds)
        and (slice_profit_entry < rebuy_sub_thresholds[rebuy_sub_grind_count])
      )
      and is_not_trade_max_stake_v3_1
    ):
      buy_amount = slice_amount * rebuy_stakes[rebuy_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      if send_notifications:
        send_msg(
          notification_msg(
            "rebuy",
            tag="rebuy_entry",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
      log.info(
        f"Rebuy (rebuy_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      if has_order_tags:
        return buy_amount, "rebuy_entry"
      else:
        return buy_amount

    return None

  def long_grind_entry_v3(
    self,
    last_candle: Series,
    previous_candle: Series,
    num_open_grinds_and_buybacks: int,
    slice_profit: float,
    slice_profit_entry: float,
    slice_profit_exit: float,
    is_derisk: bool,
  ) -> float:
    if last_candle["protections_long_global"] != True:
      return False
    # g0 — signal entry
    if last_candle["enter_long"] == True:
      self._grind_entry_tag = "g0"
      return True

    last_close = last_candle["close"]
    last_open = last_candle["open"]
    last_close_min_12 = last_candle["close_min_12"]
    last_close_max_48 = last_candle["close_max_48"]
    last_high_max_24_1h = last_candle["high_max_24_1h"]
    last_low_min_12_4h = last_candle["low_min_12_4h"]
    last_low_min_24_4h = last_candle["low_min_24_4h"]
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_3_15m = last_candle["RSI_3_15m"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_rsi_3_4h = last_candle["RSI_3_4h"]
    last_rsi_3_1d = last_candle["RSI_3_1d"]
    last_rsi_14 = last_candle["RSI_14"]
    last_rsi_14_1h = last_candle["RSI_14_1h"]
    last_rsi_14_4h = last_candle["RSI_14_4h"]
    last_rsi_20 = last_candle["RSI_20"]
    last_sma_9 = last_candle["SMA_9"]
    last_sma_16 = last_candle["SMA_16"]
    last_sma_21 = last_candle["SMA_21"]
    last_sma_30 = last_candle["SMA_30"]
    last_ema_9 = last_candle["EMA_9"]
    last_ema_12 = last_candle["EMA_12"]
    last_ema_16 = last_candle["EMA_16"]
    last_ema_20 = last_candle["EMA_20"]
    last_ema_26 = last_candle["EMA_26"]
    last_ema_100 = last_candle["EMA_100"]
    last_ema_12_4h = last_candle["EMA_12_4h"]
    last_ema_50_4h = last_candle["EMA_50_4h"]
    last_ema_100_4h = last_candle["EMA_100_4h"]
    last_ema_200_4h = last_candle["EMA_200_4h"]
    last_aroonu_14 = last_candle["AROONU_14"]
    last_aroonu_14_15m = last_candle["AROONU_14_15m"]
    last_aroonu_14_1h = last_candle["AROONU_14_1h"]
    last_aroonu_14_4h = last_candle["AROONU_14_4h"]
    last_aroonu_14_1d = last_candle["AROONU_14_1d"]
    last_roc_9_1h = last_candle["ROC_9_1h"]
    last_roc_9_4h = last_candle["ROC_9_4h"]
    last_roc_9_1d = last_candle["ROC_9_1d"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_stochrsi_k_15m = last_candle["STOCHRSIk_14_14_3_3_15m"]
    last_stochrsi_k_1h = last_candle["STOCHRSIk_14_14_3_3_1h"]
    last_stochrsi_k_4h = last_candle["STOCHRSIk_14_14_3_3_4h"]
    last_stochrsi_k_1d = last_candle["STOCHRSIk_14_14_3_3_1d"]
    last_willr_14 = last_candle["WILLR_14"]
    last_willr_84_1h = last_candle["WILLR_84_1h"]
    last_bbl_20 = last_candle["BBL_20_2.0"]
    last_bbands_20_1h = last_candle["BBB_20_2.0_1h"]
    last_cmf_20 = last_candle["CMF_20"]
    prev_rsi_20 = previous_candle["RSI_20"]
    prev_sma_9 = previous_candle["SMA_9"]
    prev_sma_21 = previous_candle["SMA_21"]
    prev_ema_12 = previous_candle["EMA_12"]
    prev_ema_26 = previous_candle["EMA_26"]

    # g1 — AROONU dip + EMA_16 drop
    if (
      (last_rsi_3 > 10.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_3_1h > 15.0)
      and (last_rsi_3_4h > 15.0)
      and (last_rsi_14 < 45.0)
      and (last_aroonu_14 < 25.0)
      and (last_aroonu_14_4h < 100.0)
      and (last_roc_9_1h < 20.0)
      and (last_close > (last_close_max_48 * 0.90))
      and (last_close < (last_low_min_24_4h * 1.60))
      and (last_close < (last_ema_16 * 0.975))
      and ((last_rsi_3_1h > 35.0) or (last_aroonu_14_1h < 100.0))
      and ((last_aroonu_14_1h < 100.0) or (last_aroonu_14_1d < 100.0))
      and ((last_aroonu_14_1d < 100.0) or (last_stochrsi_k_1h < 90.0))
    ):
      self._grind_entry_tag = "g1"
      return True
    # g2 — EMA_26 > EMA_12 divergence + BBL
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 15.0)
      and (last_rsi_3_4h > 15.0)
      and (last_rsi_14 < 30.0)
      and (last_stochrsi_k < 30.0)
      and (last_ema_26 > last_ema_12)
      and ((last_ema_26 - last_ema_12) > (last_open * 0.020))
      and ((prev_ema_26 - prev_ema_12) > (last_open / 100.0))
      and (last_close < (last_bbl_20 * 1.010))
    ):
      self._grind_entry_tag = "g2"
      return True
    # g3 — AROONU_15m dip + EMA_12 drop
    if (
      (last_rsi_3 > 10.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 10.0)
      and (last_rsi_3_4h > 15.0)
      and (last_rsi_14 < 35.0)
      and (last_aroonu_14_15m < 25.0)
      and (last_stochrsi_k_15m < 70.0)
      and (last_stochrsi_k_1h < 90.0)
      and (last_roc_9_1h > -15.0)
      and (last_roc_9_4h > -15.0)
      and (last_close > (last_close_max_48 * 0.85))
      and (last_close < (last_ema_12 * 0.980))
      and ((last_rsi_3_1h > 20.0) or (last_rsi_3_1d > 20.0))
      and ((last_rsi_3_1h > 20.0) or (last_stochrsi_k_1d < 70.0))
      and ((last_rsi_3_1h > 25.0) or (last_stochrsi_k_1h < 70.0))
      and ((last_rsi_3_4h > 30.0) or (last_stochrsi_k_4h < 60.0))
    ):
      self._grind_entry_tag = "g3"
      return True
    # g4 — multi-TF RSI + EMA_26 + BBL
    if (
      (last_rsi_3 > 10.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 10.0)
      and (last_rsi_3_4h > 10.0)
      and (last_rsi_3_1d > 10.0)
      and (last_rsi_14 < 35.0)
      and (last_aroonu_14 < 25.0)
      and (last_roc_9_1h > -20.0)
      and (last_roc_9_4h > -20.0)
      # and (last_close > (last_close_max_48 * 0.90))
      and (last_close < (last_ema_26 * 0.970))
      and (last_close < (last_bbl_20 * 0.999))
    ):
      self._grind_entry_tag = "g4"
      return True
    # g5 — deep dip + EMA_9/20
    if (
      (last_rsi_3 > 10.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 15.0)
      and (last_rsi_3_4h > 15.0)
      and (last_rsi_14 < 35.0)
      and (last_aroonu_14 < 30.0)
      and (last_roc_9_4h > -20.0)
      and (last_close > (last_high_max_24_1h * 0.80))
      and (last_close < (last_low_min_12_4h * 1.50))
      and (last_close < (last_ema_9 * 0.975))
      and (last_close < (last_ema_20 * 0.970))
    ):
      self._grind_entry_tag = "g5"
      return True
    # g6 — RSI_20 falling + SMA_16 drop
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3 < 40.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_14 > 35.0)
      and (last_roc_9_1h > -20.0)
      and (last_roc_9_4h > -20.0)
      and (last_aroonu_14 < 25.0)
      and (last_close < (last_low_min_12_4h * 1.60))
      and (last_rsi_20 < prev_rsi_20)
      and (last_close < (last_sma_16 * 0.960))
      and ((last_aroonu_14_1d < 100.0) or (last_roc_9_1d < 50.0))
    ):
      self._grind_entry_tag = "g6"
      return True
    # g7 — WILLR deep + BBB wide
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 20.0)
      and (last_rsi_3_1h > 20.0)
      and (last_rsi_3_4h > 20.0)
      and (last_willr_14 < -50.0)
      and (last_willr_84_1h < -70.0)
      and (last_stochrsi_k < 30.0)
      and (last_stochrsi_k_1h < 90.0)
      and (last_roc_9_1h > -10.0)
      and (last_roc_9_1h < 20.0)
      and (last_roc_9_4h > -10.0)
      and (last_close < (last_low_min_24_4h * 1.50))
      and (last_bbands_20_1h > 12.0)
      and (last_close_max_48 >= (last_close * 1.10))
    ):
      self._grind_entry_tag = "g7"
      return True
    # g8 — EMA_26/12 gap wide + low_min_24_1h
    if (
      (last_rsi_3 < 30.0)
      and (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 10.0)
      and (last_rsi_3_4h > 10.0)
      and (last_roc_9_1h > -10.0)
      and (last_roc_9_4h > -25.0)
      # and (last_close < (last_candle["low_min_24_1h"] * 1.30))
      and (last_ema_26 > last_ema_12)
      and ((last_ema_26 - last_ema_12) > (last_open * 0.030))
      and ((prev_ema_26 - prev_ema_12) > (last_open / 100.0))
    ):
      self._grind_entry_tag = "g8"
      return True
    # g9 — pullback recovery
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_3_1h > 20.0)
      and (last_rsi_3_4h > 20.0)
      and (last_stochrsi_k < 50.0)
      and (last_close < (last_close_max_48 * 0.90))
      and (last_close > (last_close_min_12 * 1.03))
    ):
      self._grind_entry_tag = "g9"
      return True
    # g10 — RSI_14 divergence vs 1h
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 20.0)
      and (last_stochrsi_k < 20.0)
      and (last_rsi_14 < (last_rsi_14_1h - 45.0))
    ):
      self._grind_entry_tag = "g10"
      return True
    # g11 — multi-TF RSI + SMA_30 + BBL
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 10.0)
      and (last_cmf_20 > 0.0)
      and (last_close < (last_sma_30 * 0.965))
      and (last_close < (last_bbl_20 * 1.000))
    ):
      self._grind_entry_tag = "g11"
      return True
    # g12 — EMA_26/12 divergence + close_max_48
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 10.0)
      and (last_stochrsi_k < 30.0)
      and (last_close > (last_close_max_48 * 0.90))
      and (last_close < (last_low_min_12_4h * 1.60))
      and (last_ema_26 > last_ema_12)
      and ((last_ema_26 - last_ema_12) > (last_open * 0.025))
      and ((prev_ema_26 - prev_ema_12) > (last_open / 100.0))
    ):
      self._grind_entry_tag = "g12"
      return True
    # g13 — SMA_9 cross SMA_21 + EMA_100 drop
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_1h > 20.0)
      and (last_rsi_14_1h > 40.0)
      and (last_stochrsi_k_15m < 80.0)
      and (last_roc_9_1h > -15.0)
      and (last_roc_9_4h > -15.0)
      and (prev_sma_9 < prev_sma_21)
      and (last_sma_9 > last_sma_21)
      and (last_close < (last_ema_100 * 0.975))
      and ((last_rsi_3_4h > 30.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_4h > 40.0) or (last_roc_9_4h < 30.0))
    ):
      self._grind_entry_tag = "g13"
      return True
    # g14 — SMA_9 cross SMA_21 + 4h uptrend (trend follower)
    if (
      (last_rsi_3 > 5.0)
      and (last_aroonu_14_15m < 50.0)
      and (last_stochrsi_k < 40.0)
      and (last_stochrsi_k_15m < 70.0)
      and (prev_sma_9 < prev_sma_21)
      and (last_sma_9 > last_sma_21)
      and (last_ema_12_4h > last_ema_200_4h)
      and (last_close > (last_close_max_48 * 0.90))
      and ((last_rsi_3_1h > 30.0) or (last_stochrsi_k_1h < 70.0))
      and ((last_rsi_3_1h > 40.0) or (last_aroonu_14_1h < 80.0))
      and ((last_rsi_3_1h > 55.0) or (last_stochrsi_k_1h < 70.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1d > 25.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_stochrsi_k_1h < 80.0) or (last_stochrsi_k_1d < 90.0))
    ):
      self._grind_entry_tag = "g14"
      return True
    # g15 — deep loss recovery (slice_profit < -0.16)
    if (
      (slice_profit < -0.16)
      and (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_14 < 40.0)
      and (last_aroonu_14 < 25.0)
      and (last_aroonu_14_15m < 30.0)
      and (last_stochrsi_k < 30.0)
      and (last_stochrsi_k_15m < 30.0)
      and ((last_rsi_3_1h > 30.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_rsi_3_4h > 30.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1d > 30.0) or (last_stochrsi_k_1d < 80.0))
    ):
      self._grind_entry_tag = "g15"
      return True
    # g16 — EMA_12 drop + BBL
    if (
      (last_rsi_3 > 8.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_3_1h > 15.0)
      and (last_rsi_3_4h > 15.0)
      and (last_rsi_14 < 35.0)
      and (last_close < (last_ema_12 * 0.965))
      and (last_close < (last_bbl_20 * 0.999))
    ):
      self._grind_entry_tag = "g16"
      return True
    # g17 — StochRSI + EMA_20 drop
    if (
      (last_rsi_3 > 15.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_3_1h > 15.0)
      and (last_rsi_3_4h > 15.0)
      and (last_rsi_14 < 30.0)
      and (last_stochrsi_k < 30.0)
      and (last_close < (last_ema_20 * 0.975))
      and ((last_aroonu_14_4h < 100.0) or (last_aroonu_14_1d < 100.0))
    ):
      self._grind_entry_tag = "g17"
      return True
    # g18 — moderate loss recovery (slice_profit < -0.10)
    if (
      (slice_profit < -0.10)
      and (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_3_1h > 20.0)
      and (last_rsi_3_4h > 20.0)
      and (last_rsi_14 < 40.0)
      and (last_close < (last_ema_26 * 0.970))
      and (last_close < (last_bbl_20 * 0.999))
    ):
      self._grind_entry_tag = "g18"
      return True
    # g19 — EMA_26/12 wide gap (slice_profit < -0.06)
    if (
      (slice_profit < -0.06)
      and (last_rsi_3 < 30.0)
      and (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 10.0)
      and (last_ema_26 > last_ema_12)
      and ((last_ema_26 - last_ema_12) > (last_open * 0.035))
      and ((prev_ema_26 - prev_ema_12) > (last_open / 100.0))
    ):
      self._grind_entry_tag = "g19"
      return True
    # AROONU 4h uptrend pullback recovery
    if (
      (last_rsi_3 > 10.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_3_1h > 20.0)
      and (last_rsi_14 < 42.0)
      and (last_rsi_14_4h > 50.0)
      and (last_aroonu_14 < 30.0)
      and (last_aroonu_14_4h > 50.0)
      and (last_roc_9_1d > -15.0)
      and (last_ema_50_4h > last_ema_100_4h)
      and (last_close < (last_close_max_48 * 0.95))
      and ((last_rsi_3_15m > 20.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1h > 30.0) or (last_roc_9_4h < 30.0) or (last_roc_9_1d < 30.0))
      and ((last_rsi_3_1h > 50.0) or (last_roc_9_1d < 60.0))
      and ((last_rsi_3_4h > 40.0) or (last_aroonu_14_4h < 90.0))
      and ((last_rsi_3_4h > 45.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_4h > 60.0) or (last_roc_9_4h < 40.0))
      and ((last_aroonu_14_4h < 100.0) or (last_stochrsi_k_1d < 80.0))
      and ((last_aroonu_14_4h < 100.0) or (last_aroonu_14_1d < 100.0))
      and ((last_stochrsi_k_4h < 90.0) or (last_roc_9_4h < 30.0))
    ):
      self._grind_entry_tag = "g20"
      return True
    if (
      (slice_profit_entry < -0.02)
      and (last_rsi_3 > 10.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_14 < 35.0)
      and (last_aroonu_14_15m < 50.0)
      and (last_close < (last_ema_20 * 0.955))
    ):
      self._grind_entry_tag = "g21"
      return True
    # g22 — early recovery rebuild: reclaiming off the low BEFORE the 4h trend confirms (g14 needs
    #        EMA_12_4h > EMA_200_4h and fires too late for a deep-derisk bounce). Anti-fake-rise gating via
    #        multi-TF RSI recovery + reclaim off the 4h low + not-extended. NOTE: slice_profit_entry gate
    #        removed — it self-defeats in recovery (last grind buy is in profit); underwater-scope TBD.
    if (
      (last_rsi_3 > 30.0)
      and (last_rsi_3_15m > 30.0)
      and (last_rsi_14 > 45.0)
      and (last_rsi_14_1h > 45.0)
      and (last_roc_9_1h > 0.0)
      and (last_roc_9_4h > -10.0)
      # anti-parabolic: even at a formed bottom, a parabolic 4h overshoot reverses (dead-cat).
      # cross-coin (SFP/CELR/DYDX/APE): cuts 17 severe at ~1% good cost within recovery-starts.
      and (last_roc_9_4h < 25.0)
      # recovery-started gate: only rebuild once the 4h bottom is IN (not still making new lows).
      # g22's job is the recovery rebuild — NOT entering mid-dump (that's g1..g21). AROOND high =
      # a fresh 4h low was just made = still dumping; require it low = bottom formed = recovery start.
      and (last_aroonu_14_4h < 50.0)
      # aggressive risk-free: g22 fires ONLY deep below the 4h 200-EMA (fresh recovery zone). The
      # near/above-EMA overextended-bounce zone is where dead-cats live AND where g22's late-recovery
      # adds sit — we sacrifice those wins on purpose, because g23 (extended-continuation, ~0.2% severe)
      # backstops the real recoveries above. So g22 stays clean, g23 captures the continuation.
      and (last_close < last_ema_200_4h)
      and (last_close > (last_low_min_12_4h * 1.10))
      and (last_close > (last_ema_20 * 0.97))
      and (last_close < (last_ema_20 * 1.02))
      and ((last_rsi_3_1h > 30.0) or (last_stochrsi_k_1d < 80.0))
      and ((last_rsi_3_1h > 35.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_4h > 50.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1d > 10.0) or (last_aroonu_14_1d < 70.0))
      and ((last_rsi_3_1d > 10.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1d > 15.0) or (last_aroonu_14_1h < 70.0))
      and ((last_rsi_3_1d > 40.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_rsi_3_1d > 40.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1d > 45.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1d > 45.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_1d > 45.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_rsi_3_1d > 45.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 50.0) or (last_aroonu_14_15m < 100.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1d > 65.0) or (last_aroonu_14_1h < 70.0) or (last_aroonu_14_1d < 90.0))
      and ((last_aroonu_14_15m < 70.0) or (last_aroonu_14_1h < 100.0))
      and ((last_aroonu_14_15m < 80.0) or (last_stochrsi_k_15m < 80.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1h < 80.0) or (last_stochrsi_k_1h < 80.0) or (last_stochrsi_k_1d < 90.0))
      and ((last_aroonu_14_1h < 100.0) or (last_stochrsi_k_1d < 80.0))
      and ((last_stochrsi_k_1h < 50.0) or (last_roc_9_1d > -40.0))
      and ((last_roc_9_1d > -20.0) or (last_aroonu_14_4h < 100.0))
      and ((last_roc_9_1d > -20.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_roc_9_1d > -30.0) or (last_stochrsi_k_1h < 90.0))
    ):
      self._grind_entry_tag = "g22"
      return True
    # g23 — pump-continuation scalp: extended zone ABOVE g22's EMA_20*1.02 cap. Only rides a CONFIRMED
    # continuation (price already advancing past the reclaim), so dead-cats (which roll over before
    # reaching the extended zone) are structurally avoided. Complements g22: g22 = early recovery-start
    # (ambiguous zone, dead-cat risk trimmed by P1), g23 = confirmed continuation (clean, ~0.2% severe).
    if (
      (last_rsi_3 > 30.0)
      and (last_rsi_3_15m > 30.0)
      and (last_rsi_14 > 50.0)
      and (last_rsi_14_1h > 50.0)
      and (last_roc_9_1h > 0.0)
      and (last_roc_9_4h > 0.0)
      # anti-parabolic blow-off + anti-exhaustion top
      and (last_roc_9_4h < 25.0)
      and ((last_stochrsi_k < 97.0) or (last_rsi_14 < 80.0))
      and (last_close > (last_low_min_12_4h * 1.10))
      # extended zone: above g22's 1.02*EMA cap = continuation confirmed, not a reclaim
      and (last_close >= (last_ema_20 * 1.02))
      and (last_close < (last_ema_20 * 1.12))
      and ((last_rsi_3_1h > 45.0) or (last_aroonu_14_4h < 80.0))
      and ((last_rsi_3_1h > 65.0) or (last_aroonu_14_15m < 60.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 65.0) or (last_stochrsi_k_15m < 60.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_4h > 40.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_rsi_3_4h > 50.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_1d > 15.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_rsi_3_1d > 30.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1d > 30.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_1d > 40.0) or (last_aroonu_14_15m < 80.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1d > 50.0) or (last_stochrsi_k_1h < 80.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 55.0) or (last_aroonu_14_15m < 100.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_aroonu_14_15m < 80.0) or (last_aroonu_14_1h < 100.0) or (last_roc_9_1d < 10.0))
      and ((last_aroonu_14_15m < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_1h < 100.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_4h < 100.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_1d < 90.0) or (last_roc_9_1d < 20.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_1d < 100.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_15m < 90.0) or (last_stochrsi_k_1d < 70.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_aroonu_14_1h < 80.0) or (last_aroonu_14_4h < 100.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_aroonu_14_1h < 100.0) or (last_aroonu_14_4h < 100.0))
      and ((last_aroonu_14_4h < 70.0) or (last_aroonu_14_1d < 100.0) or (last_roc_9_4h < 10.0))
      and ((last_aroonu_14_4h < 70.0) or (last_roc_9_1d < 50.0))
      and ((last_aroonu_14_4h < 100.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_aroonu_14_4h < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1d < 100.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_stochrsi_k_15m < 80.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_stochrsi_k_15m < 90.0) or (last_aroonu_14_1h < 100.0))
      and ((last_stochrsi_k_15m < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_stochrsi_k_1h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_stochrsi_k_1h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_stochrsi_k_1h < 90.0) or (last_stochrsi_k_1d < 90.0))
    ):
      self._grind_entry_tag = "g23"
      return True
    # g24 — trend-pullback continuation add: the zone ABOVE the 4h 200-EMA that g22 explicitly sacrifices.
    if (
      # momentum healthy on the pullback: RSI holds up (a real reversal cracks RSI hard)
      (last_rsi_3 > 20.0)
      and (last_rsi_3_15m > 20.0)
      and (last_rsi_14 > 40.0)
      # trend intact + this is a PULLBACK not a reversal: 4h still rising, 1h not in freefall
      and (last_roc_9_1h > -10.0)
      and (last_roc_9_4h > 0.0)
      and (last_roc_9_4h < 25.0)  # anti-parabolic blow-off top
      # bull scope-gate: confirmed 4h uptrend + price above the 200-EMA regime (complements g22's <200EMA)
      and (last_ema_12_4h > last_ema_200_4h)
      and (last_close > last_ema_200_4h)
      # shallow pullback to the short EMA — buy the dip WITHIN the trend, never the top nor a deep dump
      and (last_close < (last_ema_20 * 1.01))
      and (last_close > (last_ema_20 * 0.94))
      and ((last_rsi_3_15m > 40.0) or (last_stochrsi_k_15m < 70.0))
      and ((last_rsi_3_1h > 10.0) or (last_rsi_3_4h > 30.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1h > 10.0) or (last_aroonu_14_1h < 60.0))
      and ((last_rsi_3_1h > 15.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_1h > 25.0) or (last_rsi_3_4h > 45.0) or (last_stochrsi_k_4h < 50.0))
      and ((last_rsi_3_1h > 25.0) or (last_aroonu_14_1h < 70.0))
      and ((last_rsi_3_1h > 25.0) or (last_rsi_3_1d > 45.0) or (last_aroonu_14_1d < 70.0))
      and ((last_rsi_3_1h > 25.0) or (last_aroonu_14_1h < 80.0))
      and ((last_rsi_3_1h > 30.0) or (last_rsi_3_4h > 60.0) or (last_aroonu_14_1d < 70.0))
      and ((last_rsi_3_1h > 30.0) or (last_rsi_3_4h > 60.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1h > 30.0) or (last_stochrsi_k_1d < 80.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_1h > 35.0) or (last_rsi_3_4h > 45.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1h > 35.0) or (last_aroonu_14_1h < 60.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_1h > 35.0) or (last_stochrsi_k_1d < 90.0) or (last_roc_9_1d < 20.0))
      and ((last_rsi_3_1h > 40.0) or (last_rsi_3_4h > 40.0) or (last_aroonu_14_1d < 90.0))
      and ((last_rsi_3_1h > 40.0) or (last_rsi_3_4h > 65.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 40.0) or (last_rsi_3_1d > 60.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_1h > 40.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1h > 40.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_1h > 40.0) or (last_aroonu_14_1d < 100.0) or (last_roc_9_1d < 20.0))
      and ((last_rsi_3_1h > 40.0) or (last_stochrsi_k_1d < 80.0) or (last_roc_9_1d < 50.0))
      and ((last_rsi_3_1h > 35.0) or (last_rsi_3_4h > 50.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 40.0) or (last_rsi_3_4h > 55.0) or (last_aroonu_14_4h < 90.0))
      and ((last_rsi_3_1h > 45.0) or (last_rsi_3_4h > 45.0) or (last_rsi_3_1d > 45.0) or (last_stochrsi_k_4h < 50.0))
      and ((last_rsi_3_1h > 45.0) or (last_rsi_3_4h > 45.0) or (last_aroonu_14_4h < 60.0))
      and ((last_rsi_3_1h > 45.0) or (last_aroonu_14_4h < 80.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_1h > 50.0) or (last_rsi_3_4h > 55.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_1h < 80.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_1h < 70.0) or (last_aroonu_14_1d < 70.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_4h < 80.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_4h < 80.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_4h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1h > 55.0) or (last_rsi_3_4h > 55.0) or (last_stochrsi_k_15m < 70.0))
      and ((last_rsi_3_1h > 55.0) or (last_aroonu_14_1h < 80.0) or (last_aroonu_14_4h < 80.0))
      and ((last_rsi_3_1h > 55.0) or (last_stochrsi_k_4h < 90.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_1h > 60.0) or (last_aroonu_14_15m < 70.0) or (last_aroonu_14_4h < 80.0))
      and ((last_rsi_3_1h > 60.0) or (last_stochrsi_k_1h < 60.0) or (last_stochrsi_k_1d < 90.0))
      and ((last_rsi_3_1h > 65.0) or (last_aroonu_14_15m < 70.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1h > 65.0) or (last_aroonu_14_1h < 70.0) or (last_aroonu_14_1d < 90.0))
      and ((last_rsi_3_1h > 65.0) or (last_aroonu_14_1h < 100.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_4h > 25.0) or (last_roc_9_1d < 30.0))
      and ((last_rsi_3_4h > 40.0) or (last_rsi_3_1d > 60.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_4h > 40.0) or (last_aroonu_14_15m < 70.0) or (last_aroonu_14_1d < 90.0))
      and ((last_rsi_3_4h > 40.0) or (last_aroonu_14_1d < 90.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_4h > 40.0) or (last_stochrsi_k_15m < 60.0) or (last_aroonu_14_1d < 90.0))
      and ((last_rsi_3_4h > 45.0) or (last_rsi_3_1d > 45.0) or (last_aroonu_14_15m < 60.0))
      and ((last_rsi_3_4h > 45.0) or (last_rsi_3_1d > 45.0) or (last_stochrsi_k_15m < 60.0))
      and ((last_rsi_3_4h > 45.0) or (last_rsi_3_1d > 45.0) or (last_stochrsi_k_1h < 60.0))
      and ((last_rsi_3_4h > 45.0) or (last_rsi_3_1d > 45.0) or (last_stochrsi_k_4h < 60.0))
      and ((last_rsi_3_4h > 45.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_4h > 50.0) or (last_aroonu_14_4h < 70.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_4h > 50.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_4h > 55.0) or (last_aroonu_14_15m < 70.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_4h > 60.0) or (last_rsi_3_1d > 65.0) or (last_aroonu_14_15m < 70.0))
      and ((last_rsi_3_4h > 60.0) or (last_aroonu_14_15m < 90.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_rsi_3_4h > 60.0) or (last_aroonu_14_15m < 100.0) or (last_stochrsi_k_15m < 80.0))
      and ((last_rsi_3_4h > 60.0) or (last_stochrsi_k_15m < 70.0) or (last_stochrsi_k_1h < 70.0))
      and ((last_rsi_3_4h > 60.0) or (last_stochrsi_k_1h < 60.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_rsi_3_1d > 30.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 35.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_rsi_3_1d > 35.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_rsi_3_1d > 35.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1d > 40.0) or (last_aroonu_14_1h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 45.0) or (last_aroonu_14_15m < 50.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_rsi_3_1d > 45.0) or (last_aroonu_14_1h < 80.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_rsi_3_1d > 45.0) or (last_aroonu_14_1d < 70.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1d > 45.0) or (last_stochrsi_k_1h < 70.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1d > 50.0) or (last_aroonu_14_15m < 60.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1d > 50.0) or (last_aroonu_14_4h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 50.0) or (last_stochrsi_k_15m < 90.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_1d > 50.0) or (last_stochrsi_k_1h < 80.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 60.0) or (last_aroonu_14_1h < 80.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_14_1h < 70.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_15m < 80.0) or (last_aroonu_14_1h < 80.0) or (last_aroonu_14_4h < 80.0))
      and ((last_aroonu_14_15m < 80.0) or (last_stochrsi_k_15m < 70.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_aroonu_14_15m < 80.0) or (last_aroonu_14_1d < 100.0))
      and ((last_aroonu_14_15m < 80.0) or (last_stochrsi_k_15m < 80.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_aroonu_14_15m < 90.0) or (last_aroonu_14_1h < 80.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_aroonu_14_15m < 90.0) or (last_aroonu_14_1h < 100.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_1h < 100.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_4h < 100.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_1d < 80.0) or (last_roc_9_1d < 10.0))
      and ((last_aroonu_14_1h < 70.0) or (last_aroonu_14_4h < 100.0))
      and ((last_aroonu_14_1h < 70.0) or (last_aroonu_14_1d < 90.0) or (last_roc_9_1d < 10.0))
      and ((last_aroonu_14_1h < 80.0) or (last_aroonu_14_4h < 100.0))
      and ((last_aroonu_14_1h < 90.0) or (last_stochrsi_k_1h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1h < 90.0) or (last_stochrsi_k_1h < 90.0) or (last_roc_9_1d < 10.0))
      and ((last_aroonu_14_1h < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1h < 100.0) or (last_stochrsi_k_1d < 90.0))
      and ((last_aroonu_14_4h < 70.0) or (last_aroonu_14_1d < 100.0) or (last_roc_9_1d < 20.0))
      and ((last_aroonu_14_4h < 90.0) or (last_stochrsi_k_4h < 90.0) or (last_roc_9_1d < 10.0))
      and ((last_aroonu_14_4h < 90.0) or (last_roc_9_1d < 30.0))
      and ((last_aroonu_14_4h < 100.0) or (last_aroonu_14_1d < 100.0))
      and ((last_aroonu_14_4h < 100.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_aroonu_14_4h < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1d < 100.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_aroonu_14_1d < 100.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_aroonu_14_1d < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1d < 100.0) or (last_roc_9_4h < 15.0) or (last_roc_9_1d < 50.0))
      # do not buy an overbought top on the bounce
      and ((last_stochrsi_k < 90.0) or (last_rsi_14 < 70.0))
      and ((last_stochrsi_k_15m < 80.0) or (last_stochrsi_k_1h < 80.0) or (last_roc_9_1d < 10.0))
      and ((last_stochrsi_k_15m < 80.0) or (last_aroonu_14_1d < 100.0))
      and ((last_stochrsi_k_15m < 80.0) or (last_stochrsi_k_1d < 90.0) or (last_roc_9_1d < 20.0))
      and ((last_stochrsi_k_15m < 90.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_stochrsi_k_15m < 90.0) or (last_stochrsi_k_1d < 90.0))
      and ((last_stochrsi_k_1h < 80.0) or (last_stochrsi_k_1d < 90.0))
      and ((last_stochrsi_k_1h < 80.0) or (last_roc_9_1d > -20.0))
      and ((last_stochrsi_k_1h < 90.0) or (last_roc_9_4h < 15.0))
      and ((last_stochrsi_k_4h < 90.0) or (last_roc_9_4h < 15.0))
      and ((last_stochrsi_k_4h < 90.0) or (last_roc_9_1d > -15.0))
      and ((last_stochrsi_k_1d < 90.0) or (last_roc_9_4h < 20.0))
    ):
      self._grind_entry_tag = "g24"
      return True
    if (
      (last_rsi_3 > 15.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_14 > 40.0)
      and (last_rsi_14_1h > 40.0)
      # the coil signature: 1h momentum negative-to-flat under a flat price
      and (last_roc_9_1h > -15.0)
      and (last_roc_9_1h < 2.0)
      and (last_close > (last_ema_20 * 0.98))
      and (last_close < (last_ema_20 * 1.02))
      # squeeze integrity: regime still broken, 4h reclaim HELD, not dripping to new lows
      and (last_close < last_ema_200_4h)
      and (last_close > (last_low_min_12_4h * 1.10))
      and (last_close > (last_close_min_12 * 1.005))
      # general protections first
      and ((last_rsi_3_15m > 20.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1h > 15.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_1h > 20.0) or (last_rsi_3_4h > 20.0) or (last_aroonu_14_1d < 90.0))
      and ((last_rsi_3_1h > 20.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_rsi_3_1h > 30.0) or (last_rsi_3_1d > 30.0) or (last_stochrsi_k_1h < 70.0))
      and ((last_rsi_3_1h > 35.0) or (last_aroonu_14_1h < 70.0))
      and ((last_rsi_3_1h > 35.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_1h > 40.0) or (last_aroonu_14_4h < 80.0))
      and ((last_rsi_3_1h > 45.0) or (last_aroonu_14_1h < 90.0) or (last_stochrsi_k_1h < 70.0))
      and ((last_rsi_3_1h > 40.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 45.0) or (last_aroonu_14_1h < 90.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 45.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_1h < 70.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_1h > 55.0) or (last_rsi_3_4h > 60.0) or (last_aroonu_14_4h < 60.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_4h < 80.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 50.0) or (last_stochrsi_k_1d < 90.0) or (last_roc_9_1d < 30.0))
      and ((last_rsi_3_1h > 55.0) or (last_aroonu_14_4h < 80.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_1h > 55.0) or (last_aroonu_14_4h < 90.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 60.0) or (last_rsi_3_1d > 60.0) or (last_aroonu_14_1h < 80.0))
      and ((last_rsi_3_1h > 60.0) or (last_stochrsi_k_4h < 70.0) or (last_stochrsi_k_1d < 80.0))
      and ((last_rsi_3_1h > 60.0) or (last_stochrsi_k_4h < 80.0) or (last_roc_9_4h < 10.0))
      and ((last_rsi_3_4h > 10.0) or (last_rsi_3_1d > 40.0) or (last_stochrsi_k_15m < 80.0))
      and ((last_rsi_3_4h > 25.0) or (last_stochrsi_k_4h < 50.0) or (last_roc_9_4h < 10.0))
      and ((last_rsi_3_4h > 35.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_4h > 40.0) or (last_rsi_3_1d > 40.0) or (last_aroonu_14_15m < 70.0))
      and ((last_rsi_3_4h > 40.0) or (last_aroonu_14_15m < 100.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_rsi_3_4h > 40.0) or (last_aroonu_14_1h < 90.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_4h > 40.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_4h > 50.0) or (last_aroonu_14_15m < 80.0) or (last_aroonu_14_4h < 80.0))
      and ((last_rsi_3_4h > 50.0) or (last_stochrsi_k_15m < 70.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_4h > 55.0) or (last_aroonu_14_1h < 100.0) or (last_aroonu_14_1d < 80.0))
      and ((last_rsi_3_4h > 60.0) or (last_rsi_3_1d > 60.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_rsi_3_4h > 60.0) or (last_aroonu_14_15m < 70.0) or (last_aroonu_14_1h < 70.0))
      and ((last_rsi_3_4h > 60.0) or (last_aroonu_14_1h < 100.0) or (last_stochrsi_k_1d < 80.0))
      and ((last_rsi_3_4h > 60.0) or (last_stochrsi_k_4h < 70.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_4h > 65.0) or (last_aroonu_14_1h < 70.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_4h > 65.0) or (last_aroonu_14_4h < 80.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_4h > 65.0) or (last_stochrsi_k_4h < 70.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_4h > 65.0) or (last_stochrsi_k_4h < 90.0) or (last_roc_9_4h < 10.0))
      and ((last_rsi_3_1d > 10.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1d > 20.0) or (last_aroonu_14_1d < 90.0))
      and ((last_rsi_3_1d > 25.0) or (last_stochrsi_k_15m < 70.0))
      and ((last_rsi_3_1d > 25.0) or (last_aroonu_14_1h < 70.0))
      and ((last_rsi_3_1d > 25.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_rsi_3_1d > 30.0) or (last_aroonu_14_15m < 100.0))
      and ((last_rsi_3_1d > 30.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 40.0) or (last_aroonu_14_1h < 90.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_1d > 50.0) or (last_stochrsi_k_4h < 90.0) or (last_stochrsi_k_1d < 70.0))
      and ((last_aroonu_14_15m < 70.0) or (last_aroonu_14_1h < 100.0) or (last_stochrsi_k_1d < 80.0))
      and ((last_aroonu_14_15m < 70.0) or (last_aroonu_14_4h < 70.0) or (last_roc_9_4h < 10.0))
      and ((last_aroonu_14_15m < 80.0) or (last_stochrsi_k_15m < 70.0))
      and ((last_aroonu_14_15m < 80.0) or (last_aroonu_14_1h < 100.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_4h < 90.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1h < 80.0) or (last_aroonu_14_4h < 100.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_aroonu_14_1h < 80.0) or (last_stochrsi_k_4h < 100.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_aroonu_14_1h < 80.0) or (last_stochrsi_k_4h < 90.0) or (last_roc_9_4h < 10.0))
      and ((last_aroonu_14_1h < 100.0) or (last_aroonu_14_1d < 100.0))
      and ((last_aroonu_14_1h < 100.0) or (last_stochrsi_k_15m < 80.0))
      and ((last_aroonu_14_1h < 100.0) or (last_stochrsi_k_4h < 80.0) or (last_roc_9_4h < 10.0))
      and ((last_aroonu_14_1h < 100.0) or (last_stochrsi_k_1d < 90.0) or (last_roc_9_1d < 20.0))
      and ((last_aroonu_14_4h < 70.0) or (last_roc_9_1d > -25.0))
      and ((last_aroonu_14_4h < 70.0) or (last_roc_9_1d < 50.0))
      and ((last_aroonu_14_4h < 80.0) or (last_stochrsi_k_4h < 80.0) or (last_roc_9_4h < 10.0))
      and ((last_aroonu_14_4h < 80.0) or (last_stochrsi_k_1d < 80.0) or (last_roc_9_1d < 10.0))
      and ((last_aroonu_14_4h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_4h < 90.0) or (last_roc_9_4h < 10.0))
      and ((last_stochrsi_k_15m < 60.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_stochrsi_k_1h < 70.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_stochrsi_k_1h < 90.0) or (last_roc_9_4h > -20.0))
      and ((last_stochrsi_k_4h < 70.0) or (last_roc_9_1d > -25.0))
      and ((last_stochrsi_k_4h < 80.0) or (last_stochrsi_k_1d < 90.0) or (last_roc_9_1d < 20.0))
      and ((last_roc_9_1d > -40.0) or (last_aroonu_14_1h < 90.0))
      and ((last_roc_9_1d > -40.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_roc_9_1d > -25.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_roc_9_1d > -25.0) or (last_aroonu_14_4h < 80.0))
      and ((last_roc_9_1d > -15.0) or (last_stochrsi_k_4h < 80.0))
    ):
      self._grind_entry_tag = "g27"
      return True

    self._grind_entry_tag = ""
    return False

  def long_buyback_entry_v3(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    if (last_candle["protections_long_global"] == True) and (
      (last_candle["enter_long"] == True)
      or (
        (last_candle["RSI_3"] > 10.0)
        and (last_candle["RSI_3_15m"] > 10.0)
        and (last_candle["AROONU_14"] < 30.0)
        and (last_candle["AROONU_14_15m"] < 30.0)
      )
    ):
      return True

    return False

  def long_rebuy_entry_v3(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    if (last_candle["protections_long_global"] == True) and (
      (last_candle["enter_long"] == True)
      or (
        (last_candle["RSI_3"] > 10.0)
        and (last_candle["RSI_3_15m"] > 10.0)
        and (last_candle["AROONU_14"] < 30.0)
        and (last_candle["AROONU_14_15m"] < 30.0)
        and (last_candle["close"] < (last_candle["EMA_26"] * 0.988))
      )
    ):
      return True

  def long_grind_exit_v3(
    self,
    last_candle: Series,
    previous_candle: Series,
    slice_profit: float,
    current_time: datetime,
    min_stake: float,
    current_stake_amount: float,
    exit_rate: float,
    profit_stake: float,
    profit_ratio: float,
    name: str,
    tag: str,
    fee_open_rate: float,
    fee_close_rate: float,
    max_profit: float,
    max_profit_rate: float,
    grind_profit_stake: float,
    grind_profit_rate: float,
    grind_total_amount: float,
    grind_exit_profit_threshold: float,
    grind_open_orders,
    trade: Trade,
  ) -> tuple:
    if grind_profit_rate < (grind_exit_profit_threshold + fee_open_rate + fee_close_rate):
      return None, None

    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_14 = last_candle["RSI_14"]
    last_willr_14 = last_candle["WILLR_14"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_close = last_candle["close"]
    last_bbu_20 = last_candle["BBU_20_2.0"]

    is_normal_exit = False
    if (
      (last_rsi_3 > 99.0)
      or (last_rsi_14 > 70.0)
      or (last_willr_14 > -0.1)
      or (last_stochrsi_k > 95.0)
      or (last_close > (last_bbu_20 * 1.01))
      or ((last_rsi_3 > 90.0) and (last_rsi_14 < 50.0))
      or (
        (last_rsi_3 > 80.0)
        and (last_candle["RSI_3_1h"] < 20.0)
        and (last_candle["RSI_3_4h"] < 20.0)
        and (last_candle["ROC_9_1d"] > -10.0)
        and (last_candle["BTC_RSI_14_4h"] < 35.0)
      )
    ):
      is_normal_exit = True

    is_trailing_exit = False
    # if 0.01 <= grind_profit_rate < 0.02:
    #   if grind_profit_rate < (max_profit_rate - 0.025):
    #     is_trailing_exit = True
    # elif 0.02 <= grind_profit_rate <= 0.05:
    #   if grind_profit_rate < (max_profit_rate - 0.035):
    #     is_trailing_exit = True
    # elif 0.05 <= grind_profit_rate <= 0.08:
    #   if grind_profit_rate < (max_profit_rate - 0.045):
    #     is_trailing_exit = True
    # elif 0.08 <= grind_profit_rate <= 0.12:
    #   if grind_profit_rate < (max_profit_rate - 0.050):
    #     is_trailing_exit = True
    # elif 0.12 <= grind_profit_rate:
    #   if grind_profit_rate < (max_profit_rate - 0.055):
    #     is_trailing_exit = True
    # is_trailing_exit = grind_profit_rate > 0.04
    if is_normal_exit or is_trailing_exit:
      stake_currency = self.config["stake_currency"]
      stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
      trade_pair = trade.pair
      trade_leverage = trade.leverage
      trade_amount = trade.amount
      trade_stake_amount = trade.stake_amount
      exit_amount = grind_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - exit_amount) < (min_stake * 1.55):
        exit_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_exit_amount = exit_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if exit_amount > min_stake and ft_exit_amount > min_stake:
        self.dp.send_msg(
          self.notification_msg(
            "grinding-exit",
            tag=name,
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=exit_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit_stake,
            grind_profit_pct=grind_profit_rate,
            coin_amount=grind_total_amount,
          )
        )
        log.info(
          f"Grinding exit ({name}) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {exit_amount:{stake_fmt}} | Coin amount: {grind_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit_rate * 100.0):.2f}% ({grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = tag
        for grind_entry in grind_open_orders:
          order_tag += " " + str(grind_entry.id)
        return -ft_exit_amount, order_tag

    return None, None

  # Long Grinding Adjust Trade Position v4
  # ---------------------------------------------------------------------------------------------
  def long_grind_adjust_trade_position_v4(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ):
    dp = self.dp
    send_msg = self.dp.send_msg
    notification_msg = self.notification_msg
    config = self.config
    stake_currency = config["stake_currency"]
    is_futures_mode = self.is_futures_mode
    scale_stakes_for_min_stake = self.scale_stakes_for_min_stake
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_stake_amount = trade.stake_amount
    trade_leverage = trade.leverage
    trade_fee_open = trade.fee_open
    trade_fee_close = trade.fee_close

    # Reset so the log "Tag:" never shows a value left over from another pair's previous call
    self._grind_entry_tag = ""

    is_backtest = self.is_backtest_mode()
    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)
    if len(df) < 2:
      return None
    last_candle = None
    previous_candle = None

    def load_candles():
      # Only the (expensive on wide frames) row extraction is deferred; the frame is already fetched.
      nonlocal last_candle, previous_candle
      if last_candle is None:
        last_candle = df.iloc[-1]
        previous_candle = df.iloc[-2]

    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_exits = trade.nr_of_successful_exits

    if dp.runmode.value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = config["exit_pricing"]["price_side"]
        if trade.is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    # Finish managed partial exits before allowing another de-risk or grind.
    partial_exit = filled_exits[-1] if filled_exits else None
    if partial_exit is not None and partial_exit.safe_remaining > 0.0:
      partial_exit_tag = partial_exit.ft_order_tag or ""
      if partial_exit_tag.partition(" ")[0] in (
        "derisk_level_1",
        "derisk_level_2",
        "derisk_level_3",
        "derisk_level_4",
        "derisk_global",
        "grind_1_exit",
        "grind_1_derisk",
        "grind_2_exit",
        "grind_2_derisk",
        "grind_3_exit",
        "grind_3_derisk",
        "grind_4_exit",
        "grind_4_derisk",
        "grind_5_exit",
        "grind_5_derisk",
      ):
        partial_exit_amount = min(partial_exit.safe_remaining, trade_amount)
        exit_amount = partial_exit_amount * exit_rate / trade_leverage
        ft_exit_amount = partial_exit_amount * trade_stake_amount / trade_amount
        remaining_stake = (trade_amount - partial_exit_amount) * exit_rate / trade_leverage
        partial_exit_min_stake = min_stake or 0.0
        if (
          exit_amount > partial_exit_min_stake
          and ft_exit_amount > partial_exit_min_stake
          and (remaining_stake == 0.0 or remaining_stake >= partial_exit_min_stake * 1.55)
        ):
          return -ft_exit_amount, partial_exit_tag
        # Do not clip the recovery: a fully filled clipped order would hide the leftover.
        return None

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    current_stake_amount = trade_amount * exit_rate
    slice_amount = filled_entries[0].safe_filled * filled_entries[0].safe_price
    slice_profit = (exit_rate - filled_orders[-1].safe_price) / filled_orders[-1].safe_price
    slice_profit_entry = (exit_rate - filled_entries[-1].safe_price) / filled_entries[-1].safe_price
    slice_profit_exit = (
      ((exit_rate - filled_exits[-1].safe_price) / filled_exits[-1].safe_price) if count_of_exits > 0 else 0.0
    )

    is_rebuy_mode = all(c in self.long_rebuy_mode_tags for c in enter_tags) or (
      any(c in self.long_rebuy_mode_tags for c in enter_tags)
      and all(c in (self.long_rebuy_mode_tags + self.long_grind_mode_tags) for c in enter_tags)
    )
    # Rebuy mode, the first entry is lower than normal slot stake
    if is_rebuy_mode:
      slice_amount /= self.system_v4_rebuy_mode_stake_multiplier

    is_system_v4 = self.is_system_v4(trade)

    has_order_tags = hasattr(filled_orders[0], "ft_order_tag")

    fee_open_rate = trade_fee_open if self.custom_fee_open_rate is None else self.custom_fee_open_rate
    fee_close_rate = trade_fee_close if self.custom_fee_close_rate is None else self.custom_fee_close_rate
    fee_rate = fee_open_rate + fee_close_rate
    stake_scale_leverage = trade_leverage if is_futures_mode else 1.0
    grind_entry_retry_time = current_time - timedelta(minutes=5)

    # =========================================================================
    # GRINDING CONFIGURATION
    # =========================================================================
    if is_futures_mode:
      grind_1_stakes = self.system_v4_grind_1_stakes_futures
      grind_1_sub_thresholds = self.system_v4_grind_1_thresholds_futures
      grind_1_derisk_grinds = self.system_v4_grind_1_derisk_futures
      grind_1_profit_threshold = self.system_v4_grind_1_profit_threshold_futures

      grind_2_stakes = self.system_v4_grind_2_stakes_futures
      grind_2_sub_thresholds = self.system_v4_grind_2_thresholds_futures
      grind_2_derisk_grinds = self.system_v4_grind_2_derisk_futures
      grind_2_profit_threshold = self.system_v4_grind_2_profit_threshold_futures

      grind_3_stakes = self.system_v4_grind_3_stakes_futures
      grind_3_sub_thresholds = self.system_v4_grind_3_thresholds_futures
      grind_3_derisk_grinds = self.system_v4_grind_3_derisk_futures
      grind_3_profit_threshold = self.system_v4_grind_3_profit_threshold_futures

      grind_4_stakes = self.system_v4_grind_4_stakes_futures
      grind_4_sub_thresholds = self.system_v4_grind_4_thresholds_futures
      grind_4_derisk_grinds = self.system_v4_grind_4_derisk_futures
      grind_4_profit_threshold = self.system_v4_grind_4_profit_threshold_futures

      grind_5_stakes = self.system_v4_grind_5_stakes_futures
      grind_5_sub_thresholds = self.system_v4_grind_5_thresholds_futures
      grind_5_derisk_grinds = self.system_v4_grind_5_derisk_futures
      grind_5_profit_threshold = self.system_v4_grind_5_profit_threshold_futures

      # rebuy_stakes = self.system_v4_1_rebuy_stakes_futures
      # rebuy_sub_thresholds = self.system_v4_1_rebuy_thresholds_futures
    else:
      grind_1_stakes = self.system_v4_grind_1_stakes_spot
      grind_1_sub_thresholds = self.system_v4_grind_1_thresholds_spot
      grind_1_derisk_grinds = self.system_v4_grind_1_derisk_spot
      grind_1_profit_threshold = self.system_v4_grind_1_profit_threshold_spot

      grind_2_stakes = self.system_v4_grind_2_stakes_spot
      grind_2_sub_thresholds = self.system_v4_grind_2_thresholds_spot
      grind_2_derisk_grinds = self.system_v4_grind_2_derisk_spot
      grind_2_profit_threshold = self.system_v4_grind_2_profit_threshold_spot

      grind_3_stakes = self.system_v4_grind_3_stakes_spot
      grind_3_sub_thresholds = self.system_v4_grind_3_thresholds_spot
      grind_3_derisk_grinds = self.system_v4_grind_3_derisk_spot
      grind_3_profit_threshold = self.system_v4_grind_3_profit_threshold_spot

      grind_4_stakes = self.system_v4_grind_4_stakes_spot
      grind_4_sub_thresholds = self.system_v4_grind_4_thresholds_spot
      grind_4_derisk_grinds = self.system_v4_grind_4_derisk_spot
      grind_4_profit_threshold = self.system_v4_grind_4_profit_threshold_spot

      grind_5_stakes = self.system_v4_grind_5_stakes_spot
      grind_5_sub_thresholds = self.system_v4_grind_5_thresholds_spot
      grind_5_derisk_grinds = self.system_v4_grind_5_derisk_spot
      grind_5_profit_threshold = self.system_v4_grind_5_profit_threshold_spot

      # rebuy_stakes = self.system_v4_1_rebuy_stakes_spot
      # rebuy_sub_thresholds = self.system_v4_1_rebuy_thresholds_spot

    grind_1_max_sub_grinds = 0
    grind_1_stakes = scale_stakes_for_min_stake(
      grind_1_stakes, slice_amount, min_stake, trade_leverage, trade_leverage
    )
    grind_1_max_sub_grinds = len(grind_1_stakes)

    grind_2_max_sub_grinds = 0
    grind_2_stakes = scale_stakes_for_min_stake(
      grind_2_stakes, slice_amount, min_stake, stake_scale_leverage, trade_leverage
    )
    grind_2_max_sub_grinds = len(grind_2_stakes)

    grind_3_max_sub_grinds = 0
    grind_3_stakes = scale_stakes_for_min_stake(
      grind_3_stakes, slice_amount, min_stake, stake_scale_leverage, trade_leverage
    )
    grind_3_max_sub_grinds = len(grind_3_stakes)

    grind_4_max_sub_grinds = 0
    grind_4_stakes = scale_stakes_for_min_stake(
      grind_4_stakes, slice_amount, min_stake, stake_scale_leverage, trade_leverage
    )
    grind_4_max_sub_grinds = len(grind_4_stakes)

    grind_5_max_sub_grinds = 0
    grind_5_stakes = scale_stakes_for_min_stake(
      grind_5_stakes, slice_amount, min_stake, stake_scale_leverage, trade_leverage
    )
    grind_5_max_sub_grinds = len(grind_5_stakes)

    # rebuy_max_sub_grinds = len(rebuy_stakes)

    is_derisk_1 = False
    is_derisk_1_found = False  # derisk_level_1 de-risk exit
    derisk_1_order = None
    is_derisk_2 = False
    is_derisk_2_found = False  # derisk_level_2 de-risk exit
    derisk_2_order = None
    is_derisk_3 = False
    is_derisk_3_found = False  # derisk_level_3 de-risk exit
    derisk_3_order = None
    is_derisk_4 = False
    is_derisk_4_found = False  # derisk_level_4 de-risk exit
    derisk_4_order = None
    grind_1_sub_grind_count = 0
    grind_1_total_amount = 0.0
    grind_1_total_cost = 0.0
    grind_1_current_open_rate = 0.0
    grind_1_current_grind_stake = 0.0
    grind_1_current_grind_profit_stake = 0.0
    grind_1_current_grind_profit_rate = 0.0
    grind_1_is_exit_found = False
    grind_1_found = False
    grind_1_buy_orders = []
    grind_1_orders = []
    grind_1_distance_ratio = 0.0
    grind_1_exit_order = None
    grind_1_exit_distance_ratio = 0.0
    grind_2_sub_grind_count = 0
    grind_2_total_amount = 0.0
    grind_2_total_cost = 0.0
    grind_2_current_open_rate = 0.0
    grind_2_current_grind_stake = 0.0
    grind_2_current_grind_profit_stake = 0.0
    grind_2_current_grind_profit_rate = 0.0
    grind_2_is_exit_found = False
    grind_2_found = False
    grind_2_buy_orders = []
    grind_2_orders = []
    grind_2_distance_ratio = 0.0
    grind_2_exit_order = None
    grind_2_exit_distance_ratio = 0.0
    grind_3_sub_grind_count = 0
    grind_3_total_amount = 0.0
    grind_3_total_cost = 0.0
    grind_3_current_open_rate = 0.0
    grind_3_current_grind_stake = 0.0
    grind_3_current_grind_profit_stake = 0.0
    grind_3_current_grind_profit_rate = 0.0
    grind_3_is_exit_found = False
    grind_3_found = False
    grind_3_buy_orders = []
    grind_3_orders = []
    grind_3_distance_ratio = 0.0
    grind_3_exit_order = None
    grind_3_exit_distance_ratio = 0.0
    grind_4_sub_grind_count = 0
    grind_4_total_amount = 0.0
    grind_4_total_cost = 0.0
    grind_4_current_open_rate = 0.0
    grind_4_current_grind_stake = 0.0
    grind_4_current_grind_profit_stake = 0.0
    grind_4_current_grind_profit_rate = 0.0
    grind_4_is_exit_found = False
    grind_4_found = False
    grind_4_buy_orders = []
    grind_4_orders = []
    grind_4_distance_ratio = 0.0
    grind_4_exit_order = None
    grind_4_exit_distance_ratio = 0.0
    grind_5_sub_grind_count = 0
    grind_5_total_amount = 0.0
    grind_5_total_cost = 0.0
    grind_5_current_open_rate = 0.0
    grind_5_current_grind_stake = 0.0
    grind_5_current_grind_profit_stake = 0.0
    grind_5_current_grind_profit_rate = 0.0
    grind_5_is_exit_found = False
    grind_5_found = False
    grind_5_buy_orders = []
    grind_5_orders = []
    grind_5_distance_ratio = 0.0
    grind_5_exit_order = None
    grind_5_exit_distance_ratio = 0.0
    buyback_1_sub_grind_count = 0
    buyback_1_total_amount = 0.0
    buyback_1_total_cost = 0.0
    buyback_1_current_open_rate = 0.0
    buyback_1_current_grind_stake = 0.0
    buyback_1_current_grind_stake_profit = 0.0
    buyback_1_is_exit_found = False
    buyback_1_found = False
    buyback_1_buy_orders = []
    buyback_1_orders = []
    buyback_1_distance_ratio = 0.0
    buyback_1_exit_order = None
    buyback_1_exit_distance_ratio = 0.0
    rebuy_sub_grind_count = 0
    rebuy_total_amount = 0.0
    rebuy_total_cost = 0.0
    rebuy_current_open_rate = 0.0
    rebuy_current_grind_stake = 0.0
    rebuy_current_grind_stake_profit = 0.0
    rebuy_is_exit_found = False
    rebuy_found = False
    rebuy_buy_orders = []
    rebuy_orders = []
    rebuy_distance_ratio = 0.0
    rebuy_exit_order = None
    rebuy_exit_distance_ratio = 0.0
    for order in reversed(filled_orders):
      if (order.ft_order_side == "buy") and (order is not filled_orders[0]):
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag
        if not grind_1_is_exit_found and order_tag == "grind_1_entry":
          grind_1_sub_grind_count += 1
          grind_1_total_amount += order.safe_filled
          grind_1_total_cost += order.safe_filled * order.safe_price
          grind_1_buy_orders.append(order.id)
          grind_1_orders.append(order)
          if not grind_1_found:
            grind_1_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_1_found = True
        elif not grind_2_is_exit_found and order_tag == "grind_2_entry":
          grind_2_sub_grind_count += 1
          grind_2_total_amount += order.safe_filled
          grind_2_total_cost += order.safe_filled * order.safe_price
          grind_2_buy_orders.append(order.id)
          grind_2_orders.append(order)
          if not grind_2_found:
            grind_2_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_2_found = True
        elif not grind_3_is_exit_found and order_tag == "grind_3_entry":
          grind_3_sub_grind_count += 1
          grind_3_total_amount += order.safe_filled
          grind_3_total_cost += order.safe_filled * order.safe_price
          grind_3_buy_orders.append(order.id)
          grind_3_orders.append(order)
          if not grind_3_found:
            grind_3_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_3_found = True
        elif not grind_4_is_exit_found and order_tag == "grind_4_entry":
          grind_4_sub_grind_count += 1
          grind_4_total_amount += order.safe_filled
          grind_4_total_cost += order.safe_filled * order.safe_price
          grind_4_buy_orders.append(order.id)
          grind_4_orders.append(order)
          if not grind_4_found:
            grind_4_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_4_found = True
        elif not grind_5_is_exit_found and order_tag == "grind_5_entry":
          grind_5_sub_grind_count += 1
          grind_5_total_amount += order.safe_filled
          grind_5_total_cost += order.safe_filled * order.safe_price
          grind_5_buy_orders.append(order.id)
          grind_5_orders.append(order)
          if not grind_5_found:
            grind_5_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_5_found = True
        elif not buyback_1_is_exit_found and order_tag == "buyback_1_entry":
          buyback_1_sub_grind_count += 1
          buyback_1_total_amount += order.safe_filled
          buyback_1_total_cost += order.safe_filled * order.safe_price
          buyback_1_buy_orders.append(order.id)
          buyback_1_orders.append(order)
          if not buyback_1_found:
            buyback_1_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            buyback_1_found = True
        elif not rebuy_is_exit_found and order_tag == "rebuy_entry":
          rebuy_sub_grind_count += 1
          rebuy_total_amount += order.safe_filled
          rebuy_total_cost += order.safe_filled * order.safe_price
          rebuy_buy_orders.append(order.id)
          rebuy_orders.append(order)
          if not rebuy_found:
            rebuy_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            rebuy_found = True
      elif order.ft_order_side == "sell":
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag.partition(" ")[0]
        if order_tag == "derisk_level_1":
          if not is_derisk_1_found:
            is_derisk_1_found = True
            is_derisk_1 = True
            derisk_1_order = order
        elif order_tag == "derisk_level_2":
          if not is_derisk_2_found:
            is_derisk_2_found = True
            is_derisk_2 = True
            derisk_2_order = order
        elif order_tag == "derisk_level_3":
          if not is_derisk_3_found:
            is_derisk_3_found = True
            is_derisk_3 = True
            derisk_3_order = order
        elif order_tag == "derisk_level_4":
          if not is_derisk_4_found:
            is_derisk_4_found = True
            is_derisk_4 = True
            derisk_4_order = order
        elif not grind_1_is_exit_found and order_tag in ["grind_1_exit", "grind_1_derisk"]:
          grind_1_is_exit_found = True
          grind_1_exit_order = order
        elif not grind_2_is_exit_found and order_tag in ["grind_2_exit", "grind_2_derisk"]:
          grind_2_is_exit_found = True
          grind_2_exit_order = order
        elif not grind_3_is_exit_found and order_tag in ["grind_3_exit", "grind_3_derisk"]:
          grind_3_is_exit_found = True
          grind_3_exit_order = order
        elif not grind_4_is_exit_found and order_tag in ["grind_4_exit", "grind_4_derisk"]:
          grind_4_is_exit_found = True
          grind_4_exit_order = order
        elif not grind_5_is_exit_found and order_tag in ["grind_5_exit", "grind_5_derisk"]:
          grind_5_is_exit_found = True
          grind_5_exit_order = order
        elif not buyback_1_is_exit_found and order_tag in ["buyback_1_exit", "buyback_1_derisk"]:
          buyback_1_is_exit_found = True
          buyback_1_exit_order = order
        elif not rebuy_is_exit_found and order_tag in ["rebuy_exit", "rebuy_derisk"]:
          rebuy_is_exit_found = True
          rebuy_exit_order = order
        elif order_tag == "derisk_global":
          if not grind_1_is_exit_found:
            grind_1_is_exit_found = True
            grind_1_exit_order = order
          if not grind_2_is_exit_found:
            grind_2_is_exit_found = True
            grind_2_exit_order = order
          if not grind_3_is_exit_found:
            grind_3_is_exit_found = True
            grind_3_exit_order = order
          if not grind_4_is_exit_found:
            grind_4_is_exit_found = True
            grind_4_exit_order = order
          if not grind_5_is_exit_found:
            grind_5_is_exit_found = True
            grind_5_exit_order = order
          if not buyback_1_is_exit_found:
            buyback_1_is_exit_found = True
            buyback_1_exit_order = order
          if not rebuy_is_exit_found:
            rebuy_is_exit_found = True
            rebuy_exit_order = order

    if grind_1_sub_grind_count > 0:
      grind_1_current_open_rate = grind_1_total_cost / grind_1_total_amount
      grind_1_current_grind_stake = grind_1_total_amount * exit_rate * (1 - trade_fee_close)
      grind_1_current_grind_profit_stake = grind_1_current_grind_stake - grind_1_total_cost
      grind_1_current_grind_profit_rate = (exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
    if grind_2_sub_grind_count > 0:
      grind_2_current_open_rate = grind_2_total_cost / grind_2_total_amount
      grind_2_current_grind_stake = grind_2_total_amount * exit_rate * (1 - trade_fee_close)
      grind_2_current_grind_profit_stake = grind_2_current_grind_stake - grind_2_total_cost
      grind_2_current_grind_profit_rate = (exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
    if grind_3_sub_grind_count > 0:
      grind_3_current_open_rate = grind_3_total_cost / grind_3_total_amount
      grind_3_current_grind_stake = grind_3_total_amount * exit_rate * (1 - trade_fee_close)
      grind_3_current_grind_profit_stake = grind_3_current_grind_stake - grind_3_total_cost
      grind_3_current_grind_profit_rate = (exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
    if grind_4_sub_grind_count > 0:
      grind_4_current_open_rate = grind_4_total_cost / grind_4_total_amount
      grind_4_current_grind_stake = grind_4_total_amount * exit_rate * (1 - trade_fee_close)
      grind_4_current_grind_profit_stake = grind_4_current_grind_stake - grind_4_total_cost
      grind_4_current_grind_profit_rate = (exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
    if grind_5_sub_grind_count > 0:
      grind_5_current_open_rate = grind_5_total_cost / grind_5_total_amount
      grind_5_current_grind_stake = grind_5_total_amount * exit_rate * (1 - trade_fee_close)
      grind_5_current_grind_profit_stake = grind_5_current_grind_stake - grind_5_total_cost
      grind_5_current_grind_profit_rate = (exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
    if rebuy_sub_grind_count > 0:
      rebuy_current_open_rate = rebuy_total_cost / rebuy_total_amount
      rebuy_current_grind_stake = rebuy_total_amount * exit_rate * (1 - trade_fee_close)
      rebuy_current_grind_stake_profit = rebuy_current_grind_stake - rebuy_total_cost
    if buyback_1_sub_grind_count > 0:
      buyback_1_current_open_rate = buyback_1_total_cost / buyback_1_total_amount
      buyback_1_current_grind_stake = buyback_1_total_amount * exit_rate * (1 - trade_fee_close)
      buyback_1_current_grind_stake_profit = buyback_1_current_grind_stake - buyback_1_total_cost

    if grind_1_is_exit_found:
      grind_1_exit_distance_ratio = (exit_rate - grind_1_exit_order.safe_price) / grind_1_exit_order.safe_price
    if grind_2_is_exit_found:
      grind_2_exit_distance_ratio = (exit_rate - grind_2_exit_order.safe_price) / grind_2_exit_order.safe_price
    if grind_3_is_exit_found:
      grind_3_exit_distance_ratio = (exit_rate - grind_3_exit_order.safe_price) / grind_3_exit_order.safe_price
    if grind_4_is_exit_found:
      grind_4_exit_distance_ratio = (exit_rate - grind_4_exit_order.safe_price) / grind_4_exit_order.safe_price
    if grind_5_is_exit_found:
      grind_5_exit_distance_ratio = (exit_rate - grind_5_exit_order.safe_price) / grind_5_exit_order.safe_price
    if buyback_1_is_exit_found:
      buyback_1_exit_distance_ratio = (exit_rate - buyback_1_exit_order.safe_price) / buyback_1_exit_order.safe_price
    elif is_derisk_4_found:
      buyback_1_exit_distance_ratio = (exit_rate - derisk_4_order.safe_price) / derisk_4_order.safe_price
    if rebuy_is_exit_found:
      rebuy_exit_distance_ratio = (exit_rate - rebuy_exit_order.safe_price) / rebuy_exit_order.safe_price

    # all buybacks & grinds
    current_open_grind_stake_profit = (
      grind_1_current_grind_profit_stake
      + grind_2_current_grind_profit_stake
      + grind_3_current_grind_profit_stake
      + grind_4_current_grind_profit_stake
      + grind_5_current_grind_profit_stake
      + buyback_1_current_grind_stake_profit
      + rebuy_current_grind_stake_profit
    )
    num_open_grinds_and_buybacks = (
      grind_1_sub_grind_count
      + grind_2_sub_grind_count
      + grind_3_sub_grind_count
      + grind_4_sub_grind_count
      + grind_5_sub_grind_count
      + buyback_1_sub_grind_count
      + rebuy_sub_grind_count
    )

    # not reached the max allowed stake for all grinds
    is_not_trade_max_stake_v4 = current_stake_amount < (slice_amount * self.system_v4_max_stake)

    grind_1_cluster_max_profit_stake = trade.get_custom_data(key="grind_1_cluster_max_profit_stake") or 0.0
    grind_1_cluster_max_profit_rate = trade.get_custom_data(key="grind_1_cluster_max_profit_rate") or 0.0
    if grind_1_current_grind_profit_stake > grind_1_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_1_cluster_max_profit_stake", value=grind_1_current_grind_profit_stake)
    if grind_1_current_grind_profit_rate > grind_1_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_1_cluster_max_profit_rate", value=grind_1_current_grind_profit_rate)

    grind_2_cluster_max_profit_stake = trade.get_custom_data(key="grind_2_cluster_max_profit_stake") or 0.0
    grind_2_cluster_max_profit_rate = trade.get_custom_data(key="grind_2_cluster_max_profit_rate") or 0.0
    if grind_2_current_grind_profit_stake > grind_2_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_2_cluster_max_profit_stake", value=grind_2_current_grind_profit_stake)
    if grind_2_current_grind_profit_rate > grind_2_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_2_cluster_max_profit_rate", value=grind_2_current_grind_profit_rate)

    grind_3_cluster_max_profit_stake = trade.get_custom_data(key="grind_3_cluster_max_profit_stake") or 0.0
    grind_3_cluster_max_profit_rate = trade.get_custom_data(key="grind_3_cluster_max_profit_rate") or 0.0
    if grind_3_current_grind_profit_stake > grind_3_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_3_cluster_max_profit_stake", value=grind_3_current_grind_profit_stake)
    if grind_3_current_grind_profit_rate > grind_3_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_3_cluster_max_profit_rate", value=grind_3_current_grind_profit_rate)

    grind_4_cluster_max_profit_stake = trade.get_custom_data(key="grind_4_cluster_max_profit_stake") or 0.0
    grind_4_cluster_max_profit_rate = trade.get_custom_data(key="grind_4_cluster_max_profit_rate") or 0.0
    if grind_4_current_grind_profit_stake > grind_4_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_4_cluster_max_profit_stake", value=grind_4_current_grind_profit_stake)
    if grind_4_current_grind_profit_rate > grind_4_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_4_cluster_max_profit_rate", value=grind_4_current_grind_profit_rate)

    grind_5_cluster_max_profit_stake = trade.get_custom_data(key="grind_5_cluster_max_profit_stake") or 0.0
    grind_5_cluster_max_profit_rate = trade.get_custom_data(key="grind_5_cluster_max_profit_rate") or 0.0
    if grind_5_current_grind_profit_stake > grind_5_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_5_cluster_max_profit_stake", value=grind_5_current_grind_profit_stake)
    if grind_5_current_grind_profit_rate > grind_5_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_5_cluster_max_profit_rate", value=grind_5_current_grind_profit_rate)

    is_long_extra_checks_entry = (
      grind_entry_retry_time > filled_entries[-1].order_filled_utc
      # and ((current_time - timedelta(hours=6) > filled_orders[-1].order_filled_utc) or (slice_profit < -0.02))
      and (
        (current_time - timedelta(hours=6) > filled_orders[-1].order_filled_utc)
        or (slice_profit < -0.06)
        or (is_derisk_3)
      )
      # and (
      #   (current_stake_amount < (filled_entries[0].cost * 0.50))
      #   or (current_time - timedelta(hours=6) > filled_orders[-1].order_filled_utc)
      #   or (slice_profit < -0.06)
      # )
    )
    # is_long_extra_checks_entry = True
    is_long_grind_entry = None
    is_long_buyback_entry = None
    is_derisk_hold = None

    def long_grind_entry_signal():
      nonlocal is_long_grind_entry
      if is_long_grind_entry is None:
        load_candles()
        is_long_grind_entry = self.long_grind_entry_v4(
          last_candle,
          previous_candle,
          num_open_grinds_and_buybacks,
          slice_profit,
          slice_profit_entry,
          slice_profit_exit,
          True,
        )
        # past the near end of the de-risk range, no grind add while the 4h is at capitulation
        if profit_stake < slice_amount * (
          self.system_v4_derisk_level_1_futures[0] if is_futures_mode else self.system_v4_derisk_level_1_spot[0]
        ) / trade_leverage and self._bad_trade_controller_capitulation(last_candle, False):
          is_long_grind_entry = False
      return is_long_grind_entry

    def long_grind_4_fallback_entry():
      if slice_profit_entry >= -0.06:
        return False
      load_candles()
      if (
        (last_candle["RSI_3"] > 5.0)
        and (last_candle["RSI_3_15m"] > 10.0)
        and (last_candle["RSI_14"] < 35.0)
        and (last_candle["close"] < (last_candle["EMA_20"] * 0.985))
      ):
        self._grind_entry_tag = "g4_fb1"
        return True
      if (
        (num_open_grinds_and_buybacks == 0)
        and (last_candle["RSI_14"] < 30.0)
        and (last_candle["close"] < (last_candle["EMA_20"] * 0.980))
      ):
        self._grind_entry_tag = "g4_fb2"
        return True
      return False

    def long_grind_5_fallback_entry():
      if not (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found) or slice_profit_entry >= -0.06:
        return False
      load_candles()
      if (last_candle["RSI_3"] > 10.0) and (last_candle["RSI_3_15m"] > 20.0) and (last_candle["AROONU_14"] < 50.0):
        self._grind_entry_tag = "g5_fb1"
        return True
      return False

    def long_grind_5_liquidation_entry():
      if not (is_futures_mode and (slice_profit_entry < -0.15) and (trade.liquidation_price is not None)):
        return False
      if (trade.is_short and current_rate > trade.liquidation_price * 0.80) or (
        not trade.is_short and current_rate < trade.liquidation_price * 1.20
      ):
        self._grind_entry_tag = "g5_liq1"
        return True
      return False

    def long_grind_5_liquidation_rescue_entry():
      if (
        self.system_v4_grind_5_liquidation_rescue_enable
        and is_futures_mode
        and (trade.liquidation_price is not None)
        and (trade.liquidation_price > 0.0)
        and (trade.liquidation_price < current_rate < trade.liquidation_price * 1.20)
        and (slice_profit_entry < -self.system_v4_grind_5_liquidation_rescue_threshold)
        and (num_open_grinds_and_buybacks <= 1)
        and (
          trade_stake_amount
          + max(slice_amount * grind_5_stakes[grind_5_sub_grind_count] / trade_leverage, min_stake * 1.5)
          <= slice_amount * self.system_v4_grind_5_liquidation_rescue_max_stake / trade_leverage
        )
      ):
        self._grind_entry_tag = "g5_liq2"
        return True
      return False

    def long_buyback_entry_signal():
      nonlocal is_long_buyback_entry
      if is_long_buyback_entry is None:
        load_candles()
        is_long_buyback_entry = self.long_buyback_entry_v4(last_candle, previous_candle, slice_profit, True)
      return is_long_buyback_entry

    def derisk_hold():
      nonlocal is_derisk_hold
      if is_derisk_hold is None:
        load_candles()
        is_derisk_hold = self._bad_trade_controller_derisk_hold(last_candle, False)
      return is_derisk_hold

    stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
    send_notifications = not is_backtest
    # =========================================================================
    # DE-RISK CONFIGURATION
    # =========================================================================

    if is_system_v4:
      derisk_1_enable = self.system_v4_derisk_level_1_enable
      derisk_2_enable = self.system_v4_derisk_level_2_enable
      derisk_3_enable = self.system_v4_derisk_level_3_enable
      derisk_4_enable = self.system_v4_derisk_level_4_enable
      if is_futures_mode:
        derisk_1_threshold = self.system_v4_derisk_level_1_futures[1]
        derisk_1_stake = self.system_v4_derisk_level_1_stake_futures
        derisk_2_threshold = self.system_v4_derisk_level_2_futures[1]
        derisk_2_stake = self.system_v4_derisk_level_2_stake_futures
        derisk_3_threshold = self.system_v4_derisk_level_3_futures[1]
        derisk_3_stake = self.system_v4_derisk_level_3_stake_futures
        derisk_4_threshold = self.system_v4_derisk_level_4_futures[1]
        derisk_4_stake = self.system_v4_derisk_level_4_stake_futures
      else:
        derisk_1_threshold = self.system_v4_derisk_level_1_spot[1]
        derisk_1_stake = self.system_v4_derisk_level_1_stake_spot
        derisk_2_threshold = self.system_v4_derisk_level_2_spot[1]
        derisk_2_stake = self.system_v4_derisk_level_2_stake_spot
        derisk_3_threshold = self.system_v4_derisk_level_3_spot[1]
        derisk_3_stake = self.system_v4_derisk_level_3_stake_spot
        derisk_4_threshold = self.system_v4_derisk_level_4_spot[1]
        derisk_4_stake = self.system_v4_derisk_level_4_stake_spot
    derisk_enable = self.derisk_enable
    force_derisk_3 = (
      self.system_v4_derisk_level_3_liquidation_enable
      and derisk_enable
      and derisk_3_enable
      and not is_derisk_3_found
      and not is_rebuy_mode
      and is_futures_mode
      and (profit_stake < 0.0)
      and (trade.liquidation_price is not None)
      and (trade.liquidation_price > 0.0)
      and (
        trade.liquidation_price
        < current_rate
        <= trade.liquidation_price * (1.0 + self.system_v4_derisk_level_3_liquidation_distance)
      )
    )
    # ---------------------------------------------------------------------
    # De-risk level 1
    # ---------------------------------------------------------------------
    if (
      derisk_enable
      and derisk_1_enable
      and not (is_derisk_1_found)
      and not is_rebuy_mode
      and not force_derisk_3
      and profit_stake < slice_amount * derisk_1_threshold / trade_leverage
      and not derisk_hold()
    ):
      sell_amount = filled_entries[0].safe_filled * derisk_1_stake * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if send_notifications:
          send_msg(
            notification_msg(
              "de-risk",
              tag="Level 1",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"De-risk Level 1 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_1"
    # ---------------------------------------------------------------------
    # De-risk level 2
    # ---------------------------------------------------------------------
    if (
      derisk_enable
      and derisk_2_enable
      and not is_derisk_2_found
      and not is_rebuy_mode
      and not force_derisk_3
      and profit_stake < slice_amount * derisk_2_threshold / trade_leverage
      and not derisk_hold()
    ):
      sell_amount = filled_entries[0].safe_filled * derisk_2_stake * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if send_notifications:
          send_msg(
            notification_msg(
              "de-risk",
              tag="Level 2",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"De-risk Level 2 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_2"
    # ---------------------------------------------------------------------
    # De-risk level 3
    # ---------------------------------------------------------------------
    if (
      derisk_enable
      and derisk_3_enable
      and not is_derisk_3_found
      and not is_rebuy_mode
      and (force_derisk_3 or (profit_stake < slice_amount * derisk_3_threshold / trade_leverage and not derisk_hold()))
    ):
      sell_amount = filled_entries[0].safe_filled * derisk_3_stake * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if send_notifications:
          send_msg(
            notification_msg(
              "de-risk",
              tag="Level 3",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"De-risk Level 3 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_3"
    # ---------------------------------------------------------------------
    # De-risk level 4
    # ---------------------------------------------------------------------
    if (
      derisk_enable
      and derisk_4_enable
      and not is_derisk_4_found
      and not is_rebuy_mode
      and profit_stake < (slice_amount * derisk_4_threshold / trade_leverage)
    ):
      sell_amount = filled_entries[0].safe_filled * derisk_4_stake * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if send_notifications:
          send_msg(
            notification_msg(
              "de-risk",
              tag="Level 4",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"De-risk Level 4 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_4"

    # Grinding 1

    if (
      (self.system_v4_grind_1_enable)
      # and is_derisk_1_found
      and is_long_extra_checks_entry
      and (grind_1_sub_grind_count < grind_1_max_sub_grinds)
      and (grind_1_sub_grind_count == 0 or (grind_1_distance_ratio < grind_1_sub_thresholds[grind_1_sub_grind_count]))
      and is_not_trade_max_stake_v4
      and (
        long_grind_entry_signal()
        or self._grind_entry_before_derisk(
          False,
          exit_rate,
          grind_1_current_open_rate,
          grind_1_derisk_grinds,
          self.system_v4_grind_1_use_derisk,
        )
      )
    ):
      buy_amount = slice_amount * grind_1_stakes[grind_1_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount <= max_stake:
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-entry",
              tag="grind_1_entry",
              pair=trade_pair,
              rate=current_rate,
              stake_amount=buy_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"Grinding entry (grind_1_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
        )
        order_tag = "grind_1_entry"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    if grind_1_sub_grind_count > 0 and not (
      grind_1_current_grind_profit_rate < (grind_1_profit_threshold + fee_open_rate + fee_close_rate)
    ):
      load_candles()
      ft_exit_amount, tag = self.long_grind_exit_v4(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_1_exit",
        "grind_1_exit",
        fee_open_rate,
        fee_close_rate,
        grind_1_cluster_max_profit_stake,
        grind_1_cluster_max_profit_rate,
        grind_1_current_grind_profit_stake,
        grind_1_current_grind_profit_rate,
        grind_1_total_amount,
        grind_1_profit_threshold,
        grind_1_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v4_grind_1_use_derisk
      and (grind_1_sub_grind_count > 0)
      and (((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate) < grind_1_derisk_grinds)
    ):
      # if (
      #   self.system_v4_grind_1_use_derisk
      #   and (grind_1_sub_grind_count > 0)
      #   and (grind_1_current_grind_profit_stake < (slice_amount * grind_1_derisk_grinds))
      #   and (grind_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_1_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate)
            if grind_1_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_1_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_1_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_1_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_1_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_total_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_1_derisk"
        for grind_entry_id in grind_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 2

    if (
      (self.system_v4_grind_2_enable)
      # and is_derisk_1_found
      and is_long_extra_checks_entry
      and (grind_2_sub_grind_count < grind_2_max_sub_grinds)
      and (grind_2_sub_grind_count == 0 or (grind_2_distance_ratio < grind_2_sub_thresholds[grind_2_sub_grind_count]))
      and is_not_trade_max_stake_v4
      and (
        long_grind_entry_signal()
        or self._grind_entry_before_derisk(
          False,
          exit_rate,
          grind_2_current_open_rate,
          grind_2_derisk_grinds,
          self.system_v4_grind_2_use_derisk,
        )
      )
    ):
      buy_amount = slice_amount * grind_2_stakes[grind_2_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount <= max_stake:
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-entry",
              tag="grind_2_entry",
              pair=trade_pair,
              rate=current_rate,
              stake_amount=buy_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"Grinding entry (grind_2_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
        )
        order_tag = "grind_2_entry"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    if grind_2_sub_grind_count > 0 and not (
      grind_2_current_grind_profit_rate < (grind_2_profit_threshold + fee_open_rate + fee_close_rate)
    ):
      load_candles()
      ft_exit_amount, tag = self.long_grind_exit_v4(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_2_exit",
        "grind_2_exit",
        fee_open_rate,
        fee_close_rate,
        grind_2_cluster_max_profit_stake,
        grind_2_cluster_max_profit_rate,
        grind_2_current_grind_profit_stake,
        grind_2_current_grind_profit_rate,
        grind_2_total_amount,
        grind_2_profit_threshold,
        grind_2_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v4_grind_2_use_derisk
      and (grind_2_sub_grind_count > 0)
      and (((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate) < grind_2_derisk_grinds)
    ):
      # if (
      #   self.system_v4_grind_2_use_derisk
      #   and (grind_2_sub_grind_count > 0)
      #   and (grind_2_current_grind_profit_stake < (slice_amount * grind_2_derisk_grinds))
      #   and (grind_2_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_2_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_2_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate)
            if grind_2_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_2_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_2_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_2_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_2_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_2_total_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_2_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_2_derisk"
        for grind_entry_id in grind_2_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 3

    if (
      (self.system_v4_grind_3_enable)
      # and is_derisk_1_found
      and is_long_extra_checks_entry
      and (grind_3_sub_grind_count < grind_3_max_sub_grinds)
      and (grind_3_sub_grind_count == 0 or (grind_3_distance_ratio < grind_3_sub_thresholds[grind_3_sub_grind_count]))
      and is_not_trade_max_stake_v4
      and (
        long_grind_entry_signal()
        or self._grind_entry_before_derisk(
          False,
          exit_rate,
          grind_3_current_open_rate,
          grind_3_derisk_grinds,
          self.system_v4_grind_3_use_derisk,
        )
      )
    ):
      buy_amount = slice_amount * grind_3_stakes[grind_3_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount <= max_stake:
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-entry",
              tag="grind_3_entry",
              pair=trade_pair,
              rate=current_rate,
              stake_amount=buy_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"Grinding entry (grind_3_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
        )
        order_tag = "grind_3_entry"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    if grind_3_sub_grind_count > 0 and not (
      grind_3_current_grind_profit_rate < (grind_3_profit_threshold + fee_open_rate + fee_close_rate)
    ):
      load_candles()
      ft_exit_amount, tag = self.long_grind_exit_v4(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_3_exit",
        "grind_3_exit",
        fee_open_rate,
        fee_close_rate,
        grind_3_cluster_max_profit_stake,
        grind_3_cluster_max_profit_rate,
        grind_3_current_grind_profit_stake,
        grind_3_current_grind_profit_rate,
        grind_3_total_amount,
        grind_3_profit_threshold,
        grind_3_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v4_grind_3_use_derisk
      and (grind_3_sub_grind_count > 0)
      and (((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate) < grind_3_derisk_grinds)
    ):
      # if (
      #   self.system_v4_grind_3_use_derisk
      #   and (grind_3_sub_grind_count > 0)
      #   and (grind_3_current_grind_profit_stake < (slice_amount * grind_3_derisk_grinds))
      #   and (grind_3_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_3_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_3_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate)
            if grind_3_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_3_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_3_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_3_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_3_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_3_total_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_3_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_3_derisk"
        for grind_entry_id in grind_3_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 4

    if (
      (self.system_v4_grind_4_enable)
      # and is_derisk_1_found
      # and is_long_grind_entry
      and is_long_extra_checks_entry
      and (grind_4_sub_grind_count < grind_4_max_sub_grinds)
      and (grind_4_sub_grind_count == 0 or (grind_4_distance_ratio < grind_4_sub_thresholds[grind_4_sub_grind_count]))
      and is_not_trade_max_stake_v4
      and (
        long_grind_4_fallback_entry()
        or long_grind_entry_signal()
        or self._grind_entry_before_derisk(
          False,
          exit_rate,
          grind_4_current_open_rate,
          grind_4_derisk_grinds,
          self.system_v4_grind_4_use_derisk,
        )
      )
    ):
      buy_amount = slice_amount * grind_4_stakes[grind_4_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount <= max_stake:
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-entry",
              tag="grind_4_entry",
              pair=trade_pair,
              rate=current_rate,
              stake_amount=buy_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"Grinding entry (grind_4_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
        )
        order_tag = "grind_4_entry"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    if grind_4_sub_grind_count > 0 and not (
      grind_4_current_grind_profit_rate < (grind_4_profit_threshold + fee_open_rate + fee_close_rate)
    ):
      load_candles()
      ft_exit_amount, tag = self.long_grind_exit_v4(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_4_exit",
        "grind_4_exit",
        fee_open_rate,
        fee_close_rate,
        grind_4_cluster_max_profit_stake,
        grind_4_cluster_max_profit_rate,
        grind_4_current_grind_profit_stake,
        grind_4_current_grind_profit_rate,
        grind_4_total_amount,
        grind_4_profit_threshold,
        grind_4_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v4_grind_4_use_derisk
      and (grind_4_sub_grind_count > 0)
      and (((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate) < grind_4_derisk_grinds)
    ):
      # if (
      #   self.system_v4_grind_4_use_derisk
      #   and (grind_4_sub_grind_count > 0)
      #   and (grind_4_current_grind_profit_stake < (slice_amount * grind_4_derisk_grinds))
      #   and (grind_4_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_4_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_4_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate)
            if grind_4_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_4_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_4_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_4_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_4_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_4_total_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_4_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_4_derisk"
        for grind_entry_id in grind_4_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 5

    if (
      (self.system_v4_grind_5_enable)
      # and is_derisk_1_found
      # and is_long_grind_entry
      and is_long_extra_checks_entry
      and (grind_5_sub_grind_count < grind_5_max_sub_grinds)
      and (grind_5_sub_grind_count == 0 or (grind_5_distance_ratio < grind_5_sub_thresholds[grind_5_sub_grind_count]))
      and is_not_trade_max_stake_v4
      and (
        long_grind_5_fallback_entry()
        or long_grind_5_liquidation_entry()
        or long_grind_entry_signal()
        or long_grind_5_liquidation_rescue_entry()
        or self._grind_entry_before_derisk(
          False,
          exit_rate,
          grind_5_current_open_rate,
          grind_5_derisk_grinds,
          self.system_v4_grind_5_use_derisk,
        )
      )
    ):
      buy_amount = slice_amount * grind_5_stakes[grind_5_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount <= max_stake:
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-entry",
              tag="grind_5_entry",
              pair=trade_pair,
              rate=current_rate,
              stake_amount=buy_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"Grinding entry (grind_5_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
        )
        order_tag = "grind_5_entry"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    if grind_5_sub_grind_count > 0 and not (
      grind_5_current_grind_profit_rate < (grind_5_profit_threshold + fee_open_rate + fee_close_rate)
    ):
      load_candles()
      ft_exit_amount, tag = self.long_grind_exit_v4(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_5_exit",
        "grind_5_exit",
        fee_open_rate,
        fee_close_rate,
        grind_5_cluster_max_profit_stake,
        grind_5_cluster_max_profit_rate,
        grind_5_current_grind_profit_stake,
        grind_5_current_grind_profit_rate,
        grind_5_total_amount,
        grind_5_profit_threshold,
        grind_5_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v4_grind_5_use_derisk
      and (grind_5_sub_grind_count > 0)
      and (((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate) < grind_5_derisk_grinds)
    ):
      # if (
      #   self.system_v4_grind_5_use_derisk
      #   and (grind_5_sub_grind_count > 0)
      #   and (grind_5_current_grind_profit_stake < (slice_amount * grind_5_derisk_grinds))
      #   and (grind_5_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_5_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_5_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate)
            if grind_5_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_5_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_5_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_5_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_5_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_5_total_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_5_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_5_derisk"
        for grind_entry_id in grind_5_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Buyback 1

    if (
      self.system_v4_buyback_1_enable
      and is_system_v4
      and is_derisk_4_found
      # and is_long_extra_checks_entry
      and (buyback_1_current_open_rate == 0)
      and (
        (
          buyback_1_exit_distance_ratio
          < (
            self.system_v4_buyback_1_distance_ratio_negative_futures
            if is_futures_mode
            else self.system_v4_buyback_1_distance_ratio_negative_spot
          )
        )
        or (
          buyback_1_exit_distance_ratio
          > (
            self.system_v4_buyback_1_distance_ratio_positive_futures
            if is_futures_mode
            else self.system_v4_buyback_1_distance_ratio_positive_spot
          )
        )
      )
      and is_not_trade_max_stake_v4
      and long_buyback_entry_signal()
    ):
      buy_amount = (
        slice_amount
        * (self.system_v4_buyback_1_stake_futures if is_futures_mode else self.system_v4_buyback_1_stake_spot)
        / trade_leverage
      )
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      if send_notifications:
        send_msg(
          notification_msg(
            "buyback-entry",
            tag="buyback_1_entry",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
      log.info(
        f"Buyback entry (buyback_1_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "buyback_1_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    # if buyback_1_sub_grind_count > 0:
    #   grind_profit = (exit_rate - buyback_1_current_open_rate) / buyback_1_current_open_rate
    #   if (
    #     grind_profit
    #     > (
    #       (
    #         self.system_v4_buyback_1_profit_threshold_futures
    #         if self.is_futures_mode
    #         else self.system_v4_buyback_1_profit_threshold_spot
    #       )
    #       + fee_open_rate
    #       + fee_close_rate
    #     )
    #   ) and self.long_grind_exit_v2(last_candle, previous_candle, slice_profit, True):
    #     sell_amount = buyback_1_total_amount * exit_rate / trade.leverage
    #     if ((current_stake_amount / trade.leverage) - sell_amount) < (min_stake * 1.55):
    #       sell_amount = (trade.amount * exit_rate / trade.leverage) - (min_stake * 1.55)
    #     ft_sell_amount = sell_amount * trade.leverage * (trade.stake_amount / trade.amount) / exit_rate
    #     if sell_amount > min_stake and ft_sell_amount > min_stake:
    #       self.dp.send_msg(
    #         self.notification_msg(
    #           "buyback-exit",
    #           tag="buyback_1_exit",
    #           pair=trade.pair,
    #           rate=exit_rate,
    #           stake_amount=sell_amount,
    #           profit_stake=profit_stake,
    #           profit_ratio=profit_ratio,
    #           stake_currency=self.config["stake_currency"],
    #           grind_profit_stake=grind_profit * sell_amount * trade.leverage,
    #           grind_profit_pct=grind_profit,
    #           coin_amount=buyback_1_total_amount,
    #         )
    #       )
    #       log.info(
    #         f"Buyback exit (buyback_1_exit) [{current_time}] [{trade.pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade.leverage} {self.config['stake_currency']})"
    #       )
    #       order_tag = "buyback_1_exit"
    #       for grind_entry_id in buyback_1_buy_orders:
    #         order_tag += " " + str(grind_entry_id)
    #       if has_order_tags:
    #         return -ft_sell_amount, order_tag
    #       else:
    #         return -ft_sell_amount

    # if (
    #   self.grinding_v2_buyback_1_use_derisk
    #   and (buyback_1_sub_grind_count > 0)
    #   and (
    #     ((exit_rate - buyback_1_current_open_rate) / buyback_1_current_open_rate)
    #     < (
    #       self.grinding_v2_buyback_1_derisk_futures if self.is_futures_mode else self.grinding_v2_buyback_1_derisk_spot
    #     )
    #   )
    #   and (buyback_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.system_v4_buyback_1_use_derisk
      and (buyback_1_sub_grind_count > 0)
      and (
        buyback_1_current_grind_stake_profit
        < (
          slice_amount
          * (self.system_v4_buyback_1_derisk_futures if is_futures_mode else self.system_v4_buyback_1_derisk_spot)
        )
      )
    ):
      sell_amount = buyback_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if buyback_1_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - buyback_1_current_open_rate) / buyback_1_current_open_rate)
            if buyback_1_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "buyback-derisk",
              tag="buyback_1_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=buyback_1_current_grind_stake_profit,
              grind_profit_pct=grind_profit,
              coin_amount=buyback_1_total_amount,
            )
          )
        log.info(
          f"Buyback de-risk (buyback_1_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {buyback_1_total_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({buyback_1_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "buyback_1_derisk"
        for grind_entry_id in buyback_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Rebuy

    # if (
    #   is_system_v4_1
    #   and is_long_rebuy_entry
    #   and (
    #     (0 <= rebuy_sub_grind_count < rebuy_max_sub_grinds)
    #     and (slice_profit_entry < rebuy_sub_thresholds[rebuy_sub_grind_count])
    #   )
    #   and is_not_trade_max_stake_v4_1
    # ):
    #   buy_amount = slice_amount * rebuy_stakes[rebuy_sub_grind_count] / trade_leverage
    #   if buy_amount < (min_stake * 1.5):
    #     buy_amount = min_stake * 1.5
    #   if buy_amount > max_stake:
    #     return None
    #   if send_notifications:
    #     send_msg(
    #       notification_msg(
    #         "rebuy",
    #         tag="rebuy_entry",
    #         pair=trade_pair,
    #         rate=current_rate,
    #         stake_amount=buy_amount,
    #         profit_stake=profit_stake,
    #         profit_ratio=profit_ratio,
    #         stake_currency=stake_currency,
    #       )
    #     )
    #   log.info(
    #     f"Rebuy (rebuy_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
    #   )
    #   if has_order_tags:
    #     return buy_amount, "rebuy_entry"
    #   else:
    #     return buy_amount

    return None

  def long_grind_entry_v4(
    self,
    last_candle: Series,
    previous_candle: Series,
    num_open_grinds_and_buybacks: int,
    slice_profit: float,
    slice_profit_entry: float,
    slice_profit_exit: float,
    is_derisk: bool,
  ) -> float:
    if last_candle["protections_long_global"] != True:
      return False
    # g0 — signal entry
    if last_candle["enter_long"] == True:
      self._grind_entry_tag = "g0"
      return True

    last_close = last_candle["close"]
    last_open = last_candle["open"]
    last_close_min_12 = last_candle["close_min_12"]
    last_close_max_48 = last_candle["close_max_48"]
    last_high_max_24_1h = last_candle["high_max_24_1h"]
    last_low_min_12_4h = last_candle["low_min_12_4h"]
    last_low_min_24_4h = last_candle["low_min_24_4h"]
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_3_15m = last_candle["RSI_3_15m"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_rsi_3_4h = last_candle["RSI_3_4h"]
    last_rsi_3_1d = last_candle["RSI_3_1d"]
    last_rsi_14 = last_candle["RSI_14"]
    last_rsi_14_1h = last_candle["RSI_14_1h"]
    last_rsi_14_4h = last_candle["RSI_14_4h"]
    last_rsi_20 = last_candle["RSI_20"]
    last_sma_9 = last_candle["SMA_9"]
    last_sma_16 = last_candle["SMA_16"]
    last_sma_21 = last_candle["SMA_21"]
    last_sma_30 = last_candle["SMA_30"]
    last_ema_9 = last_candle["EMA_9"]
    last_ema_12 = last_candle["EMA_12"]
    last_ema_16 = last_candle["EMA_16"]
    last_ema_20 = last_candle["EMA_20"]
    last_ema_26 = last_candle["EMA_26"]
    last_ema_100 = last_candle["EMA_100"]
    last_ema_12_4h = last_candle["EMA_12_4h"]
    last_ema_50_4h = last_candle["EMA_50_4h"]
    last_ema_100_4h = last_candle["EMA_100_4h"]
    last_ema_200_4h = last_candle["EMA_200_4h"]
    last_aroonu_14 = last_candle["AROONU_14"]
    last_aroonu_14_15m = last_candle["AROONU_14_15m"]
    last_aroonu_14_1h = last_candle["AROONU_14_1h"]
    last_aroonu_14_4h = last_candle["AROONU_14_4h"]
    last_aroonu_14_1d = last_candle["AROONU_14_1d"]
    last_roc_9_1h = last_candle["ROC_9_1h"]
    last_roc_9_4h = last_candle["ROC_9_4h"]
    last_roc_9_1d = last_candle["ROC_9_1d"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_stochrsi_k_15m = last_candle["STOCHRSIk_14_14_3_3_15m"]
    last_stochrsi_k_1h = last_candle["STOCHRSIk_14_14_3_3_1h"]
    last_stochrsi_k_4h = last_candle["STOCHRSIk_14_14_3_3_4h"]
    last_stochrsi_k_1d = last_candle["STOCHRSIk_14_14_3_3_1d"]
    last_willr_14 = last_candle["WILLR_14"]
    last_willr_84_1h = last_candle["WILLR_84_1h"]
    last_bbl_20 = last_candle["BBL_20_2.0"]
    last_bbands_20_1h = last_candle["BBB_20_2.0_1h"]
    last_cmf_20 = last_candle["CMF_20"]
    prev_rsi_20 = previous_candle["RSI_20"]
    prev_sma_9 = previous_candle["SMA_9"]
    prev_sma_21 = previous_candle["SMA_21"]
    prev_ema_12 = previous_candle["EMA_12"]
    prev_ema_26 = previous_candle["EMA_26"]

    # g1 — AROONU dip + EMA_16 drop
    if (
      (last_rsi_3 > 10.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_3_1h > 15.0)
      and (last_rsi_3_4h > 15.0)
      and (last_rsi_14 < 45.0)
      and (last_aroonu_14 < 25.0)
      and (last_aroonu_14_4h < 100.0)
      and (last_roc_9_1h < 20.0)
      and (last_close > (last_close_max_48 * 0.90))
      and (last_close < (last_low_min_24_4h * 1.60))
      and (last_close < (last_ema_16 * 0.975))
      and ((last_rsi_3_1h > 35.0) or (last_aroonu_14_1h < 100.0))
      and ((last_aroonu_14_1h < 100.0) or (last_aroonu_14_1d < 100.0))
      and ((last_aroonu_14_1d < 100.0) or (last_stochrsi_k_1h < 90.0))
    ):
      self._grind_entry_tag = "g1"
      return True
    # g2 — EMA_26 > EMA_12 divergence + BBL
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 15.0)
      and (last_rsi_3_4h > 15.0)
      and (last_rsi_14 < 30.0)
      and (last_stochrsi_k < 30.0)
      and (last_ema_26 > last_ema_12)
      and ((last_ema_26 - last_ema_12) > (last_open * 0.020))
      and ((prev_ema_26 - prev_ema_12) > (last_open / 100.0))
      and (last_close < (last_bbl_20 * 1.010))
    ):
      self._grind_entry_tag = "g2"
      return True
    # g3 — AROONU_15m dip + EMA_12 drop
    if (
      (last_rsi_3 > 10.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 10.0)
      and (last_rsi_3_4h > 15.0)
      and (last_rsi_14 < 35.0)
      and (last_aroonu_14_15m < 25.0)
      and (last_stochrsi_k_15m < 70.0)
      and (last_stochrsi_k_1h < 90.0)
      and (last_roc_9_1h > -15.0)
      and (last_roc_9_4h > -15.0)
      and (last_close > (last_close_max_48 * 0.85))
      and (last_close < (last_ema_12 * 0.980))
      and ((last_rsi_3_1h > 20.0) or (last_rsi_3_1d > 20.0))
      and ((last_rsi_3_1h > 20.0) or (last_stochrsi_k_1d < 70.0))
      and ((last_rsi_3_1h > 25.0) or (last_stochrsi_k_1h < 70.0))
      and ((last_rsi_3_4h > 30.0) or (last_stochrsi_k_4h < 60.0))
    ):
      self._grind_entry_tag = "g3"
      return True
    # g4 — multi-TF RSI + EMA_26 + BBL
    if (
      (last_rsi_3 > 10.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 10.0)
      and (last_rsi_3_4h > 10.0)
      and (last_rsi_3_1d > 10.0)
      and (last_rsi_14 < 35.0)
      and (last_aroonu_14 < 25.0)
      and (last_roc_9_1h > -20.0)
      and (last_roc_9_4h > -20.0)
      # and (last_close > (last_close_max_48 * 0.90))
      and (last_close < (last_ema_26 * 0.970))
      and (last_close < (last_bbl_20 * 0.999))
    ):
      self._grind_entry_tag = "g4"
      return True
    # g5 — deep dip + EMA_9/20
    if (
      (last_rsi_3 > 10.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 15.0)
      and (last_rsi_3_4h > 15.0)
      and (last_rsi_14 < 35.0)
      and (last_aroonu_14 < 30.0)
      and (last_roc_9_4h > -20.0)
      and (last_close > (last_high_max_24_1h * 0.80))
      and (last_close < (last_low_min_12_4h * 1.50))
      and (last_close < (last_ema_9 * 0.975))
      and (last_close < (last_ema_20 * 0.970))
    ):
      self._grind_entry_tag = "g5"
      return True
    # g6 — RSI_20 falling + SMA_16 drop
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3 < 40.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_14 > 35.0)
      and (last_roc_9_1h > -20.0)
      and (last_roc_9_4h > -20.0)
      and (last_aroonu_14 < 25.0)
      and (last_close < (last_low_min_12_4h * 1.60))
      and (last_rsi_20 < prev_rsi_20)
      and (last_close < (last_sma_16 * 0.960))
      and ((last_aroonu_14_1d < 100.0) or (last_roc_9_1d < 50.0))
    ):
      self._grind_entry_tag = "g6"
      return True
    # g7 — WILLR deep + BBB wide
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 20.0)
      and (last_rsi_3_1h > 20.0)
      and (last_rsi_3_4h > 20.0)
      and (last_willr_14 < -50.0)
      and (last_willr_84_1h < -70.0)
      and (last_stochrsi_k < 30.0)
      and (last_stochrsi_k_1h < 90.0)
      and (last_roc_9_1h > -10.0)
      and (last_roc_9_1h < 20.0)
      and (last_roc_9_4h > -10.0)
      and (last_close < (last_low_min_24_4h * 1.50))
      and (last_bbands_20_1h > 12.0)
      and (last_close_max_48 >= (last_close * 1.10))
    ):
      self._grind_entry_tag = "g7"
      return True
    # g8 — EMA_26/12 gap wide + low_min_24_1h
    if (
      (last_rsi_3 < 30.0)
      and (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 10.0)
      and (last_rsi_3_4h > 10.0)
      and (last_roc_9_1h > -10.0)
      and (last_roc_9_4h > -25.0)
      # and (last_close < (last_candle["low_min_24_1h"] * 1.30))
      and (last_ema_26 > last_ema_12)
      and ((last_ema_26 - last_ema_12) > (last_open * 0.030))
      and ((prev_ema_26 - prev_ema_12) > (last_open / 100.0))
    ):
      self._grind_entry_tag = "g8"
      return True
    # g9 — pullback recovery
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_3_1h > 20.0)
      and (last_rsi_3_4h > 20.0)
      and (last_stochrsi_k < 50.0)
      and (last_close < (last_close_max_48 * 0.90))
      and (last_close > (last_close_min_12 * 1.03))
    ):
      self._grind_entry_tag = "g9"
      return True
    # g10 — RSI_14 divergence vs 1h
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 20.0)
      and (last_stochrsi_k < 20.0)
      and (last_rsi_14 < (last_rsi_14_1h - 45.0))
    ):
      self._grind_entry_tag = "g10"
      return True
    # g11 — multi-TF RSI + SMA_30 + BBL
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 10.0)
      and (last_cmf_20 > 0.0)
      and (last_close < (last_sma_30 * 0.965))
      and (last_close < (last_bbl_20 * 1.000))
    ):
      self._grind_entry_tag = "g11"
      return True
    # g12 — EMA_26/12 divergence + close_max_48
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_3_1h > 10.0)
      and (last_stochrsi_k < 30.0)
      and (last_close > (last_close_max_48 * 0.90))
      and (last_close < (last_low_min_12_4h * 1.60))
      and (last_ema_26 > last_ema_12)
      and ((last_ema_26 - last_ema_12) > (last_open * 0.025))
      and ((prev_ema_26 - prev_ema_12) > (last_open / 100.0))
    ):
      self._grind_entry_tag = "g12"
      return True
    # g13 — SMA_9 cross SMA_21 + EMA_100 drop
    if (
      (last_rsi_3 > 5.0)
      and (last_rsi_3_1h > 20.0)
      and (last_rsi_14_1h > 40.0)
      and (last_stochrsi_k_15m < 80.0)
      and (last_roc_9_1h > -15.0)
      and (last_roc_9_4h > -15.0)
      and (prev_sma_9 < prev_sma_21)
      and (last_sma_9 > last_sma_21)
      and (last_close < (last_ema_100 * 0.975))
      and ((last_rsi_3_4h > 30.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_4h > 40.0) or (last_roc_9_4h < 30.0))
    ):
      self._grind_entry_tag = "g13"
      return True
    # g14 — SMA_9 cross SMA_21 + 4h uptrend (trend follower)
    if (
      (last_rsi_3 > 5.0)
      and (last_aroonu_14_15m < 50.0)
      and (last_stochrsi_k < 40.0)
      and (last_stochrsi_k_15m < 70.0)
      and (prev_sma_9 < prev_sma_21)
      and (last_sma_9 > last_sma_21)
      and (last_ema_12_4h > last_ema_200_4h)
      and (last_close > (last_close_max_48 * 0.90))
      and ((last_rsi_3_1h > 30.0) or (last_stochrsi_k_1h < 70.0))
      and ((last_rsi_3_1h > 40.0) or (last_aroonu_14_1h < 80.0))
      and ((last_rsi_3_1h > 55.0) or (last_stochrsi_k_1h < 70.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1d > 25.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_stochrsi_k_1h < 80.0) or (last_stochrsi_k_1d < 90.0))
    ):
      self._grind_entry_tag = "g14"
      return True
    # g15 — deep loss recovery (slice_profit < -0.16)
    if (
      (slice_profit < -0.16)
      and (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 10.0)
      and (last_rsi_14 < 40.0)
      and (last_aroonu_14 < 25.0)
      and (last_aroonu_14_15m < 30.0)
      and (last_stochrsi_k < 30.0)
      and (last_stochrsi_k_15m < 30.0)
      and ((last_rsi_3_1h > 30.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_rsi_3_4h > 30.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1d > 30.0) or (last_stochrsi_k_1d < 80.0))
    ):
      self._grind_entry_tag = "g15"
      return True
    # g16 — EMA_12 drop + BBL
    if (
      (last_rsi_3 > 8.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_3_1h > 15.0)
      and (last_rsi_3_4h > 15.0)
      and (last_rsi_14 < 35.0)
      and (last_close < (last_ema_12 * 0.965))
      and (last_close < (last_bbl_20 * 0.999))
    ):
      self._grind_entry_tag = "g16"
      return True
    # g17 — StochRSI + EMA_20 drop
    if (
      (last_rsi_3 > 15.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_3_1h > 15.0)
      and (last_rsi_3_4h > 15.0)
      and (last_rsi_14 < 30.0)
      and (last_stochrsi_k < 30.0)
      and (last_close < (last_ema_20 * 0.975))
      and ((last_aroonu_14_4h < 100.0) or (last_aroonu_14_1d < 100.0))
    ):
      self._grind_entry_tag = "g17"
      return True
    # g18 — moderate loss recovery (slice_profit < -0.10)
    if (
      (slice_profit < -0.10)
      and (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_3_1h > 20.0)
      and (last_rsi_3_4h > 20.0)
      and (last_rsi_14 < 40.0)
      and (last_close < (last_ema_26 * 0.970))
      and (last_close < (last_bbl_20 * 0.999))
    ):
      self._grind_entry_tag = "g18"
      return True
    # g19 — EMA_26/12 wide gap (slice_profit < -0.06)
    if (
      (slice_profit < -0.06)
      and (last_rsi_3 < 30.0)
      and (last_rsi_3 > 5.0)
      and (last_rsi_3_15m > 10.0)
      and (last_ema_26 > last_ema_12)
      and ((last_ema_26 - last_ema_12) > (last_open * 0.035))
      and ((prev_ema_26 - prev_ema_12) > (last_open / 100.0))
    ):
      self._grind_entry_tag = "g19"
      return True
    # AROONU 4h uptrend pullback recovery
    if (
      (last_rsi_3 > 10.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_3_1h > 20.0)
      and (last_rsi_14 < 42.0)
      and (last_rsi_14_4h > 50.0)
      and (last_aroonu_14 < 30.0)
      and (last_aroonu_14_4h > 50.0)
      and (last_roc_9_1d > -15.0)
      and (last_ema_50_4h > last_ema_100_4h)
      and (last_close < (last_close_max_48 * 0.95))
      and ((last_rsi_3_15m > 20.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1h > 30.0) or (last_roc_9_4h < 30.0) or (last_roc_9_1d < 30.0))
      and ((last_rsi_3_1h > 50.0) or (last_roc_9_1d < 60.0))
      and ((last_rsi_3_4h > 40.0) or (last_aroonu_14_4h < 90.0))
      and ((last_rsi_3_4h > 45.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_4h > 60.0) or (last_roc_9_4h < 40.0))
      and ((last_aroonu_14_4h < 100.0) or (last_stochrsi_k_1d < 80.0))
      and ((last_aroonu_14_4h < 100.0) or (last_aroonu_14_1d < 100.0))
      and ((last_stochrsi_k_4h < 90.0) or (last_roc_9_4h < 30.0))
    ):
      self._grind_entry_tag = "g20"
      return True
    if (
      (slice_profit_entry < -0.02)
      and (last_rsi_3 > 10.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_14 < 35.0)
      and (last_aroonu_14_15m < 50.0)
      and (last_close < (last_ema_20 * 0.955))
    ):
      self._grind_entry_tag = "g21"
      return True
    # g22 — early recovery rebuild: reclaiming off the low BEFORE the 4h trend confirms (g14 needs
    #        EMA_12_4h > EMA_200_4h and fires too late for a deep-derisk bounce). Anti-fake-rise gating via
    #        multi-TF RSI recovery + reclaim off the 4h low + not-extended. NOTE: slice_profit_entry gate
    #        removed — it self-defeats in recovery (last grind buy is in profit); underwater-scope TBD.
    if (
      (last_rsi_3 > 30.0)
      and (last_rsi_3_15m > 30.0)
      and (last_rsi_14 > 45.0)
      and (last_rsi_14_1h > 45.0)
      and (last_roc_9_1h > 0.0)
      and (last_roc_9_4h > -10.0)
      # anti-parabolic: even at a formed bottom, a parabolic 4h overshoot reverses (dead-cat).
      # cross-coin (SFP/CELR/DYDX/APE): cuts 17 severe at ~1% good cost within recovery-starts.
      and (last_roc_9_4h < 25.0)
      # recovery-started gate: only rebuild once the 4h bottom is IN (not still making new lows).
      # g22's job is the recovery rebuild — NOT entering mid-dump (that's g1..g21). AROOND high =
      # a fresh 4h low was just made = still dumping; require it low = bottom formed = recovery start.
      and (last_aroonu_14_4h < 50.0)
      # aggressive risk-free: g22 fires ONLY deep below the 4h 200-EMA (fresh recovery zone). The
      # near/above-EMA overextended-bounce zone is where dead-cats live AND where g22's late-recovery
      # adds sit — we sacrifice those wins on purpose, because g23 (extended-continuation, ~0.2% severe)
      # backstops the real recoveries above. So g22 stays clean, g23 captures the continuation.
      and (last_close < last_ema_200_4h)
      and (last_close > (last_low_min_12_4h * 1.10))
      and (last_close > (last_ema_20 * 0.97))
      and (last_close < (last_ema_20 * 1.02))
      and ((last_rsi_3_1h > 30.0) or (last_stochrsi_k_1d < 80.0))
      and ((last_rsi_3_1h > 35.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_4h > 50.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1d > 10.0) or (last_aroonu_14_1d < 70.0))
      and ((last_rsi_3_1d > 10.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1d > 15.0) or (last_aroonu_14_1h < 70.0))
      and ((last_rsi_3_1d > 40.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_rsi_3_1d > 40.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1d > 45.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1d > 45.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_1d > 45.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_rsi_3_1d > 45.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 50.0) or (last_aroonu_14_15m < 100.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1d > 65.0) or (last_aroonu_14_1h < 70.0) or (last_aroonu_14_1d < 90.0))
      and ((last_aroonu_14_15m < 70.0) or (last_aroonu_14_1h < 100.0))
      and ((last_aroonu_14_15m < 80.0) or (last_stochrsi_k_15m < 80.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1h < 80.0) or (last_stochrsi_k_1h < 80.0) or (last_stochrsi_k_1d < 90.0))
      and ((last_aroonu_14_1h < 100.0) or (last_stochrsi_k_1d < 80.0))
      and ((last_stochrsi_k_1h < 50.0) or (last_roc_9_1d > -40.0))
      and ((last_roc_9_1d > -20.0) or (last_aroonu_14_4h < 100.0))
      and ((last_roc_9_1d > -20.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_roc_9_1d > -30.0) or (last_stochrsi_k_1h < 90.0))
    ):
      self._grind_entry_tag = "g22"
      return True
    # g23 — pump-continuation scalp: extended zone ABOVE g22's EMA_20*1.02 cap. Only rides a CONFIRMED
    # continuation (price already advancing past the reclaim), so dead-cats (which roll over before
    # reaching the extended zone) are structurally avoided. Complements g22: g22 = early recovery-start
    # (ambiguous zone, dead-cat risk trimmed by P1), g23 = confirmed continuation (clean, ~0.2% severe).
    if (
      (last_rsi_3 > 30.0)
      and (last_rsi_3_15m > 30.0)
      and (last_rsi_14 > 50.0)
      and (last_rsi_14_1h > 50.0)
      and (last_roc_9_1h > 0.0)
      and (last_roc_9_4h > 0.0)
      # anti-parabolic blow-off + anti-exhaustion top
      and (last_roc_9_4h < 25.0)
      and ((last_stochrsi_k < 97.0) or (last_rsi_14 < 80.0))
      and (last_close > (last_low_min_12_4h * 1.10))
      # extended zone: above g22's 1.02*EMA cap = continuation confirmed, not a reclaim
      and (last_close >= (last_ema_20 * 1.02))
      and (last_close < (last_ema_20 * 1.12))
      and ((last_rsi_3_1h > 45.0) or (last_aroonu_14_4h < 80.0))
      and ((last_rsi_3_1h > 65.0) or (last_aroonu_14_15m < 60.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 65.0) or (last_stochrsi_k_15m < 60.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_4h > 40.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_rsi_3_4h > 50.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_1d > 15.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_rsi_3_1d > 30.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1d > 30.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_1d > 40.0) or (last_aroonu_14_15m < 80.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1d > 50.0) or (last_stochrsi_k_1h < 80.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 55.0) or (last_aroonu_14_15m < 100.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_aroonu_14_15m < 80.0) or (last_aroonu_14_1h < 100.0) or (last_roc_9_1d < 10.0))
      and ((last_aroonu_14_15m < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_1h < 100.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_4h < 100.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_1d < 90.0) or (last_roc_9_1d < 20.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_1d < 100.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_15m < 90.0) or (last_stochrsi_k_1d < 70.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_aroonu_14_1h < 80.0) or (last_aroonu_14_4h < 100.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_aroonu_14_1h < 100.0) or (last_aroonu_14_4h < 100.0))
      and ((last_aroonu_14_4h < 70.0) or (last_aroonu_14_1d < 100.0) or (last_roc_9_4h < 10.0))
      and ((last_aroonu_14_4h < 70.0) or (last_roc_9_1d < 50.0))
      and ((last_aroonu_14_4h < 100.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_aroonu_14_4h < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1d < 100.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_stochrsi_k_15m < 80.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_stochrsi_k_15m < 90.0) or (last_aroonu_14_1h < 100.0))
      and ((last_stochrsi_k_15m < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_stochrsi_k_1h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_stochrsi_k_1h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_stochrsi_k_1h < 90.0) or (last_stochrsi_k_1d < 90.0))
    ):
      self._grind_entry_tag = "g23"
      return True
    # g24 — trend-pullback continuation add: the zone ABOVE the 4h 200-EMA that g22 explicitly sacrifices.
    if (
      # momentum healthy on the pullback: RSI holds up (a real reversal cracks RSI hard)
      (last_rsi_3 > 20.0)
      and (last_rsi_3_15m > 20.0)
      and (last_rsi_14 > 40.0)
      # trend intact + this is a PULLBACK not a reversal: 4h still rising, 1h not in freefall
      and (last_roc_9_1h > -10.0)
      and (last_roc_9_4h > 0.0)
      and (last_roc_9_4h < 25.0)  # anti-parabolic blow-off top
      # bull scope-gate: confirmed 4h uptrend + price above the 200-EMA regime (complements g22's <200EMA)
      and (last_ema_12_4h > last_ema_200_4h)
      and (last_close > last_ema_200_4h)
      # shallow pullback to the short EMA — buy the dip WITHIN the trend, never the top nor a deep dump
      and (last_close < (last_ema_20 * 1.01))
      and (last_close > (last_ema_20 * 0.94))
      and ((last_rsi_3_15m > 40.0) or (last_stochrsi_k_15m < 70.0))
      and ((last_rsi_3_1h > 10.0) or (last_rsi_3_4h > 30.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1h > 10.0) or (last_aroonu_14_1h < 60.0))
      and ((last_rsi_3_1h > 15.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_1h > 25.0) or (last_rsi_3_4h > 45.0) or (last_stochrsi_k_4h < 50.0))
      and ((last_rsi_3_1h > 25.0) or (last_aroonu_14_1h < 70.0))
      and ((last_rsi_3_1h > 25.0) or (last_rsi_3_1d > 45.0) or (last_aroonu_14_1d < 70.0))
      and ((last_rsi_3_1h > 25.0) or (last_aroonu_14_1h < 80.0))
      and ((last_rsi_3_1h > 30.0) or (last_rsi_3_4h > 60.0) or (last_aroonu_14_1d < 70.0))
      and ((last_rsi_3_1h > 30.0) or (last_rsi_3_4h > 60.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1h > 30.0) or (last_stochrsi_k_1d < 80.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_1h > 35.0) or (last_rsi_3_4h > 45.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1h > 35.0) or (last_aroonu_14_1h < 60.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_1h > 35.0) or (last_stochrsi_k_1d < 90.0) or (last_roc_9_1d < 20.0))
      and ((last_rsi_3_1h > 40.0) or (last_rsi_3_4h > 40.0) or (last_aroonu_14_1d < 90.0))
      and ((last_rsi_3_1h > 40.0) or (last_rsi_3_4h > 65.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 40.0) or (last_rsi_3_1d > 60.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_1h > 40.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1h > 40.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_1h > 40.0) or (last_aroonu_14_1d < 100.0) or (last_roc_9_1d < 20.0))
      and ((last_rsi_3_1h > 40.0) or (last_stochrsi_k_1d < 80.0) or (last_roc_9_1d < 50.0))
      and ((last_rsi_3_1h > 35.0) or (last_rsi_3_4h > 50.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 40.0) or (last_rsi_3_4h > 55.0) or (last_aroonu_14_4h < 90.0))
      and ((last_rsi_3_1h > 45.0) or (last_rsi_3_4h > 45.0) or (last_rsi_3_1d > 45.0) or (last_stochrsi_k_4h < 50.0))
      and ((last_rsi_3_1h > 45.0) or (last_rsi_3_4h > 45.0) or (last_aroonu_14_4h < 60.0))
      and ((last_rsi_3_1h > 45.0) or (last_aroonu_14_4h < 80.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_1h > 50.0) or (last_rsi_3_4h > 55.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_1h < 80.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_1h < 70.0) or (last_aroonu_14_1d < 70.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_4h < 80.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_4h < 80.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_4h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1h > 55.0) or (last_rsi_3_4h > 55.0) or (last_stochrsi_k_15m < 70.0))
      and ((last_rsi_3_1h > 55.0) or (last_aroonu_14_1h < 80.0) or (last_aroonu_14_4h < 80.0))
      and ((last_rsi_3_1h > 55.0) or (last_stochrsi_k_4h < 90.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_1h > 60.0) or (last_aroonu_14_15m < 70.0) or (last_aroonu_14_4h < 80.0))
      and ((last_rsi_3_1h > 60.0) or (last_stochrsi_k_1h < 60.0) or (last_stochrsi_k_1d < 90.0))
      and ((last_rsi_3_1h > 65.0) or (last_aroonu_14_15m < 70.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1h > 65.0) or (last_aroonu_14_1h < 70.0) or (last_aroonu_14_1d < 90.0))
      and ((last_rsi_3_1h > 65.0) or (last_aroonu_14_1h < 100.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_4h > 25.0) or (last_roc_9_1d < 30.0))
      and ((last_rsi_3_4h > 40.0) or (last_rsi_3_1d > 60.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_4h > 40.0) or (last_aroonu_14_15m < 70.0) or (last_aroonu_14_1d < 90.0))
      and ((last_rsi_3_4h > 40.0) or (last_aroonu_14_1d < 90.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_4h > 40.0) or (last_stochrsi_k_15m < 60.0) or (last_aroonu_14_1d < 90.0))
      and ((last_rsi_3_4h > 45.0) or (last_rsi_3_1d > 45.0) or (last_aroonu_14_15m < 60.0))
      and ((last_rsi_3_4h > 45.0) or (last_rsi_3_1d > 45.0) or (last_stochrsi_k_15m < 60.0))
      and ((last_rsi_3_4h > 45.0) or (last_rsi_3_1d > 45.0) or (last_stochrsi_k_1h < 60.0))
      and ((last_rsi_3_4h > 45.0) or (last_rsi_3_1d > 45.0) or (last_stochrsi_k_4h < 60.0))
      and ((last_rsi_3_4h > 45.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_4h > 50.0) or (last_aroonu_14_4h < 70.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_4h > 50.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_4h > 55.0) or (last_aroonu_14_15m < 70.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_4h > 60.0) or (last_rsi_3_1d > 65.0) or (last_aroonu_14_15m < 70.0))
      and ((last_rsi_3_4h > 60.0) or (last_aroonu_14_15m < 90.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_rsi_3_4h > 60.0) or (last_aroonu_14_15m < 100.0) or (last_stochrsi_k_15m < 80.0))
      and ((last_rsi_3_4h > 60.0) or (last_stochrsi_k_15m < 70.0) or (last_stochrsi_k_1h < 70.0))
      and ((last_rsi_3_4h > 60.0) or (last_stochrsi_k_1h < 60.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_rsi_3_1d > 30.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 35.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_rsi_3_1d > 35.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_rsi_3_1d > 35.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1d > 40.0) or (last_aroonu_14_1h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 45.0) or (last_aroonu_14_15m < 50.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_rsi_3_1d > 45.0) or (last_aroonu_14_1h < 80.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_rsi_3_1d > 45.0) or (last_aroonu_14_1d < 70.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1d > 45.0) or (last_stochrsi_k_1h < 70.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1d > 50.0) or (last_aroonu_14_15m < 60.0) or (last_aroonu_14_1h < 100.0))
      and ((last_rsi_3_1d > 50.0) or (last_aroonu_14_4h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 50.0) or (last_stochrsi_k_15m < 90.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_1d > 50.0) or (last_stochrsi_k_1h < 80.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 60.0) or (last_aroonu_14_1h < 80.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_14_1h < 70.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_15m < 80.0) or (last_aroonu_14_1h < 80.0) or (last_aroonu_14_4h < 80.0))
      and ((last_aroonu_14_15m < 80.0) or (last_stochrsi_k_15m < 70.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_aroonu_14_15m < 80.0) or (last_aroonu_14_1d < 100.0))
      and ((last_aroonu_14_15m < 80.0) or (last_stochrsi_k_15m < 80.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_aroonu_14_15m < 90.0) or (last_aroonu_14_1h < 80.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_aroonu_14_15m < 90.0) or (last_aroonu_14_1h < 100.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_1h < 100.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_4h < 100.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_1d < 80.0) or (last_roc_9_1d < 10.0))
      and ((last_aroonu_14_1h < 70.0) or (last_aroonu_14_4h < 100.0))
      and ((last_aroonu_14_1h < 70.0) or (last_aroonu_14_1d < 90.0) or (last_roc_9_1d < 10.0))
      and ((last_aroonu_14_1h < 80.0) or (last_aroonu_14_4h < 100.0))
      and ((last_aroonu_14_1h < 90.0) or (last_stochrsi_k_1h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1h < 90.0) or (last_stochrsi_k_1h < 90.0) or (last_roc_9_1d < 10.0))
      and ((last_aroonu_14_1h < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1h < 100.0) or (last_stochrsi_k_1d < 90.0))
      and ((last_aroonu_14_4h < 70.0) or (last_aroonu_14_1d < 100.0) or (last_roc_9_1d < 20.0))
      and ((last_aroonu_14_4h < 90.0) or (last_stochrsi_k_4h < 90.0) or (last_roc_9_1d < 10.0))
      and ((last_aroonu_14_4h < 90.0) or (last_roc_9_1d < 30.0))
      and ((last_aroonu_14_4h < 100.0) or (last_aroonu_14_1d < 100.0))
      and ((last_aroonu_14_4h < 100.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_aroonu_14_4h < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1d < 100.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_aroonu_14_1d < 100.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_aroonu_14_1d < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1d < 100.0) or (last_roc_9_4h < 15.0) or (last_roc_9_1d < 50.0))
      # do not buy an overbought top on the bounce
      and ((last_stochrsi_k < 90.0) or (last_rsi_14 < 70.0))
      and ((last_stochrsi_k_15m < 80.0) or (last_stochrsi_k_1h < 80.0) or (last_roc_9_1d < 10.0))
      and ((last_stochrsi_k_15m < 80.0) or (last_aroonu_14_1d < 100.0))
      and ((last_stochrsi_k_15m < 80.0) or (last_stochrsi_k_1d < 90.0) or (last_roc_9_1d < 20.0))
      and ((last_stochrsi_k_15m < 90.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_stochrsi_k_15m < 90.0) or (last_stochrsi_k_1d < 90.0))
      and ((last_stochrsi_k_1h < 80.0) or (last_stochrsi_k_1d < 90.0))
      and ((last_stochrsi_k_1h < 80.0) or (last_roc_9_1d > -20.0))
      and ((last_stochrsi_k_1h < 90.0) or (last_roc_9_4h < 15.0))
      and ((last_stochrsi_k_4h < 90.0) or (last_roc_9_4h < 15.0))
      and ((last_stochrsi_k_4h < 90.0) or (last_roc_9_1d > -15.0))
      and ((last_stochrsi_k_1d < 90.0) or (last_roc_9_4h < 20.0))
    ):
      self._grind_entry_tag = "g24"
      return True
    if (
      (last_rsi_3 > 15.0)
      and (last_rsi_3_15m > 15.0)
      and (last_rsi_14 > 40.0)
      and (last_rsi_14_1h > 40.0)
      # the coil signature: 1h momentum negative-to-flat under a flat price
      and (last_roc_9_1h > -15.0)
      and (last_roc_9_1h < 2.0)
      and (last_close > (last_ema_20 * 0.98))
      and (last_close < (last_ema_20 * 1.02))
      # squeeze integrity: regime still broken, 4h reclaim HELD, not dripping to new lows
      and (last_close < last_ema_200_4h)
      and (last_close > (last_low_min_12_4h * 1.10))
      and (last_close > (last_close_min_12 * 1.005))
      # general protections first
      and ((last_rsi_3_15m > 20.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1h > 15.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_1h > 20.0) or (last_rsi_3_4h > 20.0) or (last_aroonu_14_1d < 90.0))
      and ((last_rsi_3_1h > 20.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_rsi_3_1h > 30.0) or (last_rsi_3_1d > 30.0) or (last_stochrsi_k_1h < 70.0))
      and ((last_rsi_3_1h > 35.0) or (last_aroonu_14_1h < 70.0))
      and ((last_rsi_3_1h > 35.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_1h > 40.0) or (last_aroonu_14_4h < 80.0))
      and ((last_rsi_3_1h > 45.0) or (last_aroonu_14_1h < 90.0) or (last_stochrsi_k_1h < 70.0))
      and ((last_rsi_3_1h > 40.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 45.0) or (last_aroonu_14_1h < 90.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 45.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_1h < 70.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_1h > 55.0) or (last_rsi_3_4h > 60.0) or (last_aroonu_14_4h < 60.0))
      and ((last_rsi_3_1h > 50.0) or (last_aroonu_14_4h < 80.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 50.0) or (last_stochrsi_k_1d < 90.0) or (last_roc_9_1d < 30.0))
      and ((last_rsi_3_1h > 55.0) or (last_aroonu_14_4h < 80.0) or (last_aroonu_14_1d < 100.0))
      and ((last_rsi_3_1h > 55.0) or (last_aroonu_14_4h < 90.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_rsi_3_1h > 60.0) or (last_rsi_3_1d > 60.0) or (last_aroonu_14_1h < 80.0))
      and ((last_rsi_3_1h > 60.0) or (last_stochrsi_k_4h < 70.0) or (last_stochrsi_k_1d < 80.0))
      and ((last_rsi_3_1h > 60.0) or (last_stochrsi_k_4h < 80.0) or (last_roc_9_4h < 10.0))
      and ((last_rsi_3_4h > 10.0) or (last_rsi_3_1d > 40.0) or (last_stochrsi_k_15m < 80.0))
      and ((last_rsi_3_4h > 25.0) or (last_stochrsi_k_4h < 50.0) or (last_roc_9_4h < 10.0))
      and ((last_rsi_3_4h > 35.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_4h > 40.0) or (last_rsi_3_1d > 40.0) or (last_aroonu_14_15m < 70.0))
      and ((last_rsi_3_4h > 40.0) or (last_aroonu_14_15m < 100.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_rsi_3_4h > 40.0) or (last_aroonu_14_1h < 90.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_4h > 40.0) or (last_aroonu_14_4h < 70.0))
      and ((last_rsi_3_4h > 50.0) or (last_aroonu_14_15m < 80.0) or (last_aroonu_14_4h < 80.0))
      and ((last_rsi_3_4h > 50.0) or (last_stochrsi_k_15m < 70.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_4h > 55.0) or (last_aroonu_14_1h < 100.0) or (last_aroonu_14_1d < 80.0))
      and ((last_rsi_3_4h > 60.0) or (last_rsi_3_1d > 60.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_rsi_3_4h > 60.0) or (last_aroonu_14_15m < 70.0) or (last_aroonu_14_1h < 70.0))
      and ((last_rsi_3_4h > 60.0) or (last_aroonu_14_1h < 100.0) or (last_stochrsi_k_1d < 80.0))
      and ((last_rsi_3_4h > 60.0) or (last_stochrsi_k_4h < 70.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_4h > 65.0) or (last_aroonu_14_1h < 70.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_4h > 65.0) or (last_aroonu_14_4h < 80.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_4h > 65.0) or (last_stochrsi_k_4h < 70.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_4h > 65.0) or (last_stochrsi_k_4h < 90.0) or (last_roc_9_4h < 10.0))
      and ((last_rsi_3_1d > 10.0) or (last_stochrsi_k_4h < 70.0))
      and ((last_rsi_3_1d > 20.0) or (last_aroonu_14_1d < 90.0))
      and ((last_rsi_3_1d > 25.0) or (last_stochrsi_k_15m < 70.0))
      and ((last_rsi_3_1d > 25.0) or (last_aroonu_14_1h < 70.0))
      and ((last_rsi_3_1d > 25.0) or (last_stochrsi_k_1h < 90.0))
      and ((last_rsi_3_1d > 30.0) or (last_aroonu_14_15m < 100.0))
      and ((last_rsi_3_1d > 30.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_rsi_3_1d > 40.0) or (last_aroonu_14_1h < 90.0) or (last_aroonu_14_4h < 100.0))
      and ((last_rsi_3_1d > 50.0) or (last_stochrsi_k_4h < 90.0) or (last_stochrsi_k_1d < 70.0))
      and ((last_aroonu_14_15m < 70.0) or (last_aroonu_14_1h < 100.0) or (last_stochrsi_k_1d < 80.0))
      and ((last_aroonu_14_15m < 70.0) or (last_aroonu_14_4h < 70.0) or (last_roc_9_4h < 10.0))
      and ((last_aroonu_14_15m < 80.0) or (last_stochrsi_k_15m < 70.0))
      and ((last_aroonu_14_15m < 80.0) or (last_aroonu_14_1h < 100.0))
      and ((last_aroonu_14_15m < 100.0) or (last_aroonu_14_4h < 90.0))
      and ((last_aroonu_14_15m < 100.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_1h < 80.0) or (last_aroonu_14_4h < 100.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_aroonu_14_1h < 80.0) or (last_stochrsi_k_4h < 100.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_aroonu_14_1h < 80.0) or (last_stochrsi_k_4h < 90.0) or (last_roc_9_4h < 10.0))
      and ((last_aroonu_14_1h < 100.0) or (last_aroonu_14_1d < 100.0))
      and ((last_aroonu_14_1h < 100.0) or (last_stochrsi_k_15m < 80.0))
      and ((last_aroonu_14_1h < 100.0) or (last_stochrsi_k_4h < 80.0) or (last_roc_9_4h < 10.0))
      and ((last_aroonu_14_1h < 100.0) or (last_stochrsi_k_1d < 90.0) or (last_roc_9_1d < 20.0))
      and ((last_aroonu_14_4h < 70.0) or (last_roc_9_1d > -25.0))
      and ((last_aroonu_14_4h < 70.0) or (last_roc_9_1d < 50.0))
      and ((last_aroonu_14_4h < 80.0) or (last_stochrsi_k_4h < 80.0) or (last_roc_9_4h < 10.0))
      and ((last_aroonu_14_4h < 80.0) or (last_stochrsi_k_1d < 80.0) or (last_roc_9_1d < 10.0))
      and ((last_aroonu_14_4h < 90.0) or (last_stochrsi_k_4h < 90.0))
      and ((last_aroonu_14_4h < 90.0) or (last_roc_9_4h < 10.0))
      and ((last_stochrsi_k_15m < 60.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_stochrsi_k_1h < 70.0) or (last_stochrsi_k_4h < 80.0))
      and ((last_stochrsi_k_1h < 90.0) or (last_roc_9_4h > -20.0))
      and ((last_stochrsi_k_4h < 70.0) or (last_roc_9_1d > -25.0))
      and ((last_stochrsi_k_4h < 80.0) or (last_stochrsi_k_1d < 90.0) or (last_roc_9_1d < 20.0))
      and ((last_roc_9_1d > -40.0) or (last_aroonu_14_1h < 90.0))
      and ((last_roc_9_1d > -40.0) or (last_stochrsi_k_1h < 80.0))
      and ((last_roc_9_1d > -25.0) or (last_stochrsi_k_15m < 90.0))
      and ((last_roc_9_1d > -25.0) or (last_aroonu_14_4h < 80.0))
      and ((last_roc_9_1d > -15.0) or (last_stochrsi_k_4h < 80.0))
    ):
      self._grind_entry_tag = "g27"
      return True

    self._grind_entry_tag = ""
    return False

  def long_buyback_entry_v4(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    if (last_candle["protections_long_global"] == True) and (
      (last_candle["enter_long"] == True)
      or (
        (last_candle["RSI_3"] > 10.0)
        and (last_candle["RSI_3_15m"] > 10.0)
        and (last_candle["AROONU_14"] < 30.0)
        and (last_candle["AROONU_14_15m"] < 30.0)
      )
    ):
      return True

    return False

  def long_rebuy_entry_v4(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    if (last_candle["protections_long_global"] == True) and (
      (last_candle["enter_long"] == True)
      or (
        (last_candle["RSI_3"] > 10.0)
        and (last_candle["RSI_3_15m"] > 10.0)
        and (last_candle["AROONU_14"] < 30.0)
        and (last_candle["AROONU_14_15m"] < 30.0)
        and (last_candle["close"] < (last_candle["EMA_26"] * 0.988))
      )
    ):
      return True

  def long_grind_exit_v4(
    self,
    last_candle: Series,
    previous_candle: Series,
    slice_profit: float,
    current_time: datetime,
    min_stake: float,
    current_stake_amount: float,
    exit_rate: float,
    profit_stake: float,
    profit_ratio: float,
    name: str,
    tag: str,
    fee_open_rate: float,
    fee_close_rate: float,
    max_profit: float,
    max_profit_rate: float,
    grind_profit_stake: float,
    grind_profit_rate: float,
    grind_total_amount: float,
    grind_exit_profit_threshold: float,
    grind_open_orders,
    trade: Trade,
  ) -> tuple:
    # Already guarded.
    # if grind_profit_rate < (grind_exit_profit_threshold + fee_open_rate + fee_close_rate):
    # return None, None

    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_14 = last_candle["RSI_14"]
    last_willr_14 = last_candle["WILLR_14"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_close = last_candle["close"]
    last_bbu_20 = last_candle["BBU_20_2.0"]

    is_normal_exit = False
    if (
      (last_rsi_3 > 99.0)
      or (last_rsi_14 > 70.0)
      or (last_willr_14 > -0.1)
      or (last_stochrsi_k > 95.0)
      or (last_close > (last_bbu_20 * 1.01))
      or ((last_rsi_3 > 90.0) and (last_rsi_14 < 50.0))
      or (
        (last_rsi_3 > 80.0)
        and (last_candle["RSI_3_1h"] < 20.0)
        and (last_candle["RSI_3_4h"] < 20.0)
        and (last_candle["ROC_9_1d"] > -10.0)
        and (last_candle["BTC_RSI_14_4h"] < 35.0)
      )
    ):
      is_normal_exit = True

    is_trailing_exit = False
    # if 0.01 <= grind_profit_rate < 0.02:
    #   if grind_profit_rate < (max_profit_rate - 0.025):
    #     is_trailing_exit = True
    # elif 0.02 <= grind_profit_rate <= 0.05:
    #   if grind_profit_rate < (max_profit_rate - 0.035):
    #     is_trailing_exit = True
    # elif 0.05 <= grind_profit_rate <= 0.08:
    #   if grind_profit_rate < (max_profit_rate - 0.045):
    #     is_trailing_exit = True
    # elif 0.08 <= grind_profit_rate <= 0.12:
    #   if grind_profit_rate < (max_profit_rate - 0.050):
    #     is_trailing_exit = True
    # elif 0.12 <= grind_profit_rate:
    #   if grind_profit_rate < (max_profit_rate - 0.055):
    #     is_trailing_exit = True
    # is_trailing_exit = grind_profit_rate > 0.04
    if is_normal_exit or is_trailing_exit:
      stake_currency = self.config["stake_currency"]
      stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
      trade_pair = trade.pair
      trade_leverage = trade.leverage
      trade_amount = trade.amount
      trade_stake_amount = trade.stake_amount
      exit_amount = grind_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - exit_amount) < (min_stake * 1.55):
        exit_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_exit_amount = exit_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if exit_amount > min_stake and ft_exit_amount > min_stake:
        self.dp.send_msg(
          self.notification_msg(
            "grinding-exit",
            tag=name,
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=exit_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit_stake,
            grind_profit_pct=grind_profit_rate,
            coin_amount=grind_total_amount,
          )
        )
        log.info(
          f"Grinding exit ({name}) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {exit_amount:{stake_fmt}} | Coin amount: {grind_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit_rate * 100.0):.2f}% ({grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = tag
        for grind_entry in grind_open_orders:
          order_tag += " " + str(grind_entry.id)
        return -ft_exit_amount, order_tag

    return None, None

  # Long Grinding Adjust Trade Position
  # ---------------------------------------------------------------------------------------------
  def long_grind_adjust_trade_position(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ):
    dp = self.dp
    send_msg = self.dp.send_msg
    notification_msg = self.notification_msg
    scale_stakes_for_min_stake = self.scale_stakes_for_min_stake
    stake_currency = self.config["stake_currency"]
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_stake_amount = trade.stake_amount
    trade_fee_open = trade.fee_open
    trade_fee_close = trade.fee_close

    runmode_value = dp.runmode.value
    is_backtest = runmode_value in ["backtest", "hyperopt"]
    trade_open_date = None if is_backtest else trade.open_date_utc.replace(tzinfo=None)
    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    is_futures = self.is_futures_mode
    derisk_use_grind_stops = self.derisk_use_grind_stops
    long_rebuy_mode_tags = self.long_rebuy_mode_tags
    long_grind_mode_tags = self.long_grind_mode_tags
    trade_leverage = trade.leverage

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)
    if len(df) < 2:
      return None
    last_candle = df.iloc[-1]
    previous_candle = df.iloc[-2]

    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_entries = trade.nr_of_successful_entries
    count_of_exits = trade.nr_of_successful_exits

    if count_of_entries == 0:
      return None

    first_filled_entry = filled_entries[0]
    last_filled_entry = filled_entries[-1]
    last_filled_order = filled_orders[-1]

    has_order_tags = hasattr(filled_orders[0], "ft_order_tag")

    if runmode_value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = self.config["exit_pricing"]["price_side"]
        if trade.is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    slice_amount = first_filled_entry.safe_filled * first_filled_entry.safe_price
    slice_profit = (exit_rate - last_filled_order.safe_price) / last_filled_order.safe_price
    slice_profit_entry = (exit_rate - last_filled_entry.safe_price) / last_filled_entry.safe_price
    slice_profit_exit = (
      ((exit_rate - filled_exits[-1].safe_price) / filled_exits[-1].safe_price) if count_of_exits > 0 else 0.0
    )

    current_stake_amount = trade_amount * current_rate
    is_derisk = trade_amount < (first_filled_entry.safe_filled * 0.95)
    is_derisk_calc = False
    is_rebuy_mode = all(c in long_rebuy_mode_tags for c in enter_tags) or (
      any(c in long_rebuy_mode_tags for c in enter_tags)
      and all(c in (long_rebuy_mode_tags + long_grind_mode_tags) for c in enter_tags)
    )
    is_grind_mode = all(c in long_grind_mode_tags for c in enter_tags)

    fee_open_rate = trade_fee_open if self.custom_fee_open_rate is None else self.custom_fee_open_rate
    fee_close_rate = trade_fee_close if self.custom_fee_close_rate is None else self.custom_fee_close_rate
    stake_scale_leverage = trade_leverage if is_futures else 1.0
    grind_mode_stake_multipliers = (
      self.grind_mode_stake_multiplier_futures if is_futures else self.grind_mode_stake_multiplier_spot
    )
    regular_mode_stake_multipliers = (
      self.regular_mode_stake_multiplier_futures if is_futures else self.regular_mode_stake_multiplier_spot
    )
    grind_entry_retry_time = current_time - timedelta(minutes=10)
    grind_order_age_time = current_time - timedelta(hours=6)
    grind_force_order_age_time = current_time - timedelta(hours=24)

    # Rebuy mode
    if is_rebuy_mode:
      slice_amount /= self.rebuy_mode_stake_multiplier
    # Grind mode
    elif is_grind_mode:
      slice_amount /= grind_mode_stake_multipliers[0]
    elif not is_derisk and (is_backtest or trade_open_date >= datetime(2024, 2, 5)):
      rebuy_stake, order_tag, is_derisk_calc = self.long_adjust_trade_position_no_derisk(
        trade,
        enter_tags,
        current_time,
        current_rate,
        current_profit,
        min_stake,
        max_stake,
        current_entry_rate,
        current_exit_rate,
        current_entry_profit,
        current_exit_profit,
        last_candle,
        previous_candle,
        filled_orders,
        filled_entries,
        filled_exits,
        exit_rate,
        slice_amount,
        slice_profit_entry,
        slice_profit,
        profit_ratio,
        profit_stake,
        profit_init_ratio,
        current_stake_amount,
        has_order_tags,
        count_of_exits,
      )
      if rebuy_stake is not None:
        if has_order_tags:
          return rebuy_stake, order_tag
        else:
          return rebuy_stake
      elif count_of_exits == 0:
        return None
      elif not is_derisk_calc:
        return None

    if not is_rebuy_mode and not is_grind_mode:
      # First entry is lower now, therefore the grinds must adjust
      if is_backtest or trade_open_date >= datetime(2024, 4, 16):
        slice_amount /= regular_mode_stake_multipliers[0]

    is_not_trade_max_stake = current_stake_amount < (
      ((first_filled_entry.safe_filled * first_filled_entry.safe_price) * self.grinding_v1_max_stake)
      / (grind_mode_stake_multipliers[0] if is_grind_mode else 1.0)
    )

    grind_1_max_sub_grinds = 0
    grind_1_stakes = scale_stakes_for_min_stake(
      self.grind_1_stakes_futures if is_futures else self.grind_1_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_1_sub_thresholds = self.grind_1_sub_thresholds_futures if is_futures else self.grind_1_sub_thresholds_spot
    grind_1_max_sub_grinds = len(grind_1_stakes)
    grind_1_stop_grinds = self.grind_1_stop_grinds_futures if is_futures else self.grind_1_stop_grinds_spot
    grind_1_profit_threshold = (
      self.grind_1_profit_threshold_futures if is_futures else self.grind_1_profit_threshold_spot
    )

    grind_2_max_sub_grinds = 0
    grind_2_stakes = scale_stakes_for_min_stake(
      self.grind_2_stakes_futures if is_futures else self.grind_2_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_2_sub_thresholds = self.grind_2_sub_thresholds_futures if is_futures else self.grind_2_sub_thresholds_spot
    grind_2_max_sub_grinds = len(grind_2_stakes)
    grind_2_stop_grinds = self.grind_2_stop_grinds_futures if is_futures else self.grind_2_stop_grinds_spot
    grind_2_profit_threshold = (
      self.grind_2_profit_threshold_futures if is_futures else self.grind_2_profit_threshold_spot
    )

    grind_3_max_sub_grinds = 0
    grind_3_stakes = scale_stakes_for_min_stake(
      self.grind_3_stakes_futures if is_futures else self.grind_3_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_3_sub_thresholds = self.grind_3_sub_thresholds_futures if is_futures else self.grind_3_sub_thresholds_spot
    grind_3_max_sub_grinds = len(grind_3_stakes)
    grind_3_stop_grinds = self.grind_3_stop_grinds_futures if is_futures else self.grind_3_stop_grinds_spot
    grind_3_profit_threshold = (
      self.grind_3_profit_threshold_futures if is_futures else self.grind_3_profit_threshold_spot
    )

    grind_4_max_sub_grinds = 0
    grind_4_stakes = scale_stakes_for_min_stake(
      self.grind_4_stakes_futures if is_futures else self.grind_4_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_4_sub_thresholds = self.grind_4_sub_thresholds_futures if is_futures else self.grind_4_sub_thresholds_spot
    grind_4_max_sub_grinds = len(grind_4_stakes)
    grind_4_stop_grinds = self.grind_4_stop_grinds_futures if is_futures else self.grind_4_stop_grinds_spot
    grind_4_profit_threshold = (
      self.grind_4_profit_threshold_futures if is_futures else self.grind_4_profit_threshold_spot
    )

    grind_5_max_sub_grinds = 0
    grind_5_stakes = scale_stakes_for_min_stake(
      self.grind_5_stakes_futures if is_futures else self.grind_5_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_5_sub_thresholds = self.grind_5_sub_thresholds_futures if is_futures else self.grind_5_sub_thresholds_spot
    grind_5_max_sub_grinds = len(grind_5_stakes)
    grind_5_stop_grinds = self.grind_5_stop_grinds_futures if is_futures else self.grind_5_stop_grinds_spot
    grind_5_profit_threshold = (
      self.grind_5_profit_threshold_futures if is_futures else self.grind_5_profit_threshold_spot
    )

    grind_6_max_sub_grinds = 0
    grind_6_stakes = scale_stakes_for_min_stake(
      self.grind_6_stakes_futures if is_futures else self.grind_6_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_6_sub_thresholds = self.grind_6_sub_thresholds_futures if is_futures else self.grind_6_sub_thresholds_spot
    grind_6_max_sub_grinds = len(grind_6_stakes)
    grind_6_stop_grinds = self.grind_6_stop_grinds_futures if is_futures else self.grind_6_stop_grinds_spot
    grind_6_profit_threshold = (
      self.grind_6_profit_threshold_futures if is_futures else self.grind_6_profit_threshold_spot
    )

    grind_1_derisk_1_max_sub_grinds = 0
    grind_1_derisk_1_stakes = scale_stakes_for_min_stake(
      self.grind_1_derisk_1_stakes_futures if is_futures else self.grind_1_derisk_1_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_1_derisk_1_sub_thresholds = (
      self.grind_1_derisk_1_sub_thresholds_futures if is_futures else self.grind_1_derisk_1_sub_thresholds_spot
    )
    grind_1_derisk_1_max_sub_grinds = len(grind_1_derisk_1_stakes)
    grind_1_derisk_1_stop_grinds = (
      self.grind_1_derisk_1_stop_grinds_futures if is_futures else self.grind_1_derisk_1_stop_grinds_spot
    )
    grind_1_derisk_1_profit_threshold = (
      self.grind_1_derisk_1_profit_threshold_futures if is_futures else self.grind_1_derisk_1_profit_threshold_spot
    )

    grind_2_derisk_1_max_sub_grinds = 0
    grind_2_derisk_1_stakes = scale_stakes_for_min_stake(
      self.grind_2_derisk_1_stakes_futures if is_futures else self.grind_2_derisk_1_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_2_derisk_1_sub_thresholds = (
      self.grind_2_derisk_1_sub_thresholds_futures if is_futures else self.grind_2_derisk_1_sub_thresholds_spot
    )
    grind_2_derisk_1_max_sub_grinds = len(grind_2_derisk_1_stakes)
    grind_2_derisk_1_stop_grinds = (
      self.grind_2_derisk_1_stop_grinds_futures if is_futures else self.grind_2_derisk_1_stop_grinds_spot
    )
    grind_2_derisk_1_profit_threshold = (
      self.grind_2_derisk_1_profit_threshold_futures if is_futures else self.grind_2_derisk_1_profit_threshold_spot
    )

    partial_sell = False
    is_derisk_found = False  # d de-risk
    is_derisk_1 = False
    is_derisk_1_found = False  # d1 de-risk exit
    derisk_1_order = None
    derisk_1_reentry_order = None
    derisk_1_sub_grind_count = 0
    derisk_1_total_amount = 0.0
    derisk_1_total_cost = 0.0
    derisk_1_current_open_rate = 0.0
    derisk_1_current_grind_stake = 0.0
    derisk_1_current_grind_stake_profit = 0.0
    derisk_1_is_sell_found = False
    derisk_1_reentry_found = False
    derisk_1_buy_orders = []
    derisk_1_distance_ratio = 0.0
    grind_1_sub_grind_count = 0
    grind_1_total_amount = 0.0
    grind_1_total_cost = 0.0
    grind_1_current_open_rate = 0.0
    grind_1_current_grind_stake = 0.0
    grind_1_current_grind_stake_profit = 0.0
    grind_1_is_sell_found = False
    grind_1_found = False
    grind_1_buy_orders = []
    grind_1_distance_ratio = 0.0
    grind_2_sub_grind_count = 0
    grind_2_total_amount = 0.0
    grind_2_total_cost = 0.0
    grind_2_current_open_rate = 0.0
    grind_2_current_grind_stake = 0.0
    grind_2_current_grind_stake_profit = 0.0
    grind_2_is_sell_found = False
    grind_2_found = False
    grind_2_buy_orders = []
    grind_2_distance_ratio = 0.0
    grind_3_sub_grind_count = 0
    grind_3_total_amount = 0.0
    grind_3_total_cost = 0.0
    grind_3_current_open_rate = 0.0
    grind_3_current_grind_stake = 0.0
    grind_3_current_grind_stake_profit = 0.0
    grind_3_is_sell_found = False
    grind_3_found = False
    grind_3_buy_orders = []
    grind_3_distance_ratio = 0.0
    grind_4_sub_grind_count = 0
    grind_4_total_amount = 0.0
    grind_4_total_cost = 0.0
    grind_4_current_open_rate = 0.0
    grind_4_current_grind_stake = 0.0
    grind_4_current_grind_stake_profit = 0.0
    grind_4_is_sell_found = False
    grind_4_found = False
    grind_4_buy_orders = []
    grind_4_distance_ratio = 0.0
    grind_5_sub_grind_count = 0
    grind_5_total_amount = 0.0
    grind_5_total_cost = 0.0
    grind_5_current_open_rate = 0.0
    grind_5_current_grind_stake = 0.0
    grind_5_current_grind_stake_profit = 0.0
    grind_5_is_sell_found = False
    grind_5_found = False
    grind_5_buy_orders = []
    grind_5_distance_ratio = 0.0
    grind_6_sub_grind_count = 0
    grind_6_total_amount = 0.0
    grind_6_total_cost = 0.0
    grind_6_current_open_rate = 0.0
    grind_6_current_grind_stake = 0.0
    grind_6_current_grind_stake_profit = 0.0
    grind_6_is_sell_found = False
    grind_6_found = False
    grind_6_buy_orders = []
    grind_6_distance_ratio = 0.0
    grind_1_derisk_1_sub_grind_count = 0
    grind_1_derisk_1_total_amount = 0.0
    grind_1_derisk_1_total_cost = 0.0
    grind_1_derisk_1_current_open_rate = 0.0
    grind_1_derisk_1_current_grind_stake = 0.0
    grind_1_derisk_1_current_grind_stake_profit = 0.0
    grind_1_derisk_1_is_sell_found = False
    grind_1_derisk_1_found = False
    grind_1_derisk_1_buy_orders = []
    grind_1_derisk_1_distance_ratio = 0.0
    grind_2_derisk_1_sub_grind_count = 0
    grind_2_derisk_1_total_amount = 0.0
    grind_2_derisk_1_total_cost = 0.0
    grind_2_derisk_1_current_open_rate = 0.0
    grind_2_derisk_1_current_grind_stake = 0.0
    grind_2_derisk_1_current_grind_stake_profit = 0.0
    grind_2_derisk_1_is_sell_found = False
    grind_2_derisk_1_found = False
    grind_2_derisk_1_buy_orders = []
    grind_2_derisk_1_distance_ratio = 0.0
    for order in reversed(filled_orders):
      order_side = order.ft_order_side
      if (order_side == "buy") and (order is not filled_orders[0]):
        order_tag = ""
        if has_order_tags:
          order_ft_tag = order.ft_order_tag
          if order_ft_tag is not None:
            order_tag = order_ft_tag
        order_safe_filled = order.safe_filled
        order_safe_price = order.safe_price
        order_id = order.id
        if not is_derisk_1 and order_tag == "d1":
          derisk_1_sub_grind_count += 1
          derisk_1_total_amount += order_safe_filled
          derisk_1_total_cost += order_safe_filled * order_safe_price
          derisk_1_buy_orders.append(order_id)
          if not derisk_1_reentry_found and not is_derisk_1:
            derisk_1_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            derisk_1_reentry_found = True
            derisk_1_reentry_order = order
        elif not grind_1_derisk_1_is_sell_found and order_tag == "dl1":
          grind_1_derisk_1_sub_grind_count += 1
          grind_1_derisk_1_total_amount += order_safe_filled
          grind_1_derisk_1_total_cost += order_safe_filled * order_safe_price
          grind_1_derisk_1_buy_orders.append(order_id)
          if not grind_1_derisk_1_found:
            grind_1_derisk_1_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_1_derisk_1_found = True
        elif not grind_2_derisk_1_is_sell_found and order_tag == "dl2":
          grind_2_derisk_1_sub_grind_count += 1
          grind_2_derisk_1_total_amount += order_safe_filled
          grind_2_derisk_1_total_cost += order_safe_filled * order_safe_price
          grind_2_derisk_1_buy_orders.append(order_id)
          if not grind_2_derisk_1_found:
            grind_2_derisk_1_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_2_derisk_1_found = True
        elif not grind_6_is_sell_found and order_tag == "gd6":
          grind_6_sub_grind_count += 1
          grind_6_total_amount += order_safe_filled
          grind_6_total_cost += order_safe_filled * order_safe_price
          grind_6_buy_orders.append(order_id)
          if not grind_6_found:
            grind_6_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_6_found = True
        elif not grind_5_is_sell_found and order_tag == "gd5":
          grind_5_sub_grind_count += 1
          grind_5_total_amount += order_safe_filled
          grind_5_total_cost += order_safe_filled * order_safe_price
          grind_5_buy_orders.append(order_id)
          if not grind_5_found:
            grind_5_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_5_found = True
        elif not grind_4_is_sell_found and order_tag == "gd4":
          grind_4_sub_grind_count += 1
          grind_4_total_amount += order_safe_filled
          grind_4_total_cost += order_safe_filled * order_safe_price
          grind_4_buy_orders.append(order_id)
          if not grind_4_found:
            grind_4_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_4_found = True
        elif not grind_3_is_sell_found and order_tag == "gd3":
          grind_3_sub_grind_count += 1
          grind_3_total_amount += order_safe_filled
          grind_3_total_cost += order_safe_filled * order_safe_price
          grind_3_buy_orders.append(order_id)
          if not grind_3_found:
            grind_3_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_3_found = True
        elif not grind_2_is_sell_found and order_tag == "gd2":
          grind_2_sub_grind_count += 1
          grind_2_total_amount += order_safe_filled
          grind_2_total_cost += order_safe_filled * order_safe_price
          grind_2_buy_orders.append(order_id)
          if not grind_2_found:
            grind_2_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_2_found = True
        elif not grind_1_is_sell_found and order_tag not in [
          "r",
          "d1",
          "dl1",
          "dl2",
          "g1",
          "g2",
          "g3",
          "g4",
          "g5",
          "g6",
          "sg1",
          "sg2",
          "sg3",
          "sg4",
          "sg5",
          "sg6",
          "gd2",
          "gd3",
          "gd4",
          "gd5",
          "gd6",
          "gm0",
          "gmd0",
          "gdr",
        ]:
          grind_1_sub_grind_count += 1
          grind_1_total_amount += order_safe_filled
          grind_1_total_cost += order_safe_filled * order_safe_price
          grind_1_buy_orders.append(order_id)
          if not grind_1_found:
            grind_1_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_1_found = True
      elif order_side == "sell":
        if order is filled_exits[-1] and (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
          break
        order_tag = ""
        if has_order_tags:
          order_ft_tag = order.ft_order_tag
          if order_ft_tag is not None:
            order_tag = order_ft_tag.partition(" ")[0]
        if order_tag in ["dl1", "ddl1"]:
          grind_1_derisk_1_is_sell_found = True
        elif order_tag in ["dl2", "ddl2"]:
          grind_2_derisk_1_is_sell_found = True
        elif order_tag in ["gd6", "dd6"]:
          grind_6_is_sell_found = True
        elif order_tag in ["gd5", "dd5"]:
          grind_5_is_sell_found = True
        if order_tag in ["gd4", "dd4"]:
          grind_4_is_sell_found = True
        elif order_tag in ["gd3", "dd3"]:
          grind_3_is_sell_found = True
        elif order_tag in ["gd2", "dd2"]:
          grind_2_is_sell_found = True
        elif order_tag == "d1":
          if not is_derisk_1_found:
            is_derisk_1_found = True
            is_derisk_1 = True
            derisk_1_order = order
        elif order_tag in ["p", "r", "d", "dd0", "partial_exit", "force_exit", ""]:
          if order_tag == "d":
            is_derisk_found = True
            is_derisk = True
          grind_1_is_sell_found = True
          grind_2_is_sell_found = True
          grind_3_is_sell_found = True
          grind_4_is_sell_found = True
          grind_5_is_sell_found = True
          grind_6_is_sell_found = True
          grind_1_derisk_1_is_sell_found = True
          grind_2_derisk_1_is_sell_found = True
        elif order_tag not in [
          "dl1",
          "ddl1",
          "dl2",
          "ddl2",
          "g1",
          "g2",
          "g3",
          "g4",
          "g5",
          "g6",
          "sg1",
          "sg2",
          "sg3",
          "sg4",
          "sg5",
          "sg6",
          "gd2",
          "gd3",
          "gd4",
          "gd5",
          "gd6",
          "dd2",
          "dd3",
          "dd4",
          "dd5",
          "dd6",
          "gm0",
          "gmd0",
          "gdr",
        ]:
          grind_1_is_sell_found = True

    if derisk_1_sub_grind_count > 0:
      derisk_1_current_open_rate = derisk_1_total_cost / derisk_1_total_amount
      derisk_1_current_grind_stake = derisk_1_total_amount * exit_rate * (1 - trade_fee_close)
      derisk_1_current_grind_stake_profit = derisk_1_current_grind_stake - derisk_1_total_cost
    if grind_1_sub_grind_count > 0:
      grind_1_current_open_rate = grind_1_total_cost / grind_1_total_amount
      grind_1_current_grind_stake = grind_1_total_amount * exit_rate * (1 - trade_fee_close)
      grind_1_current_grind_stake_profit = grind_1_current_grind_stake - grind_1_total_cost
    if grind_2_sub_grind_count > 0:
      grind_2_current_open_rate = grind_2_total_cost / grind_2_total_amount
      grind_2_current_grind_stake = grind_2_total_amount * exit_rate * (1 - trade_fee_close)
      grind_2_current_grind_stake_profit = grind_2_current_grind_stake - grind_2_total_cost
    if grind_3_sub_grind_count > 0:
      grind_3_current_open_rate = grind_3_total_cost / grind_3_total_amount
      grind_3_current_grind_stake = grind_3_total_amount * exit_rate * (1 - trade_fee_close)
      grind_3_current_grind_stake_profit = grind_3_current_grind_stake - grind_3_total_cost
    if grind_4_sub_grind_count > 0:
      grind_4_current_open_rate = grind_4_total_cost / grind_4_total_amount
      grind_4_current_grind_stake = grind_4_total_amount * exit_rate * (1 - trade_fee_close)
      grind_4_current_grind_stake_profit = grind_4_current_grind_stake - grind_4_total_cost
    if grind_5_sub_grind_count > 0:
      grind_5_current_open_rate = grind_5_total_cost / grind_5_total_amount
      grind_5_current_grind_stake = grind_5_total_amount * exit_rate * (1 - trade_fee_close)
      grind_5_current_grind_stake_profit = grind_5_current_grind_stake - grind_5_total_cost
    if grind_6_sub_grind_count > 0:
      grind_6_current_open_rate = grind_6_total_cost / grind_6_total_amount
      grind_6_current_grind_stake = grind_6_total_amount * exit_rate * (1 - trade_fee_close)
      grind_6_current_grind_stake_profit = grind_6_current_grind_stake - grind_6_total_cost
    if grind_1_derisk_1_sub_grind_count > 0:
      grind_1_derisk_1_current_open_rate = grind_1_derisk_1_total_cost / grind_1_derisk_1_total_amount
      grind_1_derisk_1_current_grind_stake = grind_1_derisk_1_total_amount * exit_rate * (1 - trade_fee_close)
      grind_1_derisk_1_current_grind_stake_profit = grind_1_derisk_1_current_grind_stake - grind_1_derisk_1_total_cost
    if grind_2_derisk_1_sub_grind_count > 0:
      grind_2_derisk_1_current_open_rate = grind_2_derisk_1_total_cost / grind_2_derisk_1_total_amount
      grind_2_derisk_1_current_grind_stake = grind_2_derisk_1_total_amount * exit_rate * (1 - trade_fee_close)
      grind_2_derisk_1_current_grind_stake_profit = grind_2_derisk_1_current_grind_stake - grind_2_derisk_1_total_cost

    num_open_grinds = (
      grind_1_sub_grind_count
      + grind_2_sub_grind_count
      + grind_3_sub_grind_count
      + grind_4_sub_grind_count
      + grind_5_sub_grind_count
      + grind_6_sub_grind_count
      + grind_1_derisk_1_sub_grind_count
      + grind_2_derisk_1_sub_grind_count
    )
    grinds_total_stake_profit = (
      derisk_1_current_grind_stake_profit
      + grind_1_derisk_1_current_grind_stake_profit
      + grind_2_derisk_1_current_grind_stake_profit
      + grind_1_current_grind_stake_profit
      + grind_2_current_grind_stake_profit
      + grind_3_current_grind_stake_profit
      + grind_4_current_grind_stake_profit
      + grind_5_current_grind_stake_profit
      + grind_6_current_grind_stake_profit
    )
    grinds_total_amount = (
      derisk_1_total_amount
      + grind_1_derisk_1_total_amount
      + grind_2_derisk_1_total_amount
      + grind_1_total_amount
      + grind_2_total_amount
      + grind_3_total_amount
      + grind_4_total_amount
      + grind_5_total_amount
      + grind_6_total_amount
    )
    stake_fmt = ".8f" if self.config["stake_currency"] in ("BTC", "ETH", "BNB", "SOL") else ".3f"
    # Sell remaining if partial fill on exit
    if partial_sell:
      order = filled_exits[-1]
      sell_amount = order.safe_remaining * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        send_msg(
          f"Exit (remaining) [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {order.safe_remaining} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        order_tag = "p"
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    if is_grind_mode and (
      (first_filled_entry.safe_filled * (trade_stake_amount / trade_amount) - (min_stake * 1.5)) > min_stake
    ):
      is_first_entry_exit_found = False
      for order in filled_orders:
        if order.ft_order_side == "sell":
          order_tag = ""
          if has_order_tags:
            if order.ft_order_tag is not None:
              order_tag = order.ft_order_tag.partition(" ")[0]
          else:
            # no order tag support, assume the first exit is for the first buy
            is_first_entry_exit_found = True
          if order_tag in ["gm0", "gmd0"]:
            is_first_entry_exit_found = True
            break
      if not is_first_entry_exit_found:
        first_entry = first_filled_entry
        first_entry_distance_ratio = (exit_rate - first_entry.safe_price) / first_entry.safe_price
        # First entry exit
        if first_entry_distance_ratio > (
          (self.grind_mode_first_entry_profit_threshold_spot + fee_open_rate + fee_close_rate)
          if is_futures
          else (self.grind_mode_first_entry_profit_threshold_spot + fee_open_rate + fee_close_rate)
        ):
          sell_amount = first_entry.safe_filled * exit_rate / trade_leverage
          if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
            sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
          ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
          if sell_amount > min_stake and ft_sell_amount > min_stake:
            grind_profit = (exit_rate - first_entry.safe_price) / first_entry.safe_price
            coin_amount = sell_amount / exit_rate
            send_msg(
              notification_msg(
                "grinding-exit",
                tag="gm0",
                pair=trade_pair,
                rate=exit_rate,
                stake_amount=sell_amount,
                profit_stake=profit_stake,
                profit_ratio=profit_ratio,
                stake_currency=stake_currency,
                grind_profit_stake=grind_profit * sell_amount * trade_leverage,
                grind_profit_pct=grind_profit,
                coin_amount=coin_amount,
              )
            )
            log.info(
              f"Grinding exit (gm0) [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {coin_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
            )
            order_tag = "gm0"
            for grind_entry_id in grind_1_buy_orders:
              order_tag += " " + str(grind_entry_id)
            if has_order_tags:
              return -ft_sell_amount, order_tag
            else:
              return -ft_sell_amount
        # First entry de-risk
        if derisk_use_grind_stops and (
          first_entry_distance_ratio
          < (
            self.grind_mode_first_entry_stop_threshold_spot
            if is_futures
            else self.grind_mode_first_entry_stop_threshold_spot
          )
        ):
          sell_amount = first_entry.safe_filled * exit_rate / trade_leverage
          if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
            sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
          ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
          if sell_amount > min_stake and ft_sell_amount > min_stake:
            grind_profit = (exit_rate - first_entry.safe_price) / first_entry.safe_price
            coin_amount = sell_amount / exit_rate
            send_msg(
              notification_msg(
                "grinding-derisk",
                tag="gmd0",
                pair=trade_pair,
                rate=exit_rate,
                stake_amount=sell_amount,
                profit_stake=profit_stake,
                profit_ratio=profit_ratio,
                stake_currency=stake_currency,
                grind_profit_stake=grind_profit * sell_amount * trade_leverage,
                grind_profit_pct=grind_profit,
                coin_amount=coin_amount,
              )
            )
            log.info(
              f"Grinding de-risk (gmd0) [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {coin_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
            )
            order_tag = "gmd0"
            for grind_entry_id in grind_1_buy_orders:
              order_tag += " " + str(grind_entry_id)
            if has_order_tags:
              return -ft_sell_amount, order_tag
            else:
              return -ft_sell_amount

    is_long_grind_entry = self.long_grind_entry_v3(
      last_candle, previous_candle, num_open_grinds, slice_profit, slice_profit_entry, slice_profit_exit, True
    )  # 120 grinds via the v3 entry set (g0..g23) instead of the legacy grind mode
    slice_profit_lt_neg_0_06 = slice_profit < -0.06
    num_open_grinds_eq_0 = num_open_grinds == 0

    # Grinding derisk 1
    # Buy
    if (
      has_order_tags
      and is_derisk_1
      and not derisk_1_reentry_found
      and (not partial_sell)
      and (grind_1_derisk_1_sub_grind_count < grind_1_derisk_1_max_sub_grinds)
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_1_derisk_1_stakes[grind_1_derisk_1_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          (
            (grind_1_derisk_1_sub_grind_count > 0)
            and grind_1_derisk_1_distance_ratio < grind_1_derisk_1_sub_thresholds[grind_1_derisk_1_sub_grind_count]
          )
          or ((is_derisk or is_derisk_calc) and grind_1_derisk_1_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_lt_neg_0_06)
        and (
          num_open_grinds_eq_0
          or (grind_order_age_time > last_filled_order.order_filled_utc)
          or slice_profit_lt_neg_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit < -0.03))
        and is_long_grind_entry
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_1_derisk_1_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_1_derisk_1_current_open_rate) / grind_1_derisk_1_current_open_rate
          grind_profit_stake = grind_1_derisk_1_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="dl1",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_1_derisk_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (dl1) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_derisk_1_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "dl1"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_1_derisk_1_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_1_derisk_1_current_open_rate) / grind_1_derisk_1_current_open_rate
      if grind_profit > (grind_1_derisk_1_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_1_derisk_1_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="dl1",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_1_derisk_1_total_amount,
            )
          )
          log.info(
            f"Grinding exit (dl1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_derisk_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "dl1"
          for grind_entry_id in grind_1_derisk_1_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (grind_1_derisk_1_sub_grind_count > 0)
      # and (
      #   ((exit_rate - grind_1_derisk_1_current_open_rate) / grind_1_derisk_1_current_open_rate)
      #   < grind_1_derisk_1_stop_grinds
      # )
      and (grind_1_derisk_1_current_grind_stake_profit < (slice_amount * grind_1_derisk_1_stop_grinds))
      and (is_derisk or is_derisk_calc)
      # temporary
      and (is_backtest or trade_open_date >= datetime(2026, 6, 18))
    ):
      sell_amount = grind_1_derisk_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_1_derisk_1_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_1_derisk_1_current_open_rate) / grind_1_derisk_1_current_open_rate)
            if grind_1_derisk_1_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="ddl1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_1_derisk_1_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (ddl1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_derisk_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "ddl1"
        for grind_entry_id in grind_1_derisk_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding derisk 2
    # Buy
    if (
      has_order_tags
      and is_derisk_1
      and not derisk_1_reentry_found
      and (not partial_sell)
      and (grind_2_derisk_1_sub_grind_count < grind_2_derisk_1_max_sub_grinds)
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_2_derisk_1_stakes[grind_2_derisk_1_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          (
            (grind_2_derisk_1_sub_grind_count > 0)
            and grind_2_derisk_1_distance_ratio < grind_2_derisk_1_sub_thresholds[grind_2_derisk_1_sub_grind_count]
          )
          or ((is_derisk or is_derisk_calc) and grind_2_derisk_1_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_lt_neg_0_06)
        and (
          num_open_grinds_eq_0
          or (grind_order_age_time > last_filled_order.order_filled_utc)
          or slice_profit_lt_neg_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit < -0.03))
        and is_long_grind_entry
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_2_derisk_1_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_2_derisk_1_current_open_rate) / grind_2_derisk_1_current_open_rate
          grind_profit_stake = grind_2_derisk_1_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="dl2",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_2_derisk_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (dl2) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_2_derisk_1_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "dl2"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_2_derisk_1_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_2_derisk_1_current_open_rate) / grind_2_derisk_1_current_open_rate
      if grind_profit > (grind_2_derisk_1_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_2_derisk_1_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="dl2",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_2_derisk_1_total_amount,
            )
          )
          log.info(
            f"Grinding exit (dl2) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_2_derisk_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "dl2"
          for grind_entry_id in grind_2_derisk_1_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (grind_2_derisk_1_sub_grind_count > 0)
      # and (
      #   ((exit_rate - grind_2_derisk_1_current_open_rate) / grind_2_derisk_1_current_open_rate)
      #   < grind_2_derisk_1_stop_grinds
      # )
      and (grind_2_derisk_1_current_grind_stake_profit < (slice_amount * grind_2_derisk_1_stop_grinds))
      and (is_derisk or is_derisk_calc)
      # temporary
      and (is_backtest or trade_open_date >= datetime(2026, 6, 18))
    ):
      sell_amount = grind_2_derisk_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_2_derisk_1_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_2_derisk_1_current_open_rate) / grind_2_derisk_1_current_open_rate)
            if grind_2_derisk_1_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="ddl2",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_2_derisk_1_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (ddl2) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_2_derisk_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "ddl2"
        for grind_entry_id in grind_2_derisk_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 1
    # Buy
    if (not partial_sell) and (grind_1_sub_grind_count < grind_1_max_sub_grinds):
      buy_amount = slice_amount * grind_1_stakes[grind_1_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          ((grind_1_sub_grind_count > 0) and grind_1_distance_ratio < grind_1_sub_thresholds[grind_1_sub_grind_count])
          or ((is_derisk or is_derisk_calc) and grind_1_sub_grind_count == 0)
          or (is_grind_mode and grind_1_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_lt_neg_0_06)
        and (
          num_open_grinds_eq_0
          or (grind_order_age_time > last_filled_order.order_filled_utc)
          or slice_profit_lt_neg_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit < -0.03))
        and is_long_grind_entry
        and is_not_trade_max_stake
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_1_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
          grind_profit_stake = grind_1_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd1",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd1) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd1"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    if (
      is_futures
      and has_order_tags
      and (not partial_sell)
      and slice_profit < (-0.65 / trade_leverage)
      and (is_derisk or is_derisk_calc or is_grind_mode)
      and (grind_1_sub_grind_count < grind_1_max_sub_grinds)
    ):
      buy_amount = slice_amount * grind_1_stakes[grind_1_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount <= max_stake:
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_1_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
          grind_profit_stake = grind_1_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd1",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd1) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd1"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_1_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
      if grind_profit > (grind_1_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_1_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="gd1",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_1_total_amount,
            )
          )
          log.info(
            f"Grinding exit (gd1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "gd1"
          for grind_entry_id in grind_1_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (
        (grind_1_sub_grind_count > 0)
        # and (((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate) < grind_1_stop_grinds)
        and (grind_1_current_grind_stake_profit < (slice_amount * grind_1_stop_grinds))
        and (is_derisk or is_derisk_calc or is_grind_mode)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2026, 6, 18))
    ):
      sell_amount = grind_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_1_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate)
            if grind_1_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="dd1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_1_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (dd1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "dd1"
        for grind_entry_id in grind_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 2
    # Buy
    if has_order_tags and (not partial_sell) and (grind_2_sub_grind_count < grind_2_max_sub_grinds):
      buy_amount = slice_amount * grind_2_stakes[grind_2_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          ((grind_2_sub_grind_count > 0) and grind_2_distance_ratio < grind_2_sub_thresholds[grind_2_sub_grind_count])
          or ((is_derisk or is_derisk_calc) and grind_2_sub_grind_count == 0)
          or (is_grind_mode and grind_2_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_lt_neg_0_06)
        and (
          num_open_grinds_eq_0
          or (grind_order_age_time > last_filled_order.order_filled_utc)
          or slice_profit_lt_neg_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit < -0.03))
        and is_long_grind_entry
        and is_not_trade_max_stake
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_2_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
          grind_profit_stake = grind_2_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd2",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_2_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd2) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_2_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd2"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_2_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
      if grind_profit > (grind_2_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_2_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="gd2",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_2_total_amount,
            )
          )
          log.info(
            f"Grinding exit (gd2) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "gd2"
          for grind_entry_id in grind_2_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (
        (grind_2_sub_grind_count > 0)
        # and (((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate) < grind_2_stop_grinds)
        and (grind_2_current_grind_stake_profit < (slice_amount * grind_2_stop_grinds))
        and (is_derisk or is_derisk_calc or is_grind_mode)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2026, 6, 18))
    ):
      sell_amount = grind_2_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_2_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate)
            if grind_2_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="dd2",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_2_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (dd2) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "dd2"
        for grind_entry_id in grind_2_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 3
    # Buy
    if has_order_tags and (not partial_sell) and (grind_3_sub_grind_count < grind_3_max_sub_grinds):
      buy_amount = slice_amount * grind_3_stakes[grind_3_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          ((grind_3_sub_grind_count > 0) and grind_3_distance_ratio < grind_3_sub_thresholds[grind_3_sub_grind_count])
          or ((is_derisk or is_derisk_calc) and grind_3_sub_grind_count == 0)
          or (is_grind_mode and grind_3_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_lt_neg_0_06)
        and (
          num_open_grinds_eq_0
          or (grind_order_age_time > last_filled_order.order_filled_utc)
          or slice_profit_lt_neg_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit < -0.03))
        and is_long_grind_entry
        and is_not_trade_max_stake
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_3_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
          grind_profit_stake = grind_3_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd3",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_3_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd3) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_3_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd3"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_3_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
      if grind_profit > (grind_3_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_3_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="gd3",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_3_total_amount,
            )
          )
          log.info(
            f"Grinding exit (gd3) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "gd3"
          for grind_entry_id in grind_3_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (
        (grind_3_sub_grind_count > 0)
        # and (((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate) < grind_3_stop_grinds)
        and (grind_3_current_grind_stake_profit < (slice_amount * grind_3_stop_grinds))
        and (is_derisk or is_derisk_calc or is_grind_mode)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2026, 6, 18))
    ):
      sell_amount = grind_3_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_3_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate)
            if grind_3_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="dd3",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_3_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (dd3) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "dd3"
        for grind_entry_id in grind_3_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 4
    # Buy
    if has_order_tags and (not partial_sell) and (grind_4_sub_grind_count < grind_4_max_sub_grinds):
      buy_amount = slice_amount * grind_4_stakes[grind_4_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          ((grind_4_sub_grind_count > 0) and grind_4_distance_ratio < grind_4_sub_thresholds[grind_4_sub_grind_count])
          or ((is_derisk or is_derisk_calc) and grind_4_sub_grind_count == 0)
          or (is_grind_mode and grind_4_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_lt_neg_0_06)
        and (
          num_open_grinds_eq_0
          or (grind_order_age_time > last_filled_order.order_filled_utc)
          or slice_profit_lt_neg_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit < -0.03))
        and is_long_grind_entry
        and is_not_trade_max_stake
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_4_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
          grind_profit_stake = grind_4_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd4",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_4_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd4) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_4_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd4"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_4_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
      if grind_profit > (grind_4_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_4_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="gd4",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_4_total_amount,
            )
          )
          log.info(
            f"Grinding exit (gd4) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "gd4"
          for grind_entry_id in grind_4_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (
        (grind_4_sub_grind_count > 0)
        # and (((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate) < grind_4_stop_grinds)
        and (grind_4_current_grind_stake_profit < (slice_amount * grind_4_stop_grinds))
        and (is_derisk or is_derisk_calc or is_grind_mode)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2026, 6, 18))
    ):
      sell_amount = grind_4_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_4_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate)
            if grind_4_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="dd4",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_4_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (dd4) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "dd4"
        for grind_entry_id in grind_4_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    gd5_liquidation_rescue_eligible = (
      is_futures
      and (slice_profit_entry < -0.12)
      and (trade.liquidation_price is not None)
      and (current_rate < trade.liquidation_price * 1.20)
      and (trade.get_custom_data(key="gd5_liquidation_rescue_used") is None)
    )

    # Grinding 5
    # Buy
    if has_order_tags and (not partial_sell) and (grind_5_sub_grind_count < grind_5_max_sub_grinds):
      buy_amount = slice_amount * grind_5_stakes[grind_5_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          ((grind_5_sub_grind_count > 0) and grind_5_distance_ratio < grind_5_sub_thresholds[grind_5_sub_grind_count])
          or ((is_derisk or is_derisk_calc) and grind_5_sub_grind_count == 0)
          or (is_grind_mode and grind_5_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_lt_neg_0_06)
        and (
          num_open_grinds_eq_0
          or (grind_order_age_time > last_filled_order.order_filled_utc)
          or slice_profit_lt_neg_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit < -0.03))
        and (is_long_grind_entry or gd5_liquidation_rescue_eligible)
        and is_not_trade_max_stake
        and buy_amount <= max_stake
      ):
        if gd5_liquidation_rescue_eligible:
          trade.set_custom_data(key="gd5_liquidation_rescue_used", value=True)

        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_5_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
          grind_profit_stake = grind_5_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd5",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_5_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd5) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_5_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd5"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_5_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
      if grind_profit > (grind_5_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_5_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="gd5",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_5_total_amount,
            )
          )
          log.info(
            f"Grinding exit (gd5) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "gd5"
          for grind_entry_id in grind_5_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (
        (grind_5_sub_grind_count > 0)
        # and (((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate) < grind_5_stop_grinds)
        and (grind_5_current_grind_stake_profit < (slice_amount * grind_5_stop_grinds))
        and (is_derisk or is_derisk_calc or is_grind_mode)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2026, 6, 18))
    ):
      sell_amount = grind_5_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_5_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate)
            if grind_5_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="dd5",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_5_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (dd5) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "dd5"
        for grind_entry_id in grind_5_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 6
    # Buy
    if has_order_tags and (not partial_sell) and (grind_6_sub_grind_count < grind_6_max_sub_grinds):
      buy_amount = slice_amount * grind_6_stakes[grind_6_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          ((grind_6_sub_grind_count > 0) and grind_6_distance_ratio < grind_6_sub_thresholds[grind_6_sub_grind_count])
          or ((is_derisk or is_derisk_calc) and grind_6_sub_grind_count == 0)
          or (is_grind_mode and grind_6_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_lt_neg_0_06)
        and (
          num_open_grinds_eq_0
          or (grind_order_age_time > last_filled_order.order_filled_utc)
          or slice_profit_lt_neg_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit < -0.03))
        and is_long_grind_entry
        and is_not_trade_max_stake
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_6_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate
          grind_profit_stake = grind_6_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd6",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_6_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd6) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_6_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd6"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_6_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate
      if grind_profit > (grind_6_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_6_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="gd6",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_6_total_amount,
            )
          )
          log.info(
            f"Grinding exit (gd6) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_6_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "gd6"
          for grind_entry_id in grind_6_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (
        (grind_6_sub_grind_count > 0)
        # and (((exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate) < grind_6_stop_grinds)
        and (grind_6_current_grind_stake_profit < (slice_amount * grind_6_stop_grinds))
        and (is_derisk or is_derisk_calc or is_grind_mode)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2026, 6, 18))
    ):
      sell_amount = grind_6_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_6_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate)
            if grind_6_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="dd6",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_6_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (dd6) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_6_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "dd6"
        for grind_entry_id in grind_6_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # De-risk 1 reentry
    if (
      is_derisk_1
      and not derisk_1_reentry_found
      and derisk_1_order is not None
      and (
        ((current_rate - derisk_1_order.safe_price) / derisk_1_order.safe_price)
        < (self.regular_mode_derisk_1_reentry_futures if is_futures else self.regular_mode_derisk_1_reentry_spot)
      )
    ):
      buy_amount = derisk_1_order.safe_filled * derisk_1_order.safe_price
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_lt_neg_0_06)
        and (
          num_open_grinds_eq_0
          or (grind_order_age_time > last_filled_order.order_filled_utc)
          or slice_profit_lt_neg_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit < -0.03))
        and (
          # (last_candle["protections_long_rebuy"] == True)
          # and (last_candle["protections_long_global"] == True)
          (last_candle["global_protections_long_pump"] == True)
          and (last_candle["global_protections_long_dump"] == True)
        )
        and is_long_grind_entry
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if derisk_1_sub_grind_count > 0:
          grind_profit = (exit_rate - derisk_1_current_open_rate) / derisk_1_current_open_rate
          grind_profit_stake = derisk_1_current_grind_stake_profit
        send_msg(
          notification_msg(
            "re-entry",
            tag="d1",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=derisk_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Re-entry (d1) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({derisk_1_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "d1"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # De-risk level 1
    if (
      has_order_tags
      # and not is_derisk_1
      and derisk_1_reentry_found
      and derisk_1_reentry_order is not None
      # and (trade.open_date_utc.replace(tzinfo=None) >= datetime(2024, 4, 5) or is_backtest)
      and derisk_1_distance_ratio
      < (
        (self.regular_mode_derisk_1_reentry_futures if is_futures else self.regular_mode_derisk_1_reentry_spot)
        / stake_scale_leverage
      )
    ):
      sell_amount = derisk_1_reentry_order.safe_filled * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="d1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk (d1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "d1"

    # # De-risk
    # if (
    #   not is_derisk_found
    #   and (trade.open_date_utc.replace(tzinfo=None) >= datetime(2024, 2, 5) or is_backtest)
    #   and profit_stake
    #   < (
    #     slice_amount
    #     * (
    #       (self.regular_mode_derisk_futures if self.is_futures_mode else self.regular_mode_derisk_spot)
    #       if (trade.open_date_utc.replace(tzinfo=None) >= datetime(2024, 4, 16) or is_backtest)
    #       else (self.regular_mode_derisk_futures_old if self.is_futures_mode else self.regular_mode_derisk_spot_old)
    #     )
    #     # / (trade.leverage if self.is_futures_mode else 1.0)
    #   )
    # ):
    #   sell_amount = trade.amount * exit_rate / trade.leverage
    #   if ((current_stake_amount / trade.leverage) - sell_amount) < (min_stake * 1.55):
    #     sell_amount = (trade.amount * exit_rate / trade.leverage) - (min_stake * 1.55)
    #   ft_sell_amount = sell_amount * trade.leverage * (trade.stake_amount / trade.amount) / exit_rate
    #   if sell_amount > min_stake and ft_sell_amount > min_stake:
    #     grind_profit = 0.0
    #     self.dp.send_msg(
    #       f"De-risk [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
    #     )
    #     log.info(
    #       f"De-risk [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
    #     )
    #     return -ft_sell_amount, "d", is_derisk

    # # De-risk
    # if (num_open_grinds > 0) and (
    #   grinds_total_stake_profit
    #   < (slice_amount * (self.grinds_stop_futures if self.is_futures_mode else self.grinds_stop_spot))
    # ):
    #   sell_amount = grinds_total_amount * exit_rate / trade.leverage
    #   if ((current_stake_amount / trade.leverage) - sell_amount) < (min_stake * 1.55):
    #     sell_amount = (trade.amount * exit_rate / trade.leverage) - (min_stake * 1.55)
    #   ft_sell_amount = sell_amount * trade.leverage * (trade.stake_amount / trade.amount) / exit_rate
    #   if sell_amount > min_stake and ft_sell_amount > min_stake:
    #     self.dp.send_msg(
    #       f"De-risk (dd0) [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
    #     )
    #     log.info(
    #       f"De-risk (dd0) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
    #     )
    #     order_tag = "dd0"
    #     for grind_entry_id in (
    #       grind_1_buy_orders
    #       + grind_2_buy_orders
    #       + grind_3_buy_orders
    #       + grind_4_buy_orders
    #       + grind_5_buy_orders
    #       + grind_6_buy_orders
    #       + grind_1_derisk_1_buy_orders
    #       + grind_2_derisk_1_buy_orders
    #     ):
    #       order_tag += " " + str(grind_entry_id)
    #     if has_order_tags:
    #       return -ft_sell_amount, order_tag
    #     else:
    #       return -ft_sell_amount

    return None

  # Long Grinding Entry
  # ---------------------------------------------------------------------------------------------
  def long_grind_entry(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    last_aroonu_14 = last_candle["AROONU_14"]
    last_aroonu_14_15m = last_candle["AROONU_14_15m"]
    last_rsi_14_1h = last_candle["RSI_14_1h"]
    last_rsi_14_4h = last_candle["RSI_14_4h"]
    previous_ema_12 = previous_candle["EMA_12"]
    previous_ema_26 = previous_candle["EMA_26"]

    last_rsi_14 = last_candle["RSI_14"]
    last_rsi_3_15m = last_candle["RSI_3_15m"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_rsi_3_4h = last_candle["RSI_3_4h"]
    last_close = last_candle["close"]
    last_ema_26 = last_candle["EMA_26"]
    last_ema_12 = last_candle["EMA_12"]
    last_rsi_3 = last_candle["RSI_3"]
    last_stochrsi_k_1h = last_candle["STOCHRSIk_14_14_3_3_1h"]
    last_stochrsi_k_4h = last_candle["STOCHRSIk_14_14_3_3_4h"]
    last_open = last_candle["open"]

    # Reused long regular grind-entry thresholds
    last_rsi_14_lt_36 = last_rsi_14 < 36.0
    last_rsi_3_4h_gt_20 = last_rsi_3_4h > 20.0
    last_rsi_3_1h_gt_20 = last_rsi_3_1h > 20.0
    last_rsi_3_15m_gt_10 = last_rsi_3_15m > 10.0
    last_rsi_3_4h_gt_10 = last_rsi_3_4h > 10.0
    last_rsi_3_1h_gt_10 = last_rsi_3_1h > 10.0
    last_rsi_14_4h_lt_60 = last_rsi_14_4h < 60.0
    last_rsi_14_1h_lt_80 = last_rsi_14_1h < 80.0
    last_aroonu_14_15m_lt_25 = last_aroonu_14_15m < 25.0
    last_aroonu_14_lt_25 = last_aroonu_14 < 25.0

    if (
      (last_candle["protections_long_global"] == True)
      and (last_candle["protections_long_rebuy"] == True)
      and (last_candle["global_protections_long_pump"] == True)
      and (last_candle["global_protections_long_dump"] == True)
      and (
        (last_candle["enter_long"] == True)
        or (
          (last_rsi_14_lt_36)
          and (last_rsi_3 > 10.0)
          and (last_rsi_3_15m_gt_10)
          and (last_aroonu_14_lt_25)
          and (last_stochrsi_k_1h < 70.0)
          and (last_stochrsi_k_4h < 70.0)
          and (last_close < (last_candle["EMA_16"] * 0.980))
        )
        or (
          (last_rsi_14_lt_36)
          and (last_rsi_3_15m > 5.0)
          and (last_rsi_3_1h > 5.0)
          and (last_rsi_3_4h > 5.0)
          and (last_ema_26 > last_ema_12)
          and ((last_ema_26 - last_ema_12) > (last_open * 0.030))
          and ((previous_ema_26 - previous_ema_12) > (last_open / 100.0))
        )
        or (
          (last_rsi_14_lt_36)
          and (last_rsi_3 > 5.0)
          and (last_rsi_3_15m_gt_10)
          and (last_rsi_3_1h_gt_10)
          and (last_rsi_3_4h_gt_10)
          and (last_ema_26 > last_ema_12)
          and ((last_ema_26 - last_ema_12) > (last_open * 0.020))
          and ((previous_ema_26 - previous_ema_12) > (last_open / 100.0))
        )
        or (
          (last_rsi_14_lt_36)
          and (last_rsi_3 > 16.0)
          and (last_aroonu_14_15m_lt_25)
          and (last_close < (last_ema_12 * 0.984))
        )
        or (
          (last_rsi_14_lt_36)
          and (last_rsi_3_15m_gt_10)
          and (last_rsi_3_1h_gt_10)
          and (last_rsi_3_4h_gt_10)
          and (last_candle["AROONU_14_1h"] > last_candle["AROOND_14_1h"])
          and (last_candle["AROONU_14_4h"] > last_candle["AROOND_14_4h"])
          and (last_close < (last_ema_26 * 0.978))
          and (last_close < (last_candle["BBL_20_2.0"] * 0.999))
        )
        or (
          (last_rsi_14_lt_36)
          and (last_rsi_3_1h_gt_20)
          and (last_rsi_3_4h_gt_20)
          and (last_rsi_14_1h_lt_80)
          and (last_rsi_14_4h_lt_60)
          and (last_aroonu_14 > last_candle["AROOND_14"])
          and (previous_candle["AROONU_14"] < previous_candle["AROOND_14"])
        )
        or (
          (last_rsi_14_lt_36)
          and (last_rsi_3_15m > 15.0)
          and (last_rsi_3_1h_gt_20)
          and (last_rsi_3_4h_gt_20)
          and (last_rsi_14_1h_lt_80)
          and (last_rsi_14_4h_lt_60)
          and (last_candle["KST_10_15_20_30_10_10_10_15"] > last_candle["KSTs_9"])
          and (previous_candle["KST_10_15_20_30_10_10_10_15"] < previous_candle["KSTs_9"])
        )
        or (
          is_derisk
          and (last_rsi_3 > 20.0)
          and (last_rsi_3_15m > 20.0)
          and (last_rsi_3_1h_gt_20)
          and (last_rsi_3_4h_gt_20)
          and (last_rsi_14_lt_36)
          and (last_aroonu_14_lt_25)
          and (last_aroonu_14_15m_lt_25)
          and (last_candle["STOCHRSIk_14_14_3_3_15m"] < 50.0)
          and (last_close < (last_candle["EMA_20"] * 0.980))
        )
      )
    ):
      return True

    return False

  # Long Grinding Adjust Trade Position No De-Risk
  # ---------------------------------------------------------------------------------------------
  def long_adjust_trade_position_no_derisk(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    last_candle: Series,
    previous_candle: Series,
    filled_orders: "Orders",
    filled_entries: "Orders",
    filled_exits: "Orders",
    exit_rate: float,
    slice_amount: float,
    slice_profit_entry: float,
    slice_profit: float,
    profit_ratio: float,
    profit_stake: float,
    profit_init_ratio: float,
    current_stake_amount: float,
    has_order_tags: bool,
    count_of_exits: int,
    **kwargs,
  ) -> tuple[Optional[float], str, bool]:
    dp = self.dp
    send_msg = self.dp.send_msg
    notification_msg = self.notification_msg
    scale_stakes_for_min_stake = self.scale_stakes_for_min_stake
    stake_currency = self.config["stake_currency"]
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_stake_amount = trade.stake_amount
    trade_fee_open = trade.fee_open
    trade_fee_close = trade.fee_close

    is_backtest = dp.runmode.value in ["backtest", "hyperopt"]
    trade_open_date = None if is_backtest else trade.open_date_utc.replace(tzinfo=None)
    is_futures = self.is_futures_mode
    trade_leverage = trade.leverage
    stake_scale_leverage = trade_leverage if is_futures else 1.0
    regular_mode_use_grind_stops = self.regular_mode_use_grind_stops

    # Reused no-derisk slice-profit gates
    slice_profit_lt_neg_0_02 = slice_profit < -0.02
    slice_profit_lt_neg_0_03 = slice_profit < -0.03
    slice_profit_lt_neg_0_06 = slice_profit < -0.06

    last_filled_entry = filled_entries[-1]
    first_filled_order = filled_orders[0]
    last_filled_order = filled_orders[-1]

    max_rebuy_sub_grinds = 0
    regular_mode_rebuy_stakes = scale_stakes_for_min_stake(
      self.regular_mode_rebuy_stakes_futures if is_futures else self.regular_mode_rebuy_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_rebuy_sub_thresholds = (
      self.regular_mode_rebuy_thresholds_futures if is_futures else self.regular_mode_rebuy_thresholds_spot
    )
    max_rebuy_sub_grinds = len(regular_mode_rebuy_stakes)

    max_grind_1_sub_grinds = 0
    regular_mode_grind_1_stakes = scale_stakes_for_min_stake(
      self.regular_mode_grind_1_stakes_futures if is_futures else self.regular_mode_grind_1_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_grind_1_sub_thresholds = (
      self.regular_mode_grind_1_thresholds_futures if is_futures else self.regular_mode_grind_1_thresholds_spot
    )
    max_grind_1_sub_grinds = len(regular_mode_grind_1_stakes)
    regular_mode_grind_1_stop_grinds = (
      self.regular_mode_grind_1_stop_grinds_futures if is_futures else self.regular_mode_grind_1_stop_grinds_spot
    )
    regular_mode_grind_1_profit_threshold = (
      self.regular_mode_grind_1_profit_threshold_futures
      if is_futures
      else self.regular_mode_grind_1_profit_threshold_spot
    )

    max_grind_2_sub_grinds = 0
    regular_mode_grind_2_stakes = scale_stakes_for_min_stake(
      self.regular_mode_grind_2_stakes_futures if is_futures else self.regular_mode_grind_2_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_grind_2_sub_thresholds = (
      self.regular_mode_grind_2_thresholds_futures if is_futures else self.regular_mode_grind_2_thresholds_spot
    )
    max_grind_2_sub_grinds = len(regular_mode_grind_2_stakes)
    regular_mode_grind_2_stop_grinds = (
      self.regular_mode_grind_2_stop_grinds_futures if is_futures else self.regular_mode_grind_2_stop_grinds_spot
    )
    regular_mode_grind_2_profit_threshold = (
      self.regular_mode_grind_2_profit_threshold_futures
      if is_futures
      else self.regular_mode_grind_2_profit_threshold_spot
    )

    max_grind_3_sub_grinds = 0
    regular_mode_grind_3_stakes = scale_stakes_for_min_stake(
      self.regular_mode_grind_3_stakes_futures if is_futures else self.regular_mode_grind_3_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_grind_3_sub_thresholds = (
      self.regular_mode_grind_3_thresholds_futures if is_futures else self.regular_mode_grind_3_thresholds_spot
    )
    max_grind_3_sub_grinds = len(regular_mode_grind_3_stakes)
    regular_mode_grind_3_stop_grinds = (
      self.regular_mode_grind_3_stop_grinds_futures if is_futures else self.regular_mode_grind_3_stop_grinds_spot
    )
    regular_mode_grind_3_profit_threshold = (
      self.regular_mode_grind_3_profit_threshold_futures
      if is_futures
      else self.regular_mode_grind_3_profit_threshold_spot
    )

    max_grind_4_sub_grinds = 0
    regular_mode_grind_4_stakes = scale_stakes_for_min_stake(
      self.regular_mode_grind_4_stakes_futures if is_futures else self.regular_mode_grind_4_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_grind_4_sub_thresholds = (
      self.regular_mode_grind_4_thresholds_futures if is_futures else self.regular_mode_grind_4_thresholds_spot
    )
    max_grind_4_sub_grinds = len(regular_mode_grind_4_stakes)
    regular_mode_grind_4_stop_grinds = (
      self.regular_mode_grind_4_stop_grinds_futures if is_futures else self.regular_mode_grind_4_stop_grinds_spot
    )
    regular_mode_grind_4_profit_threshold = (
      self.regular_mode_grind_4_profit_threshold_futures
      if is_futures
      else self.regular_mode_grind_4_profit_threshold_spot
    )

    max_grind_5_sub_grinds = 0
    regular_mode_grind_5_stakes = scale_stakes_for_min_stake(
      self.regular_mode_grind_5_stakes_futures if is_futures else self.regular_mode_grind_5_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_grind_5_sub_thresholds = (
      self.regular_mode_grind_5_thresholds_futures if is_futures else self.regular_mode_grind_5_thresholds_spot
    )
    max_grind_5_sub_grinds = len(regular_mode_grind_5_stakes)
    regular_mode_grind_5_stop_grinds = (
      self.regular_mode_grind_5_stop_grinds_futures if is_futures else self.regular_mode_grind_5_stop_grinds_spot
    )
    regular_mode_grind_5_profit_threshold = (
      self.regular_mode_grind_5_profit_threshold_futures
      if is_futures
      else self.regular_mode_grind_5_profit_threshold_spot
    )

    max_grind_6_sub_grinds = 0
    regular_mode_grind_6_stakes = scale_stakes_for_min_stake(
      self.regular_mode_grind_6_stakes_futures if is_futures else self.regular_mode_grind_6_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_grind_6_sub_thresholds = (
      self.regular_mode_grind_6_thresholds_futures if is_futures else self.regular_mode_grind_6_thresholds_spot
    )
    max_grind_6_sub_grinds = len(regular_mode_grind_6_stakes)
    regular_mode_grind_6_stop_grinds = (
      self.regular_mode_grind_6_stop_grinds_futures if is_futures else self.regular_mode_grind_6_stop_grinds_spot
    )
    regular_mode_grind_6_profit_threshold = (
      self.regular_mode_grind_6_profit_threshold_futures
      if is_futures
      else self.regular_mode_grind_6_profit_threshold_spot
    )

    partial_sell = False
    is_derisk = False
    is_derisk_1 = False
    rebuy_sub_grind_count = 0
    rebuy_total_amount = 0.0
    rebuy_total_cost = 0.0
    rebuy_current_open_rate = 0.0
    rebuy_current_grind_stake = 0.0
    rebuy_current_grind_stake_profit = 0.0
    rebuy_is_sell_found = False
    rebuy_found = False
    rebuy_buy_orders = []
    rebuy_distance_ratio = 0.0
    grind_1_sub_grind_count = 0
    grind_1_total_amount = 0.0
    grind_1_total_cost = 0.0
    grind_1_current_open_rate = 0.0
    grind_1_current_grind_stake = 0.0
    grind_1_current_grind_stake_profit = 0.0
    grind_1_is_sell_found = False
    grind_1_found = False
    grind_1_buy_orders = []
    grind_1_distance_ratio = 0.0
    grind_2_sub_grind_count = 0
    grind_2_total_amount = 0.0
    grind_2_total_cost = 0.0
    grind_2_current_open_rate = 0.0
    grind_2_current_grind_stake = 0.0
    grind_2_current_grind_stake_profit = 0.0
    grind_2_is_sell_found = False
    grind_2_found = False
    grind_2_buy_orders = []
    grind_2_distance_ratio = 0.0
    grind_3_sub_grind_count = 0
    grind_3_total_amount = 0.0
    grind_3_total_cost = 0.0
    grind_3_current_open_rate = 0.0
    grind_3_current_grind_stake = 0.0
    grind_3_current_grind_stake_profit = 0.0
    grind_3_is_sell_found = False
    grind_3_found = False
    grind_3_buy_orders = []
    grind_3_distance_ratio = 0.0
    grind_4_sub_grind_count = 0
    grind_4_total_amount = 0.0
    grind_4_total_cost = 0.0
    grind_4_current_open_rate = 0.0
    grind_4_current_grind_stake = 0.0
    grind_4_current_grind_stake_profit = 0.0
    grind_4_is_sell_found = False
    grind_4_found = False
    grind_4_buy_orders = []
    grind_4_distance_ratio = 0.0
    grind_5_sub_grind_count = 0
    grind_5_total_amount = 0.0
    grind_5_total_cost = 0.0
    grind_5_current_open_rate = 0.0
    grind_5_current_grind_stake = 0.0
    grind_5_current_grind_stake_profit = 0.0
    grind_5_is_sell_found = False
    grind_5_found = False
    grind_5_buy_orders = []
    grind_5_distance_ratio = 0.0
    grind_6_sub_grind_count = 0
    grind_6_total_amount = 0.0
    grind_6_total_cost = 0.0
    grind_6_current_open_rate = 0.0
    grind_6_current_grind_stake = 0.0
    grind_6_current_grind_stake_profit = 0.0
    grind_6_is_sell_found = False
    grind_6_found = False
    grind_6_buy_orders = []
    grind_6_distance_ratio = 0.0
    for order in reversed(filled_orders):
      order_side = order.ft_order_side
      if (order_side == "buy") and (order is not first_filled_order):
        order_tag = ""
        if has_order_tags:
          order_ft_tag = order.ft_order_tag
          if order_ft_tag is not None:
            order_tag = order_ft_tag
        order_safe_filled = order.safe_filled
        order_safe_price = order.safe_price
        order_id = order.id
        if not grind_1_is_sell_found and order_tag == "g1":
          grind_1_sub_grind_count += 1
          grind_1_total_amount += order_safe_filled
          grind_1_total_cost += order_safe_filled * order_safe_price
          grind_1_buy_orders.append(order_id)
          if not grind_1_found:
            grind_1_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_1_found = True
        elif not grind_2_is_sell_found and order_tag == "g2":
          grind_2_sub_grind_count += 1
          grind_2_total_amount += order_safe_filled
          grind_2_total_cost += order_safe_filled * order_safe_price
          grind_2_buy_orders.append(order_id)
          if not grind_2_found:
            grind_2_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_2_found = True
        elif not grind_3_is_sell_found and order_tag == "g3":
          grind_3_sub_grind_count += 1
          grind_3_total_amount += order_safe_filled
          grind_3_total_cost += order_safe_filled * order_safe_price
          grind_3_buy_orders.append(order_id)
          if not grind_3_found:
            grind_3_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_3_found = True
        elif not grind_4_is_sell_found and order_tag == "g4":
          grind_4_sub_grind_count += 1
          grind_4_total_amount += order_safe_filled
          grind_4_total_cost += order_safe_filled * order_safe_price
          grind_4_buy_orders.append(order_id)
          if not grind_4_found:
            grind_4_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_4_found = True
        elif not grind_5_is_sell_found and order_tag == "g5":
          grind_5_sub_grind_count += 1
          grind_5_total_amount += order_safe_filled
          grind_5_total_cost += order_safe_filled * order_safe_price
          grind_5_buy_orders.append(order_id)
          if not grind_5_found:
            grind_5_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_5_found = True
        elif not grind_6_is_sell_found and order_tag == "g6":
          grind_6_sub_grind_count += 1
          grind_6_total_amount += order_safe_filled
          grind_6_total_cost += order_safe_filled * order_safe_price
          grind_6_buy_orders.append(order_id)
          if not grind_6_found:
            grind_6_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_6_found = True
        elif not rebuy_is_sell_found and order_tag not in [
          "g1",
          "g2",
          "g3",
          "g4",
          "g5",
          "g6",
          "sg1",
          "sg2",
          "sg3",
          "sg4",
          "sg5",
          "sg6",
          "dl1",
          "dl2",
          "gd1",
          "gd2",
          "gd3",
          "gd4",
          "gd5",
          "gd6",
          "gm0",
          "gmd0",
        ]:
          rebuy_sub_grind_count += 1
          rebuy_total_amount += order_safe_filled
          rebuy_total_cost += order_safe_filled * order_safe_price
          rebuy_buy_orders.append(order_id)
          if not rebuy_found:
            rebuy_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            rebuy_found = True
      elif order_side == "sell":
        if order is filled_exits[-1] and (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
          break
        order_tag = ""
        if has_order_tags:
          order_ft_tag = order.ft_order_tag
          if order_ft_tag is not None:
            order_tag = order_ft_tag.partition(" ")[0]
        if order_tag in ["g1", "sg1"]:
          grind_1_is_sell_found = True
        elif order_tag in ["g2", "sg2"]:
          grind_2_is_sell_found = True
        elif order_tag in ["g3", "sg3"]:
          grind_3_is_sell_found = True
        elif order_tag in ["g4", "sg4"]:
          grind_4_is_sell_found = True
        elif order_tag in ["g5", "sg5"]:
          grind_5_is_sell_found = True
        elif order_tag in ["g6", "sg6"]:
          grind_6_is_sell_found = True
        elif order_tag in ["d", "d1", "dd0", "ddl1", "ddl2", "dd1", "dd2", "dd3", "dd4", "dd5", "dd6"]:
          is_derisk = True
          if order_tag == "d1":
            is_derisk_1 = True
          grind_1_is_sell_found = True
          grind_2_is_sell_found = True
          grind_3_is_sell_found = True
          grind_4_is_sell_found = True
          grind_5_is_sell_found = True
          grind_6_is_sell_found = True
          rebuy_is_sell_found = True
        elif order_tag not in [
          "p",
          "g1",
          "g2",
          "g3",
          "g4",
          "g5",
          "g6",
          "sg1",
          "sg2",
          "sg3",
          "sg4",
          "sg5",
          "sg6",
          "dl1",
          "dl2",
          "gd1",
          "gd2",
          "gd3",
          "gd4",
          "gd5",
          "gd6",
          "gm0",
          "gmd0",
        ]:
          rebuy_is_sell_found = True
        if not is_derisk:
          start_amount = first_filled_order.safe_filled
          current_amount = 0.0
          for order2 in filled_orders:
            if order2.ft_order_side == "buy":
              current_amount += order2.safe_filled
            elif order2.ft_order_side == "sell":
              current_amount -= order2.safe_filled
            if order2 is order:
              if current_amount < (start_amount * 0.95):
                is_derisk = True
        # found sells for all modes
        if (
          rebuy_is_sell_found
          and grind_1_is_sell_found
          and grind_2_is_sell_found
          and grind_3_is_sell_found
          and grind_4_is_sell_found
          and grind_5_is_sell_found
          and grind_6_is_sell_found
        ):
          break

    # The trade already de-risked
    if is_derisk:
      return None, "", is_derisk
    if not has_order_tags and count_of_exits > 0:
      return None, "", is_derisk

    if rebuy_sub_grind_count > 0:
      rebuy_current_open_rate = rebuy_total_cost / rebuy_total_amount
      rebuy_current_grind_stake = rebuy_total_amount * exit_rate * (1 - trade_fee_close)
      rebuy_current_grind_stake_profit = rebuy_current_grind_stake - rebuy_total_cost
    if grind_1_sub_grind_count > 0:
      grind_1_current_open_rate = grind_1_total_cost / grind_1_total_amount
      grind_1_current_grind_stake = grind_1_total_amount * exit_rate * (1 - trade_fee_close)
      grind_1_current_grind_stake_profit = grind_1_current_grind_stake - grind_1_total_cost
    if grind_2_sub_grind_count > 0:
      grind_2_current_open_rate = grind_2_total_cost / grind_2_total_amount
      grind_2_current_grind_stake = grind_2_total_amount * exit_rate * (1 - trade_fee_close)
      grind_2_current_grind_stake_profit = grind_2_current_grind_stake - grind_2_total_cost
    if grind_3_sub_grind_count > 0:
      grind_3_current_open_rate = grind_3_total_cost / grind_3_total_amount
      grind_3_current_grind_stake = grind_3_total_amount * exit_rate * (1 - trade_fee_close)
      grind_3_current_grind_stake_profit = grind_3_current_grind_stake - grind_3_total_cost
    if grind_4_sub_grind_count > 0:
      grind_4_current_open_rate = grind_4_total_cost / grind_4_total_amount
      grind_4_current_grind_stake = grind_4_total_amount * exit_rate * (1 - trade_fee_close)
      grind_4_current_grind_stake_profit = grind_4_current_grind_stake - grind_4_total_cost
    if grind_5_sub_grind_count > 0:
      grind_5_current_open_rate = grind_5_total_cost / grind_5_total_amount
      grind_5_current_grind_stake = grind_5_total_amount * exit_rate * (1 - trade_fee_close)
      grind_5_current_grind_stake_profit = grind_5_current_grind_stake - grind_5_total_cost
    if grind_6_sub_grind_count > 0:
      grind_6_current_open_rate = grind_6_total_cost / grind_6_total_amount
      grind_6_current_grind_stake = grind_6_total_amount * exit_rate * (1 - trade_fee_close)
      grind_6_current_grind_stake_profit = grind_6_current_grind_stake - grind_6_total_cost

    num_open_grinds = (
      grind_1_sub_grind_count
      + grind_2_sub_grind_count
      + grind_3_sub_grind_count
      + grind_4_sub_grind_count
      + grind_5_sub_grind_count
      + grind_6_sub_grind_count
    )

    is_scalp_mode = all(c in self.long_scalp_mode_tags for c in enter_tags)

    fee_open_rate = trade_fee_open if self.custom_fee_open_rate is None else self.custom_fee_open_rate
    fee_close_rate = trade_fee_close if self.custom_fee_close_rate is None else self.custom_fee_close_rate

    # Sell remaining if partial fill on exit
    if partial_sell:
      order = filled_exits[-1]
      sell_amount = order.safe_remaining * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        send_msg(
          f"Exit (remaining) [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {order.safe_remaining} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        order_tag = "p"
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag
        return -ft_sell_amount, order_tag, is_derisk

    is_long_grind_entry = self.long_grind_entry(last_candle, previous_candle, slice_profit, False)

    # Rebuy
    if (not partial_sell) and (not rebuy_is_sell_found) and (rebuy_sub_grind_count < max_rebuy_sub_grinds):
      if (
        (0 <= rebuy_sub_grind_count < max_rebuy_sub_grinds)
        and (slice_profit_entry < regular_mode_rebuy_sub_thresholds[rebuy_sub_grind_count])
        and (
          (rebuy_distance_ratio if (rebuy_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_rebuy_sub_thresholds[rebuy_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=12) > last_filled_order.order_filled_utc) or (slice_profit_lt_neg_0_06))
        and is_long_grind_entry
      ):
        buy_amount = slice_amount * regular_mode_rebuy_stakes[rebuy_sub_grind_count] / stake_scale_leverage
        if buy_amount > max_stake:
          buy_amount = max_stake
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        send_msg(
          notification_msg(
            "rebuy",
            tag="r",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"Rebuy (r) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        order_tag = "r"
        return buy_amount, order_tag, is_derisk

    # Grinding g1
    # Grinding entry
    if has_order_tags and (not partial_sell) and (grind_1_sub_grind_count < max_grind_1_sub_grinds):
      if (
        (
          (grind_1_distance_ratio if (grind_1_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_grind_1_sub_thresholds[grind_1_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or (slice_profit_lt_neg_0_02))
        and (
          (num_open_grinds == 0)
          or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
          or (slice_profit_lt_neg_0_06)
        )
        and ((num_open_grinds == 0) or (slice_profit_lt_neg_0_03))
        and is_long_grind_entry
      ):
        buy_amount = slice_amount * regular_mode_grind_1_stakes[grind_1_sub_grind_count] / stake_scale_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_1_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
          grind_profit_stake = grind_1_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="g1",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (g1) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "g1"
        return buy_amount, order_tag, is_derisk

    if (
      is_futures
      and has_order_tags
      and (not partial_sell)
      and slice_profit < (-0.65 / trade_leverage)
      and (grind_1_sub_grind_count < max_grind_1_sub_grinds)
    ):
      buy_amount = slice_amount * regular_mode_grind_1_stakes[grind_1_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None, "", is_derisk
      grind_profit = 0.0
      grind_profit_stake = 0.0
      if grind_1_sub_grind_count > 0:
        grind_profit = (exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
        grind_profit_stake = grind_1_current_grind_stake_profit
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="g1",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
          grind_profit_stake=grind_1_current_grind_stake_profit,
          grind_profit_pct=grind_profit,
        )
      )
      log.info(
        f"Grinding entry (g1) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_stake_profit} {stake_currency})"
      )
      order_tag = "g1"
      return buy_amount, order_tag, is_derisk

    # Grinding Exit
    if has_order_tags and grind_1_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
      if grind_profit > (regular_mode_grind_1_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_1_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="g1",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_1_total_amount,
            )
          )
          log.info(
            f"Grinding exit (g1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "g1"
          for grind_entry_id in grind_1_buy_orders:
            order_tag += " " + str(grind_entry_id)
          return -ft_sell_amount, order_tag, is_derisk

    # Grind stop
    if (
      (
        (grind_1_sub_grind_count > 0)
        and regular_mode_use_grind_stops
        and (((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate) < regular_mode_grind_1_stop_grinds)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 4, 16))
    ):
      sell_amount = grind_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_1_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate)
            if grind_1_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="sg1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_1_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (sg1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "sg1"
        for grind_entry_id in grind_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        return -ft_sell_amount, order_tag, is_derisk

    # Grinding g2
    # Grinding entry
    if has_order_tags and (not partial_sell) and (grind_2_sub_grind_count < max_grind_2_sub_grinds):
      if (
        (
          (grind_2_distance_ratio if (grind_2_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_grind_2_sub_thresholds[grind_2_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or (slice_profit_lt_neg_0_02))
        and (
          (num_open_grinds == 0)
          or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
          or (slice_profit_lt_neg_0_06)
        )
        and ((num_open_grinds == 0) or (slice_profit_lt_neg_0_03))
        and is_long_grind_entry
      ):
        buy_amount = slice_amount * regular_mode_grind_2_stakes[grind_2_sub_grind_count] / stake_scale_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_2_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
          grind_profit_stake = grind_2_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="g2",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_2_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (g2) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_2_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "g2"
        return buy_amount, order_tag, is_derisk

    # Grinding Exit
    if has_order_tags and grind_2_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
      if grind_profit > (regular_mode_grind_2_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_2_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="g2",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_2_total_amount,
            )
          )
          log.info(
            f"Grinding exit (g2) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "g2"
          for grind_entry_id in grind_2_buy_orders:
            order_tag += " " + str(grind_entry_id)
          return -ft_sell_amount, order_tag, is_derisk

    # Grind stop
    if (
      (
        (grind_2_sub_grind_count > 0)
        and regular_mode_use_grind_stops
        and (((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate) < regular_mode_grind_2_stop_grinds)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 4, 16))
    ):
      sell_amount = grind_2_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_2_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate)
            if grind_2_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="sg2",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_2_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (sg2) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "sg2"
        for grind_entry_id in grind_2_buy_orders:
          order_tag += " " + str(grind_entry_id)
        return -ft_sell_amount, order_tag, is_derisk

    # Grinding g3
    # Grinding entry
    if has_order_tags and (not partial_sell) and (grind_3_sub_grind_count < max_grind_3_sub_grinds):
      if (
        (
          (grind_3_distance_ratio if (grind_3_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_grind_3_sub_thresholds[grind_3_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or (slice_profit_lt_neg_0_02))
        and (
          (num_open_grinds == 0)
          or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
          or (slice_profit_lt_neg_0_06)
        )
        and ((num_open_grinds == 0) or (slice_profit_lt_neg_0_03))
        and is_long_grind_entry
      ):
        buy_amount = slice_amount * regular_mode_grind_3_stakes[grind_3_sub_grind_count] / stake_scale_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_3_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
          grind_profit_stake = grind_3_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="g3",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_3_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (g3) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_3_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "g3"
        return buy_amount, order_tag, is_derisk

    # Grinding Exit
    if has_order_tags and grind_3_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
      if grind_profit > (regular_mode_grind_3_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_3_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="g3",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_3_total_amount,
            )
          )
          log.info(
            f"Grinding exit (g3) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "g3"
          for grind_entry_id in grind_3_buy_orders:
            order_tag += " " + str(grind_entry_id)
          return -ft_sell_amount, order_tag, is_derisk

    # Grind stop
    if (
      (
        (grind_3_sub_grind_count > 0)
        and regular_mode_use_grind_stops
        and (((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate) < regular_mode_grind_3_stop_grinds)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 4, 16))
    ):
      sell_amount = grind_3_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_3_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate)
            if grind_3_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="sg3",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_3_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (sg3) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "sg3"
        for grind_entry_id in grind_3_buy_orders:
          order_tag += " " + str(grind_entry_id)
        return -ft_sell_amount, order_tag, is_derisk

    # Grinding g4
    # Grinding entry
    if has_order_tags and (not partial_sell) and (grind_4_sub_grind_count < max_grind_4_sub_grinds):
      if (
        (
          (grind_4_distance_ratio if (grind_4_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_grind_4_sub_thresholds[grind_4_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or (slice_profit_lt_neg_0_02))
        and (
          (num_open_grinds == 0)
          or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
          or (slice_profit_lt_neg_0_06)
        )
        and ((num_open_grinds == 0) or (slice_profit_lt_neg_0_03))
        and is_long_grind_entry
      ):
        buy_amount = slice_amount * regular_mode_grind_4_stakes[grind_4_sub_grind_count] / stake_scale_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_4_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
          grind_profit_stake = grind_4_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="g4",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_4_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (g4) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_4_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "g4"
        return buy_amount, order_tag, is_derisk

    # Grinding Exit
    if has_order_tags and grind_4_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
      if grind_profit > (regular_mode_grind_4_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_4_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="g4",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_4_total_amount,
            )
          )
          log.info(
            f"Grinding exit (g4) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "g4"
          for grind_entry_id in grind_4_buy_orders:
            order_tag += " " + str(grind_entry_id)
          return -ft_sell_amount, order_tag, is_derisk

    # Grind stop
    if (
      (
        (grind_4_sub_grind_count > 0)
        and regular_mode_use_grind_stops
        and (((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate) < regular_mode_grind_4_stop_grinds)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 4, 16))
    ):
      sell_amount = grind_4_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_4_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate)
            if grind_4_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="sg4",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_4_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (sg4) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "sg4"
        for grind_entry_id in grind_4_buy_orders:
          order_tag += " " + str(grind_entry_id)
        return -ft_sell_amount, order_tag, is_derisk

    # Grinding g5
    # Grinding entry
    if has_order_tags and (not partial_sell) and (grind_5_sub_grind_count < max_grind_5_sub_grinds):
      if (
        (
          (grind_5_distance_ratio if (grind_5_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_grind_5_sub_thresholds[grind_5_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or (slice_profit_lt_neg_0_02))
        and (
          (num_open_grinds == 0)
          or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
          or (slice_profit_lt_neg_0_06)
        )
        and ((num_open_grinds == 0) or (slice_profit_lt_neg_0_03))
        and is_long_grind_entry
      ):
        buy_amount = slice_amount * regular_mode_grind_5_stakes[grind_5_sub_grind_count] / stake_scale_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_5_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
          grind_profit_stake = grind_5_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="g5",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_5_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (g5) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_5_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "g5"
        return buy_amount, order_tag, is_derisk

    # Grinding Exit
    if has_order_tags and grind_5_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
      if grind_profit > (regular_mode_grind_5_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_5_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="g5",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_5_total_amount,
            )
          )
          log.info(
            f"Grinding exit (g5) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "g5"
          for grind_entry_id in grind_5_buy_orders:
            order_tag += " " + str(grind_entry_id)
          return -ft_sell_amount, order_tag, is_derisk

    # Grind stop
    if (
      (
        (grind_5_sub_grind_count > 0)
        and regular_mode_use_grind_stops
        and (((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate) < regular_mode_grind_5_stop_grinds)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 4, 16))
    ):
      sell_amount = grind_5_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_5_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate)
            if grind_5_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="sg5",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_5_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (sg5) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "sg5"
        for grind_entry_id in grind_5_buy_orders:
          order_tag += " " + str(grind_entry_id)
        return -ft_sell_amount, order_tag, is_derisk

    # Grinding g6
    # Grinding entry
    if has_order_tags and (not partial_sell) and (grind_6_sub_grind_count < max_grind_6_sub_grinds):
      if (
        (
          (grind_6_distance_ratio if (grind_6_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_grind_6_sub_thresholds[grind_6_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or (slice_profit_lt_neg_0_02))
        and (
          (num_open_grinds == 0)
          or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
          or (slice_profit_lt_neg_0_06)
        )
        # and ((num_open_grinds == 0) or (slice_profit_lt_neg_0_03))
        and (is_long_grind_entry)
      ):
        buy_amount = slice_amount * regular_mode_grind_6_stakes[grind_6_sub_grind_count] / stake_scale_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_6_sub_grind_count > 0:
          grind_profit = (exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate
          grind_profit_stake = grind_6_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="g6",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_6_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (g6) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_6_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "g6"
        return buy_amount, order_tag, is_derisk

    # Grinding Exit
    if has_order_tags and grind_6_sub_grind_count > 0:
      grind_profit = (exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate
      if grind_profit > (regular_mode_grind_6_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_6_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="g6",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_6_total_amount,
            )
          )
          log.info(
            f"Grinding exit (g6) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_6_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "g6"
          for grind_entry_id in grind_6_buy_orders:
            order_tag += " " + str(grind_entry_id)
          return -ft_sell_amount, order_tag, is_derisk

    # Grind stop
    if (
      (
        (grind_6_sub_grind_count > 0)
        and regular_mode_use_grind_stops
        and (((exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate) < regular_mode_grind_6_stop_grinds)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 4, 16))
    ):
      sell_amount = grind_6_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_6_current_open_rate > 0.0:
          grind_profit = (
            ((exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate)
            if grind_6_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="sg6",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_6_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (sg6) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_6_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "sg6"
        for grind_entry_id in grind_6_buy_orders:
          order_tag += " " + str(grind_entry_id)
        return -ft_sell_amount, order_tag, is_derisk

    # De-risk
    if (
      self.derisk_enable
      and (
        profit_stake
        < (
          slice_amount
          * (
            (self.regular_mode_derisk_futures if is_futures else self.regular_mode_derisk_spot)
            if (is_backtest or trade_open_date >= datetime(2024, 9, 13))
            else (self.regular_mode_derisk_futures_old if is_futures else self.regular_mode_derisk_spot_old)
          )
          / trade_leverage
        )
      )
      and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
    ):
      sell_amount = trade_amount * exit_rate / trade_leverage - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="d",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "d", is_derisk

    # De-risk level 1
    if (
      self.derisk_enable
      and has_order_tags
      and not is_derisk_1
      and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
      and profit_stake
      < (
        slice_amount
        * (
          (self.regular_mode_derisk_1_scalp_mode_futures if is_futures else self.regular_mode_derisk_1_scalp_mode_spot)
          if is_scalp_mode
          else (
            (self.regular_mode_derisk_1_futures if is_futures else self.regular_mode_derisk_1_spot)
            if (is_backtest or trade_open_date >= datetime(2024, 9, 13))
            else (self.regular_mode_derisk_1_futures_old if is_futures else self.regular_mode_derisk_1_spot_old)
          )
        )
        / trade_leverage
      )
    ):
      sell_amount = trade_amount * exit_rate / trade_leverage - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="d1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk (d1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "d1", is_derisk

    return None, "", is_derisk

  # Long Rebuy Adjust Trade Position
  # ---------------------------------------------------------------------------------------------
  def long_rebuy_adjust_trade_position(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ) -> Optional[float]:
    # Stake limits and rebuy amounts are margin, before leverage.
    config = self.config

    dp = self.dp
    is_futures_mode = self.is_futures_mode
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_leverage = trade.leverage

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)

    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_entries = trade.nr_of_successful_entries
    count_of_exits = trade.nr_of_successful_exits

    if count_of_entries == 0:
      return None

    first_filled_order = filled_orders[0]
    last_filled_order = filled_orders[-1]
    last_filled_entry = filled_entries[-1]

    has_order_tags = hasattr(first_filled_order, "ft_order_tag")

    # The first exit is de-risk (providing the trade is still open)
    # Preserve the existing grind handoff budget after de-risk.
    if (count_of_exits > 0) and (filled_exits[0].ft_order_tag == "derisk_level_3"):
      if len(df) < 2:
        return None
      return self.long_grind_adjust_trade_position_v2(
        trade,
        enter_tags,
        current_time,
        current_rate,
        current_profit,
        min_stake,
        max_stake / trade_leverage,
        current_entry_rate,
        current_exit_rate,
        current_entry_profit,
        current_exit_profit,
      )

    if dp.runmode.value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = config["exit_pricing"]["price_side"]
        if trade.is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    slice_amount = filled_entries[0].safe_filled * filled_entries[0].safe_price
    slice_profit = (exit_rate - last_filled_order.safe_price) / last_filled_order.safe_price
    slice_profit_entry = (exit_rate - last_filled_entry.safe_price) / last_filled_entry.safe_price
    if count_of_exits > 0:
      last_filled_exit_price = filled_exits[-1].safe_price
      slice_profit_exit = (exit_rate - last_filled_exit_price) / last_filled_exit_price
    else:
      slice_profit_exit = 0.0

    current_stake_amount = trade_amount * current_rate
    stake_scale_leverage = trade_leverage if is_futures_mode else 1.0

    rebuy_mode_stakes = self.rebuy_mode_stakes_futures if is_futures_mode else self.rebuy_mode_stakes_spot
    max_sub_grinds = len(rebuy_mode_stakes)
    rebuy_mode_sub_thresholds = (
      self.rebuy_mode_thresholds_futures if is_futures_mode else self.rebuy_mode_thresholds_spot
    )
    partial_sell = False
    sub_grind_count = 0
    total_amount = 0.0
    total_cost = 0.0
    current_open_rate = 0.0
    current_grind_stake = 0.0
    current_grind_stake_profit = 0.0
    for order in reversed(filled_orders):
      if (order.ft_order_side == "buy") and (order is not first_filled_order):
        sub_grind_count += 1
        total_amount += order.safe_filled
        total_cost += order.safe_filled * order.safe_price
      elif order.ft_order_side == "sell":
        if (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
        break
    if sub_grind_count > 0:
      current_open_rate = total_cost / total_amount
      current_grind_stake = total_amount * exit_rate * (1 - trade.fee_close)
      current_grind_stake_profit = current_grind_stake - total_cost

    if (len(df) >= 2) and (not partial_sell) and (sub_grind_count < max_sub_grinds):
      last_candle = df.iloc[-1]
      previous_candle = df.iloc[-2]
      if (
        ((0 <= sub_grind_count < max_sub_grinds) and (slice_profit_entry < rebuy_mode_sub_thresholds[sub_grind_count]))
        # and (
        #   (last_candle["close"] > (last_candle["close_max_12"] * 0.94))
        #   and (last_candle["close"] > (last_candle["close_max_24"] * 0.92))
        #   and (last_candle["close"] > (last_candle["close_max_48"] * 0.90))
        #   and (last_candle["close"] > (last_candle["high_max_24_1h"] * 0.88))
        #   and (last_candle["close"] > (last_candle["high_max_48_1h"] * 0.86))
        #   and (last_candle["btc_pct_close_max_72_5m"] < 0.03)
        #   and (last_candle["btc_pct_close_max_24_5m"] < 0.03)
        # )
        and (
          (last_candle["RSI_3"] > 10.0)
          and (last_candle["RSI_3_15m"] > 10.0)
          # and (last_candle["RSI_3_1h"] > 10.0)
          # and (last_candle["RSI_3_4h"] > 10.0)
          and (last_candle["RSI_14"] < 40.0)
          and (last_candle["ROC_2"] > -0.0)
          and (last_candle["close"] < (last_candle["EMA_26"] * 0.988))
        )
      ):
        buy_amount = slice_amount * rebuy_mode_stakes[sub_grind_count] / trade_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount <= max_stake:
          dp.send_msg(
            self.notification_msg(
              "rebuy",
              tag="r",
              pair=trade_pair,
              rate=current_rate,
              stake_amount=buy_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=config["stake_currency"],
            )
          )
          log.info(
            f"Rebuy (r) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
          )
          if has_order_tags:
            return buy_amount, "r"
          else:
            return buy_amount

    if self.derisk_enable and (
      profit_stake
      < (
        slice_amount * (self.rebuy_mode_derisk_futures if is_futures_mode else self.rebuy_mode_derisk_spot)
        # / (trade.leverage if self.is_futures_mode else 1.0)
      )
    ):
      sell_amount = trade_amount * exit_rate / trade_leverage - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade.stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        dp.send_msg(
          f"❌​​ ​**Rebuy De-risk:** `Level 3`\n"
          f"🪙​ **Pair:** `{trade_pair}`\n"
          f"〽️​ **Rate:** `{exit_rate}`\n"
          f"💰 **Stake amount:** `{sell_amount}`\n"
          f"💵​ **Profit (stake):** `{profit_stake}`\n"
          f"💸 **Profit (percent):** `{(profit_ratio * 100.0):.2f}%`"
        )
        log.info(
          f"Rebuy De-risk Level 3 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        if has_order_tags:
          return -ft_sell_amount, "derisk_level_3"
        else:
          return -ft_sell_amount

    return None

  # Long Rebuy Adjust Trade Position v3
  # ---------------------------------------------------------------------------------------------
  def long_rebuy_adjust_trade_position_v3(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ) -> Optional[float]:
    # Stake limits and rebuy amounts are margin, before leverage.
    dp = self.dp
    is_futures_mode = self.is_futures_mode
    config = self.config
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_leverage = trade.leverage

    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_entries = trade.nr_of_successful_entries
    count_of_exits = trade.nr_of_successful_exits

    if count_of_entries == 0:
      return None

    first_filled_order = filled_orders[0]
    last_filled_order = filled_orders[-1]
    last_filled_entry = filled_entries[-1]

    has_order_tags = hasattr(first_filled_order, "ft_order_tag")

    # The first exit is de-risk (providing the trade is still open)
    # Preserve the existing grind handoff budget after de-risk.
    if (count_of_exits > 0) and (filled_exits[0].ft_order_tag == "derisk_level_3"):
      return self.long_grind_adjust_trade_position_v3(
        trade,
        enter_tags,
        current_time,
        current_rate,
        current_profit,
        min_stake,
        max_stake / trade_leverage,
        current_entry_rate,
        current_exit_rate,
        current_entry_profit,
        current_exit_profit,
      )

    if dp.runmode.value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = config["exit_pricing"]["price_side"]
        if trade.is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    slice_amount = filled_entries[0].safe_filled * filled_entries[0].safe_price
    slice_profit = (exit_rate - last_filled_order.safe_price) / last_filled_order.safe_price
    slice_profit_entry = (exit_rate - last_filled_entry.safe_price) / last_filled_entry.safe_price
    slice_profit_exit = (
      ((exit_rate - filled_exits[-1].safe_price) / filled_exits[-1].safe_price) if count_of_exits > 0 else 0.0
    )

    current_stake_amount = trade_amount * current_rate
    stake_scale_leverage = trade_leverage if is_futures_mode else 1.0

    if is_futures_mode:
      rebuy_mode_stakes = self.system_v3_rebuy_mode_stakes_futures
      rebuy_mode_sub_thresholds = self.system_v3_rebuy_mode_thresholds_futures
    else:
      rebuy_mode_stakes = self.system_v3_rebuy_mode_stakes_spot
      rebuy_mode_sub_thresholds = self.system_v3_rebuy_mode_thresholds_spot
    max_sub_grinds = len(rebuy_mode_stakes)
    partial_sell = False
    sub_grind_count = 0
    total_amount = 0.0
    total_cost = 0.0
    current_open_rate = 0.0
    current_grind_stake = 0.0
    current_grind_stake_profit = 0.0
    for order in reversed(filled_orders):
      if (order.ft_order_side == "buy") and (order is not first_filled_order):
        sub_grind_count += 1
        total_amount += order.safe_filled
        total_cost += order.safe_filled * order.safe_price
      elif order.ft_order_side == "sell":
        if (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
        break
    if sub_grind_count > 0:
      current_open_rate = total_cost / total_amount
      current_grind_stake = total_amount * exit_rate * (1 - trade.fee_close)
      current_grind_stake_profit = current_grind_stake - total_cost
    if (not partial_sell) and (sub_grind_count < max_sub_grinds):
      df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)
      if len(df) >= 1:
        last_candle = df.iloc[-1]
        if (
          (
            (0 <= sub_grind_count < max_sub_grinds)
            and (slice_profit_entry < rebuy_mode_sub_thresholds[sub_grind_count])
          )
          and (last_candle["protections_long_global"] == True)
          and (
            (last_candle["RSI_3"] > 10.0)
            and (last_candle["RSI_3_15m"] > 10.0)
            and (last_candle["AROONU_14"] < 30.0)
            and (last_candle["AROONU_14_15m"] < 30.0)
            # and (last_candle["ROC_9"] > -5.0)
            # and (last_candle["ROC_9_15m"] > -5.0)
            # and (last_candle["close"] > (last_candle["close_max_12"] * 0.99))
            and (last_candle["close"] < (last_candle["EMA_26"] * 0.988))
          )
        ):
          stake_currency = config["stake_currency"]
          stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
          send_notifications = not self.is_backtest_mode()
          buy_amount = slice_amount * rebuy_mode_stakes[sub_grind_count] / trade_leverage
          if buy_amount < (min_stake * 1.5):
            buy_amount = min_stake * 1.5
          if buy_amount <= max_stake:
            if send_notifications:
              dp.send_msg(
                self.notification_msg(
                  "rebuy",
                  tag="r",
                  pair=trade_pair,
                  rate=current_rate,
                  stake_amount=buy_amount,
                  profit_stake=profit_stake,
                  profit_ratio=profit_ratio,
                  stake_currency=stake_currency,
                )
              )
            log.info(
              f"Rebuy (r) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
            )
            if has_order_tags:
              return buy_amount, "r"
            else:
              return buy_amount

    if self.derisk_enable and (
      profit_stake
      < (
        slice_amount
        * (self.system_v3_rebuy_mode_derisk_futures if is_futures_mode else self.system_v3_rebuy_mode_derisk_spot)
      )
      / trade_leverage
    ):
      sell_amount = trade_amount * exit_rate / trade_leverage - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade.stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        stake_currency = config["stake_currency"]
        stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
        send_notifications = not self.is_backtest_mode()
        grind_profit = 0.0
        if send_notifications:
          dp.send_msg(
            f"❌​​ ​**Rebuy De-risk:** `Level 3`\n"
            f"🪙​ **Pair:** `{trade_pair}`\n"
            f"〽️​ **Rate:** `{exit_rate}`\n"
            f"💰 **Stake amount:** `{sell_amount:{stake_fmt}}`\n"
            f"💵​ **Profit (stake):** `{profit_stake:{stake_fmt}}`\n"
            f"💸 **Profit (percent):** `{(profit_ratio * 100.0):.2f}%`"
          )
        log.info(
          f"Rebuy De-risk Level 3 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        if has_order_tags:
          return -ft_sell_amount, "derisk_level_3"
        else:
          return -ft_sell_amount

    return None

  # Long Rebuy Adjust Trade Position v4
  # ---------------------------------------------------------------------------------------------
  def long_rebuy_adjust_trade_position_v4(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ) -> Optional[float]:
    # Stake limits and rebuy amounts are margin, before leverage.
    dp = self.dp
    is_futures_mode = self.is_futures_mode
    config = self.config
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_leverage = trade.leverage

    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_entries = trade.nr_of_successful_entries
    count_of_exits = trade.nr_of_successful_exits

    if count_of_entries == 0:
      return None

    first_filled_order = filled_orders[0]
    last_filled_order = filled_orders[-1]
    last_filled_entry = filled_entries[-1]

    has_order_tags = hasattr(first_filled_order, "ft_order_tag")

    # The first exit is de-risk (providing the trade is still open)
    # Preserve the existing grind handoff budget after de-risk.
    if (count_of_exits > 0) and (filled_exits[0].ft_order_tag == "derisk_level_3"):
      return self.long_grind_adjust_trade_position_v4(
        trade,
        enter_tags,
        current_time,
        current_rate,
        current_profit,
        min_stake,
        max_stake / trade_leverage,
        current_entry_rate,
        current_exit_rate,
        current_entry_profit,
        current_exit_profit,
      )

    if dp.runmode.value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = config["exit_pricing"]["price_side"]
        if trade.is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    slice_amount = filled_entries[0].safe_filled * filled_entries[0].safe_price
    slice_profit = (exit_rate - last_filled_order.safe_price) / last_filled_order.safe_price
    slice_profit_entry = (exit_rate - last_filled_entry.safe_price) / last_filled_entry.safe_price
    slice_profit_exit = (
      ((exit_rate - filled_exits[-1].safe_price) / filled_exits[-1].safe_price) if count_of_exits > 0 else 0.0
    )

    current_stake_amount = trade_amount * current_rate
    stake_scale_leverage = trade_leverage if is_futures_mode else 1.0

    if is_futures_mode:
      rebuy_mode_stakes = self.system_v4_rebuy_mode_stakes_futures
      rebuy_mode_sub_thresholds = self.system_v4_rebuy_mode_thresholds_futures
    else:
      rebuy_mode_stakes = self.system_v4_rebuy_mode_stakes_spot
      rebuy_mode_sub_thresholds = self.system_v4_rebuy_mode_thresholds_spot
    max_sub_grinds = len(rebuy_mode_stakes)
    partial_sell = False
    sub_grind_count = 0
    total_amount = 0.0
    total_cost = 0.0
    current_open_rate = 0.0
    current_grind_stake = 0.0
    current_grind_stake_profit = 0.0
    for order in reversed(filled_orders):
      if (order.ft_order_side == "buy") and (order is not first_filled_order):
        sub_grind_count += 1
        total_amount += order.safe_filled
        total_cost += order.safe_filled * order.safe_price
      elif order.ft_order_side == "sell":
        if (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
        break
    if sub_grind_count > 0:
      current_open_rate = total_cost / total_amount
      current_grind_stake = total_amount * exit_rate * (1 - trade.fee_close)
      current_grind_stake_profit = current_grind_stake - total_cost
    if (not partial_sell) and (sub_grind_count < max_sub_grinds):
      if (0 <= sub_grind_count < max_sub_grinds) and (slice_profit_entry < rebuy_mode_sub_thresholds[sub_grind_count]):
        df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)
        if len(df) >= 1:
          last_candle = df.iloc[-1]
          if (
            (last_candle["protections_long_global"] == True)
            and (last_candle["RSI_3"] > 10.0)
            and (last_candle["RSI_3_15m"] > 10.0)
            and (last_candle["AROONU_14"] < 30.0)
            and (last_candle["AROONU_14_15m"] < 30.0)
            # and (last_candle["ROC_9"] > -5.0)
            # and (last_candle["ROC_9_15m"] > -5.0)
            # and (last_candle["close"] > (last_candle["close_max_12"] * 0.99))
            and (last_candle["close"] < (last_candle["EMA_26"] * 0.988))
          ):
            stake_currency = config["stake_currency"]
            stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
            send_notifications = not self.is_backtest_mode()
            buy_amount = slice_amount * rebuy_mode_stakes[sub_grind_count] / trade_leverage
            if buy_amount < (min_stake * 1.5):
              buy_amount = min_stake * 1.5
            if buy_amount <= max_stake:
              if send_notifications:
                dp.send_msg(
                  self.notification_msg(
                    "rebuy",
                    tag="r",
                    pair=trade_pair,
                    rate=current_rate,
                    stake_amount=buy_amount,
                    profit_stake=profit_stake,
                    profit_ratio=profit_ratio,
                    stake_currency=stake_currency,
                  )
                )
              log.info(
                f"Rebuy (r) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
              )
              if has_order_tags:
                return buy_amount, "r"
              else:
                return buy_amount

    if self.derisk_enable and (
      profit_stake
      < (
        slice_amount
        * (self.system_v4_rebuy_mode_derisk_futures if is_futures_mode else self.system_v4_rebuy_mode_derisk_spot)
      )
      / trade_leverage
    ):
      sell_amount = trade_amount * exit_rate / trade_leverage - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade.stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        stake_currency = config["stake_currency"]
        stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
        send_notifications = not self.is_backtest_mode()
        grind_profit = 0.0
        if send_notifications:
          dp.send_msg(
            f"❌​​ ​**Rebuy De-risk:** `Level 3`\n"
            f"🪙​ **Pair:** `{trade_pair}`\n"
            f"〽️​ **Rate:** `{exit_rate}`\n"
            f"💰 **Stake amount:** `{sell_amount:{stake_fmt}}`\n"
            f"💵​ **Profit (stake):** `{profit_stake:{stake_fmt}}`\n"
            f"💸 **Profit (percent):** `{(profit_ratio * 100.0):.2f}%`"
          )
        log.info(
          f"Rebuy De-risk Level 3 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        if has_order_tags:
          return -ft_sell_amount, "derisk_level_3"
        else:
          return -ft_sell_amount

    return None

  ###############################################################################################

  # LONG GRIND FUNCTIONS ENDS HERE

  ###############################################################################################

  #   ______   __    __   ______   _______  ________         ______   ______  _______   ________
  #  /      \ |  \  |  \ /      \ |       \|        \       /      \ |      \|       \ |        \
  # |  $$$$$$\| $$  | $$|  $$$$$$\| $$$$$$$\\$$$$$$$$      |  $$$$$$\ \$$$$$$| $$$$$$$\| $$$$$$$$
  # | $$___\$$| $$__| $$| $$  | $$| $$__| $$  | $$         | $$___\$$  | $$  | $$  | $$| $$__
  #  \$$    \ | $$    $$| $$  | $$| $$    $$  | $$          \$$    \   | $$  | $$  | $$| $$  \
  #  _\$$$$$$\| $$$$$$$$| $$  | $$| $$$$$$$\  | $$          _\$$$$$$\  | $$  | $$  | $$| $$$$$
  # |  \__| $$| $$  | $$| $$__/ $$| $$  | $$  | $$         |  \__| $$ _| $$_ | $$__/ $$| $$_____
  #  \$$    $$| $$  | $$ \$$    $$| $$  | $$  | $$          \$$    $$|   $$ \| $$    $$| $$     \
  #   \$$$$$$  \$$   \$$  \$$$$$$  \$$   \$$   \$$           \$$$$$$  \$$$$$$ \$$$$$$$  \$$$$$$$$
  #

  # Short Side Functions for handling short orders
  # ---------------------------------------------------------------------------------------------

  ###############################################################################################

  # SHORT EXIT FUNCTIONS STARTS HERE

  ###############################################################################################

  #   ______  __    __  ______  _______ ________        ________ __    __ ______ ________
  #  /      \|  \  |  \/      \|       |        \      |        |  \  |  |      |        \
  # |  $$$$$$| $$  | $|  $$$$$$| $$$$$$$\$$$$$$$$      | $$$$$$$| $$  | $$\$$$$$$\$$$$$$$$
  # | $$___\$| $$__| $| $$  | $| $$__| $$ | $$         | $$__    \$$\/  $$ | $$    | $$
  #  \$$    \| $$    $| $$  | $| $$    $$ | $$         | $$  \    >$$  $$  | $$    | $$
  #  _\$$$$$$| $$$$$$$| $$  | $| $$$$$$$\ | $$         | $$$$$   /  $$$$\  | $$    | $$
  # |  \__| $| $$  | $| $$__/ $| $$  | $$ | $$         | $$_____|  $$ \$$\_| $$_   | $$
  #  \$$    $| $$  | $$\$$    $| $$  | $$ | $$         | $$     | $$  | $|   $$ \  | $$
  #   \$$$$$$ \$$   \$$ \$$$$$$ \$$   \$$  \$$          \$$$$$$$$\$$   \$$\$$$$$$   \$$
  #

  # Short Exit Normal
  # ---------------------------------------------------------------------------------------------
  def short_exit_normal(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_orders,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.short_normal_mode_name

    sell = False

    # if the profit is negative skip checking these
    if profit_init_ratio > 0.0:
      # Original sell signals
      sell, signal_name = self.short_exit_signals(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

      # Main sell signals
      if not sell:
        sell, signal_name = self.short_exit_main(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

      # Williams %R based sells
      if not sell:
        sell, signal_name = self.short_exit_williams_r(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

      # Downtrend/descending based sells
      if not sell:
        sell, signal_name = self.short_exit_dec(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

    # Stoplosses
    if not sell:
      sell, signal_name = self.short_exit_stoploss(
        mode_name,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None

    # Profit Target Signal
    # Check if pair exist on target_profit_cache
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    if target_data is not None:
      previous_rate = target_data["rate"]
      previous_profit = target_data["profit"]
      previous_sell_reason = target_data["sell_reason"]
      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )
      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"
      if previous_sell_reason == f"exit_{mode_name}_stoploss_u_e":
        if profit_ratio > (previous_profit + 0.005):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )
          if mark_pair:
            set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
      elif (profit_init_ratio > (previous_profit + 0.001)) and (
        previous_sell_reason != f"exit_{mode_name}_stoploss_doom"
      ):
        # Update the target, raise it.
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      previous_profit = None
      previous_sell_reason = ""
      target_data = profit_target_get(pair) if profit_target_get is not None else None
      if target_data is not None:
        previous_profit = target_data["profit"]
        previous_sell_reason = target_data["sell_reason"]
      if signal_name in [
        f"exit_{mode_name}_stoploss_doom",
        f"exit_{mode_name}_stoploss_u_e",
      ] and (
        previous_sell_reason
        not in [
          f"exit_{mode_name}_stoploss_doom",
          f"exit_{mode_name}_stoploss_u_e",
        ]
      ):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
      elif (previous_profit is None) or (previous_profit < profit_init_ratio):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
    else:
      if profit_init_ratio >= 0.005:
        previous_profit = None
        target_data = profit_target_get(pair) if profit_target_get is not None else None
        if target_data is not None:
          previous_profit = target_data["profit"]
        if (previous_profit is None) or (previous_profit < profit_init_ratio):
          mark_signal = f"exit_profit_{mode_name}_max"
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    if signal_name not in [
      f"exit_profit_{mode_name}_max",
      f"exit_{mode_name}_stoploss_doom",
      f"exit_{mode_name}_stoploss_u_e",
    ]:
      if sell and (signal_name is not None):
        return True, f"{signal_name}"

    #  Here ends exit signal conditions for short_exit_normal

    return False, None

  # Short Exit Pump
  # ---------------------------------------------------------------------------------------------
  def short_exit_pump(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_orders,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.short_pump_mode_name

    sell = False

    # if the profit is negative skip checking these
    if profit_init_ratio > 0.0:
      # Original sell signals
      sell, signal_name = self.short_exit_signals(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

      # Main sell signals
      if not sell:
        sell, signal_name = self.short_exit_main(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

      # Williams %R based sells
      if not sell:
        sell, signal_name = self.short_exit_williams_r(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

      # Downtrend/descending based sells
      if not sell:
        sell, signal_name = self.short_exit_dec(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

    # Stoplosses
    if not sell:
      sell, signal_name = self.short_exit_stoploss(
        mode_name,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None

    # Profit Target Signal
    # Check if pair exist on target_profit_cache
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    if target_data is not None:
      previous_rate = target_data["rate"]
      previous_profit = target_data["profit"]
      previous_sell_reason = target_data["sell_reason"]
      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )
      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"
      if previous_sell_reason == f"exit_{mode_name}_stoploss_u_e":
        if profit_ratio > (previous_profit + 0.005):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )
          if mark_pair:
            set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
      elif (profit_init_ratio > (previous_profit + 0.001)) and (
        previous_sell_reason != f"exit_{mode_name}_stoploss_doom"
      ):
        # Update the target, raise it.
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      previous_profit = None
      target_data = profit_target_get(pair) if profit_target_get is not None else None
      if target_data is not None:
        previous_profit = target_data["profit"]
      if signal_name in [
        f"exit_{mode_name}_stoploss_doom",
        f"exit_{mode_name}_stoploss_u_e",
      ]:
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
      elif (previous_profit is None) or (previous_profit < profit_init_ratio):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
    else:
      if profit_init_ratio >= 0.005:
        previous_profit = None
        target_data = profit_target_get(pair) if profit_target_get is not None else None
        if target_data is not None:
          previous_profit = target_data["profit"]
        if (previous_profit is None) or (previous_profit < profit_init_ratio):
          mark_signal = f"exit_profit_{mode_name}_max"
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    if signal_name not in [
      f"exit_profit_{mode_name}_max",
      f"exit_{mode_name}_stoploss_doom",
      f"exit_{mode_name}_stoploss_u_e",
    ]:
      if sell and (signal_name is not None):
        return True, f"{signal_name}"

    #  Here ends exit signal conditions for short_exit_pump

    return False, None

  # Short Exit Quick
  # ---------------------------------------------------------------------------------------------
  def short_exit_quick(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_orders,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.short_quick_mode_name

    sell = False

    # if the profit is negative skip checking these
    if profit_init_ratio > 0.0:
      # Original sell signals
      sell, signal_name = self.short_exit_signals(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

      # Main sell signals
      if not sell:
        sell, signal_name = self.short_exit_main(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

      # Williams %R based sells
      if not sell:
        sell, signal_name = self.short_exit_williams_r(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

      # Downtrend/descending based sells
      if not sell:
        sell, signal_name = self.short_exit_dec(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

    # Stoplosses
    if not sell:
      sell, signal_name = self.short_exit_stoploss(
        mode_name,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Extra sell logic
    if not sell:
      last_rsi_14 = last_candle["RSI_14"]
      last_rsi_3 = last_candle["RSI_3"]
      last_rsi_3_15m = last_candle["RSI_3_15m"]
      last_willr_14 = last_candle["WILLR_14"]
      if (0.09 >= profit_init_ratio > 0.02) and (last_rsi_14 < 22.0):
        sell, signal_name = True, f"exit_{mode_name}_q_1"

      elif (0.09 >= profit_init_ratio > 0.02) and (last_candle["MFI_14"] < 16.0):
        sell, signal_name = True, f"exit_{mode_name}_q_2"

      elif (0.09 >= profit_init_ratio > 0.02) and (last_willr_14 <= -99.9):
        sell, signal_name = True, f"exit_{mode_name}_q_3"

      elif (
        (0.09 >= profit_init_ratio > 0.02)
        and (last_rsi_14 <= 18.0)
        and (last_rsi_3 < 10.0)
        and (last_rsi_3_15m < 10.0)
      ):
        sell, signal_name = True, f"exit_{mode_name}_q_4"
      elif (0.09 >= profit_init_ratio > 0.02) and (last_rsi_3_15m < 4.0):
        sell, signal_name = True, f"exit_{mode_name}_q_5"
      elif (0.09 >= profit_init_ratio > 0.02) and (last_rsi_3 < 15.0) and (last_rsi_3_15m < 15.0):
        sell, signal_name = True, f"exit_{mode_name}_q_6"
      elif (0.09 >= profit_init_ratio > 0.02) and (last_rsi_3 < 10.0) and (last_rsi_3_15m < 20.0):
        sell, signal_name = True, f"exit_{mode_name}_q_7"
      elif (0.09 >= profit_init_ratio > 0.02) and (last_rsi_3 < 8.0) and (last_rsi_3_15m < 25.0):
        sell, signal_name = True, f"exit_{mode_name}_q_8"
      elif (0.09 >= profit_init_ratio > 0.02) and (last_rsi_3 < 6.0) and (last_rsi_3_15m < 30.0):
        sell, signal_name = True, f"exit_{mode_name}_q_9"
      elif (0.09 >= profit_init_ratio > 0.02) and (last_rsi_3 < 1.0):
        sell, signal_name = True, f"exit_{mode_name}_q_10"

    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None

    # Profit Target Signal
    # Check if pair exist on target_profit_cache
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    if target_data is not None:
      previous_rate = target_data["rate"]
      previous_profit = target_data["profit"]
      previous_sell_reason = target_data["sell_reason"]
      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )
      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"
      if previous_sell_reason == f"exit_{mode_name}_stoploss_u_e":
        if profit_ratio > (previous_profit + 0.001):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )
          if mark_pair:
            set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
      elif (profit_init_ratio > (previous_profit + 0.001)) and (
        previous_sell_reason != f"exit_{mode_name}_stoploss_doom"
      ):
        # Update the target, raise it.
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      previous_profit = None
      previous_sell_reason = ""
      target_data = profit_target_get(pair) if profit_target_get is not None else None
      if target_data is not None:
        previous_profit = target_data["profit"]
        previous_sell_reason = target_data["sell_reason"]
      if signal_name in [
        f"exit_{mode_name}_stoploss_doom",
        f"exit_{mode_name}_stoploss_u_e",
      ] and (
        previous_sell_reason
        not in [
          f"exit_{mode_name}_stoploss_doom",
          f"exit_{mode_name}_stoploss_u_e",
        ]
      ):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
      elif (previous_profit is None) or (previous_profit < profit_init_ratio):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
    else:
      if profit_init_ratio >= 0.005:
        previous_profit = None
        target_data = profit_target_get(pair) if profit_target_get is not None else None
        if target_data is not None:
          previous_profit = target_data["profit"]
        if (previous_profit is None) or (previous_profit < profit_init_ratio):
          mark_signal = f"exit_profit_{mode_name}_max"
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    if signal_name not in [
      f"exit_profit_{mode_name}_max",
      f"exit_{mode_name}_stoploss_doom",
      f"exit_{mode_name}_stoploss_u_e",
    ]:
      if sell and (signal_name is not None):
        return True, f"{signal_name}"

    #  Here ends exit signal conditions for short_exit_quick

    return False, None

  # Short Exit Rebuy
  # ---------------------------------------------------------------------------------------------
  def short_exit_rebuy(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    is_futures_mode = self.is_futures_mode
    trade_leverage = trade.leverage

    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.short_rebuy_mode_name

    is_backtest = self.is_backtest_mode()
    is_system_v3, is_system_v3_1, is_system_v3_2 = self.get_system_version_flags(trade)
    is_system_v4 = self.is_system_v4(trade)
    sell = False

    # Original sell signals
    sell, signal_name = self.short_exit_signals(
      mode_name,
      profit_current_stake_ratio,
      max_profit,
      max_loss,
      last_candle,
      previous_candle_1,
      trade,
      current_time,
      enter_tags,
    )

    # Main sell signals
    if not sell:
      sell, signal_name = self.short_exit_main(
        mode_name,
        profit_current_stake_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Williams %R based sells
    if not sell:
      sell, signal_name = self.short_exit_williams_r(
        mode_name,
        profit_current_stake_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Downtrend/descending based sells
    if not sell:
      sell, signal_name = self.short_exit_dec(
        mode_name,
        profit_current_stake_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Stoplosses
    if not sell:
      entry_cost = filled_entries[0].safe_filled * filled_entries[0].safe_price
      if is_system_v4:
        if self.system_v4_stops_enable and profit_stake < -(
          entry_cost
          * (
            self.system_v4_stop_threshold_futures_rebuy
            if is_futures_mode
            else self.system_v4_stop_threshold_spot_rebuy
          )
          / trade_leverage
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"
      elif is_system_v3_2:
        if self.system_v3_2_stops_enable and profit_stake < -(
          entry_cost
          * (
            self.system_v3_2_stop_threshold_futures_rebuy
            if is_futures_mode
            else self.system_v3_2_stop_threshold_spot_rebuy
          )
          / trade_leverage
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"
      elif is_system_v3_1:
        if profit_stake < -(
          entry_cost
          * (
            self.system_v3_1_stop_threshold_futures_rebuy
            if is_futures_mode
            else self.system_v3_1_stop_threshold_spot_rebuy
          )
          / trade_leverage
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"
      elif is_system_v3:
        if profit_stake < -(
          entry_cost
          * (
            self.system_v3_stop_threshold_futures_rebuy
            if is_futures_mode
            else self.system_v3_stop_threshold_spot_rebuy
          )
          / trade_leverage
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"
      else:
        if (
          profit_stake
          < -(
            entry_cost
            * (self.stop_threshold_futures_rebuy if is_futures_mode else self.stop_threshold_spot_rebuy)
            / trade_leverage
          )
          # temporary
          and (is_backtest or trade.open_date_utc.replace(tzinfo=None) >= datetime(2024, 9, 13))
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"

    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None

    # Profit Target Signal
    # Check if pair exist on target_profit_cache
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    if target_data is not None:
      previous_rate = target_data["rate"]
      previous_profit = target_data["profit"]
      previous_sell_reason = target_data["sell_reason"]
      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )
      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"
      if previous_sell_reason == f"exit_{mode_name}_stoploss_u_e":
        if profit_ratio > (previous_profit + 0.001):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )
          if mark_pair:
            set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
      elif (profit_init_ratio > (previous_profit + 0.001)) and (
        previous_sell_reason != f"exit_{mode_name}_stoploss_doom"
      ):
        # Update the target, raise it.
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      previous_profit = None
      target_data = profit_target_get(pair) if profit_target_get is not None else None
      if target_data is not None:
        previous_profit = target_data["profit"]
      if signal_name in [
        f"exit_{mode_name}_stoploss_doom",
        f"exit_{mode_name}_stoploss_u_e",
      ]:
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
      elif (previous_profit is None) or (previous_profit < profit_init_ratio):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
    else:
      if profit_init_ratio >= 0.005:
        previous_profit = None
        target_data = profit_target_get(pair) if profit_target_get is not None else None
        if target_data is not None:
          previous_profit = target_data["profit"]
        if (previous_profit is None) or (previous_profit < profit_init_ratio):
          mark_signal = f"exit_profit_{mode_name}_max"
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    if signal_name not in [
      f"exit_profit_{mode_name}_max",
      f"exit_{mode_name}_stoploss_doom",
      f"exit_{mode_name}_stoploss_u_e",
    ]:
      if sell and (signal_name is not None):
        return True, f"{signal_name}"

    #  Here ends exit signal conditions for short_exit_rebuy

    return False, None

  # Short Exit High Profit
  # ---------------------------------------------------------------------------------------------
  def short_exit_high_profit(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_orders,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.short_high_profit_mode_name

    sell = False

    # Original sell signals
    sell, signal_name = self.short_exit_signals(
      mode_name,
      profit_init_ratio,
      max_profit,
      max_loss,
      last_candle,
      previous_candle_1,
      trade,
      current_time,
      enter_tags,
    )

    # Main sell signals
    if not sell:
      sell, signal_name = self.short_exit_main(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Williams %R based sells
    if not sell:
      sell, signal_name = self.short_exit_williams_r(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Stoplosses
    if not sell:
      sell, signal_name = self.short_exit_stoploss(
        mode_name,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )
    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None

    # Profit Target Signal
    # Check if pair exist on target_profit_cache
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    if target_data is not None:
      previous_rate = target_data["rate"]
      previous_profit = target_data["profit"]
      previous_sell_reason = target_data["sell_reason"]
      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )
      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"
      if previous_sell_reason == f"exit_{mode_name}_stoploss_u_e":
        if profit_ratio > (previous_profit + 0.001):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )
          if mark_pair:
            set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
      elif (profit_init_ratio > (previous_profit + 0.001)) and (
        previous_sell_reason != f"exit_{mode_name}_stoploss_doom"
      ):
        # Update the target, raise it.
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      previous_profit = None
      target_data = profit_target_get(pair) if profit_target_get is not None else None
      if target_data is not None:
        previous_profit = target_data["profit"]
      if signal_name in [
        f"exit_{mode_name}_stoploss_doom",
        f"exit_{mode_name}_stoploss_u_e",
      ]:
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
      elif (previous_profit is None) or (previous_profit < profit_init_ratio):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
    else:
      if profit_init_ratio >= 0.03:
        previous_profit = None
        target_data = profit_target_get(pair) if profit_target_get is not None else None
        if target_data is not None:
          previous_profit = target_data["profit"]
        if (previous_profit is None) or (previous_profit < profit_init_ratio):
          mark_signal = f"exit_profit_{mode_name}_max"
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    if signal_name not in [
      f"exit_profit_{mode_name}_max",
      # f"exit_{self.short_high_profit_mode_name}_stoploss_doom",
      # f"exit_{self.short_high_profit_mode_name}_stoploss_u_e",
    ]:
      if sell and (signal_name is not None):
        return True, f"{signal_name}"

    #  Here ends exit signal conditions for short_exit_high_profit

    return False, None

  # Short Exit Rapid
  # ---------------------------------------------------------------------------------------------
  def short_exit_rapid(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    is_futures_mode = self.is_futures_mode
    stops_enable = self.stops_enable
    trade_leverage = trade.leverage

    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.short_rapid_mode_name

    is_backtest = self.is_backtest_mode()
    is_system_v3, is_system_v3_1, is_system_v3_2 = self.get_system_version_flags(trade)
    is_system_v4 = self.is_system_v4(trade)

    sell = False
    signal_name = None

    # if the profit is negative skip checking these
    if profit_init_ratio > 0.0:
      # Original sell signals
      sell, signal_name = self.short_exit_signals(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

      # Main sell signals
      if not sell:
        sell, signal_name = self.short_exit_main(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

      # Williams %R based sells
      if not sell:
        sell, signal_name = self.short_exit_williams_r(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

      # Downtrend/descending based sells
      if not sell:
        sell, signal_name = self.short_exit_dec(
          mode_name,
          profit_init_ratio,
          max_profit,
          max_loss,
          last_candle,
          previous_candle_1,
          trade,
          current_time,
          enter_tags,
        )

    # Extra exit logic
    if not sell:
      last_rsi_14 = last_candle["RSI_14"]
      last_rsi_3 = last_candle["RSI_3"]
      last_rsi_3_15m = last_candle["RSI_3_15m"]
      last_willr_14 = last_candle["WILLR_14"]
      if (0.09 >= profit_init_ratio > 0.005) and (last_rsi_14 < 22.0):
        sell, signal_name = True, f"exit_{mode_name}_rpd_1"
      elif (0.09 >= profit_init_ratio > 0.005) and (last_candle["MFI_14"] < 16.0):
        sell, signal_name = True, f"exit_{mode_name}_rpd_2"
      elif (0.09 >= profit_init_ratio > 0.005) and (last_willr_14 <= -99.9):
        sell, signal_name = True, f"exit_{mode_name}_rpd_3"
      elif (
        (0.09 >= profit_init_ratio > 0.005)
        and (last_rsi_14 <= 28.0)
        and (last_rsi_3 < 10.0)
        and (last_rsi_3_15m < 10.0)
      ):
        sell, signal_name = True, f"exit_{mode_name}_rpd_4"
      elif (0.09 >= profit_init_ratio > 0.005) and (last_rsi_3_15m < 4.0):
        sell, signal_name = True, f"exit_{mode_name}_rpd_5"
      elif (0.09 >= profit_init_ratio > 0.005) and (last_rsi_3 < 15.0) and (last_rsi_3_15m < 15.0):
        sell, signal_name = True, f"exit_{mode_name}_rpd_6"
      elif (0.09 >= profit_init_ratio > 0.005) and (last_rsi_3 < 10.0) and (last_rsi_3_15m < 20.0):
        sell, signal_name = True, f"exit_{mode_name}_rpd_7"
      elif (0.09 >= profit_init_ratio > 0.005) and (last_rsi_3 < 8.0) and (last_rsi_3_15m < 25.0):
        sell, signal_name = True, f"exit_{mode_name}_rpd_8"
      elif (0.09 >= profit_init_ratio > 0.005) and (last_rsi_3 < 6.0) and (last_rsi_3_15m < 30.0):
        sell, signal_name = True, f"exit_{mode_name}_rpd_9"
      elif (0.09 >= profit_init_ratio > 0.005) and (last_rsi_3 < 1.0):
        sell, signal_name = True, f"exit_{mode_name}_rpd_10"

      entry_cost = filled_entries[0].safe_filled * filled_entries[0].safe_price
      if is_system_v4:
        # Stoplosses
        if self.system_v4_stops_enable and (
          profit_stake
          < -(
            entry_cost
            * (
              self.system_v4_stop_threshold_rapid_futures
              if is_futures_mode
              else self.system_v4_stop_threshold_rapid_spot
            )
            / trade_leverage
          )
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"
      elif is_system_v3_2:
        # Stoplosses
        if self.system_v3_2_stops_enable and (
          profit_stake
          < -(
            entry_cost
            * (
              self.system_v3_2_stop_threshold_rapid_futures
              if is_futures_mode
              else self.system_v3_2_stop_threshold_rapid_spot
            )
            / trade_leverage
          )
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"
      elif is_system_v3_1:
        # Stoplosses
        if stops_enable and (
          profit_stake
          < -(
            entry_cost
            * (
              self.system_v3_1_stop_threshold_rapid_futures
              if is_futures_mode
              else self.system_v3_1_stop_threshold_rapid_spot
            )
            / trade_leverage
          )
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"
      elif is_system_v3:
        # Stoplosses
        if stops_enable and (
          profit_stake
          < -(
            entry_cost
            * (
              self.system_v3_stop_threshold_rapid_futures
              if is_futures_mode
              else self.system_v3_stop_threshold_rapid_spot
            )
            / trade_leverage
          )
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"
      else:
        # Stoplosses
        if (
          (
            stops_enable
            and (
              profit_stake
              < -(
                entry_cost * (self.stop_threshold_rapid_futures if is_futures_mode else self.stop_threshold_rapid_spot)
              )
            )
          )
          # temporary
          and (is_backtest or trade.open_date_utc.replace(tzinfo=None) >= datetime(2024, 9, 13))
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"

    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None

    # Profit Target Signal
    # Check if pair exist on target_profit_cache
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    if target_data is not None:
      previous_rate = target_data["rate"]
      previous_profit = target_data["profit"]
      previous_sell_reason = target_data["sell_reason"]
      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )
      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"
      if previous_sell_reason == f"exit_{mode_name}_stoploss_u_e":
        if profit_ratio > (previous_profit + 0.001):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )
          if mark_pair:
            set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
      elif (profit_init_ratio > (previous_profit + 0.001)) and (
        previous_sell_reason != f"exit_{mode_name}_stoploss_doom"
      ):
        # Update the target, raise it.
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      previous_profit = None
      previous_sell_reason = ""
      target_data = profit_target_get(pair) if profit_target_get is not None else None
      if target_data is not None:
        previous_profit = target_data["profit"]
        previous_sell_reason = target_data["sell_reason"]
      if signal_name in [
        f"exit_{mode_name}_stoploss_doom",
        f"exit_{mode_name}_stoploss_u_e",
      ] and (
        previous_sell_reason
        not in [
          f"exit_{mode_name}_stoploss_doom",
          f"exit_{mode_name}_stoploss_u_e",
        ]
      ):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
      elif (previous_profit is None) or (previous_profit < profit_init_ratio):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
    else:
      if profit_init_ratio >= 0.005:
        previous_profit = None
        target_data = profit_target_get(pair) if profit_target_get is not None else None
        if target_data is not None:
          previous_profit = target_data["profit"]
        if (previous_profit is None) or (previous_profit < profit_init_ratio):
          mark_signal = f"exit_profit_{mode_name}_max"
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    if signal_name not in [
      f"exit_profit_{mode_name}_max",
      f"exit_{mode_name}_stoploss_doom",
      f"exit_{mode_name}_stoploss_u_e",
    ]:
      if sell and (signal_name is not None):
        return True, f"{signal_name}"

    #  Here ends exit signal conditions for short_exit_rapid

    return False, None

  # Short Exit Grind
  # ---------------------------------------------------------------------------------------------
  def short_exit_grind(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    if profit_init_ratio > 0.25:
      return True, f"exit_{self.short_grind_mode_name}_g"

    #  Here ends exit signal conditions for short_exit_grind

    return False, None

  # Short Exit Top Coins
  # ---------------------------------------------------------------------------------------------
  def short_exit_top_coins(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_orders,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.short_top_coins_mode_name

    sell = False

    # Original sell signals
    sell, signal_name = self.short_exit_signals(
      mode_name,
      profit_init_ratio,
      max_profit,
      max_loss,
      last_candle,
      previous_candle_1,
      trade,
      current_time,
      enter_tags,
    )

    # Main sell signals
    if not sell:
      sell, signal_name = self.short_exit_main(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Williams %R based sells
    if not sell:
      sell, signal_name = self.short_exit_williams_r(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Downtrend/descending based sells
    if not sell:
      sell, signal_name = self.short_exit_dec(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Stoplosses
    if not sell:
      sell, signal_name = self.short_exit_stoploss(
        mode_name,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        max_profit,
        max_loss,
        filled_orders,
        filled_entries,
        filled_exits,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None

    # Profit Target Signal
    # Check if pair exist on target_profit_cache
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    if target_data is not None:
      previous_rate = target_data["rate"]
      previous_profit = target_data["profit"]
      previous_sell_reason = target_data["sell_reason"]
      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )
      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"
      if previous_sell_reason == f"exit_{mode_name}_stoploss_u_e":
        if profit_ratio > (previous_profit + 0.005):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )
          if mark_pair:
            set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
      elif (profit_init_ratio > (previous_profit + 0.001)) and (
        previous_sell_reason != f"exit_{mode_name}_stoploss_doom"
      ):
        # Update the target, raise it.
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      previous_profit = None
      previous_sell_reason = ""
      target_data = profit_target_get(pair) if profit_target_get is not None else None
      if target_data is not None:
        previous_profit = target_data["profit"]
        previous_sell_reason = target_data["sell_reason"]
      if signal_name in [
        f"exit_{mode_name}_stoploss_doom",
        f"exit_{mode_name}_stoploss_u_e",
      ] and (
        previous_sell_reason
        not in [
          f"exit_{mode_name}_stoploss_doom",
          f"exit_{mode_name}_stoploss_u_e",
        ]
      ):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
      elif (previous_profit is None) or (previous_profit < profit_init_ratio):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
    else:
      if profit_init_ratio >= 0.005:
        previous_profit = None
        target_data = profit_target_get(pair) if profit_target_get is not None else None
        if target_data is not None:
          previous_profit = target_data["profit"]
        if (previous_profit is None) or (previous_profit < profit_init_ratio):
          mark_signal = f"exit_profit_{mode_name}_max"
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    if signal_name not in [
      f"exit_profit_{mode_name}_max",
      f"exit_{mode_name}_stoploss_doom",
      f"exit_{mode_name}_stoploss_u_e",
    ]:
      if sell and (signal_name is not None):
        return True, f"{signal_name}"

    #  Here ends exit signal conditions for short_exit_top_coins

    return False, None

  # Short Exit Scalp
  # ---------------------------------------------------------------------------------------------
  def short_exit_scalp(
    self,
    pair: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    enter_tags,
  ) -> tuple:
    is_futures_mode = self.is_futures_mode
    trade_leverage = trade.leverage

    mark_profit_target = self.mark_profit_target
    set_profit_target = self._set_profit_target
    exit_profit_target = self.exit_profit_target

    mode_name = self.short_scalp_mode_name

    is_system_v3, is_system_v3_1, is_system_v3_2 = self.get_system_version_flags(trade)
    is_system_v4 = self.is_system_v4(trade)

    sell = False

    # Original sell signals
    sell, signal_name = self.short_exit_signals(
      mode_name,
      profit_init_ratio,
      max_profit,
      max_loss,
      last_candle,
      previous_candle_1,
      trade,
      current_time,
      enter_tags,
    )

    # Main sell signals
    if not sell:
      sell, signal_name = self.short_exit_main(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Williams %R based sells
    if not sell:
      sell, signal_name = self.short_exit_williams_r(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Downtrend/descending based sells
    if not sell:
      sell, signal_name = self.short_exit_dec(
        mode_name,
        profit_init_ratio,
        max_profit,
        max_loss,
        last_candle,
        previous_candle_1,
        trade,
        current_time,
        enter_tags,
      )

    # Extra exit logic
    if not sell:
      entry_cost = filled_entries[0].safe_filled * filled_entries[0].safe_price
      if is_system_v4:
        # Stoplosses
        if self.system_v4_stops_enable and (
          profit_stake
          < -(
            entry_cost
            * (
              self.system_v4_stop_threshold_scalp_futures
              if is_futures_mode
              else self.system_v4_stop_threshold_scalp_spot
            )
            / trade_leverage
          )
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"
      elif is_system_v3_2:
        # Stoplosses
        if self.system_v3_2_stops_enable and (
          profit_stake
          < -(
            entry_cost
            * (
              self.system_v3_2_stop_threshold_scalp_futures
              if is_futures_mode
              else self.system_v3_2_stop_threshold_scalp_spot
            )
            / trade_leverage
          )
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"
      elif is_system_v3_1:
        # Stoplosses
        if profit_stake < -(
          entry_cost
          * (
            self.system_v3_1_stop_threshold_scalp_futures
            if is_futures_mode
            else self.system_v3_1_stop_threshold_scalp_spot
          )
          / trade_leverage
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"
      elif is_system_v3:
        # Stoplosses
        if profit_stake < -(
          entry_cost
          * (
            self.system_v3_stop_threshold_scalp_futures
            if is_futures_mode
            else self.system_v3_stop_threshold_scalp_spot
          )
          / trade_leverage
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"
      else:
        # Stoplosses
        if profit_stake < -(
          entry_cost * (self.stop_threshold_scalp_futures if is_futures_mode else self.stop_threshold_scalp_spot)
          # / (trade.leverage if self.is_futures_mode else 1.0)
        ):
          sell, signal_name = True, f"exit_{mode_name}_stoploss_doom"

    cache = self.target_profit_cache
    cache_data = cache.data if cache is not None else None
    profit_target_get = cache_data.get if cache_data is not None else None

    # Profit Target Signal
    # Check if pair exist on target_profit_cache
    target_data = profit_target_get(pair) if profit_target_get is not None else None
    if target_data is not None:
      previous_rate = target_data["rate"]
      previous_profit = target_data["profit"]
      previous_sell_reason = target_data["sell_reason"]
      previous_time_profit_reached = datetime.fromisoformat(target_data["time_profit_reached"])

      sell_max, signal_name_max = exit_profit_target(
        mode_name,
        pair,
        trade,
        current_time,
        current_rate,
        profit_stake,
        profit_ratio,
        profit_current_stake_ratio,
        profit_init_ratio,
        last_candle,
        previous_candle_1,
        previous_rate,
        previous_profit,
        previous_sell_reason,
        previous_time_profit_reached,
        enter_tags,
      )
      if sell_max and signal_name_max is not None:
        return True, f"{signal_name_max}_m"
      if previous_sell_reason == f"exit_{mode_name}_stoploss_u_e":
        if profit_ratio > (previous_profit + 0.005):
          mark_pair, mark_signal = mark_profit_target(
            mode_name,
            pair,
            True,
            previous_sell_reason,
            trade,
            current_time,
            current_rate,
            profit_ratio,
            last_candle,
            previous_candle_1,
          )
          if mark_pair:
            set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
      elif (profit_init_ratio > (previous_profit + 0.001)) and (
        previous_sell_reason != f"exit_{mode_name}_stoploss_doom"
      ):
        # Update the target, raise it.
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          True,
          previous_sell_reason,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    # Add the pair to the list, if a sell triggered and conditions met
    if sell and signal_name is not None:
      previous_profit = None
      target_data = profit_target_get(pair) if profit_target_get is not None else None
      if target_data is not None:
        previous_profit = target_data["profit"]
      if signal_name in [
        f"exit_{mode_name}_stoploss_doom",
        f"exit_{mode_name}_stoploss_u_e",
      ]:
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
      elif (previous_profit is None) or (previous_profit < profit_init_ratio):
        mark_pair, mark_signal = mark_profit_target(
          mode_name,
          pair,
          sell,
          signal_name,
          trade,
          current_time,
          current_rate,
          profit_init_ratio,
          last_candle,
          previous_candle_1,
        )
        if mark_pair:
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)
        else:
          # Just sell it, without maximize
          return True, f"{signal_name}"
    else:
      if profit_init_ratio >= 0.005:
        previous_profit = None
        target_data = profit_target_get(pair) if profit_target_get is not None else None
        if target_data is not None:
          previous_profit = target_data["profit"]
        if (previous_profit is None) or (previous_profit < profit_init_ratio):
          mark_signal = f"exit_profit_{mode_name}_max"
          set_profit_target(pair, mark_signal, current_rate, profit_init_ratio, current_time)

    if signal_name not in [
      f"exit_profit_{mode_name}_max",
      f"exit_{mode_name}_stoploss_doom",
      f"exit_{mode_name}_stoploss_u_e",
    ]:
      if sell and (signal_name is not None):
        return True, f"{signal_name}"

    #  Here ends exit signal conditions for short_exit_derisk

    return False, None

  # Short Exit Signals
  # ---------------------------------------------------------------------------------------------
  def short_exit_signals(
    self,
    mode_name: str,
    current_profit: float,
    max_profit: float,
    max_loss: float,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    buy_tag,
  ) -> tuple:
    last_rsi_14 = last_candle["RSI_14"]
    last_close = last_candle["close"]
    last_ema_200 = last_candle["EMA_200"]
    last_ema_50 = last_candle["EMA_50"]
    last_rsi_14_1h = last_candle["RSI_14_1h"]
    last_bbl_20 = last_candle["BBL_20_2.0"]
    last_bbl_20_1h = last_candle["BBL_20_2.0_1h"]
    bb_below_count = last_candle["BB_BELOW_COUNT"]
    current_profit_gt_0_01 = current_profit > 0.01

    # Sell signal 1
    if (last_rsi_14 < 16.0) and (last_close < last_bbl_20) and bb_below_count >= 5:
      if last_close < last_ema_200:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_1_1_1"
      else:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_1_2_1"

    # Sell signal 2
    elif (last_rsi_14 < 14.0) and (last_close < last_bbl_20) and bb_below_count >= 3:
      if last_close < last_ema_200:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_2_1_1"
      else:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_2_2_1"

    # Sell signal 3
    elif last_rsi_14 < 12.0:
      if last_close < last_ema_200:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_3_1_1"
      else:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_3_2_1"

    # Sell signal 4
    elif (last_rsi_14 < 16.0) and (last_rsi_14_1h < 20.0):
      if last_close < last_ema_200:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_4_1_1"
      else:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_4_2_1"

    # Sell signal 6
    elif (last_close > last_ema_200) and (last_close < last_ema_50) and (last_rsi_14 < 21.0):
      if current_profit_gt_0_01:
        return True, f"exit_{mode_name}_6_1"

    # # Sell signal 7
    # elif (last_candle["RSI_14_1h"] < 21.0) and (last_candle["crossed_above_EMA_12_26"]):
    #   if last_candle["close"] < last_candle["EMA_200"]:
    #     if current_profit_gt_0_01:
    #       return True, f"exit_{mode_name}_7_1_1"
    #   else:
    #     if current_profit_gt_0_01:
    #       return True, f"exit_{mode_name}_7_2_1"

    # Sell signal 8
    elif last_close < last_bbl_20_1h * 0.86:
      if last_close < last_ema_200:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_8_1_1"
      else:
        if current_profit_gt_0_01:
          return True, f"exit_{mode_name}_8_2_1"

    #  Here ends exit signal conditions for short_exit_signals

    return False, None

  # Short Exit Main
  # ---------------------------------------------------------------------------------------------
  def short_exit_main(
    self,
    mode_name: str,
    current_profit: float,
    max_profit: float,
    max_loss: float,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    buy_tag,
  ) -> tuple:
    last_rsi_14 = last_candle["RSI_14"]
    last_close = last_candle["close"]
    last_ema_200 = last_candle["EMA_200"]

    if last_close < last_ema_200:
      if 0.01 > current_profit >= 0.001:
        if last_rsi_14 > 90.0:
          return True, f"exit_{mode_name}_o_0"
      elif 0.02 > current_profit >= 0.01:
        if last_rsi_14 > 72.0:
          return True, f"exit_{mode_name}_o_1"
      elif 0.03 > current_profit >= 0.02:
        if last_rsi_14 > 70.0:
          return True, f"exit_{mode_name}_o_2"
      elif 0.04 > current_profit >= 0.03:
        if last_rsi_14 > 68.0:
          return True, f"exit_{mode_name}_o_3"
      elif 0.05 > current_profit >= 0.04:
        if last_rsi_14 > 66.0:
          return True, f"exit_{mode_name}_o_4"
      elif 0.06 > current_profit >= 0.05:
        if last_rsi_14 > 64.0:
          return True, f"exit_{mode_name}_o_5"
      elif 0.07 > current_profit >= 0.06:
        if last_rsi_14 > 62.0:
          return True, f"exit_{mode_name}_o_6"
      elif 0.08 > current_profit >= 0.07:
        if last_rsi_14 > 60.0:
          return True, f"exit_{mode_name}_o_7"
      elif 0.09 > current_profit >= 0.08:
        if last_rsi_14 > 58.0:
          return True, f"exit_{mode_name}_o_8"
      elif 0.1 > current_profit >= 0.09:
        if last_rsi_14 > 56.0:
          return True, f"exit_{mode_name}_o_9"
      elif 0.12 > current_profit >= 0.1:
        if last_rsi_14 > 54.0:
          return True, f"exit_{mode_name}_o_10"
      elif 0.2 > current_profit >= 0.12:
        if last_rsi_14 > 56.0:
          return True, f"exit_{mode_name}_o_11"
      elif current_profit >= 0.2:
        if last_rsi_14 > 58.0:
          return True, f"exit_{mode_name}_o_12"
    elif last_close > last_ema_200:
      if 0.01 > current_profit >= 0.001:
        if last_rsi_14 > 88.0:
          return True, f"exit_{mode_name}_u_0"
      elif 0.02 > current_profit >= 0.01:
        if last_rsi_14 > 70.0:
          return True, f"exit_{mode_name}_u_1"
      elif 0.03 > current_profit >= 0.02:
        if last_rsi_14 > 68.0:
          return True, f"exit_{mode_name}_u_2"
      elif 0.04 > current_profit >= 0.03:
        if last_rsi_14 > 66.0:
          return True, f"exit_{mode_name}_u_3"
      elif 0.05 > current_profit >= 0.04:
        if last_rsi_14 > 64.0:
          return True, f"exit_{mode_name}_u_4"
      elif 0.06 > current_profit >= 0.05:
        if last_rsi_14 > 62.0:
          return True, f"exit_{mode_name}_u_5"
      elif 0.07 > current_profit >= 0.06:
        if last_rsi_14 > 60.0:
          return True, f"exit_{mode_name}_u_6"
      elif 0.08 > current_profit >= 0.07:
        if last_rsi_14 > 58.0:
          return True, f"exit_{mode_name}_u_7"
      elif 0.09 > current_profit >= 0.08:
        if last_rsi_14 > 56.0:
          return True, f"exit_{mode_name}_u_8"
      elif 0.1 > current_profit >= 0.09:
        if last_rsi_14 > 54.0:
          return True, f"exit_{mode_name}_u_9"
      elif 0.12 > current_profit >= 0.1:
        if last_rsi_14 > 52.0:
          return True, f"exit_{mode_name}_u_10"
      elif 0.2 > current_profit >= 0.12:
        if last_rsi_14 > 54.0:
          return True, f"exit_{mode_name}_u_11"
      elif current_profit >= 0.2:
        if last_rsi_14 > 56.0:
          return True, f"exit_{mode_name}_u_12"

    #  Here ends exit signal conditions for short_exit_main

    return False, None

  # Short Exit Williams R
  # ---------------------------------------------------------------------------------------------
  def short_exit_williams_r(
    self,
    mode_name: str,
    current_profit: float,
    max_profit: float,
    max_loss: float,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    buy_tag,
  ) -> tuple:
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_willr_480 = last_candle["WILLR_480"]
    last_aroonu_14_4h = last_candle["AROONU_14_4h"]

    if 0.01 > current_profit >= 0.001:
      if (last_stochrsi_k < 5.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 5.0):
        return True, f"exit_{mode_name}_w_0_1"
    elif 0.02 > current_profit >= 0.01:
      if (last_stochrsi_k < 5.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 5.0):
        return True, f"exit_{mode_name}_w_1_1"
    elif 0.03 > current_profit >= 0.02:
      if (last_stochrsi_k < 5.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 5.0):
        return True, f"exit_{mode_name}_w_2_1"
    elif 0.04 > current_profit >= 0.03:
      if (last_stochrsi_k < 5.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 5.0):
        return True, f"exit_{mode_name}_w_3_1"
    elif 0.05 > current_profit >= 0.04:
      if (last_stochrsi_k < 5.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 5.0):
        return True, f"exit_{mode_name}_w_4_1"
    elif 0.06 > current_profit >= 0.05:
      if (last_stochrsi_k < 10.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 10.0):
        return True, f"exit_{mode_name}_w_5_1"
    elif 0.07 > current_profit >= 0.06:
      if (last_stochrsi_k < 10.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 10.0):
        return True, f"exit_{mode_name}_w_6_1"
    elif 0.08 > current_profit >= 0.07:
      if (last_stochrsi_k < 10.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 10.0):
        return True, f"exit_{mode_name}_w_7_1"
    elif 0.09 > current_profit >= 0.08:
      if (last_stochrsi_k < 10.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 10.0):
        return True, f"exit_{mode_name}_w_8_1"
    elif 0.1 > current_profit >= 0.09:
      if (last_stochrsi_k < 10.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 10.0):
        return True, f"exit_{mode_name}_w_9_1"
    elif 0.12 > current_profit >= 0.1:
      if (last_stochrsi_k < 10.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 10.0):
        return True, f"exit_{mode_name}_w_10_1"
    elif 0.2 > current_profit >= 0.12:
      if (last_stochrsi_k < 10.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 10.0):
        return True, f"exit_{mode_name}_w_11_1"
    elif current_profit >= 0.2:
      if (last_stochrsi_k < 10.0) and (last_willr_480 < -99.0) and (last_aroonu_14_4h < 10.0):
        return True, f"exit_{mode_name}_w_12_1"

    #  Here ends exit signal conditions for short_exit_williams_r

    return False, None

  # Short Exit Dec
  # ---------------------------------------------------------------------------------------------
  def short_exit_dec(
    self,
    mode_name: str,
    current_profit: float,
    max_profit: float,
    max_loss: float,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    buy_tag,
  ) -> tuple:
    last_sma_200_inc = last_candle["SMA_200_inc_24"]
    last_rsi_14 = last_candle["RSI_14"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_aroonu_14 = last_candle["AROONU_14"]
    last_sma_200_inc_1h = last_candle["SMA_200_inc_12_1h"]
    last_sma_200_inc_4h = last_candle["SMA_200_inc_6_4h"]
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_rsi_3_4h = last_candle["RSI_3_4h"]

    if 0.01 > current_profit >= 0.001:
      if (
        last_sma_200_inc
        and last_sma_200_inc_1h
        and last_sma_200_inc_4h
        and (last_rsi_14 < 18.0)
        and (last_stochrsi_k < 5.0)
        and (last_aroonu_14 < 5.0)
      ):
        return True, f"exit_{mode_name}_d_0_1"
      if (
        (last_rsi_3 < 2.0)
        and (last_stochrsi_k < 2.0)
        and (last_rsi_3_4h > 70.0)
        and (last_rsi_3_1h > 80.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_0_2"
    elif 0.02 > current_profit >= 0.01:
      if (
        last_sma_200_inc
        and last_sma_200_inc_1h
        and last_sma_200_inc_4h
        and (last_rsi_14 < 20.0)
        and (last_stochrsi_k < 5.0)
        and (last_aroonu_14 < 5.0)
      ):
        return True, f"exit_{mode_name}_d_1_1"
      if (
        (last_rsi_3 < 2.0)
        and (last_stochrsi_k < 2.0)
        and (last_rsi_3_4h > 70.0)
        and (last_rsi_3_1h > 80.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_1_2"
    elif 0.03 > current_profit >= 0.02:
      if (
        last_sma_200_inc
        and last_sma_200_inc_1h
        and last_sma_200_inc_4h
        and (last_rsi_14 < 22.0)
        and (last_stochrsi_k < 5.0)
        and (last_aroonu_14 < 5.0)
      ):
        return True, f"exit_{mode_name}_d_2_1"
      if (
        (last_rsi_3 < 2.0)
        and (last_stochrsi_k < 2.0)
        and (last_rsi_3_4h > 70.0)
        and (last_rsi_3_1h > 80.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_2_2"
    elif 0.04 > current_profit >= 0.03:
      if last_sma_200_inc and (last_rsi_14 < 24.0) and (last_stochrsi_k < 5.0) and (last_aroonu_14 < 10.0):
        return True, f"exit_{mode_name}_d_3_1"
      if (
        (last_rsi_3 < 5.0)
        and (last_stochrsi_k < 10.0)
        and (last_rsi_3_4h > 70.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_3_2"
    elif 0.05 > current_profit >= 0.04:
      if last_sma_200_inc and (last_rsi_14 < 26.0) and (last_stochrsi_k < 8.0) and (last_aroonu_14 < 10.0):
        return True, f"exit_{mode_name}_d_4_1"
      if (
        (last_rsi_3 < 5.0)
        and (last_stochrsi_k < 10.0)
        and (last_rsi_3_4h > 70.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_4_2"
    elif 0.06 > current_profit >= 0.05:
      if last_sma_200_inc and (last_stochrsi_k < 5.0) and (last_aroonu_14 < 10.0):
        return True, f"exit_{mode_name}_d_5_1"
      if (
        (last_rsi_3 < 5.0)
        and (last_stochrsi_k < 10.0)
        and (last_rsi_3_4h > 70.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_5_2"
    elif 0.07 > current_profit >= 0.06:
      if last_sma_200_inc or ((last_stochrsi_k < 5.0) and (last_aroonu_14 < 10.0)):
        return True, f"exit_{mode_name}_d_6_1"
      if (
        (last_rsi_3 < 5.0)
        and (last_stochrsi_k < 10.0)
        and (last_rsi_3_4h > 70.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_6_2"
    elif 0.08 > current_profit >= 0.07:
      if last_sma_200_inc or ((last_stochrsi_k < 5.0) and (last_aroonu_14 < 10.0)):
        return True, f"exit_{mode_name}_d_7_1"
      if (
        (last_rsi_3 < 5.0)
        and (last_stochrsi_k < 10.0)
        and (last_rsi_3_4h > 70.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_7_2"
    elif 0.09 > current_profit >= 0.08:
      if last_sma_200_inc or ((last_stochrsi_k < 5.0) and (last_aroonu_14 < 10.0)):
        return True, f"exit_{mode_name}_d_8_1"
      if (
        (last_rsi_3 < 5.0)
        and (last_stochrsi_k < 10.0)
        and (last_rsi_3_4h > 70.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_8_2"
    elif 0.1 > current_profit >= 0.09:
      if last_sma_200_inc or ((last_stochrsi_k < 5.0) and (last_aroonu_14 < 10.0)):
        return True, f"exit_{mode_name}_d_9_1"
      if (
        (last_rsi_3 < 5.0)
        and (last_stochrsi_k < 10.0)
        and (last_rsi_3_4h > 70.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_9_2"
    elif 0.12 > current_profit >= 0.1:
      if last_sma_200_inc or ((last_stochrsi_k < 5.0) and (last_aroonu_14 < 10.0)):
        return True, f"exit_{mode_name}_d_10_1"
      if (
        (last_rsi_3 < 5.0)
        and (last_stochrsi_k < 10.0)
        and (last_rsi_3_4h > 70.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_10_2"
    elif 0.2 > current_profit >= 0.12:
      if last_sma_200_inc or ((last_stochrsi_k < 5.0) and (last_aroonu_14 < 10.0)):
        return True, f"exit_{mode_name}_d_11_1"
      if (
        (last_rsi_3 < 5.0)
        and (last_stochrsi_k < 10.0)
        and (last_rsi_3_4h > 70.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_11_2"
    elif current_profit >= 0.2:
      if last_sma_200_inc or ((last_stochrsi_k < 5.0) and (last_aroonu_14 < 10.0)):
        return True, f"exit_{mode_name}_d_12_1"
      if (
        (last_rsi_3 < 5.0)
        and (last_stochrsi_k < 10.0)
        and (last_rsi_3_4h > 70.0)
        and last_sma_200_inc
        and last_sma_200_inc_1h
      ):
        return True, f"exit_{mode_name}_d_12_2"

    #  Here ends exit signal conditions for short_exit_dec

    return False, None

  # Short Exit Stop Loss
  # ---------------------------------------------------------------------------------------------
  def short_exit_stoploss(
    self,
    mode_name: str,
    current_rate: float,
    profit_stake: float,
    profit_ratio: float,
    profit_current_stake_ratio: float,
    profit_init_ratio: float,
    max_profit: float,
    max_loss: float,
    filled_orders,
    filled_entries,
    filled_exits,
    last_candle,
    previous_candle_1,
    trade: "Trade",
    current_time: "datetime",
    buy_tag,
  ) -> tuple:
    is_futures_mode = self.is_futures_mode
    doom_stops_enable = self.doom_stops_enable
    trade_leverage = trade.leverage
    stoploss_doom = f"exit_{mode_name}_stoploss_doom"
    stoploss_u_e = f"exit_{mode_name}_stoploss_u_e"

    is_backtest = self.is_backtest_mode()
    trade_open_date = None if is_backtest else trade.open_date_utc.replace(tzinfo=None)
    is_system_v3, is_system_v3_1, is_system_v3_2 = self.get_system_version_flags(trade)
    is_system_v4 = self.is_system_v4(trade)
    if not self.stops_enable:
      return False, None

    entry_cost = filled_entries[0].safe_filled * filled_entries[0].safe_price
    if is_system_v4:
      # Stoploss doom
      if self.system_v4_stops_enable and (
        profit_stake
        < -(
          entry_cost
          * (
            self.system_v4_stop_threshold_doom_futures if is_futures_mode else self.system_v4_stop_threshold_doom_spot
          )
          / trade_leverage
        )
      ):
        return True, stoploss_doom
    elif is_system_v3_2:
      # Stoploss doom
      if self.system_v3_2_stops_enable and (
        profit_stake
        < -(
          entry_cost
          * (
            self.system_v3_2_stop_threshold_doom_futures
            if is_futures_mode
            else self.system_v3_2_stop_threshold_doom_spot
          )
          / trade_leverage
        )
      ):
        return True, stoploss_doom
    elif is_system_v3_1:
      # Stoploss doom
      if doom_stops_enable and (
        profit_stake
        < -(
          entry_cost
          * (
            self.system_v3_1_stop_threshold_doom_futures
            if is_futures_mode
            else self.system_v3_1_stop_threshold_doom_spot
          )
          / trade_leverage
        )
      ):
        return True, stoploss_doom
    elif is_system_v3:
      # Stoploss doom
      if doom_stops_enable and (
        profit_stake
        < -(
          entry_cost
          * (
            self.system_v3_stop_threshold_doom_futures if is_futures_mode else self.system_v3_stop_threshold_doom_spot
          )
          / trade_leverage
        )
      ):
        return True, stoploss_doom
    else:
      # Stoploss doom
      if (
        doom_stops_enable
        and (
          profit_stake
          < -(entry_cost * (self.stop_threshold_doom_futures if is_futures_mode else self.stop_threshold_doom_spot))
        )
        and (
          self.has_valid_entry_conditions(trade, current_rate, last_candle, previous_candle_1, filled_orders) == False
        )
        # temporary
        and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
      ):
        return True, stoploss_doom

    last_close = last_candle["close"]
    last_ema_200 = last_candle["EMA_200"]
    last_rsi_14 = last_candle["RSI_14"]
    last_cmf_20 = last_candle["CMF_20"]
    last_rsi_14_1h = last_candle["RSI_14_1h"]
    previous_rsi_14 = previous_candle_1["RSI_14"]

    # Stoploss u_e
    if (
      self.u_e_stops_enable
      and (
        profit_stake
        < -(
          entry_cost * (self.stop_threshold_futures if is_futures_mode else self.stop_threshold_spot)
          # / trade.leverage
        )
      )
      and (last_close > last_ema_200)
      and (last_cmf_20 > 0.0)
      and (((last_close - last_ema_200) / last_ema_200) < 0.010)
      and (last_rsi_14 < previous_rsi_14)
      and (last_rsi_14 < (last_rsi_14_1h - 24.0))
      # and (current_time - timedelta(minutes=720) > trade.open_date_utc)
      # temporary
      and (is_backtest or trade_open_date >= datetime(2025, 4, 3))
    ):
      return True, stoploss_u_e

    #  Here ends exit signal conditions for short_exit_stoploss

    return False, None

  ###############################################################################################

  # SHORT EXIT FUNCTIONS ENDS HERE

  ###############################################################################################

  # SHORT GRIND FUNCTIONS STARTS HERE

  ###############################################################################################

  #
  #   ______  __    __  ______  _______ ________         ______  _______  ______ __    __ _______
  #  /      \|  \  |  \/      \|       |        \       /      \|       \|      |  \  |  |       \
  # |  $$$$$$| $$  | $|  $$$$$$| $$$$$$$\$$$$$$$$      |  $$$$$$| $$$$$$$\\$$$$$| $$\ | $| $$$$$$$\
  # | $$___\$| $$__| $| $$  | $| $$__| $$ | $$         | $$ __\$| $$__| $$ | $$ | $$$\| $| $$  | $$
  #  \$$    \| $$    $| $$  | $| $$    $$ | $$         | $$|    | $$    $$ | $$ | $$$$\ $| $$  | $$
  #  _\$$$$$$| $$$$$$$| $$  | $| $$$$$$$\ | $$         | $$ \$$$| $$$$$$$\ | $$ | $$\$$ $| $$  | $$
  # |  \__| $| $$  | $| $$__/ $| $$  | $$ | $$         | $$__| $| $$  | $$_| $$_| $$ \$$$| $$__/ $$
  #  \$$    $| $$  | $$\$$    $| $$  | $$ | $$          \$$    $| $$  | $|   $$ | $$  \$$| $$    $$
  #   \$$$$$$ \$$   \$$ \$$$$$$ \$$   \$$  \$$           \$$$$$$ \$$   \$$\$$$$$$\$$   \$$\$$$$$$$
  #

  # Short Grinding Adjust Trade Position v2
  # ---------------------------------------------------------------------------------------------
  def short_grind_adjust_trade_position_v2(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ):
    dp = self.dp
    send_msg = self.dp.send_msg
    notification_msg = self.notification_msg
    scale_stakes_for_min_stake = self.scale_stakes_for_min_stake
    short_grind_exit_v2 = self.short_grind_exit_v2
    stake_currency = self.config["stake_currency"]
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_stake_amount = trade.stake_amount
    trade_fee_open = trade.fee_open
    trade_fee_close = trade.fee_close

    is_backtest = self.is_backtest_mode()
    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    is_futures = self.is_futures_mode
    trade_leverage = trade.leverage
    trade_get_custom_data = trade.get_custom_data
    trade_set_custom_data = trade.set_custom_data
    trade_is_short = trade.is_short
    derisk_enable = self.derisk_enable
    short_rebuy_mode_tags = self.short_rebuy_mode_tags
    short_grind_mode_tags = self.short_grind_mode_tags

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)
    if len(df) < 2:
      return None
    last_candle = df.iloc[-1]
    previous_candle = df.iloc[-2]

    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_exits = trade.nr_of_successful_exits

    if dp.runmode.value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = self.config["exit_pricing"]["price_side"]
        if trade_is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    first_filled_order = filled_orders[0]
    last_filled_order = filled_orders[-1]
    first_filled_entry = filled_entries[0]
    last_filled_entry = filled_entries[-1]

    current_stake_amount = trade_amount * exit_rate
    slice_amount = first_filled_entry.safe_filled * first_filled_entry.safe_price
    slice_profit = (exit_rate - last_filled_order.safe_price) / last_filled_order.safe_price
    slice_profit_entry = (exit_rate - last_filled_entry.safe_price) / last_filled_entry.safe_price
    slice_profit_exit = (
      ((exit_rate - filled_exits[-1].safe_price) / filled_exits[-1].safe_price) if count_of_exits > 0 else 0.0
    )

    is_rebuy_mode = all(c in short_rebuy_mode_tags for c in enter_tags) or (
      any(c in short_rebuy_mode_tags for c in enter_tags)
      and all(c in (short_rebuy_mode_tags + short_grind_mode_tags) for c in enter_tags)
    )

    has_order_tags = hasattr(first_filled_order, "ft_order_tag")

    fee_open_rate = trade_fee_open if self.custom_fee_open_rate is None else self.custom_fee_open_rate
    fee_close_rate = trade_fee_close if self.custom_fee_close_rate is None else self.custom_fee_close_rate
    stake_scale_leverage = trade_leverage if is_futures else 1.0
    derisk_flag_timeout = None

    def get_derisk_flag_timeout():
      nonlocal derisk_flag_timeout
      if derisk_flag_timeout is None:
        derisk_flag_timeout = current_time - timedelta(hours=96)

      return derisk_flag_timeout

    grind_1_max_sub_grinds = 0
    grind_1_stakes = scale_stakes_for_min_stake(
      self.grinding_v2_grind_1_stakes_futures if is_futures else self.grinding_v2_grind_1_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_1_sub_thresholds = (
      self.grinding_v2_grind_1_thresholds_futures if is_futures else self.grinding_v2_grind_1_thresholds_spot
    )
    grind_1_max_sub_grinds = len(grind_1_stakes)
    grind_1_derisk_grinds = (
      self.grinding_v2_grind_1_derisk_futures if is_futures else self.grinding_v2_grind_1_derisk_spot
    )
    grind_1_profit_threshold = (
      self.grinding_v2_grind_1_profit_threshold_futures
      if is_futures
      else self.grinding_v2_grind_1_profit_threshold_spot
    )

    grind_2_max_sub_grinds = 0
    grind_2_stakes = scale_stakes_for_min_stake(
      self.grinding_v2_grind_2_stakes_futures if is_futures else self.grinding_v2_grind_2_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_2_sub_thresholds = (
      self.grinding_v2_grind_2_thresholds_futures if is_futures else self.grinding_v2_grind_2_thresholds_spot
    )
    grind_2_max_sub_grinds = len(grind_2_stakes)
    grind_2_derisk_grinds = (
      self.grinding_v2_grind_2_derisk_futures if is_futures else self.grinding_v2_grind_2_derisk_spot
    )
    grind_2_profit_threshold = (
      self.grinding_v2_grind_2_profit_threshold_futures
      if is_futures
      else self.grinding_v2_grind_2_profit_threshold_spot
    )

    grind_3_max_sub_grinds = 0
    grind_3_stakes = scale_stakes_for_min_stake(
      self.grinding_v2_grind_3_stakes_futures if is_futures else self.grinding_v2_grind_3_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_3_sub_thresholds = (
      self.grinding_v2_grind_3_thresholds_futures if is_futures else self.grinding_v2_grind_3_thresholds_spot
    )
    grind_3_max_sub_grinds = len(grind_3_stakes)
    grind_3_derisk_grinds = (
      self.grinding_v2_grind_3_derisk_futures if is_futures else self.grinding_v2_grind_3_derisk_spot
    )
    grind_3_profit_threshold = (
      self.grinding_v2_grind_3_profit_threshold_futures
      if is_futures
      else self.grinding_v2_grind_3_profit_threshold_spot
    )

    grind_4_max_sub_grinds = 0
    grind_4_stakes = scale_stakes_for_min_stake(
      self.grinding_v2_grind_4_stakes_futures if is_futures else self.grinding_v2_grind_4_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_4_sub_thresholds = (
      self.grinding_v2_grind_4_thresholds_futures if is_futures else self.grinding_v2_grind_4_thresholds_spot
    )
    grind_4_max_sub_grinds = len(grind_4_stakes)
    grind_4_derisk_grinds = (
      self.grinding_v2_grind_4_derisk_futures if is_futures else self.grinding_v2_grind_4_derisk_spot
    )
    grind_4_profit_threshold = (
      self.grinding_v2_grind_4_profit_threshold_futures
      if is_futures
      else self.grinding_v2_grind_4_profit_threshold_spot
    )

    grind_5_max_sub_grinds = 0
    grind_5_stakes = scale_stakes_for_min_stake(
      self.grinding_v2_grind_5_stakes_futures if is_futures else self.grinding_v2_grind_5_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_5_sub_thresholds = (
      self.grinding_v2_grind_5_thresholds_futures if is_futures else self.grinding_v2_grind_5_thresholds_spot
    )
    grind_5_max_sub_grinds = len(grind_5_stakes)
    grind_5_derisk_grinds = (
      self.grinding_v2_grind_5_derisk_futures if is_futures else self.grinding_v2_grind_5_derisk_spot
    )
    grind_5_profit_threshold = (
      self.grinding_v2_grind_5_profit_threshold_futures
      if is_futures
      else self.grinding_v2_grind_5_profit_threshold_spot
    )

    is_derisk_1 = False
    is_derisk_1_found = False  # derisk_level_1 de-risk exit
    derisk_1_order = None
    is_derisk_2 = False
    is_derisk_2_found = False  # derisk_level_2 de-risk exit
    derisk_2_order = None
    is_derisk_3 = False
    is_derisk_3_found = False  # derisk_level_3 de-risk exit
    derisk_3_order = None
    buyback_1_sub_grind_count = 0
    buyback_1_total_amount = 0.0
    buyback_1_total_cost = 0.0
    buyback_1_current_open_rate = 0.0
    buyback_1_current_grind_stake = 0.0
    buyback_1_current_grind_stake_profit = 0.0
    buyback_1_is_exit_found = False
    buyback_1_found = False
    buyback_1_buy_orders = []
    buyback_1_orders = []
    buyback_1_distance_ratio = 0.0
    buyback_1_exit_order = None
    buyback_1_exit_distance_ratio = 0.0
    buyback_2_sub_grind_count = 0
    buyback_2_total_amount = 0.0
    buyback_2_total_cost = 0.0
    buyback_2_current_open_rate = 0.0
    buyback_2_current_grind_stake = 0.0
    buyback_2_current_grind_stake_profit = 0.0
    buyback_2_is_exit_found = False
    buyback_2_found = False
    buyback_2_buy_orders = []
    buyback_2_orders = []
    buyback_2_distance_ratio = 0.0
    buyback_2_exit_order = None
    buyback_2_exit_distance_ratio = 0.0
    buyback_3_sub_grind_count = 0
    buyback_3_total_amount = 0.0
    buyback_3_total_cost = 0.0
    buyback_3_current_open_rate = 0.0
    buyback_3_current_grind_stake = 0.0
    buyback_3_current_grind_stake_profit = 0.0
    buyback_3_is_exit_found = False
    buyback_3_found = False
    buyback_3_buy_orders = []
    buyback_3_orders = []
    buyback_3_distance_ratio = 0.0
    buyback_3_exit_order = None
    buyback_3_exit_distance_ratio = 0.0
    grind_1_sub_grind_count = 0
    grind_1_total_amount = 0.0
    grind_1_total_cost = 0.0
    grind_1_current_open_rate = 0.0
    grind_1_current_grind_stake = 0.0
    grind_1_current_grind_stake_profit = 0.0
    grind_1_is_exit_found = False
    grind_1_found = False
    grind_1_buy_orders = []
    grind_1_orders = []
    grind_1_distance_ratio = 0.0
    grind_1_exit_order = None
    grind_1_exit_distance_ratio = 0.0
    grind_2_sub_grind_count = 0
    grind_2_total_amount = 0.0
    grind_2_total_cost = 0.0
    grind_2_current_open_rate = 0.0
    grind_2_current_grind_stake = 0.0
    grind_2_current_grind_stake_profit = 0.0
    grind_2_is_exit_found = False
    grind_2_found = False
    grind_2_buy_orders = []
    grind_2_orders = []
    grind_2_distance_ratio = 0.0
    grind_2_exit_order = None
    grind_2_exit_distance_ratio = 0.0
    grind_3_sub_grind_count = 0
    grind_3_total_amount = 0.0
    grind_3_total_cost = 0.0
    grind_3_current_open_rate = 0.0
    grind_3_current_grind_stake = 0.0
    grind_3_current_grind_stake_profit = 0.0
    grind_3_is_exit_found = False
    grind_3_found = False
    grind_3_buy_orders = []
    grind_3_orders = []
    grind_3_distance_ratio = 0.0
    grind_3_exit_order = None
    grind_3_exit_distance_ratio = 0.0
    grind_4_sub_grind_count = 0
    grind_4_total_amount = 0.0
    grind_4_total_cost = 0.0
    grind_4_current_open_rate = 0.0
    grind_4_current_grind_stake = 0.0
    grind_4_current_grind_stake_profit = 0.0
    grind_4_is_exit_found = False
    grind_4_found = False
    grind_4_buy_orders = []
    grind_4_orders = []
    grind_4_distance_ratio = 0.0
    grind_4_exit_order = None
    grind_4_exit_distance_ratio = 0.0
    grind_5_sub_grind_count = 0
    grind_5_total_amount = 0.0
    grind_5_total_cost = 0.0
    grind_5_current_open_rate = 0.0
    grind_5_current_grind_stake = 0.0
    grind_5_current_grind_stake_profit = 0.0
    grind_5_is_exit_found = False
    grind_5_found = False
    grind_5_buy_orders = []
    grind_5_orders = []
    grind_5_distance_ratio = 0.0
    grind_5_exit_order = None
    grind_5_exit_distance_ratio = 0.0
    for order in reversed(filled_orders):
      if (order.ft_order_side == "sell") and (order is not first_filled_order):
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag
        if not buyback_1_is_exit_found and order_tag == "buyback_1_entry":
          buyback_1_sub_grind_count += 1
          buyback_1_total_amount += order.safe_filled
          buyback_1_total_cost += order.safe_filled * order.safe_price
          buyback_1_buy_orders.append(order.id)
          buyback_1_orders.append(order)
          if not buyback_1_found:
            buyback_1_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            buyback_1_found = True
        elif not buyback_2_is_exit_found and order_tag == "buyback_2_entry":
          buyback_2_sub_grind_count += 1
          buyback_2_total_amount += order.safe_filled
          buyback_2_total_cost += order.safe_filled * order.safe_price
          buyback_2_buy_orders.append(order.id)
          buyback_2_orders.append(order)
          if not buyback_2_found:
            buyback_2_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            buyback_2_found = True
        elif not buyback_3_is_exit_found and order_tag == "buyback_3_entry":
          buyback_3_sub_grind_count += 1
          buyback_3_total_amount += order.safe_filled
          buyback_3_total_cost += order.safe_filled * order.safe_price
          buyback_3_buy_orders.append(order.id)
          buyback_3_orders.append(order)
          if not buyback_3_found:
            buyback_3_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            buyback_3_found = True
        elif not grind_1_is_exit_found and order_tag == "grind_1_entry":
          grind_1_sub_grind_count += 1
          grind_1_total_amount += order.safe_filled
          grind_1_total_cost += order.safe_filled * order.safe_price
          grind_1_buy_orders.append(order.id)
          grind_1_orders.append(order)
          if not grind_1_found:
            grind_1_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_1_found = True
        elif not grind_2_is_exit_found and order_tag == "grind_2_entry":
          grind_2_sub_grind_count += 1
          grind_2_total_amount += order.safe_filled
          grind_2_total_cost += order.safe_filled * order.safe_price
          grind_2_buy_orders.append(order.id)
          grind_2_orders.append(order)
          if not grind_2_found:
            grind_2_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_2_found = True
        elif not grind_3_is_exit_found and order_tag == "grind_3_entry":
          grind_3_sub_grind_count += 1
          grind_3_total_amount += order.safe_filled
          grind_3_total_cost += order.safe_filled * order.safe_price
          grind_3_buy_orders.append(order.id)
          grind_3_orders.append(order)
          if not grind_3_found:
            grind_3_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_3_found = True
        elif not grind_4_is_exit_found and order_tag == "grind_4_entry":
          grind_4_sub_grind_count += 1
          grind_4_total_amount += order.safe_filled
          grind_4_total_cost += order.safe_filled * order.safe_price
          grind_4_buy_orders.append(order.id)
          grind_4_orders.append(order)
          if not grind_4_found:
            grind_4_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_4_found = True
        elif not grind_5_is_exit_found and order_tag == "grind_5_entry":
          grind_5_sub_grind_count += 1
          grind_5_total_amount += order.safe_filled
          grind_5_total_cost += order.safe_filled * order.safe_price
          grind_5_buy_orders.append(order.id)
          grind_5_orders.append(order)
          if not grind_5_found:
            grind_5_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_5_found = True
      elif order.ft_order_side == "buy":
        if order is filled_exits[-1] and (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
          # break
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag.partition(" ")[0]
        if order_tag in ["derisk_level_1", "d"]:
          if not is_derisk_1_found:
            is_derisk_1_found = True
            is_derisk_1 = True
            derisk_1_order = order
        elif order_tag == "derisk_level_2":
          if not is_derisk_2_found:
            is_derisk_2_found = True
            is_derisk_2 = True
            derisk_2_order = order
        elif order_tag == "derisk_level_3":
          if not is_derisk_3_found:
            is_derisk_3_found = True
            is_derisk_3 = True
            derisk_3_order = order
        elif not buyback_1_is_exit_found and order_tag in ["buyback_1_exit", "buyback_1_derisk"]:
          buyback_1_is_exit_found = True
          buyback_1_exit_order = order
        elif not buyback_2_is_exit_found and order_tag in ["buyback_2_exit", "buyback_2_derisk"]:
          buyback_2_is_exit_found = True
          buyback_2_exit_order = order
        elif not buyback_3_is_exit_found and order_tag in ["buyback_3_exit", "buyback_3_derisk"]:
          buyback_3_is_exit_found = True
          buyback_3_exit_order = order
        elif not grind_1_is_exit_found and order_tag in ["grind_1_exit", "grind_1_derisk"]:
          grind_1_is_exit_found = True
          grind_1_exit_order = order
        elif not grind_2_is_exit_found and order_tag in ["grind_2_exit", "grind_2_derisk"]:
          grind_2_is_exit_found = True
          grind_2_exit_order = order
        elif not grind_3_is_exit_found and order_tag in ["grind_3_exit", "grind_3_derisk"]:
          grind_3_is_exit_found = True
          grind_3_exit_order = order
        elif not grind_4_is_exit_found and order_tag in ["grind_4_exit", "grind_4_derisk"]:
          grind_4_is_exit_found = True
          grind_4_exit_order = order
        elif not grind_5_is_exit_found and order_tag in ["grind_5_exit", "grind_5_derisk"]:
          grind_5_is_exit_found = True
          grind_5_exit_order = order
        elif order_tag == "derisk_global":
          if not buyback_1_is_exit_found:
            buyback_1_is_exit_found = True
            buyback_1_exit_order = order
          if not buyback_2_is_exit_found:
            buyback_2_is_exit_found = True
            buyback_2_exit_order = order
          if not buyback_3_is_exit_found:
            buyback_3_is_exit_found = True
            buyback_3_exit_order = order
          if not grind_1_is_exit_found:
            grind_1_is_exit_found = True
            grind_1_exit_order = order
          if not grind_2_is_exit_found:
            grind_2_is_exit_found = True
            grind_2_exit_order = order
          if not grind_3_is_exit_found:
            grind_3_is_exit_found = True
            grind_3_exit_order = order
          if not grind_4_is_exit_found:
            grind_4_is_exit_found = True
            grind_4_exit_order = order
          if not grind_5_is_exit_found:
            grind_5_is_exit_found = True
            grind_5_exit_order = order

    if buyback_1_sub_grind_count > 0:
      buyback_1_current_open_rate = buyback_1_total_cost / buyback_1_total_amount
      buyback_1_current_grind_stake = buyback_1_total_amount * exit_rate * (1 - trade_fee_close)
      buyback_1_current_grind_stake_profit = buyback_1_total_cost - buyback_1_current_grind_stake
    if buyback_2_sub_grind_count > 0:
      buyback_2_current_open_rate = buyback_2_total_cost / buyback_2_total_amount
      buyback_2_current_grind_stake = buyback_2_total_amount * exit_rate * (1 - trade_fee_close)
      buyback_2_current_grind_stake_profit = buyback_2_total_cost - buyback_2_current_grind_stake
    if buyback_3_sub_grind_count > 0:
      buyback_3_current_open_rate = buyback_3_total_cost / buyback_3_total_amount
      buyback_3_current_grind_stake = buyback_3_total_amount * exit_rate * (1 - trade_fee_close)
      buyback_3_current_grind_stake_profit = buyback_3_total_cost - buyback_3_current_grind_stake
    if grind_1_sub_grind_count > 0:
      grind_1_current_open_rate = grind_1_total_cost / grind_1_total_amount
      grind_1_current_grind_stake = grind_1_total_amount * exit_rate * (1 - trade_fee_close)
      grind_1_current_grind_stake_profit = grind_1_total_cost - grind_1_current_grind_stake
    if grind_2_sub_grind_count > 0:
      grind_2_current_open_rate = grind_2_total_cost / grind_2_total_amount
      grind_2_current_grind_stake = grind_2_total_amount * exit_rate * (1 - trade_fee_close)
      grind_2_current_grind_stake_profit = grind_2_total_cost - grind_2_current_grind_stake
    if grind_3_sub_grind_count > 0:
      grind_3_current_open_rate = grind_3_total_cost / grind_3_total_amount
      grind_3_current_grind_stake = grind_3_total_amount * exit_rate * (1 - trade_fee_close)
      grind_3_current_grind_stake_profit = grind_3_total_cost - grind_3_current_grind_stake
    if grind_4_sub_grind_count > 0:
      grind_4_current_open_rate = grind_4_total_cost / grind_4_total_amount
      grind_4_current_grind_stake = grind_4_total_amount * exit_rate * (1 - trade_fee_close)
      grind_4_current_grind_stake_profit = grind_4_total_cost - grind_4_current_grind_stake
    if grind_5_sub_grind_count > 0:
      grind_5_current_open_rate = grind_5_total_cost / grind_5_total_amount
      grind_5_current_grind_stake = grind_5_total_amount * exit_rate * (1 - trade_fee_close)
      grind_5_current_grind_stake_profit = grind_5_total_cost - grind_5_current_grind_stake

    if grind_1_is_exit_found:
      grind_1_exit_distance_ratio = (exit_rate - grind_1_exit_order.safe_price) / grind_1_exit_order.safe_price
    if grind_2_is_exit_found:
      grind_2_exit_distance_ratio = (exit_rate - grind_2_exit_order.safe_price) / grind_2_exit_order.safe_price
    if grind_3_is_exit_found:
      grind_3_exit_distance_ratio = (exit_rate - grind_3_exit_order.safe_price) / grind_3_exit_order.safe_price
    if grind_4_is_exit_found:
      grind_4_exit_distance_ratio = (exit_rate - grind_4_exit_order.safe_price) / grind_4_exit_order.safe_price
    if buyback_1_is_exit_found:
      buyback_1_exit_distance_ratio = (exit_rate - buyback_1_exit_order.safe_price) / buyback_1_exit_order.safe_price
    elif is_derisk_1_found:
      buyback_1_exit_distance_ratio = (exit_rate - derisk_1_order.safe_price) / derisk_1_order.safe_price
    if buyback_2_is_exit_found:
      buyback_2_exit_distance_ratio = (exit_rate - buyback_2_exit_order.safe_price) / buyback_2_exit_order.safe_price
    elif is_derisk_2_found:
      buyback_2_exit_distance_ratio = (exit_rate - derisk_2_order.safe_price) / derisk_2_order.safe_price
    if buyback_3_is_exit_found:
      buyback_3_exit_distance_ratio = (exit_rate - buyback_3_exit_order.safe_price) / buyback_3_exit_order.safe_price
    elif is_derisk_3_found:
      buyback_3_exit_distance_ratio = (exit_rate - derisk_3_order.safe_price) / derisk_3_order.safe_price

    # all buybacks & grinds
    current_open_grind_stake_profit = (
      buyback_1_current_grind_stake_profit
      + buyback_2_current_grind_stake_profit
      + buyback_3_current_grind_stake_profit
      + grind_1_current_grind_stake_profit
      + grind_2_current_grind_stake_profit
      + grind_3_current_grind_stake_profit
      + grind_4_current_grind_stake_profit
      + grind_5_current_grind_stake_profit
    )
    num_open_grinds_and_buybacks = (
      buyback_1_sub_grind_count
      + buyback_2_sub_grind_count
      + buyback_3_sub_grind_count
      + grind_1_sub_grind_count
      + grind_2_sub_grind_count
      + grind_3_sub_grind_count
      + grind_4_sub_grind_count
      + grind_5_sub_grind_count
    )

    # Rebuy mode, the first entry is lower than normal slot stake
    if is_rebuy_mode:
      slice_amount /= self.rebuy_mode_stake_multiplier
    # not reached the max allowed stake for all grinds
    is_not_trade_max_stake = (current_stake_amount < (slice_amount * self.grinding_v2_max_stake)) and (
      num_open_grinds_and_buybacks < self.grinding_v2_max_grinds_and_buybacks
    )
    slice_profit_gt_0_06 = slice_profit > 0.06

    is_short_extra_checks_entry = (
      (current_time - timedelta(minutes=5) > last_filled_entry.order_filled_utc)
      and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or slice_profit_gt_0_06)
      and (
        (current_stake_amount < ((first_filled_entry.safe_filled * first_filled_entry.safe_price) * 0.50))
        or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
        or slice_profit_gt_0_06
      )
    )
    is_short_buyback_entry = self.short_buyback_entry_v2(last_candle, previous_candle, slice_profit, True)
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_3_15m = last_candle["RSI_3_15m"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_aroond_14 = last_candle["AROOND_14"]
    last_aroond_14_15m = last_candle["AROOND_14_15m"]
    is_short_grind_entry = (
      self.short_grind_entry_v2(last_candle, previous_candle, slice_profit, True)
      or (
        (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
        and (num_open_grinds_and_buybacks == 0)
        and (
          (last_rsi_3 < 90.0)
          and (last_rsi_3_15m < 80.0)
          and (last_rsi_3_1h < 80.0)
          and (last_rsi_3_1h < 80.0)
          and (last_aroond_14 < 50.0)
          and (last_aroond_14_15m < 50.0)
        )
      )
      or (
        is_futures
        and trade.liquidation_price is not None
        and (
          (trade_is_short and current_rate > trade.liquidation_price * 0.90)
          or (not trade_is_short and current_rate < trade.liquidation_price * 1.10)
        )
        and (slice_profit > 0.03)
        and (last_rsi_3 < 90.0)
        and (last_rsi_3_15m < 80.0)
        # and (last_candle["RSI_3_1h"] < 80.0)
        # and (last_candle["RSI_3_1h"] < 80.0)
        and (last_aroond_14 < 50.0)
        and (last_aroond_14_15m < 50.0)
      )
    )

    # De-risk level 1

    # flag it
    if (
      derisk_enable
      and self.grinding_v2_derisk_level_1_enable
      and (not is_derisk_1_found)
      and not is_rebuy_mode
      and (trade_get_custom_data(key="grinding_v2_derisk_level_1_flag") is not True)
      and (
        profit_stake
        < (
          slice_amount
          * (self.grinding_v2_derisk_level_1_futures[0] if is_futures else self.grinding_v2_derisk_level_1_spot[0])
        )
        / trade_leverage
      )
    ):
      trade_set_custom_data(key="grinding_v2_derisk_level_1_flag", value=True)
      trade_set_custom_data(key="grinding_v2_derisk_level_1_profit", value=profit_stake)
      trade_set_custom_data(key="grinding_v2_derisk_level_1_time", value=current_time.isoformat())

    flag_is_derisk_level_1 = False
    if (
      derisk_enable
      and self.grinding_v2_derisk_level_1_enable
      and (not is_derisk_1_found)
      and not is_rebuy_mode
      and (trade_get_custom_data(key="grinding_v2_derisk_level_1_flag") is True)
    ):
      flag_profit = trade_get_custom_data(key="grinding_v2_derisk_level_1_profit")
      flag_time = datetime.fromisoformat(trade_get_custom_data(key="grinding_v2_derisk_level_1_time"))
      if get_derisk_flag_timeout() > flag_time:
        if profit_stake > flag_profit:
          trade_set_custom_data(key="grinding_v2_derisk_level_1_flag", value=False)
        else:
          flag_is_derisk_level_1 = True

    if (
      derisk_enable
      and self.grinding_v2_derisk_level_1_enable
      and (not is_derisk_1_found)
      and not is_rebuy_mode
      and (
        flag_is_derisk_level_1
        or (
          profit_stake
          < (
            slice_amount
            * (self.grinding_v2_derisk_level_1_futures[1] if is_futures else self.grinding_v2_derisk_level_1_spot[1])
          )
          / trade_leverage
        )
      )
    ):
      sell_amount = (
        (
          first_filled_entry.safe_filled
          * (
            self.grinding_v2_derisk_level_1_stake_futures if is_futures else self.grinding_v2_derisk_level_1_stake_spot
          )
        )
        * exit_rate
        / trade_leverage
      )
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="Level 1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk Level 1 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_1"

    # De-risk level 2

    # flag it
    if (
      derisk_enable
      and self.grinding_v2_derisk_level_2_enable
      and (not is_derisk_2_found)
      and not is_rebuy_mode
      and (trade_get_custom_data(key="grinding_v2_derisk_level_2_flag") is not True)
      and (
        profit_stake
        < (
          slice_amount
          * (self.grinding_v2_derisk_level_2_futures[0] if is_futures else self.grinding_v2_derisk_level_2_spot[0])
        )
        / trade_leverage
      )
    ):
      trade_set_custom_data(key="grinding_v2_derisk_level_2_flag", value=True)
      trade_set_custom_data(key="grinding_v2_derisk_level_2_profit", value=profit_stake)
      trade_set_custom_data(key="grinding_v2_derisk_level_2_time", value=current_time.isoformat())

    flag_is_derisk_level_2 = False
    if (
      derisk_enable
      and self.grinding_v2_derisk_level_2_enable
      and (not is_derisk_2_found)
      and not is_rebuy_mode
      and (trade_get_custom_data(key="grinding_v2_derisk_level_2_flag") is True)
    ):
      flag_profit = trade_get_custom_data(key="grinding_v2_derisk_level_2_profit")
      flag_time = datetime.fromisoformat(trade_get_custom_data(key="grinding_v2_derisk_level_2_time"))
      if get_derisk_flag_timeout() > flag_time:
        if profit_stake > flag_profit:
          trade_set_custom_data(key="grinding_v2_derisk_level_2_flag", value=False)
        else:
          flag_is_derisk_level_2 = True

    if (
      derisk_enable
      and self.grinding_v2_derisk_level_2_enable
      and (not is_derisk_2_found)
      and not is_rebuy_mode
      and (
        flag_is_derisk_level_2
        or (
          profit_stake
          < (
            slice_amount
            * (self.grinding_v2_derisk_level_2_futures[1] if is_futures else self.grinding_v2_derisk_level_2_spot[1])
          )
          / trade_leverage
        )
      )
    ):
      sell_amount = (
        (
          first_filled_entry.safe_filled
          * (
            self.grinding_v2_derisk_level_2_stake_futures if is_futures else self.grinding_v2_derisk_level_2_stake_spot
          )
        )
        * exit_rate
        / trade_leverage
      )
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="Level 2",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk Level 2 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_2"

    # De-risk level 3

    # flag it
    if (
      derisk_enable
      and self.grinding_v2_derisk_level_3_enable
      and (not is_derisk_3_found)
      and not is_rebuy_mode
      and (trade_get_custom_data(key="grinding_v2_derisk_level_3_flag") is not True)
      and (
        profit_stake
        < (
          slice_amount
          * (self.grinding_v2_derisk_level_3_futures[0] if is_futures else self.grinding_v2_derisk_level_3_spot[0])
        )
        / trade_leverage
      )
    ):
      trade_set_custom_data(key="grinding_v2_derisk_level_3_flag", value=True)
      trade_set_custom_data(key="grinding_v2_derisk_level_3_profit", value=profit_stake)
      trade_set_custom_data(key="grinding_v2_derisk_level_3_time", value=current_time.isoformat())

    flag_is_derisk_level_3 = False
    if (
      derisk_enable
      and self.grinding_v2_derisk_level_3_enable
      and (not is_derisk_3_found)
      and not is_rebuy_mode
      and (trade_get_custom_data(key="grinding_v2_derisk_level_3_flag") is True)
    ):
      flag_profit = trade_get_custom_data(key="grinding_v2_derisk_level_3_profit")
      flag_time = datetime.fromisoformat(trade_get_custom_data(key="grinding_v2_derisk_level_3_time"))
      if get_derisk_flag_timeout() > flag_time:
        if profit_stake > flag_profit:
          trade_set_custom_data(key="grinding_v2_derisk_level_3_flag", value=False)
        else:
          flag_is_derisk_level_3 = True

    if (
      derisk_enable
      and self.grinding_v2_derisk_level_3_enable
      and (not is_derisk_3_found)
      and not is_rebuy_mode
      and (
        flag_is_derisk_level_3
        or (
          profit_stake
          < (
            slice_amount
            * (self.grinding_v2_derisk_level_3_futures[1] if is_futures else self.grinding_v2_derisk_level_3_spot[1])
          )
          / trade_leverage
        )
      )
    ):
      sell_amount = (
        (
          first_filled_entry.safe_filled
          * (
            self.grinding_v2_derisk_level_3_stake_futures if is_futures else self.grinding_v2_derisk_level_3_stake_spot
          )
        )
        * exit_rate
        / trade_leverage
      )
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="Level 3",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk Level 3 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_3"

    # De-risk global
    if (
      self.grinding_v2_derisk_global_enable
      and is_derisk_1_found
      and (
        current_open_grind_stake_profit
        < (
          slice_amount
          * (self.grinding_v2_derisk_global_futures if is_futures else self.grinding_v2_derisk_global_spot)
        )
        / trade_leverage
      )
    ):
      sell_amount = trade_amount * exit_rate / trade_leverage - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="Global",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk Global [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_global"

    # Grinding 1

    if (
      (self.grinding_v2_grind_1_enable)
      and (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
      and is_short_grind_entry
      and is_short_extra_checks_entry
      and (grind_1_sub_grind_count < grind_1_max_sub_grinds)
      and (grind_1_sub_grind_count == 0 or (-grind_1_distance_ratio < grind_1_sub_thresholds[grind_1_sub_grind_count]))
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_1_stakes[grind_1_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_1_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_1_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "grind_1_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_1_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
      if (grind_profit > (grind_1_profit_threshold + fee_open_rate + fee_close_rate)) and short_grind_exit_v2(
        last_candle, previous_candle, slice_profit, True
      ):
        sell_amount = grind_1_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="grind_1_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_1_total_amount,
            )
          )
          log.info(
            f"Grinding exit (grind_1_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "grind_1_exit"
          for grind_entry_id in grind_1_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_grind_1_use_derisk
    #   and (grind_1_sub_grind_count > 0)
    #   and ((-(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate) < grind_1_derisk_grinds)
    #   and (grind_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_grind_1_use_derisk
      and (grind_1_sub_grind_count > 0)
      and (grind_1_current_grind_stake_profit < (slice_amount * grind_1_derisk_grinds))
      and (is_backtest or grind_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = grind_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_1_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate)
            if grind_1_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_1_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_1_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_1_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "grind_1_derisk"
        for grind_entry_id in grind_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 2

    if (
      (self.grinding_v2_grind_2_enable)
      # and (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
      and is_short_grind_entry
      and is_short_extra_checks_entry
      and (grind_2_sub_grind_count < grind_2_max_sub_grinds)
      and (grind_2_sub_grind_count == 0 or (-grind_2_distance_ratio < grind_2_sub_thresholds[grind_2_sub_grind_count]))
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_2_stakes[grind_2_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_2_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_2_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "grind_2_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_2_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
      if (grind_profit > (grind_2_profit_threshold + fee_open_rate + fee_close_rate)) and short_grind_exit_v2(
        last_candle, previous_candle, slice_profit, True
      ):
        sell_amount = grind_2_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="grind_2_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_2_total_amount,
            )
          )
          log.info(
            f"Grinding exit (grind_2_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "grind_2_exit"
          for grind_entry_id in grind_2_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_grind_2_use_derisk
    #   and (grind_2_sub_grind_count > 0)
    #   and ((-(exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate) < grind_2_derisk_grinds)
    #   and (grind_2_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_grind_2_use_derisk
      and (grind_2_sub_grind_count > 0)
      and (grind_2_current_grind_stake_profit < (slice_amount * grind_2_derisk_grinds))
      and (is_backtest or grind_2_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = grind_2_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_2_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate)
            if grind_2_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_2_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_2_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_2_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "grind_2_derisk"
        for grind_entry_id in grind_2_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 3

    if (
      (self.grinding_v2_grind_3_enable)
      # and (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
      and is_short_grind_entry
      and is_short_extra_checks_entry
      and (grind_3_sub_grind_count < grind_3_max_sub_grinds)
      and (grind_3_sub_grind_count == 0 or (-grind_3_distance_ratio < grind_3_sub_thresholds[grind_3_sub_grind_count]))
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_3_stakes[grind_3_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_3_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_3_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "grind_3_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_3_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
      if (grind_profit > (grind_3_profit_threshold + fee_open_rate + fee_close_rate)) and short_grind_exit_v2(
        last_candle, previous_candle, slice_profit, True
      ):
        sell_amount = grind_3_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="grind_3_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_3_total_amount,
            )
          )
          log.info(
            f"Grinding exit (grind_3_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "grind_3_exit"
          for grind_entry_id in grind_3_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_grind_3_use_derisk
    #   and (grind_3_sub_grind_count > 0)
    #   and ((-(exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate) < grind_3_derisk_grinds)
    #   and (grind_3_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_grind_3_use_derisk
      and (grind_3_sub_grind_count > 0)
      and (grind_3_current_grind_stake_profit < (slice_amount * grind_3_derisk_grinds))
      and (is_backtest or grind_3_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = grind_3_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_3_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate)
            if grind_3_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_3_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_3_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_3_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "grind_3_derisk"
        for grind_entry_id in grind_3_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 4

    if (
      (self.grinding_v2_grind_4_enable)
      # and (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
      and (
        is_short_grind_entry
        # or (
        #   is_derisk_1_found
        #   # only queue 4 grinds open
        #   and (num_open_grinds_and_buybacks == grind_4_sub_grind_count)
        #   and (last_candle["protections_short_global"] == True)
        #   and (
        #     (slice_profit > 0.04)
        #     and (last_candle["RSI_3"] < 90.0)
        #     and (last_candle["RSI_3_15m"] < 80.0)
        #     and (last_candle["AROOND_14"] < 50.0)
        #     and (last_candle["AROOND_14_15m"] < 50.0)
        #   )
        # )
      )
      and is_short_extra_checks_entry
      and (grind_4_sub_grind_count < grind_4_max_sub_grinds)
      and (grind_4_sub_grind_count == 0 or (-grind_4_distance_ratio < grind_4_sub_thresholds[grind_4_sub_grind_count]))
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_4_stakes[grind_4_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_4_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_4_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "grind_4_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_4_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
      if (grind_profit > (grind_4_profit_threshold + fee_open_rate + fee_close_rate)) and short_grind_exit_v2(
        last_candle, previous_candle, slice_profit, True
      ):
        sell_amount = grind_4_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="grind_4_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_4_total_amount,
            )
          )
          log.info(
            f"Grinding exit (grind_4_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "grind_4_exit"
          for grind_entry_id in grind_4_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_grind_4_use_derisk
    #   and (grind_4_sub_grind_count > 0)
    #   and ((-(exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate) < grind_4_derisk_grinds)
    #   and (grind_4_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_grind_4_use_derisk
      and (grind_4_sub_grind_count > 0)
      and (grind_4_current_grind_stake_profit < (slice_amount * grind_4_derisk_grinds))
      and (is_backtest or grind_4_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = grind_4_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_4_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate)
            if grind_4_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_4_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_4_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_4_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "grind_4_derisk"
        for grind_entry_id in grind_4_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 5

    if (
      (self.grinding_v2_grind_5_enable)
      and (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
      and (
        is_short_grind_entry
        or (
          is_derisk_1_found
          and (slice_profit_entry > 0.10)
          and (slice_profit_exit > 0.04)
          and (last_candle["protections_short_global"] == True)
          # and (
          #   (slice_profit > 0.04)
          #   and (last_candle["RSI_3"] < 90.0)
          #   and (last_candle["RSI_3_15m"] < 80.0)
          #   and (last_candle["AROOND_14"] < 50.0)
          #   and (last_candle["AROOND_14_15m"] < 50.0)
          # )
        )
      )
      and is_short_extra_checks_entry
      and (grind_5_sub_grind_count < grind_5_max_sub_grinds)
      and (grind_5_sub_grind_count == 0 or (-grind_5_distance_ratio < grind_5_sub_thresholds[grind_5_sub_grind_count]))
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_5_stakes[grind_5_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_5_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_5_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "grind_5_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_5_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
      if (grind_profit > (grind_5_profit_threshold + fee_open_rate + fee_close_rate)) and short_grind_exit_v2(
        last_candle, previous_candle, slice_profit, True
      ):
        sell_amount = grind_5_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="grind_5_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_5_total_amount,
            )
          )
          log.info(
            f"Grinding exit (grind_5_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "grind_5_exit"
          for grind_entry_id in grind_5_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_grind_5_use_derisk
    #   and (grind_5_sub_grind_count > 0)
    #   and ((-(exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate) < grind_5_derisk_grinds)
    #   and (grind_5_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_grind_5_use_derisk
      and (grind_5_sub_grind_count > 0)
      and (grind_5_current_grind_stake_profit < (slice_amount * grind_5_derisk_grinds))
      and (is_backtest or grind_5_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = grind_5_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_5_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate)
            if grind_5_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_5_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_5_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_5_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "grind_5_derisk"
        for grind_entry_id in grind_5_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Buyback 1

    if (
      self.grinding_v2_buyback_1_enable
      and is_derisk_1_found
      and is_short_buyback_entry
      and is_short_extra_checks_entry
      and (buyback_1_current_open_rate == 0)
      and (
        -buyback_1_exit_distance_ratio
        < (
          self.grinding_v2_buyback_1_distance_ratio_futures
          if is_futures
          else self.grinding_v2_buyback_1_distance_ratio_spot
        )
      )
      and is_not_trade_max_stake
    ):
      buy_amount = (
        slice_amount
        * (self.grinding_v2_buyback_1_stake_futures if is_futures else self.grinding_v2_buyback_1_stake_spot)
        / trade_leverage
      )
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "buyback-entry",
          tag="buyback_1_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Buyback entry (buyback_1_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "buyback_1_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if buyback_1_sub_grind_count > 0:
      grind_profit = -(exit_rate - buyback_1_current_open_rate) / buyback_1_current_open_rate
      if (
        grind_profit
        > (
          (
            self.grinding_v2_buyback_1_profit_threshold_futures
            if is_futures
            else self.grinding_v2_buyback_1_profit_threshold_spot
          )
          + fee_open_rate
          + fee_close_rate
        )
      ) and short_grind_exit_v2(last_candle, previous_candle, slice_profit, True):
        sell_amount = buyback_1_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "buyback-exit",
              tag="buyback_1_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=buyback_1_total_amount,
            )
          )
          log.info(
            f"Buyback exit (buyback_1_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "buyback_1_exit"
          for grind_entry_id in buyback_1_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_buyback_1_use_derisk
    #   and (buyback_1_sub_grind_count > 0)
    #   and (
    #     (-(exit_rate - buyback_1_current_open_rate) / buyback_1_current_open_rate)
    #     < (
    #       self.grinding_v2_buyback_1_derisk_futures if self.is_futures_mode else self.grinding_v2_buyback_1_derisk_spot
    #     )
    #   )
    #   and (buyback_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_buyback_1_use_derisk
      and (buyback_1_sub_grind_count > 0)
      and (
        buyback_1_current_grind_stake_profit
        < (
          slice_amount
          * (self.grinding_v2_buyback_1_derisk_futures if is_futures else self.grinding_v2_buyback_1_derisk_spot)
        )
      )
      and (is_backtest or buyback_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = buyback_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if buyback_1_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - buyback_1_current_open_rate) / buyback_1_current_open_rate)
            if buyback_1_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "buyback-derisk",
            tag="buyback_1_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            coin_amount=buyback_1_total_amount,
          )
        )
        log.info(
          f"Buyback de-risk (buyback_1_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "buyback_1_derisk"
        for grind_entry_id in buyback_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # # Buyback 2

    if (
      self.grinding_v2_buyback_2_enable
      and is_derisk_2_found
      and is_short_buyback_entry
      and is_short_extra_checks_entry
      and (buyback_2_current_open_rate == 0)
      and (
        -buyback_2_exit_distance_ratio
        < (
          self.grinding_v2_buyback_2_distance_ratio_futures
          if is_futures
          else self.grinding_v2_buyback_2_distance_ratio_spot
        )
      )
      and is_not_trade_max_stake
    ):
      buy_amount = (
        slice_amount
        * (self.grinding_v2_buyback_2_stake_futures if is_futures else self.grinding_v2_buyback_2_stake_spot)
        / trade_leverage
      )
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "buyback-entry",
          tag="buyback_2_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Buyback entry (buyback_2_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "buyback_2_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if buyback_2_sub_grind_count > 0:
      grind_profit = -(exit_rate - buyback_2_current_open_rate) / buyback_2_current_open_rate
      if (
        grind_profit
        > (
          (
            self.grinding_v2_buyback_2_profit_threshold_futures
            if is_futures
            else self.grinding_v2_buyback_2_profit_threshold_spot
          )
          + fee_open_rate
          + fee_close_rate
        )
      ) and short_grind_exit_v2(last_candle, previous_candle, slice_profit, True):
        sell_amount = buyback_2_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "buyback-exit",
              tag="buyback_2_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=buyback_2_total_amount,
            )
          )
          log.info(
            f"Buyback exit (buyback_2_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_2_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "buyback_2_exit"
          for grind_entry_id in buyback_2_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_buyback_2_use_derisk
    #   and (buyback_2_sub_grind_count > 0)
    #   and (
    #     (-(exit_rate - buyback_2_current_open_rate) / buyback_2_current_open_rate)
    #     < (
    #       self.grinding_v2_buyback_2_derisk_futures if self.is_futures_mode else self.grinding_v2_buyback_2_derisk_spot
    #     )
    #   )
    #   and (buyback_2_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_buyback_2_use_derisk
      and (buyback_2_sub_grind_count > 0)
      and (
        buyback_2_current_grind_stake_profit
        < (
          slice_amount
          * (self.grinding_v2_buyback_2_derisk_futures if is_futures else self.grinding_v2_buyback_2_derisk_spot)
        )
      )
      and (is_backtest or buyback_2_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = buyback_2_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if buyback_2_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - buyback_2_current_open_rate) / buyback_2_current_open_rate)
            if buyback_2_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "buyback-derisk",
            tag="buyback_2_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            coin_amount=buyback_2_total_amount,
          )
        )
        log.info(
          f"Buyback de-risk (buyback_2_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_2_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "buyback_2_derisk"
        for grind_entry_id in buyback_2_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # # Buyback 3

    if (
      self.grinding_v2_buyback_3_enable
      and is_derisk_3_found
      and is_short_buyback_entry
      and is_short_extra_checks_entry
      and (buyback_3_current_open_rate == 0)
      and (
        -buyback_3_exit_distance_ratio
        < (
          self.grinding_v2_buyback_3_distance_ratio_futures
          if is_futures
          else self.grinding_v2_buyback_3_distance_ratio_spot
        )
      )
      and is_not_trade_max_stake
    ):
      buy_amount = (
        slice_amount
        * (self.grinding_v2_buyback_3_stake_futures if is_futures else self.grinding_v2_buyback_3_stake_spot)
        / trade_leverage
      )
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "buyback-entry",
          tag="buyback_3_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Buyback entry (buyback_3_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      order_tag = "buyback_3_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if buyback_3_sub_grind_count > 0:
      grind_profit = -(exit_rate - buyback_3_current_open_rate) / buyback_3_current_open_rate
      if (
        grind_profit
        > (
          (
            self.grinding_v2_buyback_3_profit_threshold_futures
            if is_futures
            else self.grinding_v2_buyback_3_profit_threshold_spot
          )
          + fee_open_rate
          + fee_close_rate
        )
      ) and short_grind_exit_v2(last_candle, previous_candle, slice_profit, True):
        sell_amount = buyback_3_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "buyback-exit",
              tag="buyback_3_exit",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=buyback_3_total_amount,
            )
          )
          log.info(
            f"Buyback exit (buyback_3_exit) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_3_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "buyback_3_exit"
          for grind_entry_id in buyback_3_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # if (
    #   self.grinding_v2_buyback_3_use_derisk
    #   and (buyback_3_sub_grind_count > 0)
    #   and (
    #     (-(exit_rate - buyback_3_current_open_rate) / buyback_3_current_open_rate)
    #     < (
    #       self.grinding_v2_buyback_3_derisk_futures if self.is_futures_mode else self.grinding_v2_buyback_3_derisk_spot
    #     )
    #   )
    #   and (buyback_3_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
    # ):
    if (
      self.grinding_v2_buyback_3_use_derisk
      and (buyback_3_sub_grind_count > 0)
      and (
        buyback_3_current_grind_stake_profit
        < (
          slice_amount
          * (self.grinding_v2_buyback_3_derisk_futures if is_futures else self.grinding_v2_buyback_3_derisk_spot)
        )
      )
      and (is_backtest or buyback_3_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3))
    ):
      sell_amount = buyback_3_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if buyback_3_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - buyback_3_current_open_rate) / buyback_3_current_open_rate)
            if buyback_3_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "buyback-derisk",
            tag="buyback_3_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            coin_amount=buyback_3_total_amount,
          )
        )
        log.info(
          f"Buyback de-risk (buyback_3_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {buyback_3_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "buyback_3_derisk"
        for grind_entry_id in buyback_3_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    return None

  def short_buyback_entry_v2(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    previous_ema_12 = previous_candle["EMA_12"]
    previous_ema_26 = previous_candle["EMA_26"]

    last_rsi_3_1d = last_candle["RSI_3_1d"]
    last_roc_9_1h = last_candle["ROC_9_1h"]
    last_roc_9_4h = last_candle["ROC_9_4h"]
    last_close_min_48 = last_candle["close_min_48"]
    last_low_min_6_1h = last_candle["low_min_6_1h"]
    last_low_min_12_1h = last_candle["low_min_12_1h"]
    last_open = last_candle["open"]

    last_ema_12 = last_candle["EMA_12"]
    last_ema_26 = last_candle["EMA_26"]
    last_roc_9_1d = last_candle["ROC_9_1d"]
    last_rsi_3 = last_candle["RSI_3"]

    last_close = last_candle["close"]
    last_rsi_14 = last_candle["RSI_14"]
    last_rsi_3_15m = last_candle["RSI_3_15m"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_rsi_3_4h = last_candle["RSI_3_4h"]
    last_roc_2_1h = last_candle["ROC_2_1h"]
    last_roc_2_4h = last_candle["ROC_2_4h"]
    last_protections_short_global = last_candle["protections_short_global"]
    last_enter_short = last_candle["enter_short"]
    last_aroond_14 = last_candle["AROOND_14"]
    last_aroond_14_15m = last_candle["AROOND_14_15m"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_stochrsi_k_15m = last_candle["STOCHRSIk_14_14_3_3_15m"]
    last_stochrsi_k_1h = last_candle["STOCHRSIk_14_14_3_3_1h"]
    last_stochrsi_k_4h = last_candle["STOCHRSIk_14_14_3_3_4h"]
    last_roc_2_1d = last_candle["ROC_2_1d"]
    last_ema_16 = last_candle["EMA_16"]
    last_bbu_20 = last_candle["BBU_20_2.0"]

    # Reused short buyback entry v2 thresholds
    last_roc_2_4h_lt_5 = last_roc_2_4h < 5.0
    last_roc_2_1h_lt_5 = last_roc_2_1h < 5.0
    last_rsi_14_gt_64 = last_rsi_14 > 64.0
    last_rsi_3_4h_lt_90 = last_rsi_3_4h < 90.0
    last_rsi_3_1h_lt_90 = last_rsi_3_1h < 90.0
    last_rsi_3_1d_lt_90 = last_rsi_3_1d < 90.0
    last_rsi_3_15m_lt_90 = last_rsi_3_15m < 90.0
    last_roc_9_4h_lt_5 = last_roc_9_4h < 5.0
    last_roc_9_1h_lt_5 = last_roc_9_1h < 5.0
    last_roc_9_1d_lt_5 = last_roc_9_1d < 5.0

    if (last_protections_short_global == True) and (
      (last_enter_short == True)
      or (
        (last_rsi_14_gt_64)
        and (last_rsi_3 < 80.0)
        and (last_rsi_3_15m < 70.0)
        and (last_rsi_3_1h < 70.0)
        and (last_rsi_3_4h < 70.0)
        and (last_aroond_14 < 25.0)
        and (last_roc_2_1h_lt_5)
        and (last_roc_2_4h_lt_5)
        # and (last_candle["ROC_9_4h"] > -20.0)
        # and (last_candle["ROC_9_4h"] < 40.0)
        # and (last_candle["ROC_9_1d"] > -20.0)
        # and (last_candle["ROC_9_1d"] < 50.0)
        and (last_stochrsi_k > 80.0)
        and (last_stochrsi_k_15m > 80.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_1h"] < 30.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_4h"] < 30.0)
        and (last_close < (last_close_min_48 * 1.10))
        and (last_close < (last_low_min_6_1h * 1.18))
        and (last_close < (last_low_min_12_1h * 1.25))
        # and (last_candle["close"] < (last_candle["low_min_24_4h"] * 1.20))
        and (last_close > (last_ema_16 * 1.120))
      )
      or (
        (last_rsi_14_gt_64)
        and (last_rsi_3 < 95.0)
        and (last_rsi_3_15m < 85.0)
        and (last_rsi_3_1h < 85.0)
        and (last_rsi_3_4h < 85.0)
        and (last_roc_2_1h_lt_5)
        and (last_roc_2_4h_lt_5)
        # and (last_candle["ROC_2_1d"] > -10.0)
        # and (last_candle["ROC_9_1h"] > -10.0)
        # and (last_candle["ROC_9_4h"] > -10.0)
        and (last_roc_9_1d_lt_5)
        and (last_ema_12 > last_ema_26)
        and ((last_ema_12 - last_ema_26) > (last_open * 0.020))
        and ((previous_ema_12 - previous_ema_26) > (last_open / 100.0))
      )
      or (
        (last_rsi_14_gt_64)
        and (last_rsi_3 < 90.0)
        and (last_rsi_3_15m_lt_90)
        and (last_rsi_3_1h_lt_90)
        and (last_rsi_3_4h_lt_90)
        and (last_rsi_3_1d_lt_90)
        and (last_roc_2_1h_lt_5)
        and (last_roc_2_4h_lt_5)
        and (last_roc_2_1d < 5.0)
        and (last_roc_9_1h_lt_5)
        and (last_roc_9_4h_lt_5)
        and (last_roc_9_1d < 10.0)
        # and (last_candle["ROC_9_4h"] < 40.0)
        # and (last_candle["ROC_9_1d"] < 50.0)
        and (last_aroond_14_15m < 25.0)
        and (last_close < (last_close_min_48 * 1.10))
        and (last_close < (last_low_min_6_1h * 1.18))
        and (last_close < (last_low_min_12_1h * 1.25))
        # and (last_candle["close"] < (last_candle["low_min_24_4h"] * 1.20))
        and (last_close > (last_ema_12 * 1.020))
      )
      or (
        (last_rsi_14 < 64.0)
        and (last_rsi_3_15m_lt_90)
        and (last_rsi_3_1h_lt_90)
        and (last_rsi_3_4h_lt_90)
        and (last_rsi_3_1d_lt_90)
        and (last_roc_2_1h_lt_5)
        and (last_roc_2_4h_lt_5)
        # and (last_candle["ROC_2_1d"] > -5.0)
        and (last_roc_9_1h_lt_5)
        and (last_roc_9_4h_lt_5)
        and (last_roc_9_1d_lt_5)
        and (last_stochrsi_k_1h > 20.0)
        and (last_stochrsi_k_4h > 30.0)
        # and (last_candle["close"] > (last_candle["close_max_48"] * 0.90))
        # and (last_candle["close"] < (last_candle["low_min_6_1h"] * 1.18))
        # and (last_candle["close"] < (last_candle["low_min_12_1h"] * 1.25))
        and (last_close > (last_ema_26 * 1.040))
        and (last_close > (last_bbu_20 * 1.001))
      )
    ):
      return True

    return False

  def short_grind_entry_v2(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    previous_ema_12 = previous_candle["EMA_12"]
    previous_ema_26 = previous_candle["EMA_26"]
    last_aroond_14_15m = last_candle["AROOND_14_15m"]
    last_rsi_14_1h = last_candle["RSI_14_1h"]
    last_high_max_24_4h = last_candle["high_max_24_4h"]
    last_bbu_20_2_0 = last_candle["BBU_20_2.0"]
    last_high_max_12_4h = last_candle["high_max_12_4h"]

    last_ema_12 = last_candle["EMA_12"]
    last_ema_26 = last_candle["EMA_26"]
    last_stochrsik_14_14_3_3 = last_candle["STOCHRSIk_14_14_3_3"]
    last_close_min_48 = last_candle["close_min_48"]
    last_open = last_candle["open"]
    last_aroond_14 = last_candle["AROOND_14"]
    last_roc_2_1d = last_candle["ROC_2_1d"]
    last_roc_9_1d = last_candle["ROC_9_1d"]
    last_rsi_3_1d = last_candle["RSI_3_1d"]
    last_low_min_12_1h = last_candle["low_min_12_1h"]
    last_low_min_6_1h = last_candle["low_min_6_1h"]

    last_close = last_candle["close"]
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_3_15m = last_candle["RSI_3_15m"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_rsi_3_4h = last_candle["RSI_3_4h"]
    last_rsi_14 = last_candle["RSI_14"]
    last_roc_2_1h = last_candle["ROC_2_1h"]
    last_roc_2_4h = last_candle["ROC_2_4h"]
    last_roc_9_1h = last_candle["ROC_9_1h"]
    last_roc_9_4h = last_candle["ROC_9_4h"]
    last_protections_short_global = last_candle["protections_short_global"]
    last_enter_short = last_candle["enter_short"]
    last_stochrsi_k_15m = last_candle["STOCHRSIk_14_14_3_3_15m"]
    last_stochrsi_k_1h = last_candle["STOCHRSIk_14_14_3_3_1h"]
    last_stochrsi_k_4h = last_candle["STOCHRSIk_14_14_3_3_4h"]
    last_low_min_24_4h = last_candle["low_min_24_4h"]
    last_ema_16 = last_candle["EMA_16"]

    # Reused short grind entry v2 thresholds
    last_rsi_3_lt_95 = last_rsi_3 < 95.0
    last_rsi_3_4h_lt_90 = last_rsi_3_4h < 90.0
    last_rsi_3_1h_lt_90 = last_rsi_3_1h < 90.0
    last_rsi_3_15m_lt_90 = last_rsi_3_15m < 90.0
    last_rsi_3_lt_90 = last_rsi_3 < 90.0
    last_rsi_14_gt_64 = last_rsi_14 > 64.0
    last_aroond_14_lt_25 = last_aroond_14 < 25.0
    last_stochrsik_14_14_3_3_gt_80 = last_stochrsik_14_14_3_3 > 80.0
    last_rsi_3_1d_lt_90 = last_rsi_3_1d < 90.0
    last_roc_9_4h_lt_10 = last_roc_9_4h < 10.0
    last_roc_9_1h_lt_10 = last_roc_9_1h < 10.0
    last_roc_2_4h_lt_10 = last_roc_2_4h < 10.0
    last_roc_2_1h_lt_10 = last_roc_2_1h < 10.0
    last_rsi_3_15m_lt_85 = last_rsi_3_15m < 85.0
    last_roc_2_4h_lt_5 = last_roc_2_4h < 5.0
    last_roc_2_1h_lt_5 = last_roc_2_1h < 5.0
    last_roc_2_1d_lt_10 = last_roc_2_1d < 10.0
    last_rsi_3_4h_lt_85 = last_rsi_3_4h < 85.0
    last_rsi_3_1h_lt_85 = last_rsi_3_1h < 85.0
    last_rsi_3_15m_lt_95 = last_rsi_3_15m < 95.0
    last_rsi_14_gt_65 = last_rsi_14 > 65.0
    last_roc_9_1d_lt_30 = last_roc_9_1d < 30.0

    if (last_protections_short_global == True) and (
      (last_enter_short == True)
      or (
        (last_rsi_14 > 54.0)
        and (last_rsi_3_lt_90)
        and (last_rsi_3_15m_lt_85)
        and (last_rsi_3_1h_lt_85)
        and (last_rsi_3_4h_lt_85)
        and (last_roc_2_1h_lt_10)
        and (last_roc_2_4h_lt_10)
        and (last_roc_2_1d_lt_10)
        and (last_roc_9_1h < 25.0)
        and (last_roc_9_4h < 25.0)
        and (last_roc_9_1d < 25.0)
        # and (last_candle["ROC_9_1d"] < 40.0)
        and (last_aroond_14_lt_25)
        # and (last_candle["STOCHRSIk_14_14_3_3"] < 20.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_15m"] < 20.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_1h"] < 30.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_4h"] < 30.0)
        and (last_close < (last_close_min_48 * 1.10))
        and (last_close < (last_low_min_6_1h * 1.18))
        and (last_close < (last_low_min_12_1h * 1.25))
        and (last_close > (last_high_max_24_4h * 0.85))
        and (last_close > (last_ema_16 * 1.032))
      )
      or (
        (last_rsi_14_gt_64)
        and (last_rsi_3_lt_95)
        and (last_rsi_3_15m_lt_85)
        and (last_rsi_3_1h_lt_85)
        and (last_rsi_3_4h_lt_85)
        # and (last_candle["RSI_3_1d"] > 15.0)
        and (last_roc_2_1h_lt_10)
        and (last_roc_2_4h_lt_10)
        # and (last_candle["ROC_2_1d"] > -10.0)
        and (last_roc_9_1h_lt_10)
        and (last_roc_9_4h_lt_10)
        and (last_roc_9_1d_lt_30)
        and (last_stochrsik_14_14_3_3 > 50.0)
        and (last_ema_12 > last_ema_26)
        and ((last_ema_12 - last_ema_26) > (last_open * 0.020))
        and ((previous_ema_12 - previous_ema_26) > (last_open / 100.0))
      )
      or (
        (last_rsi_14_gt_64)
        and (last_rsi_3_lt_90)
        and (last_rsi_3_15m_lt_90)
        and (last_rsi_3_1h_lt_90)
        and (last_rsi_3_4h_lt_90)
        and (last_rsi_3_1d_lt_90)
        and (last_roc_2_1h_lt_5)
        and (last_roc_2_4h_lt_5)
        and (last_roc_2_1d < 5.0)
        and (last_roc_9_1h_lt_10)
        and (last_roc_9_4h_lt_10)
        and (last_roc_9_1d < 10.0)
        # and (last_roc_9_4h < 40.0)
        # and (last_candle["ROC_9_1d"] < 50.0)
        and (last_aroond_14_15m < 25.0)
        and (last_close < (last_close_min_48 * 1.10))
        and (last_close < (last_low_min_6_1h * 1.18))
        and (last_close < (last_low_min_12_1h * 1.25))
        # and (last_close < (last_candle["low_min_24_4h"] * 1.20))
        and (last_close > (last_ema_12 * 1.020))
      )
      or (
        (last_rsi_14_gt_64)
        and (last_rsi_3_lt_90)
        and (last_rsi_3_15m_lt_90)
        and (last_rsi_3_1h_lt_90)
        and (last_rsi_3_4h_lt_90)
        and (last_rsi_3_1d_lt_90)
        and (last_roc_2_1h_lt_10)
        and (last_roc_2_4h_lt_10)
        and (last_roc_2_1d_lt_10)
        # and (last_roc_9_1h > -10.0)
        # and (last_roc_9_4h > -10.0)
        # and (last_candle["ROC_9_1d"] > -10.0)
        and (last_aroond_14_lt_25)
        and (last_close < (last_close_min_48 * 1.10))
        and (last_close < (last_low_min_6_1h * 1.18))
        and (last_close < (last_low_min_12_1h * 1.25))
        and (last_close > (last_ema_26 * 1.038))
        and (last_close > (last_bbu_20_2_0 * 1.0))
      )
      or (
        (last_rsi_14_gt_65)
        and (last_rsi_3_lt_90)
        and (last_rsi_3_15m_lt_90)
        and (last_rsi_3_1h_lt_90)
        and (last_rsi_3_4h_lt_90)
        # and (last_candle["RSI_3_1d"] > 10.0)
        and (last_roc_2_1h_lt_10)
        and (last_roc_2_4h_lt_10)
        and (last_roc_2_1d_lt_10)
        and (last_roc_9_1h_lt_10)
        and (last_roc_9_4h_lt_10)
        # and (last_candle["ROC_9_1d"] > -10.0)
        and (last_aroond_14_lt_25)
        # and (last_candle["AROONU_14_15m"] < 25.0)
        # and (last_candle["STOCHRSIk_14_14_3_3"] < 20.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_15m"] < 20.0)
        # and (last_close > (last_candle["close_max_48"] * 0.90))
        # and (last_close < (last_candle["low_min_6_1h"] * 1.18))
        # and (last_close < (last_candle["low_min_12_1h"] * 1.25))
        and (last_close > (last_high_max_12_4h * 0.80))
        and (last_close > (last_candle["EMA_9"] * 1.032))
        and (last_close > (last_candle["EMA_20"] * 1.020))
      )
      or (
        (last_rsi_14_gt_65)
        and (last_rsi_3_lt_90)
        and (last_rsi_3 > 60.0)
        # and (last_candle["RSI_4"] < 40.0)
        and (last_rsi_3_15m_lt_85)
        # and (last_rsi_3_1h > 20.0)
        # and (last_rsi_3_4h > 20.0)
        # and (last_candle["RSI_3_1d"] > 20.0)
        and (last_roc_2_1h_lt_5)
        and (last_roc_2_4h_lt_5)
        # and (last_candle["ROC_2_1d"] > -5.0)
        and (last_roc_9_1h_lt_10)
        and (last_roc_9_4h_lt_10)
        # and (last_candle["ROC_9_1d"] > -10.0)
        and (last_aroond_14_lt_25)
        # and (last_candle["AROONU_14_15m"] < 25.0)
        # and (last_candle["STOCHRSIk_14_14_3_3"] < 20.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_15m"] < 20.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_1h"] < 50.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_4h"] < 50.0)
        # and (last_close > (last_candle["close_max_48"] * 0.90))
        # and (last_close < (last_candle["low_min_6_1h"] * 1.18))
        # and (last_close < (last_candle["low_min_12_1h"] * 1.25))
        and (last_candle["RSI_20"] > previous_candle["RSI_20"])
        and (last_close > (last_candle["SMA_16"] * 1.045))
        # and (last_close < (last_candle["EMA_20"] * 0.980))
      )
      or (
        (last_rsi_3_lt_95)
        and (last_rsi_3_15m_lt_90)
        and (last_rsi_3_1h_lt_90)
        and (last_rsi_3_4h_lt_90)
        and (last_roc_2_1h_lt_5)
        and (last_roc_2_4h_lt_5)
        and (last_roc_9_1h < 5.0)
        and (last_roc_9_4h < 5.0)
        and (last_candle["WILLR_14"] > -50.0)
        # and (last_candle["AROONU_14"] < 25.0)
        and (last_stochrsik_14_14_3_3_gt_80)
        and (last_candle["WILLR_84_1h"] > -30.0)
        # and (last_candle["STOCHRSIk_14_14_3_3_1h"] < 40.0)
        and (last_close < (last_high_max_24_4h * 0.77))
        and (last_candle["BBB_20_2.0_1h"] > 12.0)
        and (last_close_min_48 <= (last_close * 0.90))
      )
      or (
        (last_rsi_3 > 70.0)
        and (last_rsi_3_lt_95)
        and (last_rsi_3_15m_lt_95)
        and (last_rsi_3_1h_lt_90)
        and (last_rsi_3_4h_lt_90)
        # and (last_roc_2_1h > -5.0)
        # and (last_roc_2_4h > -5.0)
        # and (last_roc_9_1h > -5.0)
        # and (last_roc_9_4h > -5.0)
        and (last_roc_9_1d_lt_30)
        # and (last_candle["STOCHRSIk_14_14_3_3"] < 20.0)
        # and (last_close < (last_candle["low_min_24_4h"] * 1.50))
        and (last_ema_12 > last_ema_26)
        and ((last_ema_12 - last_ema_26) > (last_open * 0.034))
        and ((previous_ema_12 - previous_ema_26) > (last_open / 100.0))
      )
      or (
        (last_rsi_3_lt_95)
        and (last_rsi_3_15m < 75.0)
        and (last_rsi_3_1h < 70.0)
        and (last_close > (last_low_min_24_4h * 1.10))
        and (last_close > (last_close_min_48 * 1.10))
        and (last_close < (last_candle["close_max_12"] * 0.92))
      )
      or (
        (last_rsi_3_lt_95)
        and (last_rsi_3_15m_lt_95)
        and (last_stochrsik_14_14_3_3_gt_80)
        and (last_rsi_14 > (last_rsi_14_1h + 45.0))
      )
      or (
        (last_rsi_3_lt_90)
        and (last_rsi_3_15m_lt_90)
        and (last_rsi_3_1h_lt_90)
        and (last_rsi_3_4h_lt_90)
        and (last_rsi_3_1d_lt_90)
        and (last_stochrsik_14_14_3_3_gt_80)
        and (last_close > (last_candle["SMA_30"] * 1.022))
        and (last_close > (last_bbu_20_2_0 * 1.0))
      )
      or (
        (last_rsi_14_gt_64)
        and (last_rsi_3_lt_95)
        and (last_rsi_3_15m_lt_90)
        and (last_rsi_3_1h_lt_90)
        and (last_rsi_3_4h_lt_90)
        and (last_rsi_3_1d_lt_90)
        and (last_stochrsik_14_14_3_3 > 70.0)
        and (last_close < (last_close_min_48 * 1.15))
        and (last_close < (last_low_min_6_1h * 1.20))
        and (last_close < (last_low_min_12_1h * 1.33))
        and (last_close > (last_high_max_12_4h * 0.75))
        and (last_ema_12 > last_ema_26)
        and ((last_ema_12 - last_ema_26) > (last_open * 0.018))
        and ((previous_ema_12 - previous_ema_26) > (last_open / 100.0))
      )
      or (
        (last_rsi_3_lt_95)
        and (previous_candle["SMA_9"] > previous_candle["SMA_21"])
        and (last_candle["SMA_9"] < last_candle["SMA_21"])
        and (last_close > (last_candle["EMA_100"] * 1.016))
        and (last_rsi_3_1h < 80.0)
        and (last_rsi_3_4h < 80.0)
      )
      or (
        (slice_profit > 0.12)
        and (last_rsi_3_lt_95)
        and (last_rsi_3_15m_lt_90)
        and (last_rsi_14 > 60.0)
        and (last_aroond_14_lt_25)
        and (last_aroond_14_15m < 30.0)
        and (last_stochrsik_14_14_3_3_gt_80)
        and (last_stochrsi_k_15m > 70.0)
        and (last_rsi_14_1h > 50.0)
        and (last_candle["RSI_14_4h"] > 50.0)
      )
      or (
        (last_rsi_14_gt_64)
        and (last_rsi_3_lt_95)
        and (last_rsi_3_1h_lt_90)
        and (last_rsi_3_4h_lt_90)
        and (last_close > (last_ema_12 * 1.001))
        and (last_close > (last_candle["BBL_20_2.0"] * 1.004))
      )
    ):
      return True

    return False

  def short_buyback_exit_v2(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_14 = last_candle["RSI_14"]
    last_willr_14 = last_candle["WILLR_14"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_close = last_candle["close"]
    last_bbl_20 = last_candle["BBL_20_2.0"]

    if (
      (last_rsi_3 < 1.0)
      or (last_rsi_14 < 30.0)
      or (last_willr_14 < -99.9)
      or (last_stochrsi_k > 5.0)
      or (last_close < (last_bbl_20 * 0.99))
      or ((last_rsi_3 < 10.0) and (last_rsi_14 > 50.0))
    ):
      return True

    return False

  def short_grind_exit_v2(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_14 = last_candle["RSI_14"]
    last_willr_14 = last_candle["WILLR_14"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_close = last_candle["close"]
    last_bbl_20 = last_candle["BBL_20_2.0"]

    if (
      (last_rsi_3 < 1.0)
      or (last_rsi_14 < 30.0)
      or (last_willr_14 < -99.9)
      or (last_stochrsi_k < 5.0)
      or (last_close < (last_bbl_20 * 0.99))
      or ((last_rsi_3 < 10.0) and (last_rsi_14 > 50.0))
    ):
      return True

    return False

  # Short Grinding Exit v3 (mirror of long_grind_exit_v3)
  # ---------------------------------------------------------------------------------------------
  def short_grind_exit_v3(
    self,
    last_candle: Series,
    previous_candle: Series,
    slice_profit: float,
    current_time: datetime,
    min_stake: float,
    current_stake_amount: float,
    exit_rate: float,
    profit_stake: float,
    profit_ratio: float,
    name: str,
    tag: str,
    fee_open_rate: float,
    fee_close_rate: float,
    max_profit: float,
    max_profit_rate: float,
    grind_profit_stake: float,
    grind_profit_rate: float,
    grind_total_amount: float,
    grind_exit_profit_threshold: float,
    grind_open_orders,
    trade: Trade,
  ) -> tuple:
    # Normalize so profit is always positive when the short is profitable.
    profit = -grind_profit_rate

    # Not enough profit after fees.
    if profit < (grind_exit_profit_threshold + fee_open_rate + fee_close_rate):
      return None, None

    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_14 = last_candle["RSI_14"]
    last_willr_14 = last_candle["WILLR_14"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_close = last_candle["close"]
    last_bbl_20 = last_candle["BBL_20_2.0"]

    is_normal_exit = False
    if (
      (last_rsi_3 < 1.0)
      or (last_rsi_14 < 30.0)
      or (last_willr_14 < -99.9)
      or (last_stochrsi_k < 5.0)
      or (last_close < (last_bbl_20 * 0.99))
      or ((last_rsi_3 < 10.0) and (last_rsi_14 > 50.0))
      or (
        (last_rsi_3 < 20.0)
        and (last_candle["RSI_3_1h"] > 80.0)
        and (last_candle["RSI_3_4h"] > 80.0)
        and (last_candle["ROC_9_1d"] < 10.0)
        and (last_candle["BTC_RSI_14_4h"] > 65.0)
      )
    ):
      is_normal_exit = True

    is_trailing_exit = False
    # max_profit = -max_profit_rate
    # drawdown = max_profit - profit
    # if 0.01 <= -grind_profit_rate < 0.02:
    #   if -grind_profit_rate < (-max_profit_rate - 0.025):
    #     is_trailing_exit = True
    # elif 0.02 <= -grind_profit_rate <= 0.05:
    #   if -grind_profit_rate < (-max_profit_rate - 0.035):
    #     is_trailing_exit = True
    # elif 0.05 <= -grind_profit_rate <= 0.08:
    #   if -grind_profit_rate < (-max_profit_rate - 0.045):
    #     is_trailing_exit = True
    # elif 0.08 <= -grind_profit_rate <= 0.12:
    #   if -grind_profit_rate < (-max_profit_rate - 0.050):
    #     is_trailing_exit = True
    # elif 0.12 <= -grind_profit_rate:
    #   if -grind_profit_rate < (-max_profit_rate - 0.055):
    #     is_trailing_exit = True
    # is_trailing_exit = -grind_profit_rate > 0.04
    stake_fmt = ".8f" if self.config["stake_currency"] in ("BTC", "ETH", "BNB", "SOL") else ".3f"
    if is_normal_exit or is_trailing_exit:
      exit_amount = grind_total_amount * exit_rate / trade.leverage
      if ((current_stake_amount / trade.leverage) - exit_amount) < (min_stake * 1.55):
        exit_amount = (trade.amount * exit_rate / trade.leverage) - (min_stake * 1.55)
      ft_exit_amount = exit_amount * trade.leverage * (trade.stake_amount / trade.amount) / exit_rate
      if exit_amount > min_stake and ft_exit_amount > min_stake:
        self.dp.send_msg(
          self.notification_msg(
            "grinding-exit",
            tag=name,
            pair=trade.pair,
            rate=exit_rate,
            stake_amount=exit_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=self.config["stake_currency"],
            grind_profit_stake=grind_profit_stake,
            grind_profit_pct=profit,
            coin_amount=grind_total_amount,
          )
        )
        log.info(
          f"Grinding exit ({name}) [{current_time}] [{trade.pair}] | Rate: {exit_rate} | Stake amount: {exit_amount:{stake_fmt}} | Coin amount: {grind_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(profit * 100.0):.2f}% ({grind_profit_stake:{stake_fmt}} {self.config['stake_currency']})"
        )
        order_tag = tag
        for grind_entry in grind_open_orders:
          order_tag += " " + str(grind_entry.id)
        return -ft_exit_amount, order_tag

    return None, None

  # Short Grinding Adjust Trade Position v3
  # ---------------------------------------------------------------------------------------------
  def short_grind_adjust_trade_position_v3(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ):
    dp = self.dp
    send_msg = self.dp.send_msg
    notification_msg = self.notification_msg
    config = self.config
    stake_currency = config["stake_currency"]
    is_futures_mode = self.is_futures_mode
    scale_stakes_for_min_stake = self.scale_stakes_for_min_stake
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_stake_amount = trade.stake_amount
    trade_leverage = trade.leverage
    trade_fee_open = trade.fee_open
    trade_fee_close = trade.fee_close

    is_backtest = self.is_backtest_mode()
    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)
    if len(df) < 2:
      return None
    last_candle = df.iloc[-1]
    previous_candle = df.iloc[-2]

    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_exits = trade.nr_of_successful_exits

    if dp.runmode.value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = config["exit_pricing"]["price_side"]
        if trade.is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    current_stake_amount = trade_amount * exit_rate
    slice_amount = filled_entries[0].safe_filled * filled_entries[0].safe_price
    slice_profit = (exit_rate - filled_orders[-1].safe_price) / filled_orders[-1].safe_price
    slice_profit_entry = (exit_rate - filled_entries[-1].safe_price) / filled_entries[-1].safe_price
    slice_profit_exit = (
      ((exit_rate - filled_exits[-1].safe_price) / filled_exits[-1].safe_price) if count_of_exits > 0 else 0.0
    )

    is_rebuy_mode = all(c in self.short_rebuy_mode_tags for c in enter_tags) or (
      any(c in self.short_rebuy_mode_tags for c in enter_tags)
      and all(c in (self.short_rebuy_mode_tags + self.short_grind_mode_tags) for c in enter_tags)
    )
    # Rebuy mode, the first entry is lower than normal slot stake
    if is_rebuy_mode:
      slice_amount /= self.system_v3_rebuy_mode_stake_multiplier

    is_system_v3, is_system_v3_1, is_system_v3_2 = self.get_system_version_flags(trade)

    has_order_tags = hasattr(filled_orders[0], "ft_order_tag")

    fee_open_rate = trade_fee_open if self.custom_fee_open_rate is None else self.custom_fee_open_rate
    fee_close_rate = trade_fee_close if self.custom_fee_close_rate is None else self.custom_fee_close_rate
    fee_rate = fee_open_rate + fee_close_rate
    stake_scale_leverage = trade_leverage if is_futures_mode else 1.0
    grind_entry_retry_time = current_time - timedelta(minutes=5)

    grind_1_max_sub_grinds = 0
    grind_1_stakes = scale_stakes_for_min_stake(
      self.system_v3_grind_1_stakes_futures if is_futures_mode else self.system_v3_grind_1_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    grind_1_sub_thresholds = (
      self.system_v3_grind_1_thresholds_futures if is_futures_mode else self.system_v3_grind_1_thresholds_spot
    )
    grind_1_max_sub_grinds = len(grind_1_stakes)
    grind_1_derisk_grinds = (
      self.system_v3_grind_1_derisk_futures if is_futures_mode else self.system_v3_grind_1_derisk_spot
    )
    grind_1_profit_threshold = (
      self.system_v3_grind_1_profit_threshold_futures
      if is_futures_mode
      else self.system_v3_grind_1_profit_threshold_spot
    )

    grind_2_max_sub_grinds = 0
    grind_2_stakes = scale_stakes_for_min_stake(
      self.system_v3_grind_2_stakes_futures if is_futures_mode else self.system_v3_grind_2_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_2_sub_thresholds = (
      self.system_v3_grind_2_thresholds_futures if is_futures_mode else self.system_v3_grind_2_thresholds_spot
    )
    grind_2_max_sub_grinds = len(grind_2_stakes)
    grind_2_derisk_grinds = (
      self.system_v3_grind_2_derisk_futures if is_futures_mode else self.system_v3_grind_2_derisk_spot
    )
    grind_2_profit_threshold = (
      self.system_v3_grind_2_profit_threshold_futures
      if is_futures_mode
      else self.system_v3_grind_2_profit_threshold_spot
    )

    grind_3_max_sub_grinds = 0
    grind_3_stakes = scale_stakes_for_min_stake(
      self.system_v3_grind_3_stakes_futures if is_futures_mode else self.system_v3_grind_3_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_3_sub_thresholds = (
      self.system_v3_grind_3_thresholds_futures if is_futures_mode else self.system_v3_grind_3_thresholds_spot
    )
    grind_3_max_sub_grinds = len(grind_3_stakes)
    grind_3_derisk_grinds = (
      self.system_v3_grind_3_derisk_futures if is_futures_mode else self.system_v3_grind_3_derisk_spot
    )
    grind_3_profit_threshold = (
      self.system_v3_grind_3_profit_threshold_futures
      if is_futures_mode
      else self.system_v3_grind_3_profit_threshold_spot
    )

    grind_4_max_sub_grinds = 0
    grind_4_stakes = scale_stakes_for_min_stake(
      self.system_v3_grind_4_stakes_futures if is_futures_mode else self.system_v3_grind_4_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_4_sub_thresholds = (
      self.system_v3_grind_4_thresholds_futures if is_futures_mode else self.system_v3_grind_4_thresholds_spot
    )
    grind_4_max_sub_grinds = len(grind_4_stakes)
    grind_4_derisk_grinds = (
      self.system_v3_grind_4_derisk_futures if is_futures_mode else self.system_v3_grind_4_derisk_spot
    )
    grind_4_profit_threshold = (
      self.system_v3_grind_4_profit_threshold_futures
      if is_futures_mode
      else self.system_v3_grind_4_profit_threshold_spot
    )

    grind_5_max_sub_grinds = 0
    grind_5_stakes = scale_stakes_for_min_stake(
      self.system_v3_grind_5_stakes_futures if is_futures_mode else self.system_v3_grind_5_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_5_sub_thresholds = (
      self.system_v3_grind_5_thresholds_futures if is_futures_mode else self.system_v3_grind_5_thresholds_spot
    )
    grind_5_max_sub_grinds = len(grind_5_stakes)
    grind_5_derisk_grinds = (
      self.system_v3_grind_5_derisk_futures if is_futures_mode else self.system_v3_grind_5_derisk_spot
    )
    grind_5_profit_threshold = (
      self.system_v3_grind_5_profit_threshold_futures
      if is_futures_mode
      else self.system_v3_grind_5_profit_threshold_spot
    )

    rebuy_stakes = self.system_v3_1_rebuy_stakes_futures if is_futures_mode else self.system_v3_1_rebuy_stakes_spot
    rebuy_max_sub_grinds = len(rebuy_stakes)
    rebuy_sub_thresholds = (
      self.system_v3_1_rebuy_thresholds_futures if is_futures_mode else self.system_v3_1_rebuy_thresholds_spot
    )

    is_derisk_1 = False
    is_derisk_1_found = False  # derisk_level_1 de-risk exit
    derisk_1_order = None
    is_derisk_2 = False
    is_derisk_2_found = False  # derisk_level_2 de-risk exit
    derisk_2_order = None
    is_derisk_3 = False
    is_derisk_3_found = False  # derisk_level_3 de-risk exit
    derisk_3_order = None
    grind_1_sub_grind_count = 0
    grind_1_total_amount = 0.0
    grind_1_total_cost = 0.0
    grind_1_current_open_rate = 0.0
    grind_1_current_grind_stake = 0.0
    grind_1_current_grind_profit_stake = 0.0
    grind_1_current_grind_profit_rate = 0.0
    grind_1_is_exit_found = False
    grind_1_found = False
    grind_1_buy_orders = []
    grind_1_orders = []
    grind_1_distance_ratio = 0.0
    grind_1_exit_order = None
    grind_1_exit_distance_ratio = 0.0
    grind_2_sub_grind_count = 0
    grind_2_total_amount = 0.0
    grind_2_total_cost = 0.0
    grind_2_current_open_rate = 0.0
    grind_2_current_grind_stake = 0.0
    grind_2_current_grind_profit_stake = 0.0
    grind_2_current_grind_profit_rate = 0.0
    grind_2_is_exit_found = False
    grind_2_found = False
    grind_2_buy_orders = []
    grind_2_orders = []
    grind_2_distance_ratio = 0.0
    grind_2_exit_order = None
    grind_2_exit_distance_ratio = 0.0
    grind_3_sub_grind_count = 0
    grind_3_total_amount = 0.0
    grind_3_total_cost = 0.0
    grind_3_current_open_rate = 0.0
    grind_3_current_grind_stake = 0.0
    grind_3_current_grind_profit_stake = 0.0
    grind_3_current_grind_profit_rate = 0.0
    grind_3_is_exit_found = False
    grind_3_found = False
    grind_3_buy_orders = []
    grind_3_orders = []
    grind_3_distance_ratio = 0.0
    grind_3_exit_order = None
    grind_3_exit_distance_ratio = 0.0
    grind_4_sub_grind_count = 0
    grind_4_total_amount = 0.0
    grind_4_total_cost = 0.0
    grind_4_current_open_rate = 0.0
    grind_4_current_grind_stake = 0.0
    grind_4_current_grind_profit_stake = 0.0
    grind_4_current_grind_profit_rate = 0.0
    grind_4_is_exit_found = False
    grind_4_found = False
    grind_4_buy_orders = []
    grind_4_orders = []
    grind_4_distance_ratio = 0.0
    grind_4_exit_order = None
    grind_4_exit_distance_ratio = 0.0
    grind_5_sub_grind_count = 0
    grind_5_total_amount = 0.0
    grind_5_total_cost = 0.0
    grind_5_current_open_rate = 0.0
    grind_5_current_grind_stake = 0.0
    grind_5_current_grind_profit_stake = 0.0
    grind_5_current_grind_profit_rate = 0.0
    grind_5_is_exit_found = False
    grind_5_found = False
    grind_5_buy_orders = []
    grind_5_orders = []
    grind_5_distance_ratio = 0.0
    grind_5_exit_order = None
    grind_5_exit_distance_ratio = 0.0
    rebuy_sub_grind_count = 0
    rebuy_total_amount = 0.0
    rebuy_total_cost = 0.0
    rebuy_current_open_rate = 0.0
    rebuy_current_grind_stake = 0.0
    rebuy_current_grind_stake_profit = 0.0
    rebuy_is_exit_found = False
    rebuy_found = False
    rebuy_buy_orders = []
    rebuy_orders = []
    rebuy_distance_ratio = 0.0
    rebuy_exit_order = None
    rebuy_exit_distance_ratio = 0.0
    for order in reversed(filled_orders):
      if (order.ft_order_side == "sell") and (order is not filled_orders[0]):
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag
        if not grind_1_is_exit_found and order_tag == "grind_1_entry":
          grind_1_sub_grind_count += 1
          grind_1_total_amount += order.safe_filled
          grind_1_total_cost += order.safe_filled * order.safe_price
          grind_1_buy_orders.append(order.id)
          grind_1_orders.append(order)
          if not grind_1_found:
            grind_1_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_1_found = True
        elif not grind_2_is_exit_found and order_tag == "grind_2_entry":
          grind_2_sub_grind_count += 1
          grind_2_total_amount += order.safe_filled
          grind_2_total_cost += order.safe_filled * order.safe_price
          grind_2_buy_orders.append(order.id)
          grind_2_orders.append(order)
          if not grind_2_found:
            grind_2_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_2_found = True
        elif not grind_3_is_exit_found and order_tag == "grind_3_entry":
          grind_3_sub_grind_count += 1
          grind_3_total_amount += order.safe_filled
          grind_3_total_cost += order.safe_filled * order.safe_price
          grind_3_buy_orders.append(order.id)
          grind_3_orders.append(order)
          if not grind_3_found:
            grind_3_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_3_found = True
        elif not grind_4_is_exit_found and order_tag == "grind_4_entry":
          grind_4_sub_grind_count += 1
          grind_4_total_amount += order.safe_filled
          grind_4_total_cost += order.safe_filled * order.safe_price
          grind_4_buy_orders.append(order.id)
          grind_4_orders.append(order)
          if not grind_4_found:
            grind_4_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_4_found = True
        elif not grind_5_is_exit_found and order_tag == "grind_5_entry":
          grind_5_sub_grind_count += 1
          grind_5_total_amount += order.safe_filled
          grind_5_total_cost += order.safe_filled * order.safe_price
          grind_5_buy_orders.append(order.id)
          grind_5_orders.append(order)
          if not grind_5_found:
            grind_5_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_5_found = True
        elif not rebuy_is_exit_found and order_tag == "rebuy_entry":
          rebuy_sub_grind_count += 1
          rebuy_total_amount += order.safe_filled
          rebuy_total_cost += order.safe_filled * order.safe_price
          rebuy_buy_orders.append(order.id)
          rebuy_orders.append(order)
          if not rebuy_found:
            rebuy_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            rebuy_found = True
      elif order.ft_order_side == "buy":
        if order is filled_exits[-1] and (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
          # break
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag.partition(" ")[0]
        if order_tag == "derisk_level_1":
          if not is_derisk_1_found:
            is_derisk_1_found = True
            is_derisk_1 = True
            derisk_1_order = order
        elif order_tag == "derisk_level_2":
          if not is_derisk_2_found:
            is_derisk_2_found = True
            is_derisk_2 = True
            derisk_2_order = order
        elif order_tag == "derisk_level_3":
          if not is_derisk_3_found:
            is_derisk_3_found = True
            is_derisk_3 = True
            derisk_3_order = order
        elif not grind_1_is_exit_found and order_tag in ["grind_1_exit", "grind_1_derisk"]:
          grind_1_is_exit_found = True
          grind_1_exit_order = order
        elif not grind_2_is_exit_found and order_tag in ["grind_2_exit", "grind_2_derisk"]:
          grind_2_is_exit_found = True
          grind_2_exit_order = order
        elif not grind_3_is_exit_found and order_tag in ["grind_3_exit", "grind_3_derisk"]:
          grind_3_is_exit_found = True
          grind_3_exit_order = order
        elif not grind_4_is_exit_found and order_tag in ["grind_4_exit", "grind_4_derisk"]:
          grind_4_is_exit_found = True
          grind_4_exit_order = order
        elif not grind_5_is_exit_found and order_tag in ["grind_5_exit", "grind_5_derisk"]:
          grind_5_is_exit_found = True
          grind_5_exit_order = order
        elif not rebuy_is_exit_found and order_tag in ["rebuy_exit", "rebuy_derisk"]:
          rebuy_is_exit_found = True
          rebuy_exit_order = order
        elif order_tag == "derisk_global":
          if not grind_1_is_exit_found:
            grind_1_is_exit_found = True
            grind_1_exit_order = order
          if not grind_2_is_exit_found:
            grind_2_is_exit_found = True
            grind_2_exit_order = order
          if not grind_3_is_exit_found:
            grind_3_is_exit_found = True
            grind_3_exit_order = order
          if not grind_4_is_exit_found:
            grind_4_is_exit_found = True
            grind_4_exit_order = order
          if not grind_5_is_exit_found:
            grind_5_is_exit_found = True
            grind_5_exit_order = order
          if not rebuy_is_exit_found:
            rebuy_is_exit_found = True
            rebuy_exit_order = order

    if grind_1_sub_grind_count > 0:
      grind_1_current_open_rate = grind_1_total_cost / grind_1_total_amount
      grind_1_current_grind_stake = grind_1_total_amount * exit_rate * (1 - trade_fee_close)
      grind_1_current_grind_profit_stake = grind_1_total_cost - grind_1_current_grind_stake
      grind_1_current_grind_profit_rate = (exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
    if grind_2_sub_grind_count > 0:
      grind_2_current_open_rate = grind_2_total_cost / grind_2_total_amount
      grind_2_current_grind_stake = grind_2_total_amount * exit_rate * (1 - trade_fee_close)
      grind_2_current_grind_profit_stake = grind_2_total_cost - grind_2_current_grind_stake
      grind_2_current_grind_profit_rate = (exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
    if grind_3_sub_grind_count > 0:
      grind_3_current_open_rate = grind_3_total_cost / grind_3_total_amount
      grind_3_current_grind_stake = grind_3_total_amount * exit_rate * (1 - trade_fee_close)
      grind_3_current_grind_profit_stake = grind_3_total_cost - grind_3_current_grind_stake
      grind_3_current_grind_profit_rate = (exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
    if grind_4_sub_grind_count > 0:
      grind_4_current_open_rate = grind_4_total_cost / grind_4_total_amount
      grind_4_current_grind_stake = grind_4_total_amount * exit_rate * (1 - trade_fee_close)
      grind_4_current_grind_profit_stake = grind_4_total_cost - grind_4_current_grind_stake
      grind_4_current_grind_profit_rate = (exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
    if grind_5_sub_grind_count > 0:
      grind_5_current_open_rate = grind_5_total_cost / grind_5_total_amount
      grind_5_current_grind_stake = grind_5_total_amount * exit_rate * (1 - trade_fee_close)
      grind_5_current_grind_profit_stake = grind_5_total_cost - grind_5_current_grind_stake
      grind_5_current_grind_profit_rate = (exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
    if rebuy_sub_grind_count > 0:
      rebuy_current_open_rate = rebuy_total_cost / rebuy_total_amount
      rebuy_current_grind_stake = rebuy_total_amount * exit_rate * (1 - trade_fee_close)
      rebuy_current_grind_stake_profit = rebuy_total_cost - rebuy_current_grind_stake

    if grind_1_is_exit_found:
      grind_1_exit_distance_ratio = (exit_rate - grind_1_exit_order.safe_price) / grind_1_exit_order.safe_price
    if grind_2_is_exit_found:
      grind_2_exit_distance_ratio = (exit_rate - grind_2_exit_order.safe_price) / grind_2_exit_order.safe_price
    if grind_3_is_exit_found:
      grind_3_exit_distance_ratio = (exit_rate - grind_3_exit_order.safe_price) / grind_3_exit_order.safe_price
    if grind_4_is_exit_found:
      grind_4_exit_distance_ratio = (exit_rate - grind_4_exit_order.safe_price) / grind_4_exit_order.safe_price
    if grind_5_is_exit_found:
      grind_5_exit_distance_ratio = (exit_rate - grind_5_exit_order.safe_price) / grind_5_exit_order.safe_price
    if rebuy_is_exit_found:
      rebuy_exit_distance_ratio = (exit_rate - rebuy_exit_order.safe_price) / rebuy_exit_order.safe_price

    # all buybacks & grinds
    current_open_grind_stake_profit = (
      grind_1_current_grind_profit_stake
      + grind_2_current_grind_profit_stake
      + grind_3_current_grind_profit_stake
      + grind_4_current_grind_profit_stake
      + grind_5_current_grind_profit_stake
      + rebuy_current_grind_stake_profit
    )
    num_open_grinds_and_buybacks = (
      grind_1_sub_grind_count
      + grind_2_sub_grind_count
      + grind_3_sub_grind_count
      + grind_4_sub_grind_count
      + grind_5_sub_grind_count
      + rebuy_sub_grind_count
    )

    # not reached the max allowed stake for all grinds
    is_not_trade_max_stake_v3 = current_stake_amount < (slice_amount * self.system_v3_max_stake)
    is_not_trade_max_stake_v3_1 = current_stake_amount < (slice_amount * self.system_v3_1_max_stake)

    grind_1_cluster_max_profit_stake = trade.get_custom_data(key="grind_1_cluster_max_profit_stake") or 0.0
    grind_1_cluster_max_profit_rate = trade.get_custom_data(key="grind_1_cluster_max_profit_rate") or 0.0
    if grind_1_current_grind_profit_stake > grind_1_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_1_cluster_max_profit_stake", value=grind_1_current_grind_profit_stake)
    if grind_1_current_grind_profit_rate < grind_1_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_1_cluster_max_profit_rate", value=grind_1_current_grind_profit_rate)

    grind_2_cluster_max_profit_stake = trade.get_custom_data(key="grind_2_cluster_max_profit_stake") or 0.0
    grind_2_cluster_max_profit_rate = trade.get_custom_data(key="grind_2_cluster_max_profit_rate") or 0.0
    if grind_2_current_grind_profit_stake > grind_2_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_2_cluster_max_profit_stake", value=grind_2_current_grind_profit_stake)
    if grind_2_current_grind_profit_rate < grind_2_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_2_cluster_max_profit_rate", value=grind_2_current_grind_profit_rate)

    grind_3_cluster_max_profit_stake = trade.get_custom_data(key="grind_3_cluster_max_profit_stake") or 0.0
    grind_3_cluster_max_profit_rate = trade.get_custom_data(key="grind_3_cluster_max_profit_rate") or 0.0
    if grind_3_current_grind_profit_stake > grind_3_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_3_cluster_max_profit_stake", value=grind_3_current_grind_profit_stake)
    if grind_3_current_grind_profit_rate < grind_3_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_3_cluster_max_profit_rate", value=grind_3_current_grind_profit_rate)

    grind_4_cluster_max_profit_stake = trade.get_custom_data(key="grind_4_cluster_max_profit_stake") or 0.0
    grind_4_cluster_max_profit_rate = trade.get_custom_data(key="grind_4_cluster_max_profit_rate") or 0.0
    if grind_4_current_grind_profit_stake > grind_4_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_4_cluster_max_profit_stake", value=grind_4_current_grind_profit_stake)
    if grind_4_current_grind_profit_rate < grind_4_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_4_cluster_max_profit_rate", value=grind_4_current_grind_profit_rate)

    grind_5_cluster_max_profit_stake = trade.get_custom_data(key="grind_5_cluster_max_profit_stake") or 0.0
    grind_5_cluster_max_profit_rate = trade.get_custom_data(key="grind_5_cluster_max_profit_rate") or 0.0
    if grind_5_current_grind_profit_stake > grind_5_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_5_cluster_max_profit_stake", value=grind_5_current_grind_profit_stake)
    if grind_5_current_grind_profit_rate < grind_5_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_5_cluster_max_profit_rate", value=grind_5_current_grind_profit_rate)

    is_short_extra_checks_entry = (
      grind_entry_retry_time > filled_entries[-1].order_filled_utc
      # and ((current_time - timedelta(hours=6) > filled_orders[-1].order_filled_utc) or (slice_profit > 0.02))
      and (
        (current_time - timedelta(hours=6) > filled_orders[-1].order_filled_utc)
        or (slice_profit > 0.06)
        or (is_derisk_3)
      )
      # and (
      #   (current_stake_amount < (filled_entries[0].cost * 0.50))
      #   or (current_time - timedelta(hours=6) > filled_orders[-1].order_filled_utc)
      #   or (slice_profit > 0.06)
      # )
    )
    # is_short_extra_checks_entry = True
    is_short_grind_entry = self.short_grind_entry_v3(
      last_candle, previous_candle, slice_profit, slice_profit_entry, True
    )
    is_short_rebuy_entry = self.short_rebuy_entry_v3(last_candle, previous_candle, slice_profit, True)
    stake_fmt = ".8f" if self.config["stake_currency"] in ("BTC", "ETH", "BNB", "SOL") else ".3f"
    # De-risk level 1

    if (
      self.derisk_enable
      and (
        (is_system_v3 and self.system_v3_derisk_level_1_enable)
        or (is_system_v3_2 and self.system_v3_2_derisk_level_1_enable)
      )
      and not is_derisk_1_found
      and not is_rebuy_mode
      and (
        profit_stake
        < (
          slice_amount
          * (
            (self.system_v3_derisk_level_1_futures[1] if is_futures_mode else self.system_v3_derisk_level_1_spot[1])
            if is_system_v3
            else (
              self.system_v3_2_derisk_level_1_futures[1]
              if is_futures_mode
              else self.system_v3_2_derisk_level_1_spot[1]
            )
          )
        )
        / trade_leverage
      )
    ):
      sell_amount = (
        (
          filled_entries[0].safe_filled
          * (
            (
              self.system_v3_derisk_level_1_stake_futures
              if is_futures_mode
              else self.system_v3_derisk_level_1_stake_spot
            )
            if is_system_v3
            else (
              self.system_v3_2_derisk_level_1_stake_futures
              if is_futures_mode
              else self.system_v3_2_derisk_level_1_stake_spot
            )
          )
        )
        * exit_rate
        / trade_leverage
      )
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="Level 1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk Level 1 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_1"

    # De-risk level 2

    if (
      self.derisk_enable
      and (
        (is_system_v3 and self.system_v3_derisk_level_2_enable)
        or (is_system_v3_2 and self.system_v3_2_derisk_level_2_enable)
      )
      and not is_derisk_2_found
      and not is_rebuy_mode
      and (
        profit_stake
        < (
          slice_amount
          * (
            (self.system_v3_derisk_level_2_futures[1] if is_futures_mode else self.system_v3_derisk_level_2_spot[1])
            if is_system_v3
            else (
              self.system_v3_2_derisk_level_2_futures[1]
              if is_futures_mode
              else self.system_v3_2_derisk_level_2_spot[1]
            )
          )
        )
        / trade_leverage
      )
    ):
      sell_amount = (
        (
          filled_entries[0].safe_filled
          * (
            (
              self.system_v3_derisk_level_2_stake_futures
              if is_futures_mode
              else self.system_v3_derisk_level_2_stake_spot
            )
            if is_system_v3
            else (
              self.system_v3_2_derisk_level_2_stake_futures
              if is_futures_mode
              else self.system_v3_2_derisk_level_2_stake_spot
            )
          )
        )
        * exit_rate
        / trade_leverage
      )
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="Level 2",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk Level 2 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_2"

    # De-risk level 3

    if (
      self.derisk_enable
      and (
        (is_system_v3 and self.system_v3_derisk_level_3_enable)
        or (is_system_v3_2 and self.system_v3_2_derisk_level_3_enable)
      )
      and not is_derisk_3_found
      and not is_rebuy_mode
      and (
        profit_stake
        < (
          slice_amount
          * (
            (self.system_v3_derisk_level_3_futures[1] if is_futures_mode else self.system_v3_derisk_level_3_spot[1])
            if is_system_v3
            else (
              self.system_v3_2_derisk_level_3_futures[1]
              if is_futures_mode
              else self.system_v3_2_derisk_level_3_spot[1]
            )
          )
        )
        / trade_leverage
      )
    ):
      sell_amount = (
        (
          filled_entries[0].safe_filled
          * (
            (
              self.system_v3_derisk_level_3_stake_futures
              if is_futures_mode
              else self.system_v3_derisk_level_3_stake_spot
            )
            if is_system_v3
            else (
              self.system_v3_2_derisk_level_3_stake_futures
              if is_futures_mode
              else self.system_v3_2_derisk_level_3_stake_spot
            )
          )
        )
        * exit_rate
        / trade_leverage
      )
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="Level 3",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk Level 3 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_3"

    # Grinding 1

    if (
      (self.system_v3_grind_1_enable)
      # and is_derisk_1_found
      and is_short_grind_entry
      and is_short_extra_checks_entry
      and (grind_1_sub_grind_count < grind_1_max_sub_grinds)
      and (grind_1_sub_grind_count == 0 or (-grind_1_distance_ratio < grind_1_sub_thresholds[grind_1_sub_grind_count]))
      and is_not_trade_max_stake_v3
    ):
      buy_amount = slice_amount * grind_1_stakes[grind_1_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_1_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_1_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
      )
      order_tag = "grind_1_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_1_sub_grind_count > 0:
      ft_exit_amount, tag = self.short_grind_exit_v3(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_1_exit",
        "grind_1_exit",
        fee_open_rate,
        fee_close_rate,
        grind_1_cluster_max_profit_stake,
        grind_1_cluster_max_profit_rate,
        grind_1_current_grind_profit_stake,
        grind_1_current_grind_profit_rate,
        grind_1_total_amount,
        grind_1_profit_threshold,
        grind_1_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v3_grind_1_use_derisk
      and (grind_1_sub_grind_count > 0)
      and ((-(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate) < grind_1_derisk_grinds)
    ):
      # if (
      #   self.system_v3_grind_1_use_derisk
      #   and (grind_1_sub_grind_count > 0)
      #   and (grind_1_current_grind_profit_stake < (slice_amount * grind_1_derisk_grinds))
      #   and (grind_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_1_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate)
            if grind_1_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_1_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_1_current_grind_profit_stake,
            grind_profit_pct=grind_profit,
            coin_amount=grind_1_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_1_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_1_derisk"
        for grind_entry_id in grind_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 2

    if (
      (self.system_v3_grind_2_enable)
      # and is_derisk_1_found
      and is_short_grind_entry
      and is_short_extra_checks_entry
      and (grind_2_sub_grind_count < grind_2_max_sub_grinds)
      and (grind_2_sub_grind_count == 0 or (-grind_2_distance_ratio < grind_2_sub_thresholds[grind_2_sub_grind_count]))
      and is_not_trade_max_stake_v3
    ):
      buy_amount = slice_amount * grind_2_stakes[grind_2_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_2_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_2_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
      )
      order_tag = "grind_2_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_2_sub_grind_count > 0:
      ft_exit_amount, tag = self.short_grind_exit_v3(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_2_exit",
        "grind_2_exit",
        fee_open_rate,
        fee_close_rate,
        grind_2_cluster_max_profit_stake,
        grind_2_cluster_max_profit_rate,
        grind_2_current_grind_profit_stake,
        grind_2_current_grind_profit_rate,
        grind_2_total_amount,
        grind_2_profit_threshold,
        grind_2_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v3_grind_2_use_derisk
      and (grind_2_sub_grind_count > 0)
      and ((-(exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate) < grind_2_derisk_grinds)
    ):
      # if (
      #   self.system_v3_grind_2_use_derisk
      #   and (grind_2_sub_grind_count > 0)
      #   and (grind_2_current_grind_profit_stake < (slice_amount * grind_2_derisk_grinds))
      #   and (grind_2_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_2_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_2_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate)
            if grind_2_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_2_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_2_current_grind_profit_stake,
            grind_profit_pct=grind_profit,
            coin_amount=grind_2_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_2_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_2_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_2_derisk"
        for grind_entry_id in grind_2_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 3

    if (
      (self.system_v3_grind_3_enable)
      # and is_derisk_1_found
      and is_short_grind_entry
      and is_short_extra_checks_entry
      and (grind_3_sub_grind_count < grind_3_max_sub_grinds)
      and (grind_3_sub_grind_count == 0 or (-grind_3_distance_ratio < grind_3_sub_thresholds[grind_3_sub_grind_count]))
      and is_not_trade_max_stake_v3
    ):
      buy_amount = slice_amount * grind_3_stakes[grind_3_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_3_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_3_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
      )
      order_tag = "grind_3_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_3_sub_grind_count > 0:
      ft_exit_amount, tag = self.short_grind_exit_v3(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_3_exit",
        "grind_3_exit",
        fee_open_rate,
        fee_close_rate,
        grind_3_cluster_max_profit_stake,
        grind_3_cluster_max_profit_rate,
        grind_3_current_grind_profit_stake,
        grind_3_current_grind_profit_rate,
        grind_3_total_amount,
        grind_3_profit_threshold,
        grind_3_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v3_grind_3_use_derisk
      and (grind_3_sub_grind_count > 0)
      and ((-(exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate) < grind_3_derisk_grinds)
    ):
      # if (
      #   self.system_v3_grind_3_use_derisk
      #   and (grind_3_sub_grind_count > 0)
      #   and (grind_3_current_grind_profit_stake < (slice_amount * grind_3_derisk_grinds))
      #   and (grind_3_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_3_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_3_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate)
            if grind_3_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_3_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_3_current_grind_profit_stake,
            grind_profit_pct=grind_profit,
            coin_amount=grind_3_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_3_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_3_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_3_derisk"
        for grind_entry_id in grind_3_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 4

    if (
      (self.system_v3_grind_4_enable)
      # and is_derisk_1_found
      # and is_short_grind_entry
      and (
        is_short_grind_entry
        or (
          (slice_profit_entry > 0.04)
          and (last_candle["RSI_3"] < 95.0)
          and (last_candle["RSI_3_15m"] < 90.0)
          and (last_candle["RSI_14"] > 65.0)
          and (last_candle["close"] > (last_candle["EMA_20"] * 1.015))
        )
        or (
          (slice_profit_entry > 0.06)
          and (num_open_grinds_and_buybacks == 0)
          and (last_candle["RSI_14"] > 70.0)
          and (last_candle["close"] > (last_candle["EMA_20"] * 1.020))
        )
      )
      and is_short_extra_checks_entry
      and (grind_4_sub_grind_count < grind_4_max_sub_grinds)
      and (grind_4_sub_grind_count == 0 or (-grind_4_distance_ratio < grind_4_sub_thresholds[grind_4_sub_grind_count]))
      and is_not_trade_max_stake_v3
    ):
      buy_amount = slice_amount * grind_4_stakes[grind_4_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_4_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_4_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
      )
      order_tag = "grind_4_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_4_sub_grind_count > 0:
      ft_exit_amount, tag = self.short_grind_exit_v3(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_4_exit",
        "grind_4_exit",
        fee_open_rate,
        fee_close_rate,
        grind_4_cluster_max_profit_stake,
        grind_4_cluster_max_profit_rate,
        grind_4_current_grind_profit_stake,
        grind_4_current_grind_profit_rate,
        grind_4_total_amount,
        grind_4_profit_threshold,
        grind_4_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v3_grind_4_use_derisk
      and (grind_4_sub_grind_count > 0)
      and ((-(exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate) < grind_4_derisk_grinds)
    ):
      # if (
      #   self.system_v3_grind_4_use_derisk
      #   and (grind_4_sub_grind_count > 0)
      #   and (grind_4_current_grind_profit_stake < (slice_amount * grind_4_derisk_grinds))
      #   and (grind_4_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_4_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_4_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate)
            if grind_4_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_4_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_4_current_grind_profit_stake,
            grind_profit_pct=grind_profit,
            coin_amount=grind_4_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_4_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_4_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_4_derisk"
        for grind_entry_id in grind_4_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 5

    if (
      (self.system_v3_grind_5_enable)
      # and is_derisk_1_found
      # and is_short_grind_entry
      and (
        is_short_grind_entry
        or (
          (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found)
          and (slice_profit_entry > 0.06)
          and (last_candle["RSI_3"] < 90.0)
          and (last_candle["RSI_3_15m"] < 80.0)
          and (last_candle["AROOND_14"] < 50.0)
        )
        or (
          (self.is_futures_mode)
          and (slice_profit_entry > 0.15)
          and (trade.liquidation_price is not None)
          and (
            (trade.is_short and current_rate > trade.liquidation_price * 0.80)
            or (not trade.is_short and current_rate < trade.liquidation_price * 1.20)
          )
        )
      )
      and is_short_extra_checks_entry
      and (grind_5_sub_grind_count < grind_5_max_sub_grinds)
      and (grind_5_sub_grind_count == 0 or (-grind_5_distance_ratio < grind_5_sub_thresholds[grind_5_sub_grind_count]))
      and is_not_trade_max_stake_v3
    ):
      buy_amount = slice_amount * grind_5_stakes[grind_5_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="grind_5_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Grinding entry (grind_5_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
      )
      order_tag = "grind_5_entry"
      if has_order_tags:
        return buy_amount, order_tag
      else:
        return buy_amount

    if grind_5_sub_grind_count > 0:
      ft_exit_amount, tag = self.short_grind_exit_v3(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_5_exit",
        "grind_5_exit",
        fee_open_rate,
        fee_close_rate,
        grind_5_cluster_max_profit_stake,
        grind_5_cluster_max_profit_rate,
        grind_5_current_grind_profit_stake,
        grind_5_current_grind_profit_rate,
        grind_5_total_amount,
        grind_5_profit_threshold,
        grind_5_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v3_grind_5_use_derisk
      and (grind_5_sub_grind_count > 0)
      and ((-(exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate) < grind_5_derisk_grinds)
    ):
      # if (
      #   self.system_v3_grind_5_use_derisk
      #   and (grind_5_sub_grind_count > 0)
      #   and (grind_5_current_grind_profit_stake < (slice_amount * grind_5_derisk_grinds))
      #   and (grind_5_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_5_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_5_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate)
            if grind_5_is_exit_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-derisk",
            tag="grind_5_derisk",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_5_current_grind_profit_stake,
            grind_profit_pct=grind_profit,
            coin_amount=grind_5_total_amount,
          )
        )
        log.info(
          f"Grinding de-risk (grind_5_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_5_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_5_derisk"
        for grind_entry_id in grind_5_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Rebuy

    if (
      is_system_v3_1
      and is_short_rebuy_entry
      and (
        (0 <= rebuy_sub_grind_count < rebuy_max_sub_grinds)
        and (slice_profit_entry < rebuy_sub_thresholds[rebuy_sub_grind_count])
      )
      and is_not_trade_max_stake_v3_1
    ):
      buy_amount = slice_amount * rebuy_stakes[rebuy_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None
      send_msg(
        notification_msg(
          "rebuy",
          tag="rebuy_entry",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
        )
      )
      log.info(
        f"Rebuy (rebuy_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
      )
      if has_order_tags:
        return buy_amount, "rebuy_entry"
      else:
        return buy_amount

    return None

  def short_grind_entry_v3(
    self,
    last_candle: Series,
    previous_candle: Series,
    slice_profit: float,
    slice_profit_entry: float,
    is_derisk: bool,
  ) -> float:
    if last_candle["protections_short_global"] != True:
      return False
    # g0 — signal entry
    if last_candle["enter_short"] == True:
      self._grind_entry_tag = "g0"
      return True
    last_close = last_candle["close"]
    last_open = last_candle["open"]
    last_close_max_12 = last_candle["close_max_12"]
    last_close_min_48 = last_candle["close_min_48"]
    last_low_min_24_1h = last_candle["low_min_24_1h"]
    last_high_max_12_4h = last_candle["high_max_12_4h"]
    last_high_max_24_4h = last_candle["high_max_24_4h"]
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_3_15m = last_candle["RSI_3_15m"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_rsi_3_4h = last_candle["RSI_3_4h"]
    last_rsi_3_1d = last_candle["RSI_3_1d"]
    last_rsi_14 = last_candle["RSI_14"]
    last_rsi_14_1h = last_candle["RSI_14_1h"]
    last_rsi_14_4h = last_candle["RSI_14_4h"]
    last_rsi_20 = last_candle["RSI_20"]
    last_sma_9 = last_candle["SMA_9"]
    last_sma_16 = last_candle["SMA_16"]
    last_sma_21 = last_candle["SMA_21"]
    last_sma_30 = last_candle["SMA_30"]
    last_ema_9 = last_candle["EMA_9"]
    last_ema_12 = last_candle["EMA_12"]
    last_ema_16 = last_candle["EMA_16"]
    last_ema_20 = last_candle["EMA_20"]
    last_ema_26 = last_candle["EMA_26"]
    last_ema_100 = last_candle["EMA_100"]
    last_ema_12_4h = last_candle["EMA_12_4h"]
    last_ema_50_4h = last_candle["EMA_50_4h"]
    last_ema_100_4h = last_candle["EMA_100_4h"]
    last_ema_200_4h = last_candle["EMA_200_4h"]
    last_roc_9_1h = last_candle["ROC_9_1h"]
    last_roc_9_4h = last_candle["ROC_9_4h"]
    last_roc_9_1d = last_candle["ROC_9_1d"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_stochrsi_k_1h = last_candle["STOCHRSIk_14_14_3_3_1h"]
    last_stochrsi_k_4h = last_candle["STOCHRSIk_14_14_3_3_4h"]
    last_stochrsi_k_1d = last_candle["STOCHRSIk_14_14_3_3_1d"]
    last_willr_14 = last_candle["WILLR_14"]
    last_willr_84_1h = last_candle["WILLR_84_1h"]
    last_bbu = last_candle["BBU_20_2.0"]
    last_bbb_1h = last_candle["BBB_20_2.0_1h"]
    last_cmf_20 = last_candle["CMF_20"]
    last_aroonu_14 = last_candle["AROONU_14"]
    last_aroonu_14_15m = last_candle["AROONU_14_15m"]
    last_aroonu_14_1d = last_candle["AROONU_14_1d"]
    last_aroonu_14_1h = last_candle["AROONU_14_1h"]
    last_aroonu_14_4h = last_candle["AROONU_14_4h"]
    last_stochrsi_k_15m = last_candle["STOCHRSIk_14_14_3_3_15m"]
    prev_rsi_20 = previous_candle["RSI_20"]
    prev_sma_9 = previous_candle["SMA_9"]
    prev_sma_21 = previous_candle["SMA_21"]
    prev_ema_12 = previous_candle["EMA_12"]
    prev_ema_26 = previous_candle["EMA_26"]

    # g1 — AROONU rally + EMA_16 rise (mirror long g1)
    if (
      (last_rsi_3 < 90.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_3_1h < 85.0)
      and (last_rsi_3_4h < 85.0)
      and (last_rsi_14 > 55.0)
      and (last_aroonu_14 > 75.0)
      and (last_aroonu_14_4h > 0.0)
      and (last_roc_9_1h > -20.0)
      and (last_close < (last_close_min_48 * 1.10))
      and (last_close > (last_high_max_24_4h * 0.40))
      and (last_close > (last_ema_16 * 1.025))
      and ((last_rsi_3_1h < 65.0) or (last_aroonu_14_1h > 0.0))
      and ((last_aroonu_14_1h > 0.0) or (last_aroonu_14_1d > 0.0))
      and ((last_aroonu_14_1d > 0.0) or (last_stochrsi_k_1h > 10.0))
    ):
      self._grind_entry_tag = "g1"
      return True
    # g2 — EMA_12 > EMA_26 divergence + BBU (mirror long g2)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 85.0)
      and (last_rsi_3_4h < 85.0)
      and (last_rsi_14 > 70.0)
      and (last_stochrsi_k > 70.0)
      and (last_ema_12 > last_ema_26)
      and ((last_ema_12 - last_ema_26) > (last_open * 0.020))
      and ((prev_ema_12 - prev_ema_26) > (last_open / 100.0))
      and (last_close > (last_bbu * 0.990))
    ):
      self._grind_entry_tag = "g2"
      return True
    # g3 — AROONU_15m rally + EMA_12 rise (mirror long g3)
    if (
      (last_rsi_3 < 90.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 90.0)
      and (last_rsi_3_4h < 85.0)
      and (last_rsi_14 > 65.0)
      and (last_aroonu_14_15m > 75.0)
      and (last_stochrsi_k_15m > 30.0)
      and (last_stochrsi_k_1h > 10.0)
      and (last_roc_9_1h < 15.0)
      and (last_roc_9_4h < 15.0)
      and (last_close < (last_close_min_48 * 1.15))
      and (last_close > (last_ema_12 * 1.020))
      and ((last_rsi_3_1h < 80.0) or (last_rsi_3_1d < 80.0))
      and ((last_rsi_3_1h < 80.0) or (last_stochrsi_k_1d > 30.0))
      and ((last_rsi_3_1h < 75.0) or (last_stochrsi_k_1h > 30.0))
      and ((last_rsi_3_4h < 70.0) or (last_stochrsi_k_4h > 40.0))
    ):
      self._grind_entry_tag = "g3"
      return True
    # g4 — multi-TF RSI + EMA_26 + BBU (mirror long g4)
    if (
      (last_rsi_3 < 90.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 90.0)
      and (last_rsi_3_4h < 90.0)
      and (last_rsi_3_1d < 90.0)
      and (last_rsi_14 > 65.0)
      and (last_aroonu_14 > 75.0)
      and (last_roc_9_1h < 20.0)
      and (last_roc_9_4h < 20.0)
      # and (last_close < (last_close_min_48 * 1.10))
      and (last_close > (last_ema_26 * 1.030))
      and (last_close > (last_bbu * 1.001))
    ):
      self._grind_entry_tag = "g4"
      return True
    # g5 — rally top + EMA_9/20 (mirror long g5)
    if (
      (last_rsi_3 < 90.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 85.0)
      and (last_rsi_3_4h < 85.0)
      and (last_rsi_14 > 65.0)
      and (last_aroonu_14 > 70.0)
      and (last_roc_9_4h < 20.0)
      and (last_close < (last_low_min_24_1h * 1.20))
      and (last_close > (last_high_max_12_4h * 0.50))
      and (last_close > (last_ema_9 * 1.025))
      and (last_close > (last_ema_20 * 1.030))
    ):
      self._grind_entry_tag = "g5"
      return True
    # g6 — RSI_20 rising + SMA_16 rise (mirror long g6)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3 > 60.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_14 < 65.0)
      and (last_roc_9_1h < 20.0)
      and (last_roc_9_4h < 20.0)
      and (last_aroonu_14 > 75.0)
      and (last_close > (last_high_max_12_4h * 0.40))
      and (last_rsi_20 > prev_rsi_20)
      and (last_close > (last_sma_16 * 1.040))
      and ((last_aroonu_14_1d > 0.0) or (last_roc_9_1d > -50.0))
    ):
      self._grind_entry_tag = "g6"
      return True
    # g7 — WILLR overbought + BBB wide (mirror long g7)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 80.0)
      and (last_rsi_3_1h < 80.0)
      and (last_rsi_3_4h < 80.0)
      and (last_willr_14 > -50.0)
      and (last_willr_84_1h > -30.0)
      and (last_stochrsi_k > 70.0)
      and (last_stochrsi_k_1h > 10.0)
      and (last_roc_9_1h < 10.0)
      and (last_roc_9_1h > -20.0)
      and (last_roc_9_4h < 10.0)
      and (last_close > (last_high_max_24_4h * 0.50))
      and (last_bbb_1h > 12.0)
      and (last_close_min_48 <= (last_close * 0.90))
    ):
      self._grind_entry_tag = "g7"
      return True
    # g8 — EMA_12/26 gap wide + high_max_24_1h (mirror long g8)
    if (
      (last_rsi_3 > 70.0)
      and (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 90.0)
      and (last_rsi_3_4h < 90.0)
      and (last_roc_9_1h < 10.0)
      and (last_roc_9_4h < 25.0)
      # and (last_close > (last_candle["high_max_24_1h"] * 0.70))
      and (last_ema_12 > last_ema_26)
      and ((last_ema_12 - last_ema_26) > (last_open * 0.030))
      and ((prev_ema_12 - prev_ema_26) > (last_open / 100.0))
    ):
      self._grind_entry_tag = "g8"
      return True
    # g9 — pullback fade (mirror long g9)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_3_1h < 80.0)
      and (last_rsi_3_4h < 80.0)
      and (last_stochrsi_k > 50.0)
      and (last_close > (last_close_min_48 * 1.10))
      and (last_close < (last_close_max_12 * 0.97))
    ):
      self._grind_entry_tag = "g9"
      return True
    # g10 — RSI_14 divergence vs 1h (mirror long g10)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 80.0)
      and (last_stochrsi_k > 80.0)
      and (last_rsi_14 > (last_rsi_14_1h + 45.0))
    ):
      self._grind_entry_tag = "g10"
      return True
    # g11 — multi-TF RSI + SMA_30 + BBU (mirror long g11)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 90.0)
      and (last_cmf_20 < 0.0)
      and (last_close > (last_sma_30 * 1.035))
      and (last_close > (last_bbu * 1.000))
    ):
      self._grind_entry_tag = "g11"
      return True
    # g12 — EMA_12/26 divergence + close_min_48 (mirror long g12)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 90.0)
      and (last_stochrsi_k > 70.0)
      and (last_close < (last_close_min_48 * 1.10))
      and (last_close > (last_high_max_12_4h * 0.40))
      and (last_ema_12 > last_ema_26)
      and ((last_ema_12 - last_ema_26) > (last_open * 0.025))
      and ((prev_ema_12 - prev_ema_26) > (last_open / 100.0))
    ):
      self._grind_entry_tag = "g12"
      return True
    # g13 — SMA_9 cross SMA_21 down + EMA_100 rise (mirror long g13)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_1h < 80.0)
      and (last_rsi_14_1h < 60.0)
      and (last_stochrsi_k_15m > 20.0)
      and (last_roc_9_1h < 15.0)
      and (last_roc_9_4h < 15.0)
      and (prev_sma_9 > prev_sma_21)
      and (last_sma_9 < last_sma_21)
      and (last_close > (last_ema_100 * 1.025))
      and ((last_rsi_3_4h < 70.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_4h < 60.0) or (last_roc_9_4h > -30.0))
    ):
      self._grind_entry_tag = "g13"
      return True
    # g14 — SMA_9 cross down + 4h downtrend (trend follower) (mirror long g14)
    if (
      (last_rsi_3 < 95.0)
      and (last_aroonu_14_15m > 50.0)
      and (last_stochrsi_k > 60.0)
      and (last_stochrsi_k_15m > 30.0)
      and (prev_sma_9 > prev_sma_21)
      and (last_sma_9 < last_sma_21)
      and (last_ema_12_4h < last_ema_200_4h)
      and (last_close < (last_close_min_48 * 1.10))
      and ((last_rsi_3_1h < 70.0) or (last_stochrsi_k_1h > 30.0))
      and ((last_rsi_3_1h < 60.0) or (last_aroonu_14_1h > 20.0))
      and ((last_rsi_3_1h < 45.0) or (last_stochrsi_k_1h > 30.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1d < 75.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_stochrsi_k_1h > 20.0) or (last_stochrsi_k_1d > 10.0))
    ):
      self._grind_entry_tag = "g14"
      return True
    # g15 — deep loss recovery (slice_profit > 0.16, positive = adverse move for a short) (mirror long g15)
    if (
      (slice_profit > 0.16)
      and (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_14 > 60.0)
      and (last_aroonu_14 > 75.0)
      and (last_aroonu_14_15m > 70.0)
      and (last_stochrsi_k > 70.0)
      and (last_stochrsi_k_15m > 70.0)
      and ((last_rsi_3_1h < 70.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_rsi_3_4h < 70.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1d < 70.0) or (last_stochrsi_k_1d > 20.0))
    ):
      self._grind_entry_tag = "g15"
      return True
    # g16 — EMA_12 rise + BBU (mirror long g16)
    if (
      (last_rsi_3 < 92.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_3_1h < 85.0)
      and (last_rsi_3_4h < 85.0)
      and (last_rsi_14 > 65.0)
      and (last_close > (last_ema_12 * 1.035))
      and (last_close > (last_bbu * 1.001))
    ):
      self._grind_entry_tag = "g16"
      return True
    # g17 — StochRSI + EMA_20 rise (mirror long g17)
    if (
      (last_rsi_3 < 85.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_3_1h < 85.0)
      and (last_rsi_3_4h < 85.0)
      and (last_rsi_14 > 70.0)
      and (last_stochrsi_k > 70.0)
      and (last_close > (last_ema_20 * 1.025))
      and ((last_aroonu_14_4h > 0.0) or (last_aroonu_14_1d > 0.0))
    ):
      self._grind_entry_tag = "g17"
      return True
    # g18 — moderate loss recovery (slice_profit > 0.10, positive = adverse move for a short) (mirror long g18)
    if (
      (slice_profit > 0.10)
      and (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_3_1h < 80.0)
      and (last_rsi_3_4h < 80.0)
      and (last_rsi_14 > 60.0)
      and (last_close > (last_ema_26 * 1.030))
      and (last_close > (last_bbu * 1.001))
    ):
      self._grind_entry_tag = "g18"
      return True
    # g19 — EMA_12/26 wide gap (slice_profit > 0.06, positive = adverse move for a short) (mirror long g19)
    if (
      (slice_profit > 0.06)
      and (last_rsi_3 > 70.0)
      and (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 90.0)
      and (last_ema_12 > last_ema_26)
      and ((last_ema_12 - last_ema_26) > (last_open * 0.035))
      and ((prev_ema_12 - prev_ema_26) > (last_open / 100.0))
    ):
      self._grind_entry_tag = "g19"
      return True
    # g20 — AROONU 4h downtrend bounce fade (mirror long g20)
    if (
      (last_rsi_3 < 90.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_3_1h < 80.0)
      and (last_rsi_14 > 58.0)
      and (last_rsi_14_4h < 50.0)
      and (last_aroonu_14 > 70.0)
      and (last_aroonu_14_4h < 50.0)
      and (last_roc_9_1d < 15.0)
      and (last_ema_50_4h < last_ema_100_4h)
      and (last_close > (last_close_min_48 * 1.05))
      and ((last_rsi_3_15m < 80.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1h < 70.0) or (last_roc_9_4h > -30.0) or (last_roc_9_1d > -30.0))
      and ((last_rsi_3_1h < 50.0) or (last_roc_9_1d > -60.0))
      and ((last_rsi_3_4h < 60.0) or (last_aroonu_14_4h > 10.0))
      and ((last_rsi_3_4h < 55.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_4h < 40.0) or (last_roc_9_4h > -40.0))
      and ((last_aroonu_14_4h > 0.0) or (last_stochrsi_k_1d > 20.0))
      and ((last_aroonu_14_4h > 0.0) or (last_aroonu_14_1d > 0.0))
      and ((last_stochrsi_k_4h > 10.0) or (last_roc_9_4h > -30.0))
    ):
      self._grind_entry_tag = "g20"
      return True
    # g21 — EMA_20 rise (slice_profit_entry > 0.02, positive = adverse move for a short) (mirror long g21)
    if (
      (slice_profit_entry > 0.02)
      and (last_rsi_3 < 90.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_14 > 65.0)
      and (last_aroonu_14_15m > 50.0)
      and (last_close > (last_ema_20 * 1.045))
    ):
      self._grind_entry_tag = "g21"
      return True
    # g22 — early breakdown rebuild: rejecting off the high BEFORE the 4h trend confirms (g14 needs
    #        EMA_12_4h < EMA_200_4h and fires too late for a deep-derisk rejection). Anti-fake-drop gating via
    #        multi-TF RSI weakness + rejection off the 4h high + not-extended. (mirror long g22)
    if (
      (last_rsi_3 < 70.0)
      and (last_rsi_3_15m < 70.0)
      and (last_rsi_14 < 55.0)
      and (last_rsi_14_1h < 55.0)
      and (last_roc_9_1h < 0.0)
      and (last_roc_9_4h < 10.0)
      # anti-capitulative: even at a formed top, a capitulative 4h overshoot reverses (dead-bounce).
      # cross-coin (SFP/CELR/DYDX/APE): cuts 17 severe at ~1% good cost within breakdown-starts.
      and (last_roc_9_4h > -25.0)
      # breakdown-started gate: only rebuild once the 4h top is IN (not still making new highs).
      # g22's job is the breakdown rebuild — NOT entering mid-pump (that's g1..g21). AROOND low =
      # a fresh 4h high was just made = still pumping; require it high = top formed = breakdown start.
      and (last_aroonu_14_4h > 50.0)
      # aggressive risk-free: g22 fires ONLY deep above the 4h 200-EMA (fresh breakdown zone). The
      # near/below-EMA overextended-pullback zone is where dead-cats live AND where g22's late-breakdown
      # adds sit — we sacrifice those wins on purpose, because g23 (extended-continuation, ~0.2% severe)
      # backstops the real breakdowns below. So g22 stays clean, g23 captures the continuation.
      and (last_close > last_ema_200_4h)
      and (last_close < (last_high_max_12_4h * 0.90))
      and (last_close < (last_ema_20 * 1.03))
      and (last_close > (last_ema_20 * 0.98))
      and ((last_rsi_3_1h < 70.0) or (last_stochrsi_k_1d > 20.0))
      and ((last_rsi_3_1h < 65.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_4h < 50.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1d < 90.0) or (last_aroonu_14_1d > 30.0))
      and ((last_rsi_3_1d < 90.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1d < 85.0) or (last_aroonu_14_1h > 30.0))
      and ((last_rsi_3_1d < 60.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_rsi_3_1d < 60.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1d < 55.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1d < 55.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_1d < 55.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_rsi_3_1d < 55.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 50.0) or (last_aroonu_14_15m > 0.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1d < 35.0) or (last_aroonu_14_1h > 30.0) or (last_aroonu_14_1d > 10.0))
      and ((last_aroonu_14_15m > 30.0) or (last_aroonu_14_1h > 0.0))
      and ((last_aroonu_14_15m > 20.0) or (last_stochrsi_k_15m > 20.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1h > 20.0) or (last_stochrsi_k_1h > 20.0) or (last_stochrsi_k_1d > 10.0))
      and ((last_aroonu_14_1h > 0.0) or (last_stochrsi_k_1d > 20.0))
      and ((last_stochrsi_k_1h > 50.0) or (last_roc_9_1d < 40.0))
      and ((last_roc_9_1d < 20.0) or (last_aroonu_14_4h > 0.0))
      and ((last_roc_9_1d < 20.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_roc_9_1d < 30.0) or (last_stochrsi_k_1h > 10.0))
    ):
      self._grind_entry_tag = "g22"
      return True
    # g23 — breakdown-continuation scalp: extended zone BELOW g22's EMA_20*0.98 cap. Only rides a CONFIRMED
    # continuation (price already declining past the rejection), so dead-bounces (which roll over before
    # reaching the extended zone) are structurally avoided. Complements g22: g22 = early breakdown-start,
    # g23 = confirmed continuation. (mirror long g23)
    if (
      (last_rsi_3 < 70.0)
      and (last_rsi_3_15m < 70.0)
      and (last_rsi_14 < 50.0)
      and (last_rsi_14_1h < 50.0)
      and (last_roc_9_1h < 0.0)
      and (last_roc_9_4h < 0.0)
      # anti-capitulative blow-off + anti-exhaustion bottom
      and (last_roc_9_4h > -25.0)
      and ((last_stochrsi_k > 3.0) or (last_rsi_14 > 20.0))
      and (last_close < (last_high_max_12_4h * 0.90))
      # extended zone: below g22's 0.98*EMA cap = continuation confirmed, not a rejection
      and (last_close <= (last_ema_20 * 0.98))
      and (last_close > (last_ema_20 * 0.88))
      and ((last_rsi_3_1h < 55.0) or (last_aroonu_14_4h > 20.0))
      and ((last_rsi_3_1h < 35.0) or (last_aroonu_14_15m > 40.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 35.0) or (last_stochrsi_k_15m > 40.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_4h < 60.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_rsi_3_4h < 50.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_1d < 85.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_rsi_3_1d < 70.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1d < 70.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_1d < 60.0) or (last_aroonu_14_15m > 20.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1d < 50.0) or (last_stochrsi_k_1h > 20.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 45.0) or (last_aroonu_14_15m > 0.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_aroonu_14_15m > 20.0) or (last_aroonu_14_1h > 0.0) or (last_roc_9_1d > -10.0))
      and ((last_aroonu_14_15m > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_1h > 0.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_4h > 0.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_1d > 10.0) or (last_roc_9_1d > -20.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_1d > 0.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_15m > 10.0) or (last_stochrsi_k_1d > 30.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_aroonu_14_1h > 20.0) or (last_aroonu_14_4h > 0.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_aroonu_14_1h > 0.0) or (last_aroonu_14_4h > 0.0))
      and ((last_aroonu_14_4h > 30.0) or (last_aroonu_14_1d > 0.0) or (last_roc_9_4h > -10.0))
      and ((last_aroonu_14_4h > 30.0) or (last_roc_9_1d > -50.0))
      and ((last_aroonu_14_4h > 0.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_aroonu_14_4h > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1d > 0.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_stochrsi_k_15m > 20.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_stochrsi_k_15m > 10.0) or (last_aroonu_14_1h > 0.0))
      and ((last_stochrsi_k_15m > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_stochrsi_k_1h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_stochrsi_k_1h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_stochrsi_k_1h > 10.0) or (last_stochrsi_k_1d > 10.0))
    ):
      self._grind_entry_tag = "g23"
      return True
    # g24 — downtrend-bounce continuation add: the zone BELOW the 4h 200-EMA that g22 explicitly sacrifices.
    # (mirror long g24)
    if (
      # momentum healthy on the bounce: RSI holds up (a real reversal cracks RSI hard)
      (last_rsi_3 < 80.0)
      and (last_rsi_3_15m < 80.0)
      and (last_rsi_14 < 60.0)
      # trend intact + this is a BOUNCE not a reversal: 4h still falling, 1h not in melt-up
      and (last_roc_9_1h < 10.0)
      and (last_roc_9_4h < 0.0)
      and (last_roc_9_4h > -25.0)  # anti-parabolic blow-off top
      # bear scope-gate: confirmed 4h downtrend + price below the 200-EMA regime (complements g22's <200EMA)
      and (last_ema_12_4h < last_ema_200_4h)
      and (last_close < last_ema_200_4h)
      # shallow bounce to the short EMA — sell the dip WITHIN the trend, never the bottom nor a deep pump
      and (last_close > (last_ema_20 * 0.99))
      and (last_close < (last_ema_20 * 1.06))
      and ((last_rsi_3_15m < 60.0) or (last_stochrsi_k_15m > 30.0))
      and ((last_rsi_3_1h < 90.0) or (last_rsi_3_4h < 70.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1h < 90.0) or (last_aroonu_14_1h > 40.0))
      and ((last_rsi_3_1h < 85.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_1h < 75.0) or (last_rsi_3_4h < 55.0) or (last_stochrsi_k_4h > 50.0))
      and ((last_rsi_3_1h < 75.0) or (last_aroonu_14_1h > 30.0))
      and ((last_rsi_3_1h < 75.0) or (last_rsi_3_1d < 55.0) or (last_aroonu_14_1d > 30.0))
      and ((last_rsi_3_1h < 75.0) or (last_aroonu_14_1h > 20.0))
      and ((last_rsi_3_1h < 70.0) or (last_rsi_3_4h < 40.0) or (last_aroonu_14_1d > 30.0))
      and ((last_rsi_3_1h < 70.0) or (last_rsi_3_4h < 40.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1h < 70.0) or (last_stochrsi_k_1d > 20.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_1h < 65.0) or (last_rsi_3_4h < 55.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1h < 65.0) or (last_aroonu_14_1h > 40.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_1h < 65.0) or (last_stochrsi_k_1d > 10.0) or (last_roc_9_1d > -20.0))
      and ((last_rsi_3_1h < 60.0) or (last_rsi_3_4h < 60.0) or (last_aroonu_14_1d > 10.0))
      and ((last_rsi_3_1h < 60.0) or (last_rsi_3_4h < 35.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 60.0) or (last_rsi_3_1d < 40.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_1h < 60.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1h < 60.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_1h < 60.0) or (last_aroonu_14_1d > 0.0) or (last_roc_9_1d > -20.0))
      and ((last_rsi_3_1h < 60.0) or (last_stochrsi_k_1d > 20.0) or (last_roc_9_1d > -50.0))
      and ((last_rsi_3_1h < 65.0) or (last_rsi_3_4h < 50.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 60.0) or (last_rsi_3_4h < 45.0) or (last_aroonu_14_4h > 10.0))
      and ((last_rsi_3_1h < 55.0) or (last_rsi_3_4h < 55.0) or (last_rsi_3_1d < 55.0) or (last_stochrsi_k_4h > 50.0))
      and ((last_rsi_3_1h < 55.0) or (last_aroonu_14_4h > 20.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_1h < 55.0) or (last_rsi_3_4h < 55.0) or (last_aroonu_14_4h > 40.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_1h > 20.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1h < 50.0) or (last_rsi_3_4h < 45.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_1h > 30.0) or (last_aroonu_14_1d > 30.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_4h > 20.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_4h > 20.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_4h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1h < 45.0) or (last_rsi_3_4h < 45.0) or (last_stochrsi_k_15m > 30.0))
      and ((last_rsi_3_1h < 45.0) or (last_aroonu_14_1h > 20.0) or (last_aroonu_14_4h > 20.0))
      and ((last_rsi_3_1h < 45.0) or (last_stochrsi_k_4h > 10.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_1h < 40.0) or (last_aroonu_14_15m > 30.0) or (last_aroonu_14_4h > 20.0))
      and ((last_rsi_3_1h < 40.0) or (last_stochrsi_k_1h > 40.0) or (last_stochrsi_k_1d > 10.0))
      and ((last_rsi_3_1h < 35.0) or (last_aroonu_14_15m > 30.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1h < 35.0) or (last_aroonu_14_1h > 30.0) or (last_aroonu_14_1d > 10.0))
      and ((last_rsi_3_1h < 35.0) or (last_aroonu_14_1h > 0.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_4h < 75.0) or (last_roc_9_1d > -30.0))
      and ((last_rsi_3_4h < 60.0) or (last_rsi_3_1d < 40.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_4h < 60.0) or (last_aroonu_14_15m > 30.0) or (last_aroonu_14_1d > 10.0))
      and ((last_rsi_3_4h < 60.0) or (last_aroonu_14_1d > 10.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_4h < 60.0) or (last_stochrsi_k_15m > 40.0) or (last_aroonu_14_1d > 10.0))
      and ((last_rsi_3_4h < 55.0) or (last_rsi_3_1d < 55.0) or (last_aroonu_14_15m > 40.0))
      and ((last_rsi_3_4h < 55.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_4h < 55.0) or (last_rsi_3_1d < 55.0) or (last_stochrsi_k_15m > 40.0))
      and ((last_rsi_3_4h < 50.0) or (last_aroonu_14_4h > 30.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_4h < 55.0) or (last_rsi_3_1d < 55.0) or (last_stochrsi_k_1h > 40.0))
      and ((last_rsi_3_4h < 50.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_4h < 55.0) or (last_rsi_3_1d < 55.0) or (last_stochrsi_k_4h > 40.0))
      and ((last_rsi_3_4h < 45.0) or (last_aroonu_14_15m > 30.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_4h < 40.0) or (last_rsi_3_1d < 35.0) or (last_aroonu_14_15m > 30.0))
      and ((last_rsi_3_4h < 40.0) or (last_aroonu_14_15m > 10.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_rsi_3_4h < 40.0) or (last_aroonu_14_15m > 0.0) or (last_stochrsi_k_15m > 20.0))
      and ((last_rsi_3_4h < 40.0) or (last_stochrsi_k_15m > 30.0) or (last_stochrsi_k_1h > 30.0))
      and ((last_rsi_3_4h < 40.0) or (last_stochrsi_k_1h > 40.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_rsi_3_1d < 70.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 65.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_rsi_3_1d < 65.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_rsi_3_1d < 65.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1d < 60.0) or (last_aroonu_14_1h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 55.0) or (last_aroonu_14_15m > 50.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_rsi_3_1d < 55.0) or (last_stochrsi_k_1h > 30.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1d < 50.0) or (last_aroonu_14_15m > 40.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1d < 50.0) or (last_aroonu_14_4h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 55.0) or (last_aroonu_14_1h > 20.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_rsi_3_1d < 55.0) or (last_aroonu_14_1d > 30.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1d < 50.0) or (last_stochrsi_k_15m > 10.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_1d < 50.0) or (last_stochrsi_k_1h > 20.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 40.0) or (last_aroonu_14_1h > 20.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_14_1h > 30.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_15m > 20.0) or (last_aroonu_14_1h > 20.0) or (last_aroonu_14_4h > 20.0))
      and ((last_aroonu_14_15m > 20.0) or (last_stochrsi_k_15m > 30.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_aroonu_14_15m > 20.0) or (last_aroonu_14_1d > 0.0))
      and ((last_aroonu_14_15m > 20.0) or (last_stochrsi_k_15m > 20.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_aroonu_14_15m > 10.0) or (last_aroonu_14_1h > 20.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_aroonu_14_15m > 10.0) or (last_aroonu_14_1h > 0.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_1h > 0.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_4h > 0.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_1d > 20.0) or (last_roc_9_1d > -10.0))
      and ((last_aroonu_14_1h > 30.0) or (last_aroonu_14_4h > 0.0))
      and ((last_aroonu_14_1h > 30.0) or (last_aroonu_14_1d > 10.0) or (last_roc_9_1d > -10.0))
      and ((last_aroonu_14_1h > 20.0) or (last_aroonu_14_4h > 0.0))
      and ((last_aroonu_14_1h > 10.0) or (last_stochrsi_k_1h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1h > 10.0) or (last_stochrsi_k_1h > 10.0) or (last_roc_9_1d > -10.0))
      and ((last_aroonu_14_1h > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1h > 0.0) or (last_stochrsi_k_1d > 10.0))
      and ((last_aroonu_14_4h > 30.0) or (last_aroonu_14_1d > 0.0) or (last_roc_9_1d > -20.0))
      and ((last_aroonu_14_4h > 10.0) or (last_stochrsi_k_4h > 10.0) or (last_roc_9_1d > -10.0))
      and ((last_aroonu_14_4h > 10.0) or (last_roc_9_1d > -30.0))
      and ((last_aroonu_14_4h > 0.0) or (last_aroonu_14_1d > 0.0))
      and ((last_aroonu_14_4h > 0.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_aroonu_14_4h > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1d > 0.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_aroonu_14_1d > 0.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_aroonu_14_1d > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1d > 0.0) or (last_roc_9_4h > -15.0) or (last_roc_9_1d > -50.0))
      # do not sell an oversold bottom on the pullback
      and ((last_stochrsi_k > 10.0) or (last_rsi_14 > 30.0))
      and ((last_stochrsi_k_15m > 20.0) or (last_stochrsi_k_1h > 20.0) or (last_roc_9_1d > -10.0))
      and ((last_stochrsi_k_15m > 20.0) or (last_aroonu_14_1d > 0.0))
      and ((last_stochrsi_k_15m > 20.0) or (last_stochrsi_k_1d > 10.0) or (last_roc_9_1d > -20.0))
      and ((last_stochrsi_k_15m > 10.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_stochrsi_k_15m > 10.0) or (last_stochrsi_k_1d > 10.0))
      and ((last_stochrsi_k_1h > 20.0) or (last_stochrsi_k_1d > 10.0))
      and ((last_stochrsi_k_1h > 20.0) or (last_roc_9_1d < 20.0))
      and ((last_stochrsi_k_1h > 10.0) or (last_roc_9_4h > -15.0))
      and ((last_stochrsi_k_4h > 10.0) or (last_roc_9_4h > -15.0))
      and ((last_stochrsi_k_4h > 10.0) or (last_roc_9_1d < 15.0))
      and ((last_stochrsi_k_1d > 10.0) or (last_roc_9_4h > -20.0))
    ):
      self._grind_entry_tag = "g24"
      return True
    # g27 — coil (mirror of long g27)
    if (
      (last_rsi_3 < 85.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_14 < 60.0)
      and (last_rsi_14_1h < 60.0)
      # the coil signature: 1h momentum negative-to-flat under a flat price
      and (last_roc_9_1h < 15.0)
      and (last_roc_9_1h > -2.0)
      and (last_close < (last_ema_20 * 1.02))
      and (last_close > (last_ema_20 * 0.98))
      # squeeze integrity: regime still broken, 4h rejection HELD, not dripping to new highs
      and (last_close > last_ema_200_4h)
      and (last_close < (last_high_max_12_4h * 0.90))
      and (last_close < (last_close_max_12 * 0.995))
      # general protections first
      and ((last_rsi_3_15m < 80.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1h < 85.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_1h < 80.0) or (last_rsi_3_4h < 80.0) or (last_aroonu_14_1d > 10.0))
      and ((last_rsi_3_1h < 80.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_rsi_3_1h < 70.0) or (last_rsi_3_1d < 70.0) or (last_stochrsi_k_1h > 30.0))
      and ((last_rsi_3_1h < 65.0) or (last_aroonu_14_1h > 30.0))
      and ((last_rsi_3_1h < 65.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_1h < 60.0) or (last_aroonu_14_4h > 20.0))
      and ((last_rsi_3_1h < 55.0) or (last_aroonu_14_1h > 10.0) or (last_stochrsi_k_1h > 30.0))
      and ((last_rsi_3_1h < 60.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 55.0) or (last_aroonu_14_1h > 10.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 55.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_1h > 30.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_1h < 45.0) or (last_rsi_3_4h < 40.0) or (last_aroonu_14_4h > 40.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_4h > 20.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 50.0) or (last_stochrsi_k_1d > 10.0) or (last_roc_9_1d > -30.0))
      and ((last_rsi_3_1h < 45.0) or (last_aroonu_14_4h > 20.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_1h < 45.0) or (last_aroonu_14_4h > 10.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 40.0) or (last_rsi_3_1d < 40.0) or (last_aroonu_14_1h > 20.0))
      and ((last_rsi_3_1h < 40.0) or (last_stochrsi_k_4h > 30.0) or (last_stochrsi_k_1d > 20.0))
      and ((last_rsi_3_1h < 40.0) or (last_stochrsi_k_4h > 20.0) or (last_roc_9_4h > -10.0))
      and ((last_rsi_3_4h < 90.0) or (last_rsi_3_1d < 60.0) or (last_stochrsi_k_15m > 20.0))
      and ((last_rsi_3_4h < 75.0) or (last_stochrsi_k_4h > 50.0) or (last_roc_9_4h > -10.0))
      and ((last_rsi_3_4h < 65.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_4h < 60.0) or (last_rsi_3_1d < 60.0) or (last_aroonu_14_15m > 30.0))
      and ((last_rsi_3_4h < 60.0) or (last_aroonu_14_15m > 0.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_rsi_3_4h < 60.0) or (last_aroonu_14_1h > 10.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_4h < 60.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_4h < 50.0) or (last_aroonu_14_15m > 20.0) or (last_aroonu_14_4h > 20.0))
      and ((last_rsi_3_4h < 50.0) or (last_stochrsi_k_15m > 30.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_4h < 45.0) or (last_aroonu_14_1h > 0.0) or (last_aroonu_14_1d > 20.0))
      and ((last_rsi_3_4h < 40.0) or (last_rsi_3_1d < 40.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_rsi_3_4h < 40.0) or (last_aroonu_14_15m > 30.0) or (last_aroonu_14_1h > 30.0))
      and ((last_rsi_3_4h < 40.0) or (last_aroonu_14_1h > 0.0) or (last_stochrsi_k_1d > 20.0))
      and ((last_rsi_3_4h < 40.0) or (last_stochrsi_k_4h > 30.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_4h < 35.0) or (last_aroonu_14_1h > 30.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_4h < 35.0) or (last_aroonu_14_4h > 20.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_4h < 35.0) or (last_stochrsi_k_4h > 30.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_4h < 35.0) or (last_stochrsi_k_4h > 10.0) or (last_roc_9_4h > -10.0))
      and ((last_rsi_3_1d < 90.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1d < 80.0) or (last_aroonu_14_1d > 10.0))
      and ((last_rsi_3_1d < 75.0) or (last_stochrsi_k_15m > 30.0))
      and ((last_rsi_3_1d < 75.0) or (last_aroonu_14_1h > 30.0))
      and ((last_rsi_3_1d < 75.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_rsi_3_1d < 70.0) or (last_aroonu_14_15m > 0.0))
      and ((last_rsi_3_1d < 70.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 60.0) or (last_aroonu_14_1h > 10.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_1d < 50.0) or (last_stochrsi_k_4h > 10.0) or (last_stochrsi_k_1d > 30.0))
      and ((last_aroonu_14_15m > 30.0) or (last_aroonu_14_1h > 0.0) or (last_stochrsi_k_1d > 20.0))
      and ((last_aroonu_14_15m > 30.0) or (last_aroonu_14_4h > 30.0) or (last_roc_9_4h > -10.0))
      and ((last_aroonu_14_15m > 20.0) or (last_stochrsi_k_15m > 30.0))
      and ((last_aroonu_14_15m > 20.0) or (last_aroonu_14_1h > 0.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_4h > 10.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1h > 20.0) or (last_aroonu_14_4h > 0.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_aroonu_14_1h > 20.0) or (last_stochrsi_k_4h > 0.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_aroonu_14_1h > 20.0) or (last_stochrsi_k_4h > 10.0) or (last_roc_9_4h > -10.0))
      and ((last_aroonu_14_1h > 0.0) or (last_aroonu_14_1d > 0.0))
      and ((last_aroonu_14_1h > 0.0) or (last_stochrsi_k_15m > 20.0))
      and ((last_aroonu_14_1h > 0.0) or (last_stochrsi_k_4h > 20.0) or (last_roc_9_4h > -10.0))
      and ((last_aroonu_14_1h > 0.0) or (last_stochrsi_k_1d > 10.0) or (last_roc_9_1d > -20.0))
      and ((last_aroonu_14_4h > 30.0) or (last_roc_9_1d < 25.0))
      and ((last_aroonu_14_4h > 30.0) or (last_roc_9_1d > -50.0))
      and ((last_aroonu_14_4h > 20.0) or (last_stochrsi_k_4h > 20.0) or (last_roc_9_4h > -10.0))
      and ((last_aroonu_14_4h > 20.0) or (last_stochrsi_k_1d > 20.0) or (last_roc_9_1d > -10.0))
      and ((last_aroonu_14_4h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_4h > 10.0) or (last_roc_9_4h > -10.0))
      and ((last_stochrsi_k_15m > 40.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_stochrsi_k_1h > 30.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_stochrsi_k_1h > 10.0) or (last_roc_9_4h < 20.0))
      and ((last_stochrsi_k_4h > 30.0) or (last_roc_9_1d < 25.0))
      and ((last_stochrsi_k_4h > 20.0) or (last_stochrsi_k_1d > 10.0) or (last_roc_9_1d > -20.0))
      and ((last_roc_9_1d < 40.0) or (last_aroonu_14_1h > 10.0))
      and ((last_roc_9_1d < 40.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_roc_9_1d < 25.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_roc_9_1d < 25.0) or (last_aroonu_14_4h > 20.0))
      and ((last_roc_9_1d < 15.0) or (last_stochrsi_k_4h > 20.0))
    ):
      self._grind_entry_tag = "g27"
      return True

    self._grind_entry_tag = ""
    return False

  def short_rebuy_entry_v3(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    if (last_candle["protections_short_global"] == True) and (
      (last_candle["enter_short"] == True)
      or (
        (last_candle["RSI_3"] < 90.0)
        and (last_candle["RSI_3_15m"] < 90.0)
        and (last_candle["AROOND_14"] < 30.0)
        and (last_candle["AROOND_14_15m"] < 30.0)
        and (last_candle["close"] > (last_candle["EMA_26"] * 1.012))
      )
    ):
      return True

    return False

  # Short Grinding Adjust Trade Position v4
  # ---------------------------------------------------------------------------------------------
  def short_grind_adjust_trade_position_v4(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ):
    dp = self.dp
    send_msg = self.dp.send_msg
    notification_msg = self.notification_msg
    config = self.config
    stake_currency = config["stake_currency"]
    is_futures_mode = self.is_futures_mode
    scale_stakes_for_min_stake = self.scale_stakes_for_min_stake
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_stake_amount = trade.stake_amount
    trade_leverage = trade.leverage
    trade_fee_open = trade.fee_open
    trade_fee_close = trade.fee_close

    # Reset so the log "Tag:" never shows a value left over from another pair's previous call
    self._grind_entry_tag = ""

    is_backtest = self.is_backtest_mode()
    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)
    if len(df) < 2:
      return None
    last_candle = None
    previous_candle = None

    def load_candles():
      # Only the (expensive on wide frames) row extraction is deferred; the frame is already fetched.
      nonlocal last_candle, previous_candle
      if last_candle is None:
        last_candle = df.iloc[-1]
        previous_candle = df.iloc[-2]

    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_exits = trade.nr_of_successful_exits

    if dp.runmode.value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = config["exit_pricing"]["price_side"]
        if trade.is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    # Finish managed partial exits before allowing another de-risk or grind.
    partial_exit = filled_exits[-1] if filled_exits else None
    if partial_exit is not None and partial_exit.safe_remaining > 0.0:
      partial_exit_tag = partial_exit.ft_order_tag or ""
      if partial_exit_tag.partition(" ")[0] in (
        "derisk_level_1",
        "derisk_level_2",
        "derisk_level_3",
        "derisk_level_4",
        "derisk_global",
        "grind_1_exit",
        "grind_1_derisk",
        "grind_2_exit",
        "grind_2_derisk",
        "grind_3_exit",
        "grind_3_derisk",
        "grind_4_exit",
        "grind_4_derisk",
        "grind_5_exit",
        "grind_5_derisk",
      ):
        partial_exit_amount = min(partial_exit.safe_remaining, trade_amount)
        exit_amount = partial_exit_amount * exit_rate / trade_leverage
        ft_exit_amount = partial_exit_amount * trade_stake_amount / trade_amount
        remaining_stake = (trade_amount - partial_exit_amount) * exit_rate / trade_leverage
        partial_exit_min_stake = min_stake or 0.0
        if (
          exit_amount > partial_exit_min_stake
          and ft_exit_amount > partial_exit_min_stake
          and (remaining_stake == 0.0 or remaining_stake >= partial_exit_min_stake * 1.55)
        ):
          return -ft_exit_amount, partial_exit_tag
        # Do not clip the recovery: a fully filled clipped order would hide the leftover.
        return None

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    current_stake_amount = trade_amount * exit_rate
    slice_amount = filled_entries[0].safe_filled * filled_entries[0].safe_price
    slice_profit = (exit_rate - filled_orders[-1].safe_price) / filled_orders[-1].safe_price
    slice_profit_entry = (exit_rate - filled_entries[-1].safe_price) / filled_entries[-1].safe_price
    slice_profit_exit = (
      ((exit_rate - filled_exits[-1].safe_price) / filled_exits[-1].safe_price) if count_of_exits > 0 else 0.0
    )

    is_rebuy_mode = all(c in self.short_rebuy_mode_tags for c in enter_tags) or (
      any(c in self.short_rebuy_mode_tags for c in enter_tags)
      and all(c in (self.short_rebuy_mode_tags + self.short_grind_mode_tags) for c in enter_tags)
    )
    # Rebuy mode, the first entry is lower than normal slot stake
    if is_rebuy_mode:
      slice_amount /= self.system_v4_rebuy_mode_stake_multiplier

    is_system_v4 = self.is_system_v4(trade)

    has_order_tags = hasattr(filled_orders[0], "ft_order_tag")

    fee_open_rate = trade_fee_open if self.custom_fee_open_rate is None else self.custom_fee_open_rate
    fee_close_rate = trade_fee_close if self.custom_fee_close_rate is None else self.custom_fee_close_rate
    fee_rate = fee_open_rate + fee_close_rate
    stake_scale_leverage = trade_leverage if is_futures_mode else 1.0
    grind_entry_retry_time = current_time - timedelta(minutes=5)

    # =========================================================================
    # GRINDING CONFIGURATION
    # =========================================================================
    if is_futures_mode:
      grind_1_stakes = self.system_v4_grind_1_stakes_futures
      grind_1_sub_thresholds = self.system_v4_grind_1_thresholds_futures
      grind_1_derisk_grinds = self.system_v4_grind_1_derisk_futures
      grind_1_profit_threshold = self.system_v4_grind_1_profit_threshold_futures

      grind_2_stakes = self.system_v4_grind_2_stakes_futures
      grind_2_sub_thresholds = self.system_v4_grind_2_thresholds_futures
      grind_2_derisk_grinds = self.system_v4_grind_2_derisk_futures
      grind_2_profit_threshold = self.system_v4_grind_2_profit_threshold_futures

      grind_3_stakes = self.system_v4_grind_3_stakes_futures
      grind_3_sub_thresholds = self.system_v4_grind_3_thresholds_futures
      grind_3_derisk_grinds = self.system_v4_grind_3_derisk_futures
      grind_3_profit_threshold = self.system_v4_grind_3_profit_threshold_futures

      grind_4_stakes = self.system_v4_grind_4_stakes_futures
      grind_4_sub_thresholds = self.system_v4_grind_4_thresholds_futures
      grind_4_derisk_grinds = self.system_v4_grind_4_derisk_futures
      grind_4_profit_threshold = self.system_v4_grind_4_profit_threshold_futures

      grind_5_stakes = self.system_v4_grind_5_stakes_futures
      grind_5_sub_thresholds = self.system_v4_grind_5_thresholds_futures
      grind_5_derisk_grinds = self.system_v4_grind_5_derisk_futures
      grind_5_profit_threshold = self.system_v4_grind_5_profit_threshold_futures

      # rebuy_stakes = self.system_v4_1_rebuy_stakes_futures
      # rebuy_sub_thresholds = self.system_v4_1_rebuy_thresholds_futures
    else:
      grind_1_stakes = self.system_v4_grind_1_stakes_spot
      grind_1_sub_thresholds = self.system_v4_grind_1_thresholds_spot
      grind_1_derisk_grinds = self.system_v4_grind_1_derisk_spot
      grind_1_profit_threshold = self.system_v4_grind_1_profit_threshold_spot

      grind_2_stakes = self.system_v4_grind_2_stakes_spot
      grind_2_sub_thresholds = self.system_v4_grind_2_thresholds_spot
      grind_2_derisk_grinds = self.system_v4_grind_2_derisk_spot
      grind_2_profit_threshold = self.system_v4_grind_2_profit_threshold_spot

      grind_3_stakes = self.system_v4_grind_3_stakes_spot
      grind_3_sub_thresholds = self.system_v4_grind_3_thresholds_spot
      grind_3_derisk_grinds = self.system_v4_grind_3_derisk_spot
      grind_3_profit_threshold = self.system_v4_grind_3_profit_threshold_spot

      grind_4_stakes = self.system_v4_grind_4_stakes_spot
      grind_4_sub_thresholds = self.system_v4_grind_4_thresholds_spot
      grind_4_derisk_grinds = self.system_v4_grind_4_derisk_spot
      grind_4_profit_threshold = self.system_v4_grind_4_profit_threshold_spot

      grind_5_stakes = self.system_v4_grind_5_stakes_spot
      grind_5_sub_thresholds = self.system_v4_grind_5_thresholds_spot
      grind_5_derisk_grinds = self.system_v4_grind_5_derisk_spot
      grind_5_profit_threshold = self.system_v4_grind_5_profit_threshold_spot

      # rebuy_stakes = self.system_v4_1_rebuy_stakes_spot
      # rebuy_sub_thresholds = self.system_v4_1_rebuy_thresholds_spot

    grind_1_max_sub_grinds = 0
    grind_1_stakes = scale_stakes_for_min_stake(
      grind_1_stakes, slice_amount, min_stake, trade_leverage, trade_leverage
    )
    grind_1_max_sub_grinds = len(grind_1_stakes)

    grind_2_max_sub_grinds = 0
    grind_2_stakes = scale_stakes_for_min_stake(
      grind_2_stakes, slice_amount, min_stake, stake_scale_leverage, trade_leverage
    )
    grind_2_max_sub_grinds = len(grind_2_stakes)

    grind_3_max_sub_grinds = 0
    grind_3_stakes = scale_stakes_for_min_stake(
      grind_3_stakes, slice_amount, min_stake, stake_scale_leverage, trade_leverage
    )
    grind_3_max_sub_grinds = len(grind_3_stakes)

    grind_4_max_sub_grinds = 0
    grind_4_stakes = scale_stakes_for_min_stake(
      grind_4_stakes, slice_amount, min_stake, stake_scale_leverage, trade_leverage
    )
    grind_4_max_sub_grinds = len(grind_4_stakes)

    grind_5_max_sub_grinds = 0
    grind_5_stakes = scale_stakes_for_min_stake(
      grind_5_stakes,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_5_max_sub_grinds = len(grind_5_stakes)

    # rebuy_max_sub_grinds = len(rebuy_stakes)

    is_derisk_1 = False
    is_derisk_1_found = False  # derisk_level_1 de-risk exit
    derisk_1_order = None
    is_derisk_2 = False
    is_derisk_2_found = False  # derisk_level_2 de-risk exit
    derisk_2_order = None
    is_derisk_3 = False
    is_derisk_3_found = False  # derisk_level_3 de-risk exit
    derisk_3_order = None
    grind_1_sub_grind_count = 0
    grind_1_total_amount = 0.0
    grind_1_total_cost = 0.0
    grind_1_current_open_rate = 0.0
    grind_1_current_grind_stake = 0.0
    grind_1_current_grind_profit_stake = 0.0
    grind_1_current_grind_profit_rate = 0.0
    grind_1_is_exit_found = False
    grind_1_found = False
    grind_1_buy_orders = []
    grind_1_orders = []
    grind_1_distance_ratio = 0.0
    grind_1_exit_order = None
    grind_1_exit_distance_ratio = 0.0
    grind_2_sub_grind_count = 0
    grind_2_total_amount = 0.0
    grind_2_total_cost = 0.0
    grind_2_current_open_rate = 0.0
    grind_2_current_grind_stake = 0.0
    grind_2_current_grind_profit_stake = 0.0
    grind_2_current_grind_profit_rate = 0.0
    grind_2_is_exit_found = False
    grind_2_found = False
    grind_2_buy_orders = []
    grind_2_orders = []
    grind_2_distance_ratio = 0.0
    grind_2_exit_order = None
    grind_2_exit_distance_ratio = 0.0
    grind_3_sub_grind_count = 0
    grind_3_total_amount = 0.0
    grind_3_total_cost = 0.0
    grind_3_current_open_rate = 0.0
    grind_3_current_grind_stake = 0.0
    grind_3_current_grind_profit_stake = 0.0
    grind_3_current_grind_profit_rate = 0.0
    grind_3_is_exit_found = False
    grind_3_found = False
    grind_3_buy_orders = []
    grind_3_orders = []
    grind_3_distance_ratio = 0.0
    grind_3_exit_order = None
    grind_3_exit_distance_ratio = 0.0
    grind_4_sub_grind_count = 0
    grind_4_total_amount = 0.0
    grind_4_total_cost = 0.0
    grind_4_current_open_rate = 0.0
    grind_4_current_grind_stake = 0.0
    grind_4_current_grind_profit_stake = 0.0
    grind_4_current_grind_profit_rate = 0.0
    grind_4_is_exit_found = False
    grind_4_found = False
    grind_4_buy_orders = []
    grind_4_orders = []
    grind_4_distance_ratio = 0.0
    grind_4_exit_order = None
    grind_4_exit_distance_ratio = 0.0
    grind_5_sub_grind_count = 0
    grind_5_total_amount = 0.0
    grind_5_total_cost = 0.0
    grind_5_current_open_rate = 0.0
    grind_5_current_grind_stake = 0.0
    grind_5_current_grind_profit_stake = 0.0
    grind_5_current_grind_profit_rate = 0.0
    grind_5_is_exit_found = False
    grind_5_found = False
    grind_5_buy_orders = []
    grind_5_orders = []
    grind_5_distance_ratio = 0.0
    grind_5_exit_order = None
    grind_5_exit_distance_ratio = 0.0
    rebuy_sub_grind_count = 0
    rebuy_total_amount = 0.0
    rebuy_total_cost = 0.0
    rebuy_current_open_rate = 0.0
    rebuy_current_grind_stake = 0.0
    rebuy_current_grind_stake_profit = 0.0
    rebuy_is_exit_found = False
    rebuy_found = False
    rebuy_buy_orders = []
    rebuy_orders = []
    rebuy_distance_ratio = 0.0
    rebuy_exit_order = None
    rebuy_exit_distance_ratio = 0.0
    for order in reversed(filled_orders):
      if (order.ft_order_side == "sell") and (order is not filled_orders[0]):
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag
        if not grind_1_is_exit_found and order_tag == "grind_1_entry":
          grind_1_sub_grind_count += 1
          grind_1_total_amount += order.safe_filled
          grind_1_total_cost += order.safe_filled * order.safe_price
          grind_1_buy_orders.append(order.id)
          grind_1_orders.append(order)
          if not grind_1_found:
            grind_1_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_1_found = True
        elif not grind_2_is_exit_found and order_tag == "grind_2_entry":
          grind_2_sub_grind_count += 1
          grind_2_total_amount += order.safe_filled
          grind_2_total_cost += order.safe_filled * order.safe_price
          grind_2_buy_orders.append(order.id)
          grind_2_orders.append(order)
          if not grind_2_found:
            grind_2_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_2_found = True
        elif not grind_3_is_exit_found and order_tag == "grind_3_entry":
          grind_3_sub_grind_count += 1
          grind_3_total_amount += order.safe_filled
          grind_3_total_cost += order.safe_filled * order.safe_price
          grind_3_buy_orders.append(order.id)
          grind_3_orders.append(order)
          if not grind_3_found:
            grind_3_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_3_found = True
        elif not grind_4_is_exit_found and order_tag == "grind_4_entry":
          grind_4_sub_grind_count += 1
          grind_4_total_amount += order.safe_filled
          grind_4_total_cost += order.safe_filled * order.safe_price
          grind_4_buy_orders.append(order.id)
          grind_4_orders.append(order)
          if not grind_4_found:
            grind_4_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_4_found = True
        elif not grind_5_is_exit_found and order_tag == "grind_5_entry":
          grind_5_sub_grind_count += 1
          grind_5_total_amount += order.safe_filled
          grind_5_total_cost += order.safe_filled * order.safe_price
          grind_5_buy_orders.append(order.id)
          grind_5_orders.append(order)
          if not grind_5_found:
            grind_5_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            grind_5_found = True
        elif not rebuy_is_exit_found and order_tag == "rebuy_entry":
          rebuy_sub_grind_count += 1
          rebuy_total_amount += order.safe_filled
          rebuy_total_cost += order.safe_filled * order.safe_price
          rebuy_buy_orders.append(order.id)
          rebuy_orders.append(order)
          if not rebuy_found:
            rebuy_distance_ratio = (exit_rate - order.safe_price) / order.safe_price
            rebuy_found = True
      elif order.ft_order_side == "buy":
        order_tag = ""
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag.partition(" ")[0]
        if order_tag == "derisk_level_1":
          if not is_derisk_1_found:
            is_derisk_1_found = True
            is_derisk_1 = True
            derisk_1_order = order
        elif order_tag == "derisk_level_2":
          if not is_derisk_2_found:
            is_derisk_2_found = True
            is_derisk_2 = True
            derisk_2_order = order
        elif order_tag == "derisk_level_3":
          if not is_derisk_3_found:
            is_derisk_3_found = True
            is_derisk_3 = True
            derisk_3_order = order
        elif not grind_1_is_exit_found and order_tag in ["grind_1_exit", "grind_1_derisk"]:
          grind_1_is_exit_found = True
          grind_1_exit_order = order
        elif not grind_2_is_exit_found and order_tag in ["grind_2_exit", "grind_2_derisk"]:
          grind_2_is_exit_found = True
          grind_2_exit_order = order
        elif not grind_3_is_exit_found and order_tag in ["grind_3_exit", "grind_3_derisk"]:
          grind_3_is_exit_found = True
          grind_3_exit_order = order
        elif not grind_4_is_exit_found and order_tag in ["grind_4_exit", "grind_4_derisk"]:
          grind_4_is_exit_found = True
          grind_4_exit_order = order
        elif not grind_5_is_exit_found and order_tag in ["grind_5_exit", "grind_5_derisk"]:
          grind_5_is_exit_found = True
          grind_5_exit_order = order
        elif not rebuy_is_exit_found and order_tag in ["rebuy_exit", "rebuy_derisk"]:
          rebuy_is_exit_found = True
          rebuy_exit_order = order
        elif order_tag == "derisk_global":
          if not grind_1_is_exit_found:
            grind_1_is_exit_found = True
            grind_1_exit_order = order
          if not grind_2_is_exit_found:
            grind_2_is_exit_found = True
            grind_2_exit_order = order
          if not grind_3_is_exit_found:
            grind_3_is_exit_found = True
            grind_3_exit_order = order
          if not grind_4_is_exit_found:
            grind_4_is_exit_found = True
            grind_4_exit_order = order
          if not grind_5_is_exit_found:
            grind_5_is_exit_found = True
            grind_5_exit_order = order
          if not rebuy_is_exit_found:
            rebuy_is_exit_found = True
            rebuy_exit_order = order

    if grind_1_sub_grind_count > 0:
      grind_1_current_open_rate = grind_1_total_cost / grind_1_total_amount
      grind_1_current_grind_stake = grind_1_total_amount * exit_rate * (1 - trade_fee_close)
      grind_1_current_grind_profit_stake = grind_1_total_cost - grind_1_current_grind_stake
      grind_1_current_grind_profit_rate = (exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
    if grind_2_sub_grind_count > 0:
      grind_2_current_open_rate = grind_2_total_cost / grind_2_total_amount
      grind_2_current_grind_stake = grind_2_total_amount * exit_rate * (1 - trade_fee_close)
      grind_2_current_grind_profit_stake = grind_2_total_cost - grind_2_current_grind_stake
      grind_2_current_grind_profit_rate = (exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
    if grind_3_sub_grind_count > 0:
      grind_3_current_open_rate = grind_3_total_cost / grind_3_total_amount
      grind_3_current_grind_stake = grind_3_total_amount * exit_rate * (1 - trade_fee_close)
      grind_3_current_grind_profit_stake = grind_3_total_cost - grind_3_current_grind_stake
      grind_3_current_grind_profit_rate = (exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
    if grind_4_sub_grind_count > 0:
      grind_4_current_open_rate = grind_4_total_cost / grind_4_total_amount
      grind_4_current_grind_stake = grind_4_total_amount * exit_rate * (1 - trade_fee_close)
      grind_4_current_grind_profit_stake = grind_4_total_cost - grind_4_current_grind_stake
      grind_4_current_grind_profit_rate = (exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
    if grind_5_sub_grind_count > 0:
      grind_5_current_open_rate = grind_5_total_cost / grind_5_total_amount
      grind_5_current_grind_stake = grind_5_total_amount * exit_rate * (1 - trade_fee_close)
      grind_5_current_grind_profit_stake = grind_5_total_cost - grind_5_current_grind_stake
      grind_5_current_grind_profit_rate = (exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
    if rebuy_sub_grind_count > 0:
      rebuy_current_open_rate = rebuy_total_cost / rebuy_total_amount
      rebuy_current_grind_stake = rebuy_total_amount * exit_rate * (1 - trade_fee_close)
      rebuy_current_grind_stake_profit = rebuy_total_cost - rebuy_current_grind_stake

    if grind_1_is_exit_found:
      grind_1_exit_distance_ratio = (exit_rate - grind_1_exit_order.safe_price) / grind_1_exit_order.safe_price
    if grind_2_is_exit_found:
      grind_2_exit_distance_ratio = (exit_rate - grind_2_exit_order.safe_price) / grind_2_exit_order.safe_price
    if grind_3_is_exit_found:
      grind_3_exit_distance_ratio = (exit_rate - grind_3_exit_order.safe_price) / grind_3_exit_order.safe_price
    if grind_4_is_exit_found:
      grind_4_exit_distance_ratio = (exit_rate - grind_4_exit_order.safe_price) / grind_4_exit_order.safe_price
    if grind_5_is_exit_found:
      grind_5_exit_distance_ratio = (exit_rate - grind_5_exit_order.safe_price) / grind_5_exit_order.safe_price
    if rebuy_is_exit_found:
      rebuy_exit_distance_ratio = (exit_rate - rebuy_exit_order.safe_price) / rebuy_exit_order.safe_price

    # all buybacks & grinds
    current_open_grind_stake_profit = (
      grind_1_current_grind_profit_stake
      + grind_2_current_grind_profit_stake
      + grind_3_current_grind_profit_stake
      + grind_4_current_grind_profit_stake
      + grind_5_current_grind_profit_stake
      + rebuy_current_grind_stake_profit
    )
    num_open_grinds_and_buybacks = (
      grind_1_sub_grind_count
      + grind_2_sub_grind_count
      + grind_3_sub_grind_count
      + grind_4_sub_grind_count
      + grind_5_sub_grind_count
      + rebuy_sub_grind_count
    )

    # not reached the max allowed stake for all grinds
    is_not_trade_max_stake_v4 = current_stake_amount < (slice_amount * self.system_v4_max_stake)

    grind_1_cluster_max_profit_stake = trade.get_custom_data(key="grind_1_cluster_max_profit_stake") or 0.0
    grind_1_cluster_max_profit_rate = trade.get_custom_data(key="grind_1_cluster_max_profit_rate") or 0.0
    if grind_1_current_grind_profit_stake > grind_1_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_1_cluster_max_profit_stake", value=grind_1_current_grind_profit_stake)
    if grind_1_current_grind_profit_rate < grind_1_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_1_cluster_max_profit_rate", value=grind_1_current_grind_profit_rate)

    grind_2_cluster_max_profit_stake = trade.get_custom_data(key="grind_2_cluster_max_profit_stake") or 0.0
    grind_2_cluster_max_profit_rate = trade.get_custom_data(key="grind_2_cluster_max_profit_rate") or 0.0
    if grind_2_current_grind_profit_stake > grind_2_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_2_cluster_max_profit_stake", value=grind_2_current_grind_profit_stake)
    if grind_2_current_grind_profit_rate < grind_2_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_2_cluster_max_profit_rate", value=grind_2_current_grind_profit_rate)

    grind_3_cluster_max_profit_stake = trade.get_custom_data(key="grind_3_cluster_max_profit_stake") or 0.0
    grind_3_cluster_max_profit_rate = trade.get_custom_data(key="grind_3_cluster_max_profit_rate") or 0.0
    if grind_3_current_grind_profit_stake > grind_3_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_3_cluster_max_profit_stake", value=grind_3_current_grind_profit_stake)
    if grind_3_current_grind_profit_rate < grind_3_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_3_cluster_max_profit_rate", value=grind_3_current_grind_profit_rate)

    grind_4_cluster_max_profit_stake = trade.get_custom_data(key="grind_4_cluster_max_profit_stake") or 0.0
    grind_4_cluster_max_profit_rate = trade.get_custom_data(key="grind_4_cluster_max_profit_rate") or 0.0
    if grind_4_current_grind_profit_stake > grind_4_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_4_cluster_max_profit_stake", value=grind_4_current_grind_profit_stake)
    if grind_4_current_grind_profit_rate < grind_4_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_4_cluster_max_profit_rate", value=grind_4_current_grind_profit_rate)

    grind_5_cluster_max_profit_stake = trade.get_custom_data(key="grind_5_cluster_max_profit_stake") or 0.0
    grind_5_cluster_max_profit_rate = trade.get_custom_data(key="grind_5_cluster_max_profit_rate") or 0.0
    if grind_5_current_grind_profit_stake > grind_5_cluster_max_profit_stake:
      trade.set_custom_data(key="grind_5_cluster_max_profit_stake", value=grind_5_current_grind_profit_stake)
    if grind_5_current_grind_profit_rate < grind_5_cluster_max_profit_rate:
      trade.set_custom_data(key="grind_5_cluster_max_profit_rate", value=grind_5_current_grind_profit_rate)

    is_short_extra_checks_entry = (
      grind_entry_retry_time > filled_entries[-1].order_filled_utc
      # and ((current_time - timedelta(hours=6) > filled_orders[-1].order_filled_utc) or (slice_profit > 0.02))
      and (
        (current_time - timedelta(hours=6) > filled_orders[-1].order_filled_utc)
        or (slice_profit > 0.06)
        or (is_derisk_3)
      )
      # and (
      #   (current_stake_amount < (filled_entries[0].cost * 0.50))
      #   or (current_time - timedelta(hours=6) > filled_orders[-1].order_filled_utc)
      #   or (slice_profit > 0.06)
      # )
    )
    # is_short_extra_checks_entry = True
    is_short_grind_entry = None
    is_short_buyback_entry = None
    is_derisk_hold = None

    def short_grind_entry_signal():
      nonlocal is_short_grind_entry
      if is_short_grind_entry is None:
        load_candles()
        is_short_grind_entry = self.short_grind_entry_v4(
          last_candle, previous_candle, slice_profit, slice_profit_entry, True
        )
        # past the near end of the de-risk range, no grind add while the 4h is at capitulation
        if profit_stake < slice_amount * (
          self.system_v4_derisk_level_1_futures[0] if is_futures_mode else self.system_v4_derisk_level_1_spot[0]
        ) / trade_leverage and self._bad_trade_controller_capitulation(last_candle, True):
          is_short_grind_entry = False
      return is_short_grind_entry

    def short_grind_4_fallback_entry():
      if slice_profit_entry <= 0.04:
        return False
      load_candles()
      if (
        (last_candle["RSI_3"] < 95.0)
        and (last_candle["RSI_3_15m"] < 90.0)
        and (last_candle["RSI_14"] > 65.0)
        and (last_candle["close"] > (last_candle["EMA_20"] * 1.015))
      ):
        self._grind_entry_tag = "g4_fb1"
        return True
      if (
        (slice_profit_entry > 0.06)
        and (num_open_grinds_and_buybacks == 0)
        and (last_candle["RSI_14"] > 70.0)
        and (last_candle["close"] > (last_candle["EMA_20"] * 1.020))
      ):
        self._grind_entry_tag = "g4_fb2"
        return True
      return False

    def short_grind_5_fallback_entry():
      if not (is_derisk_1_found or is_derisk_2_found or is_derisk_3_found) or slice_profit_entry <= 0.06:
        return False
      load_candles()
      if (last_candle["RSI_3"] < 90.0) and (last_candle["RSI_3_15m"] < 80.0) and (last_candle["AROOND_14"] < 50.0):
        self._grind_entry_tag = "g5_fb1"
        return True
      return False

    def short_grind_5_liquidation_entry():
      if not (is_futures_mode and (slice_profit_entry > 0.15) and (trade.liquidation_price is not None)):
        return False
      if (trade.is_short and current_rate > trade.liquidation_price * 0.80) or (
        not trade.is_short and current_rate < trade.liquidation_price * 1.20
      ):
        self._grind_entry_tag = "g5_liq1"
        return True
      return False

    def short_grind_5_liquidation_rescue_entry():
      if (
        self.system_v4_grind_5_liquidation_rescue_enable
        and is_futures_mode
        and (trade.liquidation_price is not None)
        and (trade.liquidation_price > 0.0)
        and (trade.liquidation_price * 0.80 < current_rate < trade.liquidation_price)
        and (slice_profit_entry > self.system_v4_grind_5_liquidation_rescue_threshold)
        and (num_open_grinds_and_buybacks <= 1)
        and (
          trade_stake_amount
          + max(slice_amount * grind_5_stakes[grind_5_sub_grind_count] / trade_leverage, min_stake * 1.5)
          <= slice_amount * self.system_v4_grind_5_liquidation_rescue_max_stake / trade_leverage
        )
      ):
        self._grind_entry_tag = "g5_liq2"
        return True
      return False

    def derisk_hold():
      nonlocal is_derisk_hold
      if is_derisk_hold is None:
        is_derisk_hold = False
        if self.bad_trade_controller_derisk_hold_short_enable:
          load_candles()
          is_derisk_hold = self._bad_trade_controller_derisk_hold(last_candle, True)
      return is_derisk_hold

    stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
    send_notifications = not is_backtest
    # =========================================================================
    # DE-RISK CONFIGURATION
    # =========================================================================
    if is_system_v4:
      derisk_1_enable = self.system_v4_derisk_level_1_enable
      derisk_2_enable = self.system_v4_derisk_level_2_enable
      derisk_3_enable = self.system_v4_derisk_level_3_enable
      if is_futures_mode:
        derisk_1_threshold = self.system_v4_derisk_level_1_futures[1]
        derisk_1_stake = self.system_v4_derisk_level_1_stake_futures
        derisk_2_threshold = self.system_v4_derisk_level_2_futures[1]
        derisk_2_stake = self.system_v4_derisk_level_2_stake_futures
        derisk_3_threshold = self.system_v4_derisk_level_3_futures[1]
        derisk_3_stake = self.system_v4_derisk_level_3_stake_futures
      else:
        derisk_1_threshold = self.system_v4_derisk_level_1_spot[1]
        derisk_1_stake = self.system_v4_derisk_level_1_stake_spot
        derisk_2_threshold = self.system_v4_derisk_level_2_spot[1]
        derisk_2_stake = self.system_v4_derisk_level_2_stake_spot
        derisk_3_threshold = self.system_v4_derisk_level_3_spot[1]
        derisk_3_stake = self.system_v4_derisk_level_3_stake_spot
    else:
      derisk_1_enable = derisk_2_enable = derisk_3_enable = False
      derisk_1_threshold = derisk_2_threshold = derisk_3_threshold = 0.0
      derisk_1_stake = derisk_2_stake = derisk_3_stake = 0.0
      if is_futures_mode:
        derisk_1_threshold = self.system_v4_2_derisk_level_1_futures[1]
        derisk_1_stake = self.system_v4_2_derisk_level_1_stake_futures
        derisk_2_threshold = self.system_v4_2_derisk_level_2_futures[1]
        derisk_2_stake = self.system_v4_2_derisk_level_2_stake_futures
        derisk_3_threshold = self.system_v4_2_derisk_level_3_futures[1]
        derisk_3_stake = self.system_v4_2_derisk_level_3_stake_futures
      else:
        derisk_1_threshold = self.system_v4_2_derisk_level_1_spot[1]
        derisk_1_stake = self.system_v4_2_derisk_level_1_stake_spot
        derisk_2_threshold = self.system_v4_2_derisk_level_2_spot[1]
        derisk_2_stake = self.system_v4_2_derisk_level_2_stake_spot
        derisk_3_threshold = self.system_v4_2_derisk_level_3_spot[1]
        derisk_3_stake = self.system_v4_2_derisk_level_3_stake_spot
    derisk_enable = self.derisk_enable
    force_derisk_3 = (
      self.system_v4_derisk_level_3_liquidation_enable
      and derisk_enable
      and derisk_3_enable
      and not is_derisk_3_found
      and not is_rebuy_mode
      and is_futures_mode
      and (profit_stake < 0.0)
      and (trade.liquidation_price is not None)
      and (trade.liquidation_price > 0.0)
      and (
        trade.liquidation_price * (1.0 - self.system_v4_derisk_level_3_liquidation_distance)
        <= current_rate
        < trade.liquidation_price
      )
    )
    # ---------------------------------------------------------------------
    # De-risk level 1
    # ---------------------------------------------------------------------
    if (
      derisk_enable
      and derisk_1_enable
      and not is_derisk_1_found
      and not is_rebuy_mode
      and not force_derisk_3
      and profit_stake < slice_amount * derisk_1_threshold / trade_leverage
      and not derisk_hold()
    ):
      sell_amount = filled_entries[0].safe_filled * derisk_1_stake * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if send_notifications:
          send_msg(
            notification_msg(
              "de-risk",
              tag="Level 1",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"De-risk Level 1 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_1"
    # ---------------------------------------------------------------------
    # De-risk level 2
    # ---------------------------------------------------------------------
    if (
      derisk_enable
      and derisk_2_enable
      and not is_derisk_2_found
      and not is_rebuy_mode
      and not force_derisk_3
      and profit_stake < slice_amount * derisk_2_threshold / trade_leverage
      and not derisk_hold()
    ):
      sell_amount = filled_entries[0].safe_filled * derisk_2_stake * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if send_notifications:
          send_msg(
            notification_msg(
              "de-risk",
              tag="Level 2",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"De-risk Level 2 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_2"
    # ---------------------------------------------------------------------
    # De-risk level 3
    # ---------------------------------------------------------------------
    if (
      derisk_enable
      and derisk_3_enable
      and not is_derisk_3_found
      and not is_rebuy_mode
      and (force_derisk_3 or (profit_stake < slice_amount * derisk_3_threshold / trade_leverage and not derisk_hold()))
    ):
      sell_amount = filled_entries[0].safe_filled * derisk_3_stake * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if send_notifications:
          send_msg(
            notification_msg(
              "de-risk",
              tag="Level 3",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"De-risk Level 3 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "derisk_level_3"

    # Grinding 1

    if (
      (self.system_v4_grind_1_enable)
      # and is_derisk_1_found
      and is_short_extra_checks_entry
      and (grind_1_sub_grind_count < grind_1_max_sub_grinds)
      and (grind_1_sub_grind_count == 0 or (-grind_1_distance_ratio < grind_1_sub_thresholds[grind_1_sub_grind_count]))
      and is_not_trade_max_stake_v4
      and (
        short_grind_entry_signal()
        or self._grind_entry_before_derisk(
          True,
          exit_rate,
          grind_1_current_open_rate,
          grind_1_derisk_grinds,
          self.system_v4_grind_1_use_derisk,
        )
      )
    ):
      buy_amount = slice_amount * grind_1_stakes[grind_1_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount <= max_stake:
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-entry",
              tag="grind_1_entry",
              pair=trade_pair,
              rate=current_rate,
              stake_amount=buy_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"Grinding entry (grind_1_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
        )
        order_tag = "grind_1_entry"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    if grind_1_sub_grind_count > 0 and not (
      -grind_1_current_grind_profit_rate < (grind_1_profit_threshold + fee_open_rate + fee_close_rate)
    ):
      load_candles()
      ft_exit_amount, tag = self.short_grind_exit_v4(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_1_exit",
        "grind_1_exit",
        fee_open_rate,
        fee_close_rate,
        grind_1_cluster_max_profit_stake,
        grind_1_cluster_max_profit_rate,
        grind_1_current_grind_profit_stake,
        grind_1_current_grind_profit_rate,
        grind_1_total_amount,
        grind_1_profit_threshold,
        grind_1_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v4_grind_1_use_derisk
      and (grind_1_sub_grind_count > 0)
      and ((-(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate) < grind_1_derisk_grinds)
    ):
      # if (
      #   self.system_v4_grind_1_use_derisk
      #   and (grind_1_sub_grind_count > 0)
      #   and (grind_1_current_grind_profit_stake < (slice_amount * grind_1_derisk_grinds))
      #   and (grind_1_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_1_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate)
            if grind_1_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_1_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_1_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_1_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_1_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_1_derisk"
        for grind_entry_id in grind_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 2

    if (
      (self.system_v4_grind_2_enable)
      # and is_derisk_1_found
      and is_short_extra_checks_entry
      and (grind_2_sub_grind_count < grind_2_max_sub_grinds)
      and (grind_2_sub_grind_count == 0 or (-grind_2_distance_ratio < grind_2_sub_thresholds[grind_2_sub_grind_count]))
      and is_not_trade_max_stake_v4
      and (
        short_grind_entry_signal()
        or self._grind_entry_before_derisk(
          True,
          exit_rate,
          grind_2_current_open_rate,
          grind_2_derisk_grinds,
          self.system_v4_grind_2_use_derisk,
        )
      )
    ):
      buy_amount = slice_amount * grind_2_stakes[grind_2_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount <= max_stake:
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-entry",
              tag="grind_2_entry",
              pair=trade_pair,
              rate=current_rate,
              stake_amount=buy_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"Grinding entry (grind_2_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
        )
        order_tag = "grind_2_entry"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    if grind_2_sub_grind_count > 0 and not (
      -grind_2_current_grind_profit_rate < (grind_2_profit_threshold + fee_open_rate + fee_close_rate)
    ):
      load_candles()
      ft_exit_amount, tag = self.short_grind_exit_v4(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_2_exit",
        "grind_2_exit",
        fee_open_rate,
        fee_close_rate,
        grind_2_cluster_max_profit_stake,
        grind_2_cluster_max_profit_rate,
        grind_2_current_grind_profit_stake,
        grind_2_current_grind_profit_rate,
        grind_2_total_amount,
        grind_2_profit_threshold,
        grind_2_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v4_grind_2_use_derisk
      and (grind_2_sub_grind_count > 0)
      and ((-(exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate) < grind_2_derisk_grinds)
    ):
      # if (
      #   self.system_v4_grind_2_use_derisk
      #   and (grind_2_sub_grind_count > 0)
      #   and (grind_2_current_grind_profit_stake < (slice_amount * grind_2_derisk_grinds))
      #   and (grind_2_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_2_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_2_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate)
            if grind_2_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_2_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_2_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_2_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_2_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_2_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_2_derisk"
        for grind_entry_id in grind_2_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 3

    if (
      (self.system_v4_grind_3_enable)
      # and is_derisk_1_found
      and is_short_extra_checks_entry
      and (grind_3_sub_grind_count < grind_3_max_sub_grinds)
      and (grind_3_sub_grind_count == 0 or (-grind_3_distance_ratio < grind_3_sub_thresholds[grind_3_sub_grind_count]))
      and is_not_trade_max_stake_v4
      and (
        short_grind_entry_signal()
        or self._grind_entry_before_derisk(
          True,
          exit_rate,
          grind_3_current_open_rate,
          grind_3_derisk_grinds,
          self.system_v4_grind_3_use_derisk,
        )
      )
    ):
      buy_amount = slice_amount * grind_3_stakes[grind_3_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount <= max_stake:
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-entry",
              tag="grind_3_entry",
              pair=trade_pair,
              rate=current_rate,
              stake_amount=buy_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"Grinding entry (grind_3_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
        )
        order_tag = "grind_3_entry"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    if grind_3_sub_grind_count > 0 and not (
      -grind_3_current_grind_profit_rate < (grind_3_profit_threshold + fee_open_rate + fee_close_rate)
    ):
      load_candles()
      ft_exit_amount, tag = self.short_grind_exit_v4(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_3_exit",
        "grind_3_exit",
        fee_open_rate,
        fee_close_rate,
        grind_3_cluster_max_profit_stake,
        grind_3_cluster_max_profit_rate,
        grind_3_current_grind_profit_stake,
        grind_3_current_grind_profit_rate,
        grind_3_total_amount,
        grind_3_profit_threshold,
        grind_3_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v4_grind_3_use_derisk
      and (grind_3_sub_grind_count > 0)
      and ((-(exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate) < grind_3_derisk_grinds)
    ):
      # if (
      #   self.system_v4_grind_3_use_derisk
      #   and (grind_3_sub_grind_count > 0)
      #   and (grind_3_current_grind_profit_stake < (slice_amount * grind_3_derisk_grinds))
      #   and (grind_3_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_3_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_3_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate)
            if grind_3_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_3_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_3_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_3_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_3_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_3_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_3_derisk"
        for grind_entry_id in grind_3_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 4

    if (
      (self.system_v4_grind_4_enable)
      # and is_derisk_1_found
      # and is_short_grind_entry
      and is_short_extra_checks_entry
      and (grind_4_sub_grind_count < grind_4_max_sub_grinds)
      and (grind_4_sub_grind_count == 0 or (-grind_4_distance_ratio < grind_4_sub_thresholds[grind_4_sub_grind_count]))
      and is_not_trade_max_stake_v4
      and (
        short_grind_4_fallback_entry()
        or short_grind_entry_signal()
        or self._grind_entry_before_derisk(
          True,
          exit_rate,
          grind_4_current_open_rate,
          grind_4_derisk_grinds,
          self.system_v4_grind_4_use_derisk,
        )
      )
    ):
      buy_amount = slice_amount * grind_4_stakes[grind_4_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount <= max_stake:
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-entry",
              tag="grind_4_entry",
              pair=trade_pair,
              rate=current_rate,
              stake_amount=buy_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"Grinding entry (grind_4_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
        )
        order_tag = "grind_4_entry"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    if grind_4_sub_grind_count > 0 and not (
      -grind_4_current_grind_profit_rate < (grind_4_profit_threshold + fee_open_rate + fee_close_rate)
    ):
      load_candles()
      ft_exit_amount, tag = self.short_grind_exit_v4(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_4_exit",
        "grind_4_exit",
        fee_open_rate,
        fee_close_rate,
        grind_4_cluster_max_profit_stake,
        grind_4_cluster_max_profit_rate,
        grind_4_current_grind_profit_stake,
        grind_4_current_grind_profit_rate,
        grind_4_total_amount,
        grind_4_profit_threshold,
        grind_4_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v4_grind_4_use_derisk
      and (grind_4_sub_grind_count > 0)
      and ((-(exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate) < grind_4_derisk_grinds)
    ):
      # if (
      #   self.system_v4_grind_4_use_derisk
      #   and (grind_4_sub_grind_count > 0)
      #   and (grind_4_current_grind_profit_stake < (slice_amount * grind_4_derisk_grinds))
      #   and (grind_4_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_4_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_4_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate)
            if grind_4_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_4_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_4_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_4_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_4_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_4_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_4_derisk"
        for grind_entry_id in grind_4_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 5

    if (
      (self.system_v4_grind_5_enable)
      # and is_derisk_1_found
      # and is_short_grind_entry
      and is_short_extra_checks_entry
      and (grind_5_sub_grind_count < grind_5_max_sub_grinds)
      and (grind_5_sub_grind_count == 0 or (-grind_5_distance_ratio < grind_5_sub_thresholds[grind_5_sub_grind_count]))
      and is_not_trade_max_stake_v4
      and (
        short_grind_5_fallback_entry()
        or short_grind_5_liquidation_entry()
        or short_grind_entry_signal()
        or short_grind_5_liquidation_rescue_entry()
        or self._grind_entry_before_derisk(
          True,
          exit_rate,
          grind_5_current_open_rate,
          grind_5_derisk_grinds,
          self.system_v4_grind_5_use_derisk,
        )
      )
    ):
      buy_amount = slice_amount * grind_5_stakes[grind_5_sub_grind_count] / trade_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount <= max_stake:
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-entry",
              tag="grind_5_entry",
              pair=trade_pair,
              rate=current_rate,
              stake_amount=buy_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
            )
          )
        log.info(
          f"Grinding entry (grind_5_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Tag: {self._grind_entry_tag}"
        )
        order_tag = "grind_5_entry"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    if grind_5_sub_grind_count > 0 and not (
      -grind_5_current_grind_profit_rate < (grind_5_profit_threshold + fee_open_rate + fee_close_rate)
    ):
      load_candles()
      ft_exit_amount, tag = self.short_grind_exit_v4(
        last_candle,
        previous_candle,
        slice_profit,
        current_time,
        min_stake,
        current_stake_amount,
        exit_rate,
        profit_stake,
        profit_ratio,
        "grind_5_exit",
        "grind_5_exit",
        fee_open_rate,
        fee_close_rate,
        grind_5_cluster_max_profit_stake,
        grind_5_cluster_max_profit_rate,
        grind_5_current_grind_profit_stake,
        grind_5_current_grind_profit_rate,
        grind_5_total_amount,
        grind_5_profit_threshold,
        grind_5_orders,
        trade,
      )
      if ft_exit_amount is not None and tag is not None:
        return ft_exit_amount, tag

    if (
      self.system_v4_grind_5_use_derisk
      and (grind_5_sub_grind_count > 0)
      and ((-(exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate) < grind_5_derisk_grinds)
    ):
      # if (
      #   self.system_v4_grind_5_use_derisk
      #   and (grind_5_sub_grind_count > 0)
      #   and (grind_5_current_grind_profit_stake < (slice_amount * grind_5_derisk_grinds))
      #   and (grind_5_orders[-1].order_date_utc.replace(tzinfo=None) >= datetime(2025, 8, 3) or is_backtest)
      # ):
      sell_amount = grind_5_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_5_current_open_rate > 0.0:
          grind_profit = (
            -((exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate)
            if grind_5_is_exit_found
            else profit_ratio
          )
        if send_notifications:
          send_msg(
            notification_msg(
              "grinding-derisk",
              tag="grind_5_derisk",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_5_current_grind_profit_stake,
              grind_profit_pct=grind_profit,
              coin_amount=grind_5_total_amount,
            )
          )
        log.info(
          f"Grinding de-risk (grind_5_derisk) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_5_current_grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = "grind_5_derisk"
        for grind_entry_id in grind_5_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Rebuy

    # if (
    #   is_system_v4
    #   and is_short_rebuy_entry
    #   and (
    #     (0 <= rebuy_sub_grind_count < rebuy_max_sub_grinds)
    #     and (slice_profit_entry < rebuy_sub_thresholds[rebuy_sub_grind_count])
    #   )
    #   and is_not_trade_max_stake_v4
    # ):
    #   buy_amount = slice_amount * rebuy_stakes[rebuy_sub_grind_count] / trade_leverage
    #   if buy_amount < (min_stake * 1.5):
    #     buy_amount = min_stake * 1.5
    #   if buy_amount > max_stake:
    #     return None
    #   send_msg(
    #     notification_msg(
    #       "rebuy",
    #       tag="rebuy_entry",
    #       pair=trade_pair,
    #       rate=current_rate,
    #       stake_amount=buy_amount,
    #       profit_stake=profit_stake,
    #       profit_ratio=profit_ratio,
    #       stake_currency=stake_currency,
    #     )
    #   )
    #   log.info(
    #     f"Rebuy (rebuy_entry) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
    #   )
    #   if has_order_tags:
    #     return buy_amount, "rebuy_entry"
    #   else:
    #     return buy_amount

    return None

  def short_grind_entry_v4(
    self,
    last_candle: Series,
    previous_candle: Series,
    slice_profit: float,
    slice_profit_entry: float,
    is_derisk: bool,
  ) -> float:
    if last_candle["protections_short_global"] != True:
      return False
    # g0 — signal entry
    if last_candle["enter_short"] == True:
      self._grind_entry_tag = "g0"
      return True
    last_close = last_candle["close"]
    last_open = last_candle["open"]
    last_close_max_12 = last_candle["close_max_12"]
    last_close_min_48 = last_candle["close_min_48"]
    last_low_min_24_1h = last_candle["low_min_24_1h"]
    last_high_max_12_4h = last_candle["high_max_12_4h"]
    last_high_max_24_4h = last_candle["high_max_24_4h"]
    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_3_15m = last_candle["RSI_3_15m"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_rsi_3_4h = last_candle["RSI_3_4h"]
    last_rsi_3_1d = last_candle["RSI_3_1d"]
    last_rsi_14 = last_candle["RSI_14"]
    last_rsi_14_1h = last_candle["RSI_14_1h"]
    last_rsi_14_4h = last_candle["RSI_14_4h"]
    last_rsi_20 = last_candle["RSI_20"]
    last_sma_9 = last_candle["SMA_9"]
    last_sma_16 = last_candle["SMA_16"]
    last_sma_21 = last_candle["SMA_21"]
    last_sma_30 = last_candle["SMA_30"]
    last_ema_9 = last_candle["EMA_9"]
    last_ema_12 = last_candle["EMA_12"]
    last_ema_16 = last_candle["EMA_16"]
    last_ema_20 = last_candle["EMA_20"]
    last_ema_26 = last_candle["EMA_26"]
    last_ema_100 = last_candle["EMA_100"]
    last_ema_12_4h = last_candle["EMA_12_4h"]
    last_ema_50_4h = last_candle["EMA_50_4h"]
    last_ema_100_4h = last_candle["EMA_100_4h"]
    last_ema_200_4h = last_candle["EMA_200_4h"]
    last_roc_9_1h = last_candle["ROC_9_1h"]
    last_roc_9_4h = last_candle["ROC_9_4h"]
    last_roc_9_1d = last_candle["ROC_9_1d"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_stochrsi_k_1h = last_candle["STOCHRSIk_14_14_3_3_1h"]
    last_stochrsi_k_4h = last_candle["STOCHRSIk_14_14_3_3_4h"]
    last_stochrsi_k_1d = last_candle["STOCHRSIk_14_14_3_3_1d"]
    last_willr_14 = last_candle["WILLR_14"]
    last_willr_84_1h = last_candle["WILLR_84_1h"]
    last_bbu = last_candle["BBU_20_2.0"]
    last_bbb_1h = last_candle["BBB_20_2.0_1h"]
    last_cmf_20 = last_candle["CMF_20"]
    last_aroonu_14 = last_candle["AROONU_14"]
    last_aroonu_14_15m = last_candle["AROONU_14_15m"]
    last_aroonu_14_1d = last_candle["AROONU_14_1d"]
    last_aroonu_14_1h = last_candle["AROONU_14_1h"]
    last_aroonu_14_4h = last_candle["AROONU_14_4h"]
    last_stochrsi_k_15m = last_candle["STOCHRSIk_14_14_3_3_15m"]
    prev_rsi_20 = previous_candle["RSI_20"]
    prev_sma_9 = previous_candle["SMA_9"]
    prev_sma_21 = previous_candle["SMA_21"]
    prev_ema_12 = previous_candle["EMA_12"]
    prev_ema_26 = previous_candle["EMA_26"]

    # g1 — AROONU rally + EMA_16 rise (mirror long g1)
    if (
      (last_rsi_3 < 90.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_3_1h < 85.0)
      and (last_rsi_3_4h < 85.0)
      and (last_rsi_14 > 55.0)
      and (last_aroonu_14 > 75.0)
      and (last_aroonu_14_4h > 0.0)
      and (last_roc_9_1h > -20.0)
      and (last_close < (last_close_min_48 * 1.10))
      and (last_close > (last_high_max_24_4h * 0.40))
      and (last_close > (last_ema_16 * 1.025))
      and ((last_rsi_3_1h < 65.0) or (last_aroonu_14_1h > 0.0))
      and ((last_aroonu_14_1h > 0.0) or (last_aroonu_14_1d > 0.0))
      and ((last_aroonu_14_1d > 0.0) or (last_stochrsi_k_1h > 10.0))
    ):
      self._grind_entry_tag = "g1"
      return True
    # g2 — EMA_12 > EMA_26 divergence + BBU (mirror long g2)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 85.0)
      and (last_rsi_3_4h < 85.0)
      and (last_rsi_14 > 70.0)
      and (last_stochrsi_k > 70.0)
      and (last_ema_12 > last_ema_26)
      and ((last_ema_12 - last_ema_26) > (last_open * 0.020))
      and ((prev_ema_12 - prev_ema_26) > (last_open / 100.0))
      and (last_close > (last_bbu * 0.990))
    ):
      self._grind_entry_tag = "g2"
      return True
    # g3 — AROONU_15m rally + EMA_12 rise (mirror long g3)
    if (
      (last_rsi_3 < 90.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 90.0)
      and (last_rsi_3_4h < 85.0)
      and (last_rsi_14 > 65.0)
      and (last_aroonu_14_15m > 75.0)
      and (last_stochrsi_k_15m > 30.0)
      and (last_stochrsi_k_1h > 10.0)
      and (last_roc_9_1h < 15.0)
      and (last_roc_9_4h < 15.0)
      and (last_close < (last_close_min_48 * 1.15))
      and (last_close > (last_ema_12 * 1.020))
      and ((last_rsi_3_1h < 80.0) or (last_rsi_3_1d < 80.0))
      and ((last_rsi_3_1h < 80.0) or (last_stochrsi_k_1d > 30.0))
      and ((last_rsi_3_1h < 75.0) or (last_stochrsi_k_1h > 30.0))
      and ((last_rsi_3_4h < 70.0) or (last_stochrsi_k_4h > 40.0))
    ):
      self._grind_entry_tag = "g3"
      return True
    # g4 — multi-TF RSI + EMA_26 + BBU (mirror long g4)
    if (
      (last_rsi_3 < 90.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 90.0)
      and (last_rsi_3_4h < 90.0)
      and (last_rsi_3_1d < 90.0)
      and (last_rsi_14 > 65.0)
      and (last_aroonu_14 > 75.0)
      and (last_roc_9_1h < 20.0)
      and (last_roc_9_4h < 20.0)
      # and (last_close < (last_close_min_48 * 1.10))
      and (last_close > (last_ema_26 * 1.030))
      and (last_close > (last_bbu * 1.001))
    ):
      self._grind_entry_tag = "g4"
      return True
    # g5 — rally top + EMA_9/20 (mirror long g5)
    if (
      (last_rsi_3 < 90.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 85.0)
      and (last_rsi_3_4h < 85.0)
      and (last_rsi_14 > 65.0)
      and (last_aroonu_14 > 70.0)
      and (last_roc_9_4h < 20.0)
      and (last_close < (last_low_min_24_1h * 1.20))
      and (last_close > (last_high_max_12_4h * 0.50))
      and (last_close > (last_ema_9 * 1.025))
      and (last_close > (last_ema_20 * 1.030))
    ):
      self._grind_entry_tag = "g5"
      return True
    # g6 — RSI_20 rising + SMA_16 rise (mirror long g6)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3 > 60.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_14 < 65.0)
      and (last_roc_9_1h < 20.0)
      and (last_roc_9_4h < 20.0)
      and (last_aroonu_14 > 75.0)
      and (last_close > (last_high_max_12_4h * 0.40))
      and (last_rsi_20 > prev_rsi_20)
      and (last_close > (last_sma_16 * 1.040))
      and ((last_aroonu_14_1d > 0.0) or (last_roc_9_1d > -50.0))
    ):
      self._grind_entry_tag = "g6"
      return True
    # g7 — WILLR overbought + BBB wide (mirror long g7)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 80.0)
      and (last_rsi_3_1h < 80.0)
      and (last_rsi_3_4h < 80.0)
      and (last_willr_14 > -50.0)
      and (last_willr_84_1h > -30.0)
      and (last_stochrsi_k > 70.0)
      and (last_stochrsi_k_1h > 10.0)
      and (last_roc_9_1h < 10.0)
      and (last_roc_9_1h > -20.0)
      and (last_roc_9_4h < 10.0)
      and (last_close > (last_high_max_24_4h * 0.50))
      and (last_bbb_1h > 12.0)
      and (last_close_min_48 <= (last_close * 0.90))
    ):
      self._grind_entry_tag = "g7"
      return True
    # g8 — EMA_12/26 gap wide + high_max_24_1h (mirror long g8)
    if (
      (last_rsi_3 > 70.0)
      and (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 90.0)
      and (last_rsi_3_4h < 90.0)
      and (last_roc_9_1h < 10.0)
      and (last_roc_9_4h < 25.0)
      # and (last_close > (last_candle["high_max_24_1h"] * 0.70))
      and (last_ema_12 > last_ema_26)
      and ((last_ema_12 - last_ema_26) > (last_open * 0.030))
      and ((prev_ema_12 - prev_ema_26) > (last_open / 100.0))
    ):
      self._grind_entry_tag = "g8"
      return True
    # g9 — pullback fade (mirror long g9)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_3_1h < 80.0)
      and (last_rsi_3_4h < 80.0)
      and (last_stochrsi_k > 50.0)
      and (last_close > (last_close_min_48 * 1.10))
      and (last_close < (last_close_max_12 * 0.97))
    ):
      self._grind_entry_tag = "g9"
      return True
    # g10 — RSI_14 divergence vs 1h (mirror long g10)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 80.0)
      and (last_stochrsi_k > 80.0)
      and (last_rsi_14 > (last_rsi_14_1h + 45.0))
    ):
      self._grind_entry_tag = "g10"
      return True
    # g11 — multi-TF RSI + SMA_30 + BBU (mirror long g11)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 90.0)
      and (last_cmf_20 < 0.0)
      and (last_close > (last_sma_30 * 1.035))
      and (last_close > (last_bbu * 1.000))
    ):
      self._grind_entry_tag = "g11"
      return True
    # g12 — EMA_12/26 divergence + close_min_48 (mirror long g12)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_3_1h < 90.0)
      and (last_stochrsi_k > 70.0)
      and (last_close < (last_close_min_48 * 1.10))
      and (last_close > (last_high_max_12_4h * 0.40))
      and (last_ema_12 > last_ema_26)
      and ((last_ema_12 - last_ema_26) > (last_open * 0.025))
      and ((prev_ema_12 - prev_ema_26) > (last_open / 100.0))
    ):
      self._grind_entry_tag = "g12"
      return True
    # g13 — SMA_9 cross SMA_21 down + EMA_100 rise (mirror long g13)
    if (
      (last_rsi_3 < 95.0)
      and (last_rsi_3_1h < 80.0)
      and (last_rsi_14_1h < 60.0)
      and (last_stochrsi_k_15m > 20.0)
      and (last_roc_9_1h < 15.0)
      and (last_roc_9_4h < 15.0)
      and (prev_sma_9 > prev_sma_21)
      and (last_sma_9 < last_sma_21)
      and (last_close > (last_ema_100 * 1.025))
      and ((last_rsi_3_4h < 70.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_4h < 60.0) or (last_roc_9_4h > -30.0))
    ):
      self._grind_entry_tag = "g13"
      return True
    # g14 — SMA_9 cross down + 4h downtrend (trend follower) (mirror long g14)
    if (
      (last_rsi_3 < 95.0)
      and (last_aroonu_14_15m > 50.0)
      and (last_stochrsi_k > 60.0)
      and (last_stochrsi_k_15m > 30.0)
      and (prev_sma_9 > prev_sma_21)
      and (last_sma_9 < last_sma_21)
      and (last_ema_12_4h < last_ema_200_4h)
      and (last_close < (last_close_min_48 * 1.10))
      and ((last_rsi_3_1h < 70.0) or (last_stochrsi_k_1h > 30.0))
      and ((last_rsi_3_1h < 60.0) or (last_aroonu_14_1h > 20.0))
      and ((last_rsi_3_1h < 45.0) or (last_stochrsi_k_1h > 30.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1d < 75.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_stochrsi_k_1h > 20.0) or (last_stochrsi_k_1d > 10.0))
    ):
      self._grind_entry_tag = "g14"
      return True
    # g15 — deep loss recovery (slice_profit > 0.16, positive = adverse move for a short) (mirror long g15)
    if (
      (slice_profit > 0.16)
      and (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 90.0)
      and (last_rsi_14 > 60.0)
      and (last_aroonu_14 > 75.0)
      and (last_aroonu_14_15m > 70.0)
      and (last_stochrsi_k > 70.0)
      and (last_stochrsi_k_15m > 70.0)
      and ((last_rsi_3_1h < 70.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_rsi_3_4h < 70.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1d < 70.0) or (last_stochrsi_k_1d > 20.0))
    ):
      self._grind_entry_tag = "g15"
      return True
    # g16 — EMA_12 rise + BBU (mirror long g16)
    if (
      (last_rsi_3 < 92.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_3_1h < 85.0)
      and (last_rsi_3_4h < 85.0)
      and (last_rsi_14 > 65.0)
      and (last_close > (last_ema_12 * 1.035))
      and (last_close > (last_bbu * 1.001))
    ):
      self._grind_entry_tag = "g16"
      return True
    # g17 — StochRSI + EMA_20 rise (mirror long g17)
    if (
      (last_rsi_3 < 85.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_3_1h < 85.0)
      and (last_rsi_3_4h < 85.0)
      and (last_rsi_14 > 70.0)
      and (last_stochrsi_k > 70.0)
      and (last_close > (last_ema_20 * 1.025))
      and ((last_aroonu_14_4h > 0.0) or (last_aroonu_14_1d > 0.0))
    ):
      self._grind_entry_tag = "g17"
      return True
    # g18 — moderate loss recovery (slice_profit > 0.10, positive = adverse move for a short) (mirror long g18)
    if (
      (slice_profit > 0.10)
      and (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_3_1h < 80.0)
      and (last_rsi_3_4h < 80.0)
      and (last_rsi_14 > 60.0)
      and (last_close > (last_ema_26 * 1.030))
      and (last_close > (last_bbu * 1.001))
    ):
      self._grind_entry_tag = "g18"
      return True
    # g19 — EMA_12/26 wide gap (slice_profit > 0.06, positive = adverse move for a short) (mirror long g19)
    if (
      (slice_profit > 0.06)
      and (last_rsi_3 > 70.0)
      and (last_rsi_3 < 95.0)
      and (last_rsi_3_15m < 90.0)
      and (last_ema_12 > last_ema_26)
      and ((last_ema_12 - last_ema_26) > (last_open * 0.035))
      and ((prev_ema_12 - prev_ema_26) > (last_open / 100.0))
    ):
      self._grind_entry_tag = "g19"
      return True
    # g20 — AROONU 4h downtrend bounce fade (mirror long g20)
    if (
      (last_rsi_3 < 90.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_3_1h < 80.0)
      and (last_rsi_14 > 58.0)
      and (last_rsi_14_4h < 50.0)
      and (last_aroonu_14 > 70.0)
      and (last_aroonu_14_4h < 50.0)
      and (last_roc_9_1d < 15.0)
      and (last_ema_50_4h < last_ema_100_4h)
      and (last_close > (last_close_min_48 * 1.05))
      and ((last_rsi_3_15m < 80.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1h < 70.0) or (last_roc_9_4h > -30.0) or (last_roc_9_1d > -30.0))
      and ((last_rsi_3_1h < 50.0) or (last_roc_9_1d > -60.0))
      and ((last_rsi_3_4h < 60.0) or (last_aroonu_14_4h > 10.0))
      and ((last_rsi_3_4h < 55.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_4h < 40.0) or (last_roc_9_4h > -40.0))
      and ((last_aroonu_14_4h > 0.0) or (last_stochrsi_k_1d > 20.0))
      and ((last_aroonu_14_4h > 0.0) or (last_aroonu_14_1d > 0.0))
      and ((last_stochrsi_k_4h > 10.0) or (last_roc_9_4h > -30.0))
    ):
      self._grind_entry_tag = "g20"
      return True
    # g21 — EMA_20 rise (slice_profit_entry > 0.02, positive = adverse move for a short) (mirror long g21)
    if (
      (slice_profit_entry > 0.02)
      and (last_rsi_3 < 90.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_14 > 65.0)
      and (last_aroonu_14_15m > 50.0)
      and (last_close > (last_ema_20 * 1.045))
    ):
      self._grind_entry_tag = "g21"
      return True
    # g22 — early breakdown rebuild: rejecting off the high BEFORE the 4h trend confirms (g14 needs
    #        EMA_12_4h < EMA_200_4h and fires too late for a deep-derisk rejection). Anti-fake-drop gating via
    #        multi-TF RSI weakness + rejection off the 4h high + not-extended. (mirror long g22)
    if (
      (last_rsi_3 < 70.0)
      and (last_rsi_3_15m < 70.0)
      and (last_rsi_14 < 55.0)
      and (last_rsi_14_1h < 55.0)
      and (last_roc_9_1h < 0.0)
      and (last_roc_9_4h < 10.0)
      # anti-capitulative: even at a formed top, a capitulative 4h overshoot reverses (dead-bounce).
      # cross-coin (SFP/CELR/DYDX/APE): cuts 17 severe at ~1% good cost within breakdown-starts.
      and (last_roc_9_4h > -25.0)
      # breakdown-started gate: only rebuild once the 4h top is IN (not still making new highs).
      # g22's job is the breakdown rebuild — NOT entering mid-pump (that's g1..g21). AROOND low =
      # a fresh 4h high was just made = still pumping; require it high = top formed = breakdown start.
      and (last_aroonu_14_4h > 50.0)
      # aggressive risk-free: g22 fires ONLY deep above the 4h 200-EMA (fresh breakdown zone). The
      # near/below-EMA overextended-pullback zone is where dead-cats live AND where g22's late-breakdown
      # adds sit — we sacrifice those wins on purpose, because g23 (extended-continuation, ~0.2% severe)
      # backstops the real breakdowns below. So g22 stays clean, g23 captures the continuation.
      and (last_close > last_ema_200_4h)
      and (last_close < (last_high_max_12_4h * 0.90))
      and (last_close < (last_ema_20 * 1.03))
      and (last_close > (last_ema_20 * 0.98))
      and ((last_rsi_3_1h < 70.0) or (last_stochrsi_k_1d > 20.0))
      and ((last_rsi_3_1h < 65.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_4h < 50.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1d < 90.0) or (last_aroonu_14_1d > 30.0))
      and ((last_rsi_3_1d < 90.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1d < 85.0) or (last_aroonu_14_1h > 30.0))
      and ((last_rsi_3_1d < 60.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_rsi_3_1d < 60.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1d < 55.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1d < 55.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_1d < 55.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_rsi_3_1d < 55.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 50.0) or (last_aroonu_14_15m > 0.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1d < 35.0) or (last_aroonu_14_1h > 30.0) or (last_aroonu_14_1d > 10.0))
      and ((last_aroonu_14_15m > 30.0) or (last_aroonu_14_1h > 0.0))
      and ((last_aroonu_14_15m > 20.0) or (last_stochrsi_k_15m > 20.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1h > 20.0) or (last_stochrsi_k_1h > 20.0) or (last_stochrsi_k_1d > 10.0))
      and ((last_aroonu_14_1h > 0.0) or (last_stochrsi_k_1d > 20.0))
      and ((last_stochrsi_k_1h > 50.0) or (last_roc_9_1d < 40.0))
      and ((last_roc_9_1d < 20.0) or (last_aroonu_14_4h > 0.0))
      and ((last_roc_9_1d < 20.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_roc_9_1d < 30.0) or (last_stochrsi_k_1h > 10.0))
    ):
      self._grind_entry_tag = "g22"
      return True
    # g23 — breakdown-continuation scalp: extended zone BELOW g22's EMA_20*0.98 cap. Only rides a CONFIRMED
    # continuation (price already declining past the rejection), so dead-bounces (which roll over before
    # reaching the extended zone) are structurally avoided. Complements g22: g22 = early breakdown-start,
    # g23 = confirmed continuation. (mirror long g23)
    if (
      (last_rsi_3 < 70.0)
      and (last_rsi_3_15m < 70.0)
      and (last_rsi_14 < 50.0)
      and (last_rsi_14_1h < 50.0)
      and (last_roc_9_1h < 0.0)
      and (last_roc_9_4h < 0.0)
      # anti-capitulative blow-off + anti-exhaustion bottom
      and (last_roc_9_4h > -25.0)
      and ((last_stochrsi_k > 3.0) or (last_rsi_14 > 20.0))
      and (last_close < (last_high_max_12_4h * 0.90))
      # extended zone: below g22's 0.98*EMA cap = continuation confirmed, not a rejection
      and (last_close <= (last_ema_20 * 0.98))
      and (last_close > (last_ema_20 * 0.88))
      and ((last_rsi_3_1h < 55.0) or (last_aroonu_14_4h > 20.0))
      and ((last_rsi_3_1h < 35.0) or (last_aroonu_14_15m > 40.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 35.0) or (last_stochrsi_k_15m > 40.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_4h < 60.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_rsi_3_4h < 50.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_1d < 85.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_rsi_3_1d < 70.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1d < 70.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_1d < 60.0) or (last_aroonu_14_15m > 20.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1d < 50.0) or (last_stochrsi_k_1h > 20.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 45.0) or (last_aroonu_14_15m > 0.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_aroonu_14_15m > 20.0) or (last_aroonu_14_1h > 0.0) or (last_roc_9_1d > -10.0))
      and ((last_aroonu_14_15m > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_1h > 0.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_4h > 0.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_1d > 10.0) or (last_roc_9_1d > -20.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_1d > 0.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_15m > 10.0) or (last_stochrsi_k_1d > 30.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_aroonu_14_1h > 20.0) or (last_aroonu_14_4h > 0.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_aroonu_14_1h > 0.0) or (last_aroonu_14_4h > 0.0))
      and ((last_aroonu_14_4h > 30.0) or (last_aroonu_14_1d > 0.0) or (last_roc_9_4h > -10.0))
      and ((last_aroonu_14_4h > 30.0) or (last_roc_9_1d > -50.0))
      and ((last_aroonu_14_4h > 0.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_aroonu_14_4h > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1d > 0.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_stochrsi_k_15m > 20.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_stochrsi_k_15m > 10.0) or (last_aroonu_14_1h > 0.0))
      and ((last_stochrsi_k_15m > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_stochrsi_k_1h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_stochrsi_k_1h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_stochrsi_k_1h > 10.0) or (last_stochrsi_k_1d > 10.0))
    ):
      self._grind_entry_tag = "g23"
      return True
    # g24 — downtrend-bounce continuation add: the zone BELOW the 4h 200-EMA that g22 explicitly sacrifices.
    # (mirror long g24)
    if (
      # momentum healthy on the bounce: RSI holds up (a real reversal cracks RSI hard)
      (last_rsi_3 < 80.0)
      and (last_rsi_3_15m < 80.0)
      and (last_rsi_14 < 60.0)
      # trend intact + this is a BOUNCE not a reversal: 4h still falling, 1h not in melt-up
      and (last_roc_9_1h < 10.0)
      and (last_roc_9_4h < 0.0)
      and (last_roc_9_4h > -25.0)  # anti-parabolic blow-off top
      # bear scope-gate: confirmed 4h downtrend + price below the 200-EMA regime (complements g22's <200EMA)
      and (last_ema_12_4h < last_ema_200_4h)
      and (last_close < last_ema_200_4h)
      # shallow bounce to the short EMA — sell the dip WITHIN the trend, never the bottom nor a deep pump
      and (last_close > (last_ema_20 * 0.99))
      and (last_close < (last_ema_20 * 1.06))
      and ((last_rsi_3_15m < 60.0) or (last_stochrsi_k_15m > 30.0))
      and ((last_rsi_3_1h < 90.0) or (last_rsi_3_4h < 70.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1h < 90.0) or (last_aroonu_14_1h > 40.0))
      and ((last_rsi_3_1h < 85.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_1h < 75.0) or (last_rsi_3_4h < 55.0) or (last_stochrsi_k_4h > 50.0))
      and ((last_rsi_3_1h < 75.0) or (last_aroonu_14_1h > 30.0))
      and ((last_rsi_3_1h < 75.0) or (last_rsi_3_1d < 55.0) or (last_aroonu_14_1d > 30.0))
      and ((last_rsi_3_1h < 75.0) or (last_aroonu_14_1h > 20.0))
      and ((last_rsi_3_1h < 70.0) or (last_rsi_3_4h < 40.0) or (last_aroonu_14_1d > 30.0))
      and ((last_rsi_3_1h < 70.0) or (last_rsi_3_4h < 40.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1h < 70.0) or (last_stochrsi_k_1d > 20.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_1h < 65.0) or (last_rsi_3_4h < 55.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1h < 65.0) or (last_aroonu_14_1h > 40.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_1h < 65.0) or (last_stochrsi_k_1d > 10.0) or (last_roc_9_1d > -20.0))
      and ((last_rsi_3_1h < 60.0) or (last_rsi_3_4h < 60.0) or (last_aroonu_14_1d > 10.0))
      and ((last_rsi_3_1h < 60.0) or (last_rsi_3_4h < 35.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 60.0) or (last_rsi_3_1d < 40.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_1h < 60.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1h < 60.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_1h < 60.0) or (last_aroonu_14_1d > 0.0) or (last_roc_9_1d > -20.0))
      and ((last_rsi_3_1h < 60.0) or (last_stochrsi_k_1d > 20.0) or (last_roc_9_1d > -50.0))
      and ((last_rsi_3_1h < 65.0) or (last_rsi_3_4h < 50.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 60.0) or (last_rsi_3_4h < 45.0) or (last_aroonu_14_4h > 10.0))
      and ((last_rsi_3_1h < 55.0) or (last_rsi_3_4h < 55.0) or (last_rsi_3_1d < 55.0) or (last_stochrsi_k_4h > 50.0))
      and ((last_rsi_3_1h < 55.0) or (last_aroonu_14_4h > 20.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_1h < 55.0) or (last_rsi_3_4h < 55.0) or (last_aroonu_14_4h > 40.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_1h > 20.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1h < 50.0) or (last_rsi_3_4h < 45.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_1h > 30.0) or (last_aroonu_14_1d > 30.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_4h > 20.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_4h > 20.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_4h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1h < 45.0) or (last_rsi_3_4h < 45.0) or (last_stochrsi_k_15m > 30.0))
      and ((last_rsi_3_1h < 45.0) or (last_aroonu_14_1h > 20.0) or (last_aroonu_14_4h > 20.0))
      and ((last_rsi_3_1h < 45.0) or (last_stochrsi_k_4h > 10.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_1h < 40.0) or (last_aroonu_14_15m > 30.0) or (last_aroonu_14_4h > 20.0))
      and ((last_rsi_3_1h < 40.0) or (last_stochrsi_k_1h > 40.0) or (last_stochrsi_k_1d > 10.0))
      and ((last_rsi_3_1h < 35.0) or (last_aroonu_14_15m > 30.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1h < 35.0) or (last_aroonu_14_1h > 30.0) or (last_aroonu_14_1d > 10.0))
      and ((last_rsi_3_1h < 35.0) or (last_aroonu_14_1h > 0.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_4h < 75.0) or (last_roc_9_1d > -30.0))
      and ((last_rsi_3_4h < 60.0) or (last_rsi_3_1d < 40.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_4h < 60.0) or (last_aroonu_14_15m > 30.0) or (last_aroonu_14_1d > 10.0))
      and ((last_rsi_3_4h < 60.0) or (last_aroonu_14_1d > 10.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_4h < 60.0) or (last_stochrsi_k_15m > 40.0) or (last_aroonu_14_1d > 10.0))
      and ((last_rsi_3_4h < 55.0) or (last_rsi_3_1d < 55.0) or (last_aroonu_14_15m > 40.0))
      and ((last_rsi_3_4h < 55.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_4h < 55.0) or (last_rsi_3_1d < 55.0) or (last_stochrsi_k_15m > 40.0))
      and ((last_rsi_3_4h < 50.0) or (last_aroonu_14_4h > 30.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_4h < 55.0) or (last_rsi_3_1d < 55.0) or (last_stochrsi_k_1h > 40.0))
      and ((last_rsi_3_4h < 50.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_4h < 55.0) or (last_rsi_3_1d < 55.0) or (last_stochrsi_k_4h > 40.0))
      and ((last_rsi_3_4h < 45.0) or (last_aroonu_14_15m > 30.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_4h < 40.0) or (last_rsi_3_1d < 35.0) or (last_aroonu_14_15m > 30.0))
      and ((last_rsi_3_4h < 40.0) or (last_aroonu_14_15m > 10.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_rsi_3_4h < 40.0) or (last_aroonu_14_15m > 0.0) or (last_stochrsi_k_15m > 20.0))
      and ((last_rsi_3_4h < 40.0) or (last_stochrsi_k_15m > 30.0) or (last_stochrsi_k_1h > 30.0))
      and ((last_rsi_3_4h < 40.0) or (last_stochrsi_k_1h > 40.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_rsi_3_1d < 70.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 65.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_rsi_3_1d < 65.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_rsi_3_1d < 65.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1d < 60.0) or (last_aroonu_14_1h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 55.0) or (last_aroonu_14_15m > 50.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_rsi_3_1d < 55.0) or (last_stochrsi_k_1h > 30.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1d < 50.0) or (last_aroonu_14_15m > 40.0) or (last_aroonu_14_1h > 0.0))
      and ((last_rsi_3_1d < 50.0) or (last_aroonu_14_4h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 55.0) or (last_aroonu_14_1h > 20.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_rsi_3_1d < 55.0) or (last_aroonu_14_1d > 30.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1d < 50.0) or (last_stochrsi_k_15m > 10.0) or (last_roc_9_1d > -10.0))
      and ((last_rsi_3_1d < 50.0) or (last_stochrsi_k_1h > 20.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 40.0) or (last_aroonu_14_1h > 20.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_14_1h > 30.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_15m > 20.0) or (last_aroonu_14_1h > 20.0) or (last_aroonu_14_4h > 20.0))
      and ((last_aroonu_14_15m > 20.0) or (last_stochrsi_k_15m > 30.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_aroonu_14_15m > 20.0) or (last_aroonu_14_1d > 0.0))
      and ((last_aroonu_14_15m > 20.0) or (last_stochrsi_k_15m > 20.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_aroonu_14_15m > 10.0) or (last_aroonu_14_1h > 20.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_aroonu_14_15m > 10.0) or (last_aroonu_14_1h > 0.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_1h > 0.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_4h > 0.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_1d > 20.0) or (last_roc_9_1d > -10.0))
      and ((last_aroonu_14_1h > 30.0) or (last_aroonu_14_4h > 0.0))
      and ((last_aroonu_14_1h > 30.0) or (last_aroonu_14_1d > 10.0) or (last_roc_9_1d > -10.0))
      and ((last_aroonu_14_1h > 20.0) or (last_aroonu_14_4h > 0.0))
      and ((last_aroonu_14_1h > 10.0) or (last_stochrsi_k_1h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1h > 10.0) or (last_stochrsi_k_1h > 10.0) or (last_roc_9_1d > -10.0))
      and ((last_aroonu_14_1h > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1h > 0.0) or (last_stochrsi_k_1d > 10.0))
      and ((last_aroonu_14_4h > 30.0) or (last_aroonu_14_1d > 0.0) or (last_roc_9_1d > -20.0))
      and ((last_aroonu_14_4h > 10.0) or (last_stochrsi_k_4h > 10.0) or (last_roc_9_1d > -10.0))
      and ((last_aroonu_14_4h > 10.0) or (last_roc_9_1d > -30.0))
      and ((last_aroonu_14_4h > 0.0) or (last_aroonu_14_1d > 0.0))
      and ((last_aroonu_14_4h > 0.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_aroonu_14_4h > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1d > 0.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_aroonu_14_1d > 0.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_aroonu_14_1d > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1d > 0.0) or (last_roc_9_4h > -15.0) or (last_roc_9_1d > -50.0))
      # do not sell an oversold bottom on the pullback
      and ((last_stochrsi_k > 10.0) or (last_rsi_14 > 30.0))
      and ((last_stochrsi_k_15m > 20.0) or (last_stochrsi_k_1h > 20.0) or (last_roc_9_1d > -10.0))
      and ((last_stochrsi_k_15m > 20.0) or (last_aroonu_14_1d > 0.0))
      and ((last_stochrsi_k_15m > 20.0) or (last_stochrsi_k_1d > 10.0) or (last_roc_9_1d > -20.0))
      and ((last_stochrsi_k_15m > 10.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_stochrsi_k_15m > 10.0) or (last_stochrsi_k_1d > 10.0))
      and ((last_stochrsi_k_1h > 20.0) or (last_stochrsi_k_1d > 10.0))
      and ((last_stochrsi_k_1h > 20.0) or (last_roc_9_1d < 20.0))
      and ((last_stochrsi_k_1h > 10.0) or (last_roc_9_4h > -15.0))
      and ((last_stochrsi_k_4h > 10.0) or (last_roc_9_4h > -15.0))
      and ((last_stochrsi_k_4h > 10.0) or (last_roc_9_1d < 15.0))
      and ((last_stochrsi_k_1d > 10.0) or (last_roc_9_4h > -20.0))
    ):
      self._grind_entry_tag = "g24"
      return True
    # g27 — coil (mirror of long g27)
    if (
      (last_rsi_3 < 85.0)
      and (last_rsi_3_15m < 85.0)
      and (last_rsi_14 < 60.0)
      and (last_rsi_14_1h < 60.0)
      # the coil signature: 1h momentum negative-to-flat under a flat price
      and (last_roc_9_1h < 15.0)
      and (last_roc_9_1h > -2.0)
      and (last_close < (last_ema_20 * 1.02))
      and (last_close > (last_ema_20 * 0.98))
      # squeeze integrity: regime still broken, 4h rejection HELD, not dripping to new highs
      and (last_close > last_ema_200_4h)
      and (last_close < (last_high_max_12_4h * 0.90))
      and (last_close < (last_close_max_12 * 0.995))
      # general protections first
      and ((last_rsi_3_15m < 80.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1h < 85.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_1h < 80.0) or (last_rsi_3_4h < 80.0) or (last_aroonu_14_1d > 10.0))
      and ((last_rsi_3_1h < 80.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_rsi_3_1h < 70.0) or (last_rsi_3_1d < 70.0) or (last_stochrsi_k_1h > 30.0))
      and ((last_rsi_3_1h < 65.0) or (last_aroonu_14_1h > 30.0))
      and ((last_rsi_3_1h < 65.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_1h < 60.0) or (last_aroonu_14_4h > 20.0))
      and ((last_rsi_3_1h < 55.0) or (last_aroonu_14_1h > 10.0) or (last_stochrsi_k_1h > 30.0))
      and ((last_rsi_3_1h < 60.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 55.0) or (last_aroonu_14_1h > 10.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 55.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_1h > 30.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_1h < 45.0) or (last_rsi_3_4h < 40.0) or (last_aroonu_14_4h > 40.0))
      and ((last_rsi_3_1h < 50.0) or (last_aroonu_14_4h > 20.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 50.0) or (last_stochrsi_k_1d > 10.0) or (last_roc_9_1d > -30.0))
      and ((last_rsi_3_1h < 45.0) or (last_aroonu_14_4h > 20.0) or (last_aroonu_14_1d > 0.0))
      and ((last_rsi_3_1h < 45.0) or (last_aroonu_14_4h > 10.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_rsi_3_1h < 40.0) or (last_rsi_3_1d < 40.0) or (last_aroonu_14_1h > 20.0))
      and ((last_rsi_3_1h < 40.0) or (last_stochrsi_k_4h > 30.0) or (last_stochrsi_k_1d > 20.0))
      and ((last_rsi_3_1h < 40.0) or (last_stochrsi_k_4h > 20.0) or (last_roc_9_4h > -10.0))
      and ((last_rsi_3_4h < 90.0) or (last_rsi_3_1d < 60.0) or (last_stochrsi_k_15m > 20.0))
      and ((last_rsi_3_4h < 75.0) or (last_stochrsi_k_4h > 50.0) or (last_roc_9_4h > -10.0))
      and ((last_rsi_3_4h < 65.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_4h < 60.0) or (last_rsi_3_1d < 60.0) or (last_aroonu_14_15m > 30.0))
      and ((last_rsi_3_4h < 60.0) or (last_aroonu_14_15m > 0.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_rsi_3_4h < 60.0) or (last_aroonu_14_1h > 10.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_4h < 60.0) or (last_aroonu_14_4h > 30.0))
      and ((last_rsi_3_4h < 50.0) or (last_aroonu_14_15m > 20.0) or (last_aroonu_14_4h > 20.0))
      and ((last_rsi_3_4h < 50.0) or (last_stochrsi_k_15m > 30.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_4h < 45.0) or (last_aroonu_14_1h > 0.0) or (last_aroonu_14_1d > 20.0))
      and ((last_rsi_3_4h < 40.0) or (last_rsi_3_1d < 40.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_rsi_3_4h < 40.0) or (last_aroonu_14_15m > 30.0) or (last_aroonu_14_1h > 30.0))
      and ((last_rsi_3_4h < 40.0) or (last_aroonu_14_1h > 0.0) or (last_stochrsi_k_1d > 20.0))
      and ((last_rsi_3_4h < 40.0) or (last_stochrsi_k_4h > 30.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_4h < 35.0) or (last_aroonu_14_1h > 30.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_4h < 35.0) or (last_aroonu_14_4h > 20.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_4h < 35.0) or (last_stochrsi_k_4h > 30.0) or (last_roc_9_1d < 10.0))
      and ((last_rsi_3_4h < 35.0) or (last_stochrsi_k_4h > 10.0) or (last_roc_9_4h > -10.0))
      and ((last_rsi_3_1d < 90.0) or (last_stochrsi_k_4h > 30.0))
      and ((last_rsi_3_1d < 80.0) or (last_aroonu_14_1d > 10.0))
      and ((last_rsi_3_1d < 75.0) or (last_stochrsi_k_15m > 30.0))
      and ((last_rsi_3_1d < 75.0) or (last_aroonu_14_1h > 30.0))
      and ((last_rsi_3_1d < 75.0) or (last_stochrsi_k_1h > 10.0))
      and ((last_rsi_3_1d < 70.0) or (last_aroonu_14_15m > 0.0))
      and ((last_rsi_3_1d < 70.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_rsi_3_1d < 60.0) or (last_aroonu_14_1h > 10.0) or (last_aroonu_14_4h > 0.0))
      and ((last_rsi_3_1d < 50.0) or (last_stochrsi_k_4h > 10.0) or (last_stochrsi_k_1d > 30.0))
      and ((last_aroonu_14_15m > 30.0) or (last_aroonu_14_1h > 0.0) or (last_stochrsi_k_1d > 20.0))
      and ((last_aroonu_14_15m > 30.0) or (last_aroonu_14_4h > 30.0) or (last_roc_9_4h > -10.0))
      and ((last_aroonu_14_15m > 20.0) or (last_stochrsi_k_15m > 30.0))
      and ((last_aroonu_14_15m > 20.0) or (last_aroonu_14_1h > 0.0))
      and ((last_aroonu_14_15m > 0.0) or (last_aroonu_14_4h > 10.0))
      and ((last_aroonu_14_15m > 0.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_1h > 20.0) or (last_aroonu_14_4h > 0.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_aroonu_14_1h > 20.0) or (last_stochrsi_k_4h > 0.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_aroonu_14_1h > 20.0) or (last_stochrsi_k_4h > 10.0) or (last_roc_9_4h > -10.0))
      and ((last_aroonu_14_1h > 0.0) or (last_aroonu_14_1d > 0.0))
      and ((last_aroonu_14_1h > 0.0) or (last_stochrsi_k_15m > 20.0))
      and ((last_aroonu_14_1h > 0.0) or (last_stochrsi_k_4h > 20.0) or (last_roc_9_4h > -10.0))
      and ((last_aroonu_14_1h > 0.0) or (last_stochrsi_k_1d > 10.0) or (last_roc_9_1d > -20.0))
      and ((last_aroonu_14_4h > 30.0) or (last_roc_9_1d < 25.0))
      and ((last_aroonu_14_4h > 30.0) or (last_roc_9_1d > -50.0))
      and ((last_aroonu_14_4h > 20.0) or (last_stochrsi_k_4h > 20.0) or (last_roc_9_4h > -10.0))
      and ((last_aroonu_14_4h > 20.0) or (last_stochrsi_k_1d > 20.0) or (last_roc_9_1d > -10.0))
      and ((last_aroonu_14_4h > 10.0) or (last_stochrsi_k_4h > 10.0))
      and ((last_aroonu_14_4h > 10.0) or (last_roc_9_4h > -10.0))
      and ((last_stochrsi_k_15m > 40.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_stochrsi_k_1h > 30.0) or (last_stochrsi_k_4h > 20.0))
      and ((last_stochrsi_k_1h > 10.0) or (last_roc_9_4h < 20.0))
      and ((last_stochrsi_k_4h > 30.0) or (last_roc_9_1d < 25.0))
      and ((last_stochrsi_k_4h > 20.0) or (last_stochrsi_k_1d > 10.0) or (last_roc_9_1d > -20.0))
      and ((last_roc_9_1d < 40.0) or (last_aroonu_14_1h > 10.0))
      and ((last_roc_9_1d < 40.0) or (last_stochrsi_k_1h > 20.0))
      and ((last_roc_9_1d < 25.0) or (last_stochrsi_k_15m > 10.0))
      and ((last_roc_9_1d < 25.0) or (last_aroonu_14_4h > 20.0))
      and ((last_roc_9_1d < 15.0) or (last_stochrsi_k_4h > 20.0))
    ):
      self._grind_entry_tag = "g27"
      return True

    self._grind_entry_tag = ""
    return False

  def short_rebuy_entry_v4(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    if (last_candle["protections_short_global"] == True) and (
      (last_candle["enter_short"] == True)
      or (
        (last_candle["RSI_3"] < 90.0)
        and (last_candle["RSI_3_15m"] < 90.0)
        and (last_candle["AROOND_14"] < 30.0)
        and (last_candle["AROOND_14_15m"] < 30.0)
        and (last_candle["close"] > (last_candle["EMA_26"] * 1.012))
      )
    ):
      return True

    return False

  # Short Grinding Exit v4 (mirror of long_grind_exit_v4)
  # ---------------------------------------------------------------------------------------------
  def short_grind_exit_v4(
    self,
    last_candle: Series,
    previous_candle: Series,
    slice_profit: float,
    current_time: datetime,
    min_stake: float,
    current_stake_amount: float,
    exit_rate: float,
    profit_stake: float,
    profit_ratio: float,
    name: str,
    tag: str,
    fee_open_rate: float,
    fee_close_rate: float,
    max_profit: float,
    max_profit_rate: float,
    grind_profit_stake: float,
    grind_profit_rate: float,
    grind_total_amount: float,
    grind_exit_profit_threshold: float,
    grind_open_orders,
    trade: Trade,
  ) -> tuple:
    # Normalize so profit is always positive when the short is profitable.
    profit = -grind_profit_rate

    # Not enough profit after fees.
    # Already guarded.
    # if profit < (grind_exit_profit_threshold + fee_open_rate + fee_close_rate):
    # return None, None

    last_rsi_3 = last_candle["RSI_3"]
    last_rsi_14 = last_candle["RSI_14"]
    last_willr_14 = last_candle["WILLR_14"]
    last_stochrsi_k = last_candle["STOCHRSIk_14_14_3_3"]
    last_close = last_candle["close"]
    last_bbl_20 = last_candle["BBL_20_2.0"]

    is_normal_exit = False
    if (
      (last_rsi_3 < 1.0)
      or (last_rsi_14 < 30.0)
      or (last_willr_14 < -99.9)
      or (last_stochrsi_k < 5.0)
      or (last_close < (last_bbl_20 * 0.99))
      or ((last_rsi_3 < 10.0) and (last_rsi_14 > 50.0))
      or (
        (last_rsi_3 < 20.0)
        and (last_candle["RSI_3_1h"] > 80.0)
        and (last_candle["RSI_3_4h"] > 80.0)
        and (last_candle["ROC_9_1d"] < 10.0)
        and (last_candle["BTC_RSI_14_4h"] > 65.0)
      )
    ):
      is_normal_exit = True

    is_trailing_exit = False
    # max_profit = -max_profit_rate
    # drawdown = max_profit - profit
    # if 0.01 <= -grind_profit_rate < 0.02:
    #   if -grind_profit_rate < (-max_profit_rate - 0.025):
    #     is_trailing_exit = True
    # elif 0.02 <= -grind_profit_rate <= 0.05:
    #   if -grind_profit_rate < (-max_profit_rate - 0.035):
    #     is_trailing_exit = True
    # elif 0.05 <= -grind_profit_rate <= 0.08:
    #   if -grind_profit_rate < (-max_profit_rate - 0.045):
    #     is_trailing_exit = True
    # elif 0.08 <= -grind_profit_rate <= 0.12:
    #   if -grind_profit_rate < (-max_profit_rate - 0.050):
    #     is_trailing_exit = True
    # elif 0.12 <= -grind_profit_rate:
    #   if -grind_profit_rate < (-max_profit_rate - 0.055):
    #     is_trailing_exit = True
    # is_trailing_exit = -grind_profit_rate > 0.04
    if is_normal_exit or is_trailing_exit:
      stake_currency = self.config["stake_currency"]
      stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
      trade_pair = trade.pair
      trade_leverage = trade.leverage
      trade_amount = trade.amount
      trade_stake_amount = trade.stake_amount
      exit_amount = grind_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - exit_amount) < (min_stake * 1.55):
        exit_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_exit_amount = exit_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if exit_amount > min_stake and ft_exit_amount > min_stake:
        self.dp.send_msg(
          self.notification_msg(
            "grinding-exit",
            tag=name,
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=exit_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit_stake,
            grind_profit_pct=profit,
            coin_amount=grind_total_amount,
          )
        )
        log.info(
          f"Grinding exit ({name}) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {exit_amount:{stake_fmt}} | Coin amount: {grind_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(profit * 100.0):.2f}% ({grind_profit_stake:{stake_fmt}} {stake_currency})"
        )
        order_tag = tag
        for grind_entry in grind_open_orders:
          order_tag += " " + str(grind_entry.id)
        return -ft_exit_amount, order_tag

    return None, None

  # Short Grinding Adjust Trade Position
  # ---------------------------------------------------------------------------------------------
  def short_grind_adjust_trade_position(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ):
    dp = self.dp
    send_msg = self.dp.send_msg
    notification_msg = self.notification_msg
    scale_stakes_for_min_stake = self.scale_stakes_for_min_stake
    stake_currency = self.config["stake_currency"]
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_stake_amount = trade.stake_amount
    trade_fee_open = trade.fee_open
    trade_fee_close = trade.fee_close

    runmode_value = dp.runmode.value
    is_backtest = runmode_value in ["backtest", "hyperopt"]
    trade_open_date = None if is_backtest else trade.open_date_utc.replace(tzinfo=None)
    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    is_futures = self.is_futures_mode
    derisk_use_grind_stops = self.derisk_use_grind_stops
    short_rebuy_mode_tags = self.short_rebuy_mode_tags
    short_grind_mode_tags = self.short_grind_mode_tags
    trade_leverage = trade.leverage

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)
    if len(df) < 2:
      return None
    last_candle = df.iloc[-1]
    previous_candle = df.iloc[-2]

    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_entries = trade.nr_of_successful_entries
    count_of_exits = trade.nr_of_successful_exits

    if count_of_entries == 0:
      return None

    first_filled_entry = filled_entries[0]
    last_filled_entry = filled_entries[-1]
    last_filled_order = filled_orders[-1]

    has_order_tags = hasattr(filled_orders[0], "ft_order_tag")

    if runmode_value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = self.config["exit_pricing"]["price_side"]
        if trade.is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    slice_amount = first_filled_entry.safe_filled * first_filled_entry.safe_price
    slice_profit = (exit_rate - last_filled_order.safe_price) / last_filled_order.safe_price
    slice_profit_entry = (exit_rate - last_filled_entry.safe_price) / last_filled_entry.safe_price
    slice_profit_exit = (
      ((exit_rate - filled_exits[-1].safe_price) / filled_exits[-1].safe_price) if count_of_exits > 0 else 0.0
    )

    current_stake_amount = trade_amount * current_rate
    is_derisk = trade_amount < (first_filled_entry.safe_filled * 0.95)
    is_derisk_calc = False
    is_rebuy_mode = all(c in short_rebuy_mode_tags for c in enter_tags) or (
      any(c in short_rebuy_mode_tags for c in enter_tags)
      and all(c in (short_rebuy_mode_tags + short_grind_mode_tags) for c in enter_tags)
    )
    is_grind_mode = all(c in short_grind_mode_tags for c in enter_tags)

    fee_open_rate = trade_fee_open if self.custom_fee_open_rate is None else self.custom_fee_open_rate
    fee_close_rate = trade_fee_close if self.custom_fee_close_rate is None else self.custom_fee_close_rate
    stake_scale_leverage = trade_leverage if is_futures else 1.0
    grind_mode_stake_multipliers = (
      self.grind_mode_stake_multiplier_futures if is_futures else self.grind_mode_stake_multiplier_spot
    )
    regular_mode_stake_multipliers = (
      self.regular_mode_stake_multiplier_futures if is_futures else self.regular_mode_stake_multiplier_spot
    )
    grind_entry_retry_time = current_time - timedelta(minutes=10)
    grind_order_age_time = current_time - timedelta(hours=6)
    grind_force_order_age_time = current_time - timedelta(hours=24)

    # Rebuy mode
    if is_rebuy_mode:
      slice_amount /= self.rebuy_mode_stake_multiplier
    # Grind mode
    elif is_grind_mode:
      slice_amount /= grind_mode_stake_multipliers[0]
    elif not is_derisk and (is_backtest or trade_open_date >= datetime(2024, 2, 5)):
      rebuy_stake, order_tag, is_derisk_calc = self.short_adjust_trade_position_no_derisk(
        trade,
        enter_tags,
        current_time,
        current_rate,
        current_profit,
        min_stake,
        max_stake,
        current_entry_rate,
        current_exit_rate,
        current_entry_profit,
        current_exit_profit,
        last_candle,
        previous_candle,
        filled_orders,
        filled_entries,
        filled_exits,
        exit_rate,
        slice_amount,
        slice_profit_entry,
        slice_profit,
        profit_ratio,
        profit_stake,
        profit_init_ratio,
        current_stake_amount,
        has_order_tags,
        count_of_exits,
      )
      if rebuy_stake is not None:
        if has_order_tags:
          return rebuy_stake, order_tag
        else:
          return rebuy_stake
      elif count_of_exits == 0:
        return None
      elif not is_derisk_calc:
        return None

    if not is_rebuy_mode and not is_grind_mode:
      # First entry is lower now, therefore the grinds must adjust
      if is_backtest or trade_open_date >= datetime(2024, 4, 16):
        slice_amount /= regular_mode_stake_multipliers[0]

    is_not_trade_max_stake = current_stake_amount < (
      ((first_filled_entry.safe_filled * first_filled_entry.safe_price) * self.grinding_v1_max_stake)
      / (grind_mode_stake_multipliers[0] if is_grind_mode else 1.0)
    )

    grind_1_max_sub_grinds = 0
    grind_1_stakes = scale_stakes_for_min_stake(
      self.grind_1_stakes_futures if is_futures else self.grind_1_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_1_sub_thresholds = self.grind_1_sub_thresholds_futures if is_futures else self.grind_1_sub_thresholds_spot
    grind_1_max_sub_grinds = len(grind_1_stakes)
    grind_1_stop_grinds = self.grind_1_stop_grinds_futures if is_futures else self.grind_1_stop_grinds_spot
    grind_1_profit_threshold = (
      self.grind_1_profit_threshold_futures if is_futures else self.grind_1_profit_threshold_spot
    )

    grind_2_max_sub_grinds = 0
    grind_2_stakes = scale_stakes_for_min_stake(
      self.grind_2_stakes_futures if is_futures else self.grind_2_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_2_sub_thresholds = self.grind_2_sub_thresholds_futures if is_futures else self.grind_2_sub_thresholds_spot
    grind_2_max_sub_grinds = len(grind_2_stakes)
    grind_2_stop_grinds = self.grind_2_stop_grinds_futures if is_futures else self.grind_2_stop_grinds_spot
    grind_2_profit_threshold = (
      self.grind_2_profit_threshold_futures if is_futures else self.grind_2_profit_threshold_spot
    )

    grind_3_max_sub_grinds = 0
    grind_3_stakes = scale_stakes_for_min_stake(
      self.grind_3_stakes_futures if is_futures else self.grind_3_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_3_sub_thresholds = self.grind_3_sub_thresholds_futures if is_futures else self.grind_3_sub_thresholds_spot
    grind_3_max_sub_grinds = len(grind_3_stakes)
    grind_3_stop_grinds = self.grind_3_stop_grinds_futures if is_futures else self.grind_3_stop_grinds_spot
    grind_3_profit_threshold = (
      self.grind_3_profit_threshold_futures if is_futures else self.grind_3_profit_threshold_spot
    )

    grind_4_max_sub_grinds = 0
    grind_4_stakes = scale_stakes_for_min_stake(
      self.grind_4_stakes_futures if is_futures else self.grind_4_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_4_sub_thresholds = self.grind_4_sub_thresholds_futures if is_futures else self.grind_4_sub_thresholds_spot
    grind_4_max_sub_grinds = len(grind_4_stakes)
    grind_4_stop_grinds = self.grind_4_stop_grinds_futures if is_futures else self.grind_4_stop_grinds_spot
    grind_4_profit_threshold = (
      self.grind_4_profit_threshold_futures if is_futures else self.grind_4_profit_threshold_spot
    )

    grind_5_max_sub_grinds = 0
    grind_5_stakes = scale_stakes_for_min_stake(
      self.grind_5_stakes_futures if is_futures else self.grind_5_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_5_sub_thresholds = self.grind_5_sub_thresholds_futures if is_futures else self.grind_5_sub_thresholds_spot
    grind_5_max_sub_grinds = len(grind_5_stakes)
    grind_5_stop_grinds = self.grind_5_stop_grinds_futures if is_futures else self.grind_5_stop_grinds_spot
    grind_5_profit_threshold = (
      self.grind_5_profit_threshold_futures if is_futures else self.grind_5_profit_threshold_spot
    )

    grind_6_max_sub_grinds = 0
    grind_6_stakes = scale_stakes_for_min_stake(
      self.grind_6_stakes_futures if is_futures else self.grind_6_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_6_sub_thresholds = self.grind_6_sub_thresholds_futures if is_futures else self.grind_6_sub_thresholds_spot
    grind_6_max_sub_grinds = len(grind_6_stakes)
    grind_6_stop_grinds = self.grind_6_stop_grinds_futures if is_futures else self.grind_6_stop_grinds_spot
    grind_6_profit_threshold = (
      self.grind_6_profit_threshold_futures if is_futures else self.grind_6_profit_threshold_spot
    )

    grind_1_derisk_1_max_sub_grinds = 0
    grind_1_derisk_1_stakes = scale_stakes_for_min_stake(
      self.grind_1_derisk_1_stakes_futures if is_futures else self.grind_1_derisk_1_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_1_derisk_1_sub_thresholds = (
      self.grind_1_derisk_1_sub_thresholds_futures if is_futures else self.grind_1_derisk_1_sub_thresholds_spot
    )
    grind_1_derisk_1_max_sub_grinds = len(grind_1_derisk_1_stakes)
    grind_1_derisk_1_stop_grinds = (
      self.grind_1_derisk_1_stop_grinds_futures if is_futures else self.grind_1_derisk_1_stop_grinds_spot
    )
    grind_1_derisk_1_profit_threshold = (
      self.grind_1_derisk_1_profit_threshold_futures if is_futures else self.grind_1_derisk_1_profit_threshold_spot
    )

    grind_2_derisk_1_max_sub_grinds = 0
    grind_2_derisk_1_stakes = scale_stakes_for_min_stake(
      self.grind_2_derisk_1_stakes_futures if is_futures else self.grind_2_derisk_1_stakes_spot,
      slice_amount,
      min_stake,
      stake_scale_leverage,
      trade_leverage,
    )
    grind_2_derisk_1_sub_thresholds = (
      self.grind_2_derisk_1_sub_thresholds_futures if is_futures else self.grind_2_derisk_1_sub_thresholds_spot
    )
    grind_2_derisk_1_max_sub_grinds = len(grind_2_derisk_1_stakes)
    grind_2_derisk_1_stop_grinds = (
      self.grind_2_derisk_1_stop_grinds_futures if is_futures else self.grind_2_derisk_1_stop_grinds_spot
    )
    grind_2_derisk_1_profit_threshold = (
      self.grind_2_derisk_1_profit_threshold_futures if is_futures else self.grind_2_derisk_1_profit_threshold_spot
    )

    partial_sell = False
    is_derisk_found = False  # d de-risk
    is_derisk_1 = False
    is_derisk_1_found = False  # d1 de-risk exit
    derisk_1_order = None
    derisk_1_reentry_order = None
    derisk_1_sub_grind_count = 0
    derisk_1_total_amount = 0.0
    derisk_1_total_cost = 0.0
    derisk_1_current_open_rate = 0.0
    derisk_1_current_grind_stake = 0.0
    derisk_1_current_grind_stake_profit = 0.0
    derisk_1_is_sell_found = False
    derisk_1_reentry_found = False
    derisk_1_buy_orders = []
    derisk_1_distance_ratio = 0.0
    grind_1_sub_grind_count = 0
    grind_1_total_amount = 0.0
    grind_1_total_cost = 0.0
    grind_1_current_open_rate = 0.0
    grind_1_current_grind_stake = 0.0
    grind_1_current_grind_stake_profit = 0.0
    grind_1_is_sell_found = False
    grind_1_found = False
    grind_1_buy_orders = []
    grind_1_distance_ratio = 0.0
    grind_2_sub_grind_count = 0
    grind_2_total_amount = 0.0
    grind_2_total_cost = 0.0
    grind_2_current_open_rate = 0.0
    grind_2_current_grind_stake = 0.0
    grind_2_current_grind_stake_profit = 0.0
    grind_2_is_sell_found = False
    grind_2_found = False
    grind_2_buy_orders = []
    grind_2_distance_ratio = 0.0
    grind_3_sub_grind_count = 0
    grind_3_total_amount = 0.0
    grind_3_total_cost = 0.0
    grind_3_current_open_rate = 0.0
    grind_3_current_grind_stake = 0.0
    grind_3_current_grind_stake_profit = 0.0
    grind_3_is_sell_found = False
    grind_3_found = False
    grind_3_buy_orders = []
    grind_3_distance_ratio = 0.0
    grind_4_sub_grind_count = 0
    grind_4_total_amount = 0.0
    grind_4_total_cost = 0.0
    grind_4_current_open_rate = 0.0
    grind_4_current_grind_stake = 0.0
    grind_4_current_grind_stake_profit = 0.0
    grind_4_is_sell_found = False
    grind_4_found = False
    grind_4_buy_orders = []
    grind_4_distance_ratio = 0.0
    grind_5_sub_grind_count = 0
    grind_5_total_amount = 0.0
    grind_5_total_cost = 0.0
    grind_5_current_open_rate = 0.0
    grind_5_current_grind_stake = 0.0
    grind_5_current_grind_stake_profit = 0.0
    grind_5_is_sell_found = False
    grind_5_found = False
    grind_5_buy_orders = []
    grind_5_distance_ratio = 0.0
    grind_6_sub_grind_count = 0
    grind_6_total_amount = 0.0
    grind_6_total_cost = 0.0
    grind_6_current_open_rate = 0.0
    grind_6_current_grind_stake = 0.0
    grind_6_current_grind_stake_profit = 0.0
    grind_6_is_sell_found = False
    grind_6_found = False
    grind_6_buy_orders = []
    grind_6_distance_ratio = 0.0
    grind_1_derisk_1_sub_grind_count = 0
    grind_1_derisk_1_total_amount = 0.0
    grind_1_derisk_1_total_cost = 0.0
    grind_1_derisk_1_current_open_rate = 0.0
    grind_1_derisk_1_current_grind_stake = 0.0
    grind_1_derisk_1_current_grind_stake_profit = 0.0
    grind_1_derisk_1_is_sell_found = False
    grind_1_derisk_1_found = False
    grind_1_derisk_1_buy_orders = []
    grind_1_derisk_1_distance_ratio = 0.0
    grind_2_derisk_1_sub_grind_count = 0
    grind_2_derisk_1_total_amount = 0.0
    grind_2_derisk_1_total_cost = 0.0
    grind_2_derisk_1_current_open_rate = 0.0
    grind_2_derisk_1_current_grind_stake = 0.0
    grind_2_derisk_1_current_grind_stake_profit = 0.0
    grind_2_derisk_1_is_sell_found = False
    grind_2_derisk_1_found = False
    grind_2_derisk_1_buy_orders = []
    grind_2_derisk_1_distance_ratio = 0.0
    for order in reversed(filled_orders):
      order_side = order.ft_order_side
      if (order_side == "sell") and (order is not filled_orders[0]):
        order_tag = ""
        if has_order_tags:
          order_ft_tag = order.ft_order_tag
          if order_ft_tag is not None:
            order_tag = order_ft_tag
        order_safe_filled = order.safe_filled
        order_safe_price = order.safe_price
        order_id = order.id
        if not is_derisk_1 and order_tag == "d1":
          derisk_1_sub_grind_count += 1
          derisk_1_total_amount += order_safe_filled
          derisk_1_total_cost += order_safe_filled * order_safe_price
          derisk_1_buy_orders.append(order_id)
          if not derisk_1_reentry_found and not is_derisk_1:
            derisk_1_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            derisk_1_reentry_found = True
            derisk_1_reentry_order = order
        elif not grind_1_derisk_1_is_sell_found and order_tag == "dl1":
          grind_1_derisk_1_sub_grind_count += 1
          grind_1_derisk_1_total_amount += order_safe_filled
          grind_1_derisk_1_total_cost += order_safe_filled * order_safe_price
          grind_1_derisk_1_buy_orders.append(order_id)
          if not grind_1_derisk_1_found:
            grind_1_derisk_1_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_1_derisk_1_found = True
        elif not grind_2_derisk_1_is_sell_found and order_tag == "dl2":
          grind_2_derisk_1_sub_grind_count += 1
          grind_2_derisk_1_total_amount += order_safe_filled
          grind_2_derisk_1_total_cost += order_safe_filled * order_safe_price
          grind_2_derisk_1_buy_orders.append(order_id)
          if not grind_2_derisk_1_found:
            grind_2_derisk_1_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_2_derisk_1_found = True
        elif not grind_6_is_sell_found and order_tag == "gd6":
          grind_6_sub_grind_count += 1
          grind_6_total_amount += order_safe_filled
          grind_6_total_cost += order_safe_filled * order_safe_price
          grind_6_buy_orders.append(order_id)
          if not grind_6_found:
            grind_6_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_6_found = True
        elif not grind_5_is_sell_found and order_tag == "gd5":
          grind_5_sub_grind_count += 1
          grind_5_total_amount += order_safe_filled
          grind_5_total_cost += order_safe_filled * order_safe_price
          grind_5_buy_orders.append(order_id)
          if not grind_5_found:
            grind_5_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_5_found = True
        elif not grind_4_is_sell_found and order_tag == "gd4":
          grind_4_sub_grind_count += 1
          grind_4_total_amount += order_safe_filled
          grind_4_total_cost += order_safe_filled * order_safe_price
          grind_4_buy_orders.append(order_id)
          if not grind_4_found:
            grind_4_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_4_found = True
        elif not grind_3_is_sell_found and order_tag == "gd3":
          grind_3_sub_grind_count += 1
          grind_3_total_amount += order_safe_filled
          grind_3_total_cost += order_safe_filled * order_safe_price
          grind_3_buy_orders.append(order_id)
          if not grind_3_found:
            grind_3_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_3_found = True
        elif not grind_2_is_sell_found and order_tag == "gd2":
          grind_2_sub_grind_count += 1
          grind_2_total_amount += order_safe_filled
          grind_2_total_cost += order_safe_filled * order_safe_price
          grind_2_buy_orders.append(order_id)
          if not grind_2_found:
            grind_2_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_2_found = True
        elif not grind_1_is_sell_found and order_tag not in [
          "r",
          "d1",
          "dl1",
          "dl2",
          "g1",
          "g2",
          "g3",
          "g4",
          "g5",
          "g6",
          "sg1",
          "sg2",
          "sg3",
          "sg4",
          "sg5",
          "sg6",
          "gd2",
          "gd3",
          "gd4",
          "gd5",
          "gd6",
          "gm0",
          "gmd0",
          "gdr",
        ]:
          grind_1_sub_grind_count += 1
          grind_1_total_amount += order_safe_filled
          grind_1_total_cost += order_safe_filled * order_safe_price
          grind_1_buy_orders.append(order_id)
          if not grind_1_found:
            grind_1_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_1_found = True
      elif order_side == "buy":
        if order is filled_exits[-1] and (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
          break
        order_tag = ""
        if has_order_tags:
          order_ft_tag = order.ft_order_tag
          if order_ft_tag is not None:
            order_tag = order_ft_tag.partition(" ")[0]
        if order_tag in ["dl1", "ddl1"]:
          grind_1_derisk_1_is_sell_found = True
        elif order_tag in ["dl2", "ddl2"]:
          grind_2_derisk_1_is_sell_found = True
        elif order_tag in ["gd6", "dd6"]:
          grind_6_is_sell_found = True
        elif order_tag in ["gd5", "dd5"]:
          grind_5_is_sell_found = True
        if order_tag in ["gd4", "dd4"]:
          grind_4_is_sell_found = True
        elif order_tag in ["gd3", "dd3"]:
          grind_3_is_sell_found = True
        elif order_tag in ["gd2", "dd2"]:
          grind_2_is_sell_found = True
        elif order_tag == "d1":
          if not is_derisk_1_found:
            is_derisk_1_found = True
            is_derisk_1 = True
            derisk_1_order = order
        elif order_tag in ["p", "r", "d", "dd0", "partial_exit", "force_exit", ""]:
          if order_tag == "d":
            is_derisk_found = True
            is_derisk = True
          grind_1_is_sell_found = True
          grind_2_is_sell_found = True
          grind_3_is_sell_found = True
          grind_4_is_sell_found = True
          grind_5_is_sell_found = True
          grind_6_is_sell_found = True
          grind_1_derisk_1_is_sell_found = True
          grind_2_derisk_1_is_sell_found = True
        elif order_tag not in [
          "dl1",
          "ddl1",
          "dl2",
          "ddl2",
          "g1",
          "g2",
          "g3",
          "g4",
          "g5",
          "g6",
          "sg1",
          "sg2",
          "sg3",
          "sg4",
          "sg5",
          "sg6",
          "gd2",
          "gd3",
          "gd4",
          "gd5",
          "gd6",
          "dd2",
          "dd3",
          "dd4",
          "dd5",
          "dd6",
          "gm0",
          "gmd0",
          "gdr",
        ]:
          grind_1_is_sell_found = True

    if derisk_1_sub_grind_count > 0:
      derisk_1_current_open_rate = derisk_1_total_cost / derisk_1_total_amount
      derisk_1_current_grind_stake = derisk_1_total_amount * exit_rate * (1 + trade_fee_close)
      derisk_1_current_grind_stake_profit = derisk_1_total_cost - derisk_1_current_grind_stake
    if grind_1_sub_grind_count > 0:
      grind_1_current_open_rate = grind_1_total_cost / grind_1_total_amount
      grind_1_current_grind_stake = grind_1_total_amount * exit_rate * (1 + trade_fee_close)
      grind_1_current_grind_stake_profit = grind_1_total_cost - grind_1_current_grind_stake
    if grind_2_sub_grind_count > 0:
      grind_2_current_open_rate = grind_2_total_cost / grind_2_total_amount
      grind_2_current_grind_stake = grind_2_total_amount * exit_rate * (1 + trade_fee_close)
      grind_2_current_grind_stake_profit = grind_2_total_cost - grind_2_current_grind_stake
    if grind_3_sub_grind_count > 0:
      grind_3_current_open_rate = grind_3_total_cost / grind_3_total_amount
      grind_3_current_grind_stake = grind_3_total_amount * exit_rate * (1 + trade_fee_close)
      grind_3_current_grind_stake_profit = grind_3_total_cost - grind_3_current_grind_stake
    if grind_4_sub_grind_count > 0:
      grind_4_current_open_rate = grind_4_total_cost / grind_4_total_amount
      grind_4_current_grind_stake = grind_4_total_amount * exit_rate * (1 + trade_fee_close)
      grind_4_current_grind_stake_profit = grind_4_total_cost - grind_4_current_grind_stake
    if grind_5_sub_grind_count > 0:
      grind_5_current_open_rate = grind_5_total_cost / grind_5_total_amount
      grind_5_current_grind_stake = grind_5_total_amount * exit_rate * (1 + trade_fee_close)
      grind_5_current_grind_stake_profit = grind_5_total_cost - grind_5_current_grind_stake
    if grind_6_sub_grind_count > 0:
      grind_6_current_open_rate = grind_6_total_cost / grind_6_total_amount
      grind_6_current_grind_stake = grind_6_total_amount * exit_rate * (1 + trade_fee_close)
      grind_6_current_grind_stake_profit = grind_6_total_cost - grind_6_current_grind_stake
    if grind_1_derisk_1_sub_grind_count > 0:
      grind_1_derisk_1_current_open_rate = grind_1_derisk_1_total_cost / grind_1_derisk_1_total_amount
      grind_1_derisk_1_current_grind_stake = grind_1_derisk_1_total_amount * exit_rate * (1 + trade_fee_close)
      grind_1_derisk_1_current_grind_stake_profit = grind_1_derisk_1_total_cost - grind_1_derisk_1_current_grind_stake
    if grind_2_derisk_1_sub_grind_count > 0:
      grind_2_derisk_1_current_open_rate = grind_2_derisk_1_total_cost / grind_2_derisk_1_total_amount
      grind_2_derisk_1_current_grind_stake = grind_2_derisk_1_total_amount * exit_rate * (1 + trade_fee_close)
      grind_2_derisk_1_current_grind_stake_profit = grind_2_derisk_1_total_cost - grind_2_derisk_1_current_grind_stake

    num_open_grinds = (
      grind_1_sub_grind_count
      + grind_2_sub_grind_count
      + grind_3_sub_grind_count
      + grind_4_sub_grind_count
      + grind_5_sub_grind_count
      + grind_6_sub_grind_count
      + grind_1_derisk_1_sub_grind_count
      + grind_2_derisk_1_sub_grind_count
    )
    grinds_total_stake_profit = (
      derisk_1_current_grind_stake_profit
      + grind_1_derisk_1_current_grind_stake_profit
      + grind_2_derisk_1_current_grind_stake_profit
      + grind_1_current_grind_stake_profit
      + grind_2_current_grind_stake_profit
      + grind_3_current_grind_stake_profit
      + grind_4_current_grind_stake_profit
      + grind_5_current_grind_stake_profit
      + grind_6_current_grind_stake_profit
    )
    grinds_total_amount = (
      derisk_1_total_amount
      + grind_1_derisk_1_total_amount
      + grind_2_derisk_1_total_amount
      + grind_1_total_amount
      + grind_2_total_amount
      + grind_3_total_amount
      + grind_4_total_amount
      + grind_5_total_amount
      + grind_6_total_amount
    )
    stake_fmt = ".8f" if self.config["stake_currency"] in ("BTC", "ETH", "BNB", "SOL") else ".3f"
    # Sell remaining if partial fill on exit
    if partial_sell:
      order = filled_exits[-1]
      sell_amount = order.safe_remaining * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        send_msg(
          f"Exit (remaining) [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {order.safe_remaining} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        order_tag = "p"
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    if is_grind_mode and (
      (first_filled_entry.safe_filled * (trade_stake_amount / trade_amount) - (min_stake * 1.5)) > min_stake
    ):
      is_first_entry_exit_found = False
      for order in filled_orders:
        if order.ft_order_side == "buy":
          order_tag = ""
          if has_order_tags:
            if order.ft_order_tag is not None:
              order_tag = order.ft_order_tag.partition(" ")[0]
          else:
            # no order tag support, assume the first exit is for the first buy
            is_first_entry_exit_found = True
          if order_tag in ["gm0", "gmd0"]:
            is_first_entry_exit_found = True
            break
      if not is_first_entry_exit_found:
        first_entry = first_filled_entry
        first_entry_distance_ratio = -(exit_rate - first_entry.safe_price) / first_entry.safe_price
        # First entry exit
        if first_entry_distance_ratio > (
          (self.grind_mode_first_entry_profit_threshold_spot + fee_open_rate + fee_close_rate)
          if is_futures
          else (self.grind_mode_first_entry_profit_threshold_spot + fee_open_rate + fee_close_rate)
        ):
          sell_amount = first_entry.safe_filled * exit_rate / trade_leverage
          if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
            sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
          ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
          if sell_amount > min_stake and ft_sell_amount > min_stake:
            grind_profit = -(exit_rate - first_entry.safe_price) / first_entry.safe_price
            coin_amount = sell_amount / exit_rate
            send_msg(
              notification_msg(
                "grinding-exit",
                tag="gm0",
                pair=trade_pair,
                rate=exit_rate,
                stake_amount=sell_amount,
                profit_stake=profit_stake,
                profit_ratio=profit_ratio,
                stake_currency=stake_currency,
                grind_profit_stake=grind_profit * sell_amount * trade_leverage,
                grind_profit_pct=grind_profit,
                coin_amount=coin_amount,
              )
            )
            log.info(
              f"Grinding exit (gm0) [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {coin_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
            )
            order_tag = "gm0"
            for grind_entry_id in grind_1_buy_orders:
              order_tag += " " + str(grind_entry_id)
            if has_order_tags:
              return -ft_sell_amount, order_tag
            else:
              return -ft_sell_amount
        # First entry de-risk
        if derisk_use_grind_stops and (
          first_entry_distance_ratio
          < (
            self.grind_mode_first_entry_stop_threshold_spot
            if is_futures
            else self.grind_mode_first_entry_stop_threshold_spot
          )
        ):
          sell_amount = first_entry.safe_filled * exit_rate / trade_leverage
          if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
            sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
          ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
          if sell_amount > min_stake and ft_sell_amount > min_stake:
            grind_profit = -(exit_rate - first_entry.safe_price) / first_entry.safe_price
            coin_amount = sell_amount / exit_rate
            send_msg(
              notification_msg(
                "grinding-derisk",
                tag="gmd0",
                pair=trade_pair,
                rate=exit_rate,
                stake_amount=sell_amount,
                profit_stake=profit_stake,
                profit_ratio=profit_ratio,
                stake_currency=stake_currency,
                grind_profit_stake=grind_profit * sell_amount * trade_leverage,
                grind_profit_pct=grind_profit,
                coin_amount=coin_amount,
              )
            )
            log.info(
              f"Grinding de-risk (gmd0) [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {coin_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
            )
            order_tag = "gmd0"
            for grind_entry_id in grind_1_buy_orders:
              order_tag += " " + str(grind_entry_id)
            if has_order_tags:
              return -ft_sell_amount, order_tag
            else:
              return -ft_sell_amount

    is_short_grind_entry = self.short_grind_entry(last_candle, previous_candle, slice_profit, True)
    slice_profit_gt_0_06 = slice_profit > 0.06
    num_open_grinds_eq_0 = num_open_grinds == 0

    # Grinding derisk 1
    # Buy
    if (
      has_order_tags
      and is_derisk_1
      and not derisk_1_reentry_found
      and (not partial_sell)
      and (grind_1_derisk_1_sub_grind_count < grind_1_derisk_1_max_sub_grinds)
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_1_derisk_1_stakes[grind_1_derisk_1_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          (
            (grind_1_derisk_1_sub_grind_count > 0)
            and -grind_1_derisk_1_distance_ratio < grind_1_derisk_1_sub_thresholds[grind_1_derisk_1_sub_grind_count]
          )
          or ((is_derisk or is_derisk_calc) and grind_1_derisk_1_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06)
        and (
          num_open_grinds_eq_0 or (grind_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit > 0.03))
        and is_short_grind_entry
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_1_derisk_1_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_1_derisk_1_current_open_rate) / grind_1_derisk_1_current_open_rate
          grind_profit_stake = grind_1_derisk_1_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="dl1",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_1_derisk_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (dl1) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_derisk_1_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "dl1"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_1_derisk_1_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_1_derisk_1_current_open_rate) / grind_1_derisk_1_current_open_rate
      if grind_profit > (grind_1_derisk_1_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_1_derisk_1_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="dl1",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_1_derisk_1_total_amount,
            )
          )
          log.info(
            f"Grinding exit (dl1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_derisk_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "dl1"
          for grind_entry_id in grind_1_derisk_1_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (grind_1_derisk_1_sub_grind_count > 0)
      # and (
      #   (-(exit_rate - grind_1_derisk_1_current_open_rate) / grind_1_derisk_1_current_open_rate)
      #   < grind_1_derisk_1_stop_grinds
      # )
      and (grind_1_derisk_1_current_grind_stake_profit < (slice_amount * grind_1_derisk_1_stop_grinds))
      and (is_derisk or is_derisk_calc)
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
    ):
      sell_amount = grind_1_derisk_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_1_derisk_1_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_1_derisk_1_current_open_rate) / grind_1_derisk_1_current_open_rate)
            if grind_1_derisk_1_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="ddl1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_1_derisk_1_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (ddl1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_derisk_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "ddl1"
        for grind_entry_id in grind_1_derisk_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding derisk 2
    # Buy
    if (
      has_order_tags
      and is_derisk_1
      and not derisk_1_reentry_found
      and (not partial_sell)
      and (grind_2_derisk_1_sub_grind_count < grind_2_derisk_1_max_sub_grinds)
      and is_not_trade_max_stake
    ):
      buy_amount = slice_amount * grind_2_derisk_1_stakes[grind_2_derisk_1_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          (
            (grind_2_derisk_1_sub_grind_count > 0)
            and -grind_2_derisk_1_distance_ratio < grind_2_derisk_1_sub_thresholds[grind_2_derisk_1_sub_grind_count]
          )
          or ((is_derisk or is_derisk_calc) and grind_2_derisk_1_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06)
        and (
          num_open_grinds_eq_0 or (grind_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit > 0.03))
        and is_short_grind_entry
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_2_derisk_1_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_2_derisk_1_current_open_rate) / grind_2_derisk_1_current_open_rate
          grind_profit_stake = grind_2_derisk_1_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="dl2",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_2_derisk_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (dl2) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_2_derisk_1_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "dl2"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_2_derisk_1_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_2_derisk_1_current_open_rate) / grind_2_derisk_1_current_open_rate
      if grind_profit > (grind_2_derisk_1_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_2_derisk_1_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="dl2",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_2_derisk_1_total_amount,
            )
          )
          log.info(
            f"Grinding exit (dl2) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_2_derisk_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "dl2"
          for grind_entry_id in grind_2_derisk_1_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (grind_2_derisk_1_sub_grind_count > 0)
      # and (
      #   (-(exit_rate - grind_2_derisk_1_current_open_rate) / grind_2_derisk_1_current_open_rate)
      #   < grind_2_derisk_1_stop_grinds
      # )
      and (grind_2_derisk_1_current_grind_stake_profit < (slice_amount * grind_2_derisk_1_stop_grinds))
      and (is_derisk or is_derisk_calc)
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
    ):
      sell_amount = grind_2_derisk_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_2_derisk_1_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_2_derisk_1_current_open_rate) / grind_2_derisk_1_current_open_rate)
            if grind_2_derisk_1_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="ddl2",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_2_derisk_1_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (ddl2) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_2_derisk_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "ddl2"
        for grind_entry_id in grind_2_derisk_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 1
    # Buy
    if (not partial_sell) and (grind_1_sub_grind_count < grind_1_max_sub_grinds):
      buy_amount = slice_amount * grind_1_stakes[grind_1_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          ((grind_1_sub_grind_count > 0) and -grind_1_distance_ratio < grind_1_sub_thresholds[grind_1_sub_grind_count])
          or ((is_derisk or is_derisk_calc) and grind_1_sub_grind_count == 0)
          or (is_grind_mode and grind_1_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06)
        and (
          num_open_grinds_eq_0 or (grind_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit > 0.03))
        and is_short_grind_entry
        and is_not_trade_max_stake
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_1_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
          grind_profit_stake = grind_1_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd1",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd1) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd1"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    if (
      is_futures
      and has_order_tags
      and (not partial_sell)
      and slice_profit > (0.65 / trade_leverage)
      and (is_derisk or is_derisk_calc or is_grind_mode)
      and (grind_1_sub_grind_count < grind_1_max_sub_grinds)
    ):
      buy_amount = slice_amount * grind_1_stakes[grind_1_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount <= max_stake:
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_1_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
          grind_profit_stake = grind_1_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd1",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd1) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd1"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_1_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
      if grind_profit > (grind_1_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_1_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="gd1",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_1_total_amount,
            )
          )
          log.info(
            f"Grinding exit (gd1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "gd1"
          for grind_entry_id in grind_1_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (
        (grind_1_sub_grind_count > 0)
        # and ((-(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate) < grind_1_stop_grinds)
        and (grind_1_current_grind_stake_profit < (slice_amount * grind_1_stop_grinds))
        and (is_derisk or is_derisk_calc or is_grind_mode)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
    ):
      sell_amount = grind_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_1_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate)
            if grind_1_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="dd1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_1_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (dd1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "dd1"
        for grind_entry_id in grind_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 2
    # Buy
    if has_order_tags and (not partial_sell) and (grind_2_sub_grind_count < grind_2_max_sub_grinds):
      buy_amount = slice_amount * grind_2_stakes[grind_2_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          ((grind_2_sub_grind_count > 0) and -grind_2_distance_ratio < grind_2_sub_thresholds[grind_2_sub_grind_count])
          or ((is_derisk or is_derisk_calc) and grind_2_sub_grind_count == 0)
          or (is_grind_mode and grind_2_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06)
        and (
          num_open_grinds_eq_0 or (grind_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit > 0.03))
        and is_short_grind_entry
        and is_not_trade_max_stake
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_2_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
          grind_profit_stake = grind_2_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd2",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_2_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd2) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_2_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd2"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_2_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
      if grind_profit > (grind_2_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_2_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="gd2",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_2_total_amount,
            )
          )
          log.info(
            f"Grinding exit (gd2) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "gd2"
          for grind_entry_id in grind_2_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (
        (grind_2_sub_grind_count > 0)
        # and ((-(exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate) < grind_2_stop_grinds)
        and (grind_2_current_grind_stake_profit < (slice_amount * grind_2_stop_grinds))
        and (is_derisk or is_derisk_calc or is_grind_mode)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
    ):
      sell_amount = grind_2_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_2_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate)
            if grind_2_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="dd2",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_2_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (dd2) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "dd2"
        for grind_entry_id in grind_2_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 3
    # Buy
    if has_order_tags and (not partial_sell) and (grind_3_sub_grind_count < grind_3_max_sub_grinds):
      buy_amount = slice_amount * grind_3_stakes[grind_3_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          ((grind_3_sub_grind_count > 0) and -grind_3_distance_ratio < grind_3_sub_thresholds[grind_3_sub_grind_count])
          or ((is_derisk or is_derisk_calc) and grind_3_sub_grind_count == 0)
          or (is_grind_mode and grind_3_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06)
        and (
          num_open_grinds_eq_0 or (grind_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit > 0.03))
        and is_short_grind_entry
        and is_not_trade_max_stake
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_3_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
          grind_profit_stake = grind_3_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd3",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_3_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd3) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_3_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd3"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_3_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
      if grind_profit > (grind_3_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_3_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="gd3",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_3_total_amount,
            )
          )
          log.info(
            f"Grinding exit (gd3) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "gd3"
          for grind_entry_id in grind_3_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (
        (grind_3_sub_grind_count > 0)
        # and ((-(exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate) < grind_3_stop_grinds)
        and (grind_3_current_grind_stake_profit < (slice_amount * grind_3_stop_grinds))
        and (is_derisk or is_derisk_calc or is_grind_mode)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
    ):
      sell_amount = grind_3_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_3_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate)
            if grind_3_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="dd3",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_3_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (dd3) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "dd3"
        for grind_entry_id in grind_3_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 4
    # Buy
    if has_order_tags and (not partial_sell) and (grind_4_sub_grind_count < grind_4_max_sub_grinds):
      buy_amount = slice_amount * grind_4_stakes[grind_4_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          ((grind_4_sub_grind_count > 0) and -grind_4_distance_ratio < grind_4_sub_thresholds[grind_4_sub_grind_count])
          or ((is_derisk or is_derisk_calc) and grind_4_sub_grind_count == 0)
          or (is_grind_mode and grind_4_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06)
        and (
          num_open_grinds_eq_0 or (grind_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit > 0.03))
        and is_short_grind_entry
        and is_not_trade_max_stake
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_4_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
          grind_profit_stake = grind_4_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd4",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_4_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd4) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_4_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd4"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_4_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
      if grind_profit > (grind_4_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_4_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="gd4",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_4_total_amount,
            )
          )
          log.info(
            f"Grinding exit (gd4) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "gd4"
          for grind_entry_id in grind_4_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (
        (grind_4_sub_grind_count > 0)
        # and ((-(exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate) < grind_4_stop_grinds)
        and (grind_4_current_grind_stake_profit < (slice_amount * grind_4_stop_grinds))
        and (is_derisk or is_derisk_calc or is_grind_mode)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
    ):
      sell_amount = grind_4_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_4_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate)
            if grind_4_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="dd4",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_4_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (dd4) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "dd4"
        for grind_entry_id in grind_4_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    gd5_liquidation_rescue_eligible = (
      is_futures
      and (slice_profit_entry > 0.12)
      and (trade.liquidation_price is not None)
      and (current_rate > trade.liquidation_price * 0.80)
      and (trade.get_custom_data(key="gd5_liquidation_rescue_used") is None)
    )

    # Grinding 5
    # Buy
    if has_order_tags and (not partial_sell) and (grind_5_sub_grind_count < grind_5_max_sub_grinds):
      buy_amount = slice_amount * grind_5_stakes[grind_5_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          ((grind_5_sub_grind_count > 0) and -grind_5_distance_ratio < grind_5_sub_thresholds[grind_5_sub_grind_count])
          or ((is_derisk or is_derisk_calc) and grind_5_sub_grind_count == 0)
          or (is_grind_mode and grind_5_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06)
        and (
          num_open_grinds_eq_0 or (grind_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit > 0.03))
        and (is_short_grind_entry or gd5_liquidation_rescue_eligible)
        and is_not_trade_max_stake
        and buy_amount <= max_stake
      ):
        if gd5_liquidation_rescue_eligible:
          trade.set_custom_data(key="gd5_liquidation_rescue_used", value=True)

        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_5_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
          grind_profit_stake = grind_5_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd5",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_5_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd5) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_5_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd5"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_5_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
      if grind_profit > (grind_5_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_5_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="gd5",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_5_total_amount,
            )
          )
          log.info(
            f"Grinding exit (gd5) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "gd5"
          for grind_entry_id in grind_5_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (
        (grind_5_sub_grind_count > 0)
        # and ((-(exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate) < grind_5_stop_grinds)
        and (grind_5_current_grind_stake_profit < (slice_amount * grind_5_stop_grinds))
        and (is_derisk or is_derisk_calc or is_grind_mode)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
    ):
      sell_amount = grind_5_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_5_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate)
            if grind_5_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="dd5",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_5_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (dd5) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "dd5"
        for grind_entry_id in grind_5_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # Grinding 6
    # Buy
    if has_order_tags and (not partial_sell) and (grind_6_sub_grind_count < grind_6_max_sub_grinds):
      buy_amount = slice_amount * grind_6_stakes[grind_6_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (
          ((grind_6_sub_grind_count > 0) and -grind_6_distance_ratio < grind_6_sub_thresholds[grind_6_sub_grind_count])
          or ((is_derisk or is_derisk_calc) and grind_6_sub_grind_count == 0)
          or (is_grind_mode and grind_6_sub_grind_count == 0)
        )
        and (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06)
        and (
          num_open_grinds_eq_0 or (grind_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit > 0.03))
        and is_short_grind_entry
        and is_not_trade_max_stake
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_6_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate
          grind_profit_stake = grind_6_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="gd6",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_6_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (gd6) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_6_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "gd6"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # Sell
    if grind_6_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate
      if grind_profit > (grind_6_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_6_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="gd6",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_6_total_amount,
            )
          )
          log.info(
            f"Grinding exit (gd6) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_6_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage:{stake_fmt}} {stake_currency})"
          )
          order_tag = "gd6"
          for grind_entry_id in grind_6_buy_orders:
            order_tag += " " + str(grind_entry_id)
          if has_order_tags:
            return -ft_sell_amount, order_tag
          else:
            return -ft_sell_amount

    # Grind stop
    if (
      derisk_use_grind_stops
      and (
        (grind_6_sub_grind_count > 0)
        # and ((-(exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate) < grind_6_stop_grinds)
        and (grind_6_current_grind_stake_profit < (slice_amount * grind_6_stop_grinds))
        and (is_derisk or is_derisk_calc or is_grind_mode)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
    ):
      sell_amount = grind_6_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_6_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate)
            if grind_6_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="dd6",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_6_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (dd6) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Coin amount: {grind_6_total_amount} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "dd6"
        for grind_entry_id in grind_6_buy_orders:
          order_tag += " " + str(grind_entry_id)
        if has_order_tags:
          return -ft_sell_amount, order_tag
        else:
          return -ft_sell_amount

    # De-risk 1 reentry
    if (
      is_derisk_1
      and not derisk_1_reentry_found
      and derisk_1_order is not None
      and (
        (-(current_rate - derisk_1_order.safe_price) / derisk_1_order.safe_price)
        < (self.regular_mode_derisk_1_reentry_futures if is_futures else self.regular_mode_derisk_1_reentry_spot)
      )
    ):
      buy_amount = derisk_1_order.safe_filled * derisk_1_order.safe_price
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5

      if (
        (grind_entry_retry_time > last_filled_entry.order_filled_utc)
        and ((grind_force_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06)
        and (
          num_open_grinds_eq_0 or (grind_order_age_time > last_filled_order.order_filled_utc) or slice_profit_gt_0_06
        )
        # and ((num_open_grinds == 0) or (slice_profit > 0.03))
        and (
          # (last_candle["protections_short_rebuy"] == True)
          # and (last_candle["protections_short_global"] == True)
          (last_candle["global_protections_short_pump"] == True)
          and (last_candle["global_protections_short_dump"] == True)
        )
        and is_short_grind_entry
        and buy_amount <= max_stake
      ):
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if derisk_1_sub_grind_count > 0:
          grind_profit = -(exit_rate - derisk_1_current_open_rate) / derisk_1_current_open_rate
          grind_profit_stake = derisk_1_current_grind_stake_profit
        send_msg(
          notification_msg(
            "re-entry",
            tag="d1",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=derisk_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Re-entry (d1) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({derisk_1_current_grind_stake_profit:{stake_fmt}} {stake_currency})"
        )
        order_tag = "d1"
        if has_order_tags:
          return buy_amount, order_tag
        else:
          return buy_amount

    # De-risk level 1
    if (
      has_order_tags
      # and not is_derisk_1
      and derisk_1_reentry_found
      and derisk_1_reentry_order is not None
      # and (trade.open_date_utc.replace(tzinfo=None) >= datetime(2024, 4, 5) or is_backtest)
      and -derisk_1_distance_ratio
      < (
        (self.regular_mode_derisk_1_reentry_futures if is_futures else self.regular_mode_derisk_1_reentry_spot)
        / stake_scale_leverage
      )
    ):
      sell_amount = derisk_1_reentry_order.safe_filled * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="d1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk (d1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "d1"

    return None

  # Short Grinding Entry
  # ---------------------------------------------------------------------------------------------
  def short_grind_entry(
    self, last_candle: Series, previous_candle: Series, slice_profit: float, is_derisk: bool
  ) -> float:
    last_aroond_14 = last_candle["AROOND_14"]
    last_aroond_14_15m = last_candle["AROOND_14_15m"]
    last_rsi_14_1h = last_candle["RSI_14_1h"]
    last_rsi_14_4h = last_candle["RSI_14_4h"]
    previous_ema_12 = previous_candle["EMA_12"]
    previous_ema_26 = previous_candle["EMA_26"]

    last_rsi_14 = last_candle["RSI_14"]
    last_rsi_3_15m = last_candle["RSI_3_15m"]
    last_rsi_3_1h = last_candle["RSI_3_1h"]
    last_rsi_3_4h = last_candle["RSI_3_4h"]
    last_close = last_candle["close"]
    last_ema_12 = last_candle["EMA_12"]
    last_ema_26 = last_candle["EMA_26"]
    last_rsi_3 = last_candle["RSI_3"]
    last_open = last_candle["open"]

    # Reused short regular grind-entry thresholds
    last_rsi_14_gt_64 = last_rsi_14 > 64.0
    last_rsi_3_4h_lt_80 = last_rsi_3_4h < 80.0
    last_rsi_3_1h_lt_80 = last_rsi_3_1h < 80.0
    last_rsi_3_15m_lt_90 = last_rsi_3_15m < 90.0
    last_rsi_3_4h_lt_90 = last_rsi_3_4h < 90.0
    last_rsi_3_1h_lt_90 = last_rsi_3_1h < 90.0
    last_rsi_14_4h_gt_40 = last_rsi_14_4h > 40.0
    last_rsi_14_1h_gt_20 = last_rsi_14_1h > 20.0
    last_aroond_14_15m_lt_25 = last_aroond_14_15m < 25.0
    last_aroond_14_lt_25 = last_aroond_14 < 25.0

    if (
      (last_candle["protections_short_global"] == True)
      and (last_candle["protections_short_rebuy"] == True)
      and (last_candle["global_protections_short_pump"] == True)
      and (last_candle["global_protections_short_dump"] == True)
      and (
        (last_candle["enter_short"] == True)
        or (
          (last_rsi_14_gt_64)
          and (last_rsi_3 < 90.0)
          and (last_rsi_3_15m_lt_90)
          and (last_aroond_14_lt_25)
          and (last_candle["STOCHRSIk_14_14_3_3_1h"] > 30.0)
          and (last_candle["STOCHRSIk_14_14_3_3_4h"] > 30.0)
          and (last_close > (last_candle["EMA_16"] * 1.020))
        )
        or (
          (last_rsi_14_gt_64)
          and (last_rsi_3_15m < 95.0)
          and (last_rsi_3_1h < 95.0)
          and (last_rsi_3_4h < 95.0)
          and (last_ema_12 > last_ema_26)
          and ((last_ema_12 - last_ema_26) > (last_open * 0.030))
          and ((previous_ema_12 - previous_ema_26) > (last_open / 100.0))
        )
        or (
          (last_rsi_14_gt_64)
          and (last_rsi_3 < 95.0)
          and (last_rsi_3_15m_lt_90)
          and (last_rsi_3_1h_lt_90)
          and (last_rsi_3_4h_lt_90)
          and (last_ema_12 > last_ema_26)
          and ((last_ema_12 - last_ema_26) > (last_open * 0.020))
          and ((previous_ema_12 - previous_ema_26) > (last_open / 100.0))
        )
        or (
          (last_rsi_14_gt_64)
          and (last_rsi_3 < 84.0)
          and (last_aroond_14_15m_lt_25)
          and (last_close > (last_ema_12 * 1.016))
        )
        or (
          (last_rsi_14_gt_64)
          and (last_rsi_3_15m_lt_90)
          and (last_rsi_3_1h_lt_90)
          and (last_rsi_3_4h_lt_90)
          and (last_candle["AROONU_14_1h"] < last_candle["AROOND_14_1h"])
          and (last_candle["AROONU_14_4h"] < last_candle["AROOND_14_4h"])
          and (last_close > (last_ema_26 * 1.022))
          and (last_close > (last_candle["BBL_20_2.0"] * 1.001))
        )
        or (
          (last_rsi_14_gt_64)
          and (last_rsi_3_1h_lt_80)
          and (last_rsi_3_4h_lt_80)
          and (last_rsi_14_1h_gt_20)
          and (last_rsi_14_4h_gt_40)
          and (last_candle["AROONU_14"] < last_aroond_14)
          and (previous_candle["AROONU_14"] > previous_candle["AROOND_14"])
        )
        or (
          (last_rsi_14_gt_64)
          and (last_rsi_3_15m < 85.0)
          and (last_rsi_3_1h_lt_80)
          and (last_rsi_3_4h_lt_80)
          and (last_rsi_14_1h_gt_20)
          and (last_rsi_14_4h_gt_40)
          and (last_candle["KST_10_15_20_30_10_10_10_15"] < last_candle["KSTs_9"])
          and (previous_candle["KST_10_15_20_30_10_10_10_15"] > previous_candle["KSTs_9"])
        )
        or (
          is_derisk
          and (last_rsi_3 < 80.0)
          and (last_rsi_3_15m < 80.0)
          and (last_rsi_3_1h_lt_80)
          and (last_rsi_3_4h_lt_80)
          and (last_rsi_14_gt_64)
          and (last_aroond_14_lt_25)
          and (last_aroond_14_15m_lt_25)
          and (last_candle["STOCHRSIk_14_14_3_3_15m"] > 50.0)
          and (last_close > (last_candle["EMA_20"] * 1.020))
        )
      )
    ):
      return True

    return False

  # Short Grinding Adjust Trade Position No De-Risk
  # ---------------------------------------------------------------------------------------------
  def short_adjust_trade_position_no_derisk(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    last_candle: Series,
    previous_candle: Series,
    filled_orders: "Orders",
    filled_entries: "Orders",
    filled_exits: "Orders",
    exit_rate: float,
    slice_amount: float,
    slice_profit_entry: float,
    slice_profit: float,
    profit_ratio: float,
    profit_stake: float,
    profit_init_ratio: float,
    current_stake_amount: float,
    has_order_tags: bool,
    count_of_exits: int,
    **kwargs,
  ) -> tuple[Optional[float], str, bool]:
    dp = self.dp
    send_msg = self.dp.send_msg
    notification_msg = self.notification_msg
    scale_stakes_for_min_stake = self.scale_stakes_for_min_stake
    stake_currency = self.config["stake_currency"]
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_stake_amount = trade.stake_amount
    trade_fee_open = trade.fee_open
    trade_fee_close = trade.fee_close

    is_backtest = dp.runmode.value in ["backtest", "hyperopt"]
    trade_open_date = None if is_backtest else trade.open_date_utc.replace(tzinfo=None)
    is_futures = self.is_futures_mode
    trade_leverage = trade.leverage
    stake_scale_leverage = trade_leverage if is_futures else 1.0
    regular_mode_use_grind_stops = self.regular_mode_use_grind_stops

    # Reused no-derisk slice-profit gates
    slice_profit_gt_0_02 = slice_profit > 0.02
    slice_profit_gt_0_03 = slice_profit > 0.03
    slice_profit_gt_0_06 = slice_profit > 0.06

    last_filled_entry = filled_entries[-1]
    first_filled_order = filled_orders[0]
    last_filled_order = filled_orders[-1]

    max_rebuy_sub_grinds = 0
    regular_mode_rebuy_stakes = scale_stakes_for_min_stake(
      self.regular_mode_rebuy_stakes_futures if is_futures else self.regular_mode_rebuy_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_rebuy_sub_thresholds = (
      self.regular_mode_rebuy_thresholds_futures if is_futures else self.regular_mode_rebuy_thresholds_spot
    )
    max_rebuy_sub_grinds = len(regular_mode_rebuy_stakes)

    max_grind_1_sub_grinds = 0
    regular_mode_grind_1_stakes = scale_stakes_for_min_stake(
      self.regular_mode_grind_1_stakes_futures if is_futures else self.regular_mode_grind_1_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_grind_1_sub_thresholds = (
      self.regular_mode_grind_1_thresholds_futures if is_futures else self.regular_mode_grind_1_thresholds_spot
    )
    max_grind_1_sub_grinds = len(regular_mode_grind_1_stakes)
    regular_mode_grind_1_stop_grinds = (
      self.regular_mode_grind_1_stop_grinds_futures if is_futures else self.regular_mode_grind_1_stop_grinds_spot
    )
    regular_mode_grind_1_profit_threshold = (
      self.regular_mode_grind_1_profit_threshold_futures
      if is_futures
      else self.regular_mode_grind_1_profit_threshold_spot
    )

    max_grind_2_sub_grinds = 0
    regular_mode_grind_2_stakes = scale_stakes_for_min_stake(
      self.regular_mode_grind_2_stakes_futures if is_futures else self.regular_mode_grind_2_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_grind_2_sub_thresholds = (
      self.regular_mode_grind_2_thresholds_futures if is_futures else self.regular_mode_grind_2_thresholds_spot
    )
    max_grind_2_sub_grinds = len(regular_mode_grind_2_stakes)
    regular_mode_grind_2_stop_grinds = (
      self.regular_mode_grind_2_stop_grinds_futures if is_futures else self.regular_mode_grind_2_stop_grinds_spot
    )
    regular_mode_grind_2_profit_threshold = (
      self.regular_mode_grind_2_profit_threshold_futures
      if is_futures
      else self.regular_mode_grind_2_profit_threshold_spot
    )

    max_grind_3_sub_grinds = 0
    regular_mode_grind_3_stakes = scale_stakes_for_min_stake(
      self.regular_mode_grind_3_stakes_futures if is_futures else self.regular_mode_grind_3_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_grind_3_sub_thresholds = (
      self.regular_mode_grind_3_thresholds_futures if is_futures else self.regular_mode_grind_3_thresholds_spot
    )
    max_grind_3_sub_grinds = len(regular_mode_grind_3_stakes)
    regular_mode_grind_3_stop_grinds = (
      self.regular_mode_grind_3_stop_grinds_futures if is_futures else self.regular_mode_grind_3_stop_grinds_spot
    )
    regular_mode_grind_3_profit_threshold = (
      self.regular_mode_grind_3_profit_threshold_futures
      if is_futures
      else self.regular_mode_grind_3_profit_threshold_spot
    )

    max_grind_4_sub_grinds = 0
    regular_mode_grind_4_stakes = scale_stakes_for_min_stake(
      self.regular_mode_grind_4_stakes_futures if is_futures else self.regular_mode_grind_4_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_grind_4_sub_thresholds = (
      self.regular_mode_grind_4_thresholds_futures if is_futures else self.regular_mode_grind_4_thresholds_spot
    )
    max_grind_4_sub_grinds = len(regular_mode_grind_4_stakes)
    regular_mode_grind_4_stop_grinds = (
      self.regular_mode_grind_4_stop_grinds_futures if is_futures else self.regular_mode_grind_4_stop_grinds_spot
    )
    regular_mode_grind_4_profit_threshold = (
      self.regular_mode_grind_4_profit_threshold_futures
      if is_futures
      else self.regular_mode_grind_4_profit_threshold_spot
    )

    max_grind_5_sub_grinds = 0
    regular_mode_grind_5_stakes = scale_stakes_for_min_stake(
      self.regular_mode_grind_5_stakes_futures if is_futures else self.regular_mode_grind_5_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_grind_5_sub_thresholds = (
      self.regular_mode_grind_5_thresholds_futures if is_futures else self.regular_mode_grind_5_thresholds_spot
    )
    max_grind_5_sub_grinds = len(regular_mode_grind_5_stakes)
    regular_mode_grind_5_stop_grinds = (
      self.regular_mode_grind_5_stop_grinds_futures if is_futures else self.regular_mode_grind_5_stop_grinds_spot
    )
    regular_mode_grind_5_profit_threshold = (
      self.regular_mode_grind_5_profit_threshold_futures
      if is_futures
      else self.regular_mode_grind_5_profit_threshold_spot
    )

    max_grind_6_sub_grinds = 0
    regular_mode_grind_6_stakes = scale_stakes_for_min_stake(
      self.regular_mode_grind_6_stakes_futures if is_futures else self.regular_mode_grind_6_stakes_spot,
      slice_amount,
      min_stake,
      trade_leverage,
      trade_leverage,
    )
    regular_mode_grind_6_sub_thresholds = (
      self.regular_mode_grind_6_thresholds_futures if is_futures else self.regular_mode_grind_6_thresholds_spot
    )
    max_grind_6_sub_grinds = len(regular_mode_grind_6_stakes)
    regular_mode_grind_6_stop_grinds = (
      self.regular_mode_grind_6_stop_grinds_futures if is_futures else self.regular_mode_grind_6_stop_grinds_spot
    )
    regular_mode_grind_6_profit_threshold = (
      self.regular_mode_grind_6_profit_threshold_futures
      if is_futures
      else self.regular_mode_grind_6_profit_threshold_spot
    )

    partial_sell = False
    is_derisk = False
    is_derisk_1 = False
    rebuy_sub_grind_count = 0
    rebuy_total_amount = 0.0
    rebuy_total_cost = 0.0
    rebuy_current_open_rate = 0.0
    rebuy_current_grind_stake = 0.0
    rebuy_current_grind_stake_profit = 0.0
    rebuy_is_sell_found = False
    rebuy_found = False
    rebuy_buy_orders = []
    rebuy_distance_ratio = 0.0
    grind_1_sub_grind_count = 0
    grind_1_total_amount = 0.0
    grind_1_total_cost = 0.0
    grind_1_current_open_rate = 0.0
    grind_1_current_grind_stake = 0.0
    grind_1_current_grind_stake_profit = 0.0
    grind_1_is_sell_found = False
    grind_1_found = False
    grind_1_buy_orders = []
    grind_1_distance_ratio = 0.0
    grind_2_sub_grind_count = 0
    grind_2_total_amount = 0.0
    grind_2_total_cost = 0.0
    grind_2_current_open_rate = 0.0
    grind_2_current_grind_stake = 0.0
    grind_2_current_grind_stake_profit = 0.0
    grind_2_is_sell_found = False
    grind_2_found = False
    grind_2_buy_orders = []
    grind_2_distance_ratio = 0.0
    grind_3_sub_grind_count = 0
    grind_3_total_amount = 0.0
    grind_3_total_cost = 0.0
    grind_3_current_open_rate = 0.0
    grind_3_current_grind_stake = 0.0
    grind_3_current_grind_stake_profit = 0.0
    grind_3_is_sell_found = False
    grind_3_found = False
    grind_3_buy_orders = []
    grind_3_distance_ratio = 0.0
    grind_4_sub_grind_count = 0
    grind_4_total_amount = 0.0
    grind_4_total_cost = 0.0
    grind_4_current_open_rate = 0.0
    grind_4_current_grind_stake = 0.0
    grind_4_current_grind_stake_profit = 0.0
    grind_4_is_sell_found = False
    grind_4_found = False
    grind_4_buy_orders = []
    grind_4_distance_ratio = 0.0
    grind_5_sub_grind_count = 0
    grind_5_total_amount = 0.0
    grind_5_total_cost = 0.0
    grind_5_current_open_rate = 0.0
    grind_5_current_grind_stake = 0.0
    grind_5_current_grind_stake_profit = 0.0
    grind_5_is_sell_found = False
    grind_5_found = False
    grind_5_buy_orders = []
    grind_5_distance_ratio = 0.0
    grind_6_sub_grind_count = 0
    grind_6_total_amount = 0.0
    grind_6_total_cost = 0.0
    grind_6_current_open_rate = 0.0
    grind_6_current_grind_stake = 0.0
    grind_6_current_grind_stake_profit = 0.0
    grind_6_is_sell_found = False
    grind_6_found = False
    grind_6_buy_orders = []
    grind_6_distance_ratio = 0.0
    for order in reversed(filled_orders):
      order_side = order.ft_order_side
      if (order_side == "sell") and (order is not first_filled_order):
        order_tag = ""
        if has_order_tags:
          order_ft_tag = order.ft_order_tag
          if order_ft_tag is not None:
            order_tag = order_ft_tag
        order_safe_filled = order.safe_filled
        order_safe_price = order.safe_price
        order_id = order.id
        if not grind_1_is_sell_found and order_tag == "g1":
          grind_1_sub_grind_count += 1
          grind_1_total_amount += order_safe_filled
          grind_1_total_cost += order_safe_filled * order_safe_price
          grind_1_buy_orders.append(order_id)
          if not grind_1_found:
            grind_1_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_1_found = True
        elif not grind_2_is_sell_found and order_tag == "g2":
          grind_2_sub_grind_count += 1
          grind_2_total_amount += order_safe_filled
          grind_2_total_cost += order_safe_filled * order_safe_price
          grind_2_buy_orders.append(order_id)
          if not grind_2_found:
            grind_2_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_2_found = True
        elif not grind_3_is_sell_found and order_tag == "g3":
          grind_3_sub_grind_count += 1
          grind_3_total_amount += order_safe_filled
          grind_3_total_cost += order_safe_filled * order_safe_price
          grind_3_buy_orders.append(order_id)
          if not grind_3_found:
            grind_3_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_3_found = True
        elif not grind_4_is_sell_found and order_tag == "g4":
          grind_4_sub_grind_count += 1
          grind_4_total_amount += order_safe_filled
          grind_4_total_cost += order_safe_filled * order_safe_price
          grind_4_buy_orders.append(order_id)
          if not grind_4_found:
            grind_4_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_4_found = True
        elif not grind_5_is_sell_found and order_tag == "g5":
          grind_5_sub_grind_count += 1
          grind_5_total_amount += order_safe_filled
          grind_5_total_cost += order_safe_filled * order_safe_price
          grind_5_buy_orders.append(order_id)
          if not grind_5_found:
            grind_5_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_5_found = True
        elif not grind_6_is_sell_found and order_tag == "g6":
          grind_6_sub_grind_count += 1
          grind_6_total_amount += order_safe_filled
          grind_6_total_cost += order_safe_filled * order_safe_price
          grind_6_buy_orders.append(order_id)
          if not grind_6_found:
            grind_6_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            grind_6_found = True
        elif not rebuy_is_sell_found and order_tag not in [
          "g1",
          "g2",
          "g3",
          "g4",
          "g5",
          "g6",
          "sg1",
          "sg2",
          "sg3",
          "sg4",
          "sg5",
          "sg6",
          "dl1",
          "dl2",
          "gd1",
          "gd2",
          "gd3",
          "gd4",
          "gd5",
          "gd6",
          "gm0",
          "gmd0",
        ]:
          rebuy_sub_grind_count += 1
          rebuy_total_amount += order_safe_filled
          rebuy_total_cost += order_safe_filled * order_safe_price
          rebuy_buy_orders.append(order_id)
          if not rebuy_found:
            rebuy_distance_ratio = (exit_rate - order_safe_price) / order_safe_price
            rebuy_found = True
      elif order_side == "buy":
        if order is filled_exits[-1] and (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
          break
        order_tag = ""
        if has_order_tags:
          order_ft_tag = order.ft_order_tag
          if order_ft_tag is not None:
            order_tag = order_ft_tag.partition(" ")[0]
        if order_tag in ["g1", "sg1"]:
          grind_1_is_sell_found = True
        elif order_tag in ["g2", "sg2"]:
          grind_2_is_sell_found = True
        elif order_tag in ["g3", "sg3"]:
          grind_3_is_sell_found = True
        elif order_tag in ["g4", "sg4"]:
          grind_4_is_sell_found = True
        elif order_tag in ["g5", "sg5"]:
          grind_5_is_sell_found = True
        elif order_tag in ["g6", "sg6"]:
          grind_6_is_sell_found = True
        elif order_tag in ["d", "d1", "dd0", "ddl1", "ddl2", "dd1", "dd2", "dd3", "dd4", "dd5", "dd6"]:
          is_derisk = True
          if order_tag == "d1":
            is_derisk_1 = True
          grind_1_is_sell_found = True
          grind_2_is_sell_found = True
          grind_3_is_sell_found = True
          grind_4_is_sell_found = True
          grind_5_is_sell_found = True
          grind_6_is_sell_found = True
          rebuy_is_sell_found = True
        elif order_tag not in [
          "p",
          "g1",
          "g2",
          "g3",
          "g4",
          "g5",
          "g6",
          "sg1",
          "sg2",
          "sg3",
          "sg4",
          "sg5",
          "sg6",
          "dl1",
          "dl2",
          "gd1",
          "gd2",
          "gd3",
          "gd4",
          "gd5",
          "gd6",
          "gm0",
          "gmd0",
        ]:
          rebuy_is_sell_found = True
        if not is_derisk:
          start_amount = first_filled_order.safe_filled
          current_amount = 0.0
          for order2 in filled_orders:
            if order2.ft_order_side == "sell":
              current_amount += order2.safe_filled
            elif order2.ft_order_side == "buy":
              current_amount -= order2.safe_filled
            if order2 is order:
              if current_amount < (start_amount * 0.95):
                is_derisk = True
        # found sells for all modes
        if (
          rebuy_is_sell_found
          and grind_1_is_sell_found
          and grind_2_is_sell_found
          and grind_3_is_sell_found
          and grind_4_is_sell_found
          and grind_5_is_sell_found
          and grind_6_is_sell_found
        ):
          break

    # The trade already de-risked
    if is_derisk:
      return None, "", is_derisk
    if not has_order_tags and count_of_exits > 0:
      return None, "", is_derisk

    if rebuy_sub_grind_count > 0:
      rebuy_current_open_rate = rebuy_total_cost / rebuy_total_amount
      rebuy_current_grind_stake = rebuy_total_amount * exit_rate * (1 + trade_fee_close)
      rebuy_current_grind_stake_profit = rebuy_total_cost - rebuy_current_grind_stake
    if grind_1_sub_grind_count > 0:
      grind_1_current_open_rate = grind_1_total_cost / grind_1_total_amount
      grind_1_current_grind_stake = grind_1_total_amount * exit_rate * (1 + trade_fee_close)
      grind_1_current_grind_stake_profit = grind_1_total_cost - grind_1_current_grind_stake
    if grind_2_sub_grind_count > 0:
      grind_2_current_open_rate = grind_2_total_cost / grind_2_total_amount
      grind_2_current_grind_stake = grind_2_total_amount * exit_rate * (1 + trade_fee_close)
      grind_2_current_grind_stake_profit = grind_2_total_cost - grind_2_current_grind_stake
    if grind_3_sub_grind_count > 0:
      grind_3_current_open_rate = grind_3_total_cost / grind_3_total_amount
      grind_3_current_grind_stake = grind_3_total_amount * exit_rate * (1 + trade_fee_close)
      grind_3_current_grind_stake_profit = grind_3_total_cost - grind_3_current_grind_stake
    if grind_4_sub_grind_count > 0:
      grind_4_current_open_rate = grind_4_total_cost / grind_4_total_amount
      grind_4_current_grind_stake = grind_4_total_amount * exit_rate * (1 + trade_fee_close)
      grind_4_current_grind_stake_profit = grind_4_total_cost - grind_4_current_grind_stake
    if grind_5_sub_grind_count > 0:
      grind_5_current_open_rate = grind_5_total_cost / grind_5_total_amount
      grind_5_current_grind_stake = grind_5_total_amount * exit_rate * (1 + trade_fee_close)
      grind_5_current_grind_stake_profit = grind_5_total_cost - grind_5_current_grind_stake
    if grind_6_sub_grind_count > 0:
      grind_6_current_open_rate = grind_6_total_cost / grind_6_total_amount
      grind_6_current_grind_stake = grind_6_total_amount * exit_rate * (1 + trade_fee_close)
      grind_6_current_grind_stake_profit = grind_6_current_grind_stake - grind_6_total_cost

    num_open_grinds = (
      grind_1_sub_grind_count
      + grind_2_sub_grind_count
      + grind_3_sub_grind_count
      + grind_4_sub_grind_count
      + grind_5_sub_grind_count
      + grind_6_sub_grind_count
    )

    is_scalp_mode = all(c in self.short_scalp_mode_tags for c in enter_tags)

    fee_open_rate = trade_fee_open if self.custom_fee_open_rate is None else self.custom_fee_open_rate
    fee_close_rate = trade_fee_close if self.custom_fee_close_rate is None else self.custom_fee_close_rate

    # Sell remaining if partial fill on exit
    if partial_sell:
      order = filled_exits[-1]
      sell_amount = order.safe_remaining * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        send_msg(
          f"Exit (remaining) [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {order.safe_remaining} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        order_tag = "p"
        if has_order_tags:
          if order.ft_order_tag is not None:
            order_tag = order.ft_order_tag
        return -ft_sell_amount, order_tag, is_derisk

    is_short_grind_entry = self.short_grind_entry(last_candle, previous_candle, slice_profit, False)

    # Rebuy
    if (not partial_sell) and (not rebuy_is_sell_found) and (rebuy_sub_grind_count < max_rebuy_sub_grinds):
      if (
        (0 <= rebuy_sub_grind_count < max_rebuy_sub_grinds)
        and (slice_profit_entry < regular_mode_rebuy_sub_thresholds[rebuy_sub_grind_count])
        and (
          (-rebuy_distance_ratio if (rebuy_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_rebuy_sub_thresholds[rebuy_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=12) > last_filled_order.order_filled_utc) or (slice_profit_gt_0_06))
        and is_short_grind_entry
      ):
        buy_amount = slice_amount * regular_mode_rebuy_stakes[rebuy_sub_grind_count] / stake_scale_leverage
        if buy_amount > max_stake:
          buy_amount = max_stake
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        send_msg(
          notification_msg(
            "rebuy",
            tag="r",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"Rebuy (r) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        order_tag = "r"
        return buy_amount, order_tag, is_derisk

    # Grinding g1
    # Grinding entry
    if has_order_tags and (not partial_sell) and (grind_1_sub_grind_count < max_grind_1_sub_grinds):
      if (
        (
          (-grind_1_distance_ratio if (grind_1_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_grind_1_sub_thresholds[grind_1_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or (slice_profit_gt_0_02))
        and (
          (num_open_grinds == 0)
          or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
          or (slice_profit_gt_0_06)
        )
        and ((num_open_grinds == 0) or (slice_profit_gt_0_03))
        and is_short_grind_entry
      ):
        buy_amount = slice_amount * regular_mode_grind_1_stakes[grind_1_sub_grind_count] / stake_scale_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_1_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
          grind_profit_stake = grind_1_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="g1",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_1_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (g1) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "g1"
        return buy_amount, order_tag, is_derisk

    if (
      is_futures
      and has_order_tags
      and (not partial_sell)
      and slice_profit > (0.65 / trade_leverage)
      and (grind_1_sub_grind_count < max_grind_1_sub_grinds)
    ):
      buy_amount = slice_amount * regular_mode_grind_1_stakes[grind_1_sub_grind_count] / stake_scale_leverage
      if buy_amount < (min_stake * 1.5):
        buy_amount = min_stake * 1.5
      if buy_amount > max_stake:
        return None, "", is_derisk
      grind_profit = 0.0
      grind_profit_stake = 0.0
      if grind_1_sub_grind_count > 0:
        grind_profit = -(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
        grind_profit_stake = grind_1_current_grind_stake_profit
      send_msg(
        notification_msg(
          "grinding-entry",
          tag="g1",
          pair=trade_pair,
          rate=current_rate,
          stake_amount=buy_amount,
          profit_stake=profit_stake,
          profit_ratio=profit_ratio,
          stake_currency=stake_currency,
          grind_profit_stake=grind_1_current_grind_stake_profit,
          grind_profit_pct=grind_profit,
        )
      )
      log.info(
        f"Grinding entry (g1) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_1_current_grind_stake_profit} {stake_currency})"
      )
      order_tag = "g1"
      return buy_amount, order_tag, is_derisk

    # Grinding Exit
    if has_order_tags and grind_1_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate
      if grind_profit > (regular_mode_grind_1_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_1_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="g1",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_1_total_amount,
            )
          )
          log.info(
            f"Grinding exit (g1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "g1"
          for grind_entry_id in grind_1_buy_orders:
            order_tag += " " + str(grind_entry_id)
          return -ft_sell_amount, order_tag, is_derisk

    # Grind stop
    if (
      (
        (grind_1_sub_grind_count > 0)
        and regular_mode_use_grind_stops
        and ((-(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate) < regular_mode_grind_1_stop_grinds)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 4, 16))
    ):
      sell_amount = grind_1_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_1_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_1_current_open_rate) / grind_1_current_open_rate)
            if grind_1_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="sg1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_1_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (sg1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_1_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "sg1"
        for grind_entry_id in grind_1_buy_orders:
          order_tag += " " + str(grind_entry_id)
        return -ft_sell_amount, order_tag, is_derisk

    # Grinding g2
    # Grinding entry
    if has_order_tags and (not partial_sell) and (grind_2_sub_grind_count < max_grind_2_sub_grinds):
      if (
        (
          (-grind_2_distance_ratio if (grind_2_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_grind_2_sub_thresholds[grind_2_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or (slice_profit_gt_0_02))
        and (
          (num_open_grinds == 0)
          or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
          or (slice_profit_gt_0_06)
        )
        and ((num_open_grinds == 0) or (slice_profit_gt_0_03))
        and is_short_grind_entry
      ):
        buy_amount = slice_amount * regular_mode_grind_2_stakes[grind_2_sub_grind_count] / stake_scale_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_2_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
          grind_profit_stake = grind_2_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="g2",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_2_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (g2) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_2_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "g2"
        return buy_amount, order_tag, is_derisk

    # Grinding Exit
    if has_order_tags and grind_2_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate
      if grind_profit > (regular_mode_grind_2_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_2_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="g2",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_2_total_amount,
            )
          )
          log.info(
            f"Grinding exit (g2) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "g2"
          for grind_entry_id in grind_2_buy_orders:
            order_tag += " " + str(grind_entry_id)
          return -ft_sell_amount, order_tag, is_derisk

    # Grind stop
    if (
      (
        (grind_2_sub_grind_count > 0)
        and regular_mode_use_grind_stops
        and ((-(exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate) < regular_mode_grind_2_stop_grinds)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 4, 16))
    ):
      sell_amount = grind_2_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_2_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_2_current_open_rate) / grind_2_current_open_rate)
            if grind_2_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="sg2",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_2_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (sg2) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_2_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "sg2"
        for grind_entry_id in grind_2_buy_orders:
          order_tag += " " + str(grind_entry_id)
        return -ft_sell_amount, order_tag, is_derisk

    # Grinding g3
    # Grinding entry
    if has_order_tags and (not partial_sell) and (grind_3_sub_grind_count < max_grind_3_sub_grinds):
      if (
        (
          (-grind_3_distance_ratio if (grind_3_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_grind_3_sub_thresholds[grind_3_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or (slice_profit_gt_0_02))
        and (
          (num_open_grinds == 0)
          or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
          or (slice_profit_gt_0_06)
        )
        and ((num_open_grinds == 0) or (slice_profit_gt_0_03))
        and is_short_grind_entry
      ):
        buy_amount = slice_amount * regular_mode_grind_3_stakes[grind_3_sub_grind_count] / stake_scale_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_3_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
          grind_profit_stake = grind_3_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="g3",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_3_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (g3) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_3_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "g3"
        return buy_amount, order_tag, is_derisk

    # Grinding Exit
    if has_order_tags and grind_3_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate
      if grind_profit > (regular_mode_grind_3_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_3_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="g3",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_3_total_amount,
            )
          )
          log.info(
            f"Grinding exit (g3) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "g3"
          for grind_entry_id in grind_3_buy_orders:
            order_tag += " " + str(grind_entry_id)
          return -ft_sell_amount, order_tag, is_derisk

    # Grind stop
    if (
      (
        (grind_3_sub_grind_count > 0)
        and regular_mode_use_grind_stops
        and ((-(exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate) < regular_mode_grind_3_stop_grinds)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 4, 16))
    ):
      sell_amount = grind_3_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_3_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_3_current_open_rate) / grind_3_current_open_rate)
            if grind_3_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="sg3",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_3_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (sg3) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_3_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "sg3"
        for grind_entry_id in grind_3_buy_orders:
          order_tag += " " + str(grind_entry_id)
        return -ft_sell_amount, order_tag, is_derisk

    # Grinding g4
    # Grinding entry
    if has_order_tags and (not partial_sell) and (grind_4_sub_grind_count < max_grind_4_sub_grinds):
      if (
        (
          (-grind_4_distance_ratio if (grind_4_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_grind_4_sub_thresholds[grind_4_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or (slice_profit_gt_0_02))
        and (
          (num_open_grinds == 0)
          or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
          or (slice_profit_gt_0_06)
        )
        and ((num_open_grinds == 0) or (slice_profit_gt_0_03))
        and is_short_grind_entry
      ):
        buy_amount = slice_amount * regular_mode_grind_4_stakes[grind_4_sub_grind_count] / stake_scale_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_4_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
          grind_profit_stake = grind_4_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="g4",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_4_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (g4) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_4_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "g4"
        return buy_amount, order_tag, is_derisk

    # Grinding Exit
    if has_order_tags and grind_4_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate
      if grind_profit > (regular_mode_grind_4_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_4_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="g4",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_4_total_amount,
            )
          )
          log.info(
            f"Grinding exit (g4) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "g4"
          for grind_entry_id in grind_4_buy_orders:
            order_tag += " " + str(grind_entry_id)
          return -ft_sell_amount, order_tag, is_derisk

    # Grind stop
    if (
      (
        (grind_4_sub_grind_count > 0)
        and regular_mode_use_grind_stops
        and ((-(exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate) < regular_mode_grind_4_stop_grinds)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 4, 16))
    ):
      sell_amount = grind_4_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_4_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_4_current_open_rate) / grind_4_current_open_rate)
            if grind_4_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="sg4",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_4_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (sg4) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_4_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "sg4"
        for grind_entry_id in grind_4_buy_orders:
          order_tag += " " + str(grind_entry_id)
        return -ft_sell_amount, order_tag, is_derisk

    # Grinding g5
    # Grinding entry
    if has_order_tags and (not partial_sell) and (grind_5_sub_grind_count < max_grind_5_sub_grinds):
      if (
        (
          (-grind_5_distance_ratio if (grind_5_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_grind_5_sub_thresholds[grind_5_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or (slice_profit_gt_0_02))
        and (
          (num_open_grinds == 0)
          or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
          or (slice_profit_gt_0_06)
        )
        and ((num_open_grinds == 0) or (slice_profit_gt_0_03))
        and is_short_grind_entry
      ):
        buy_amount = slice_amount * regular_mode_grind_5_stakes[grind_5_sub_grind_count] / stake_scale_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_5_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
          grind_profit_stake = grind_5_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="g5",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_5_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (g5) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_5_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "g5"
        return buy_amount, order_tag, is_derisk

    # Grinding Exit
    if has_order_tags and grind_5_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate
      if grind_profit > (regular_mode_grind_5_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_5_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="g5",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_5_total_amount,
            )
          )
          log.info(
            f"Grinding exit (g5) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "g5"
          for grind_entry_id in grind_5_buy_orders:
            order_tag += " " + str(grind_entry_id)
          return -ft_sell_amount, order_tag, is_derisk

    # Grind stop
    if (
      (
        (grind_5_sub_grind_count > 0)
        and regular_mode_use_grind_stops
        and ((-(exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate) < regular_mode_grind_5_stop_grinds)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 4, 16))
    ):
      sell_amount = grind_5_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_5_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_5_current_open_rate) / grind_5_current_open_rate)
            if grind_5_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="sg5",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_5_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (sg5) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_5_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "sg5"
        for grind_entry_id in grind_5_buy_orders:
          order_tag += " " + str(grind_entry_id)
        return -ft_sell_amount, order_tag, is_derisk

    # Grinding g6
    # Grinding entry
    if has_order_tags and (not partial_sell) and (grind_6_sub_grind_count < max_grind_6_sub_grinds):
      if (
        (
          (-grind_6_distance_ratio if (grind_6_sub_grind_count > 0) else profit_init_ratio)
          < (regular_mode_grind_6_sub_thresholds[grind_6_sub_grind_count])
        )
        and (current_time - timedelta(minutes=10) > last_filled_entry.order_filled_utc)
        and ((current_time - timedelta(hours=2) > last_filled_order.order_filled_utc) or (slice_profit_gt_0_02))
        and (
          (num_open_grinds == 0)
          or (current_time - timedelta(hours=6) > last_filled_order.order_filled_utc)
          or (slice_profit_gt_0_06)
        )
        # and ((num_open_grinds == 0) or (slice_profit_gt_0_03))
        and (is_short_grind_entry)
      ):
        buy_amount = slice_amount * regular_mode_grind_6_stakes[grind_6_sub_grind_count] / stake_scale_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount > max_stake:
          return None, "", is_derisk
        grind_profit = 0.0
        grind_profit_stake = 0.0
        if grind_6_sub_grind_count > 0:
          grind_profit = -(exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate
          grind_profit_stake = grind_6_current_grind_stake_profit
        send_msg(
          notification_msg(
            "grinding-entry",
            tag="g6",
            pair=trade_pair,
            rate=current_rate,
            stake_amount=buy_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_6_current_grind_stake_profit,
            grind_profit_pct=grind_profit,
          )
        )
        log.info(
          f"Grinding entry (g6) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_6_current_grind_stake_profit} {stake_currency})"
        )
        order_tag = "g6"
        return buy_amount, order_tag, is_derisk

    # Grinding Exit
    if has_order_tags and grind_6_sub_grind_count > 0:
      grind_profit = -(exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate
      if grind_profit > (regular_mode_grind_6_profit_threshold + fee_open_rate + fee_close_rate):
        sell_amount = grind_6_total_amount * exit_rate / trade_leverage
        if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
          sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
        ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
        if sell_amount > min_stake and ft_sell_amount > min_stake:
          send_msg(
            notification_msg(
              "grinding-exit",
              tag="g6",
              pair=trade_pair,
              rate=exit_rate,
              stake_amount=sell_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=stake_currency,
              grind_profit_stake=grind_profit * sell_amount * trade_leverage,
              grind_profit_pct=grind_profit,
              coin_amount=grind_6_total_amount,
            )
          )
          log.info(
            f"Grinding exit (g6) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_6_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}% ({grind_profit * sell_amount * trade_leverage} {stake_currency})"
          )
          order_tag = "g6"
          for grind_entry_id in grind_6_buy_orders:
            order_tag += " " + str(grind_entry_id)
          return -ft_sell_amount, order_tag, is_derisk

    # Grind stop
    if (
      (
        (grind_6_sub_grind_count > 0)
        and regular_mode_use_grind_stops
        and ((-(exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate) < regular_mode_grind_6_stop_grinds)
      )
      # temporary
      and (is_backtest or trade_open_date >= datetime(2024, 4, 16))
    ):
      sell_amount = grind_6_total_amount * exit_rate / trade_leverage
      if ((current_stake_amount / trade_leverage) - sell_amount) < (min_stake * 1.55):
        sell_amount = (trade_amount * exit_rate / trade_leverage) - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        if grind_6_current_open_rate > 0.0:
          grind_profit = (
            (-(exit_rate - grind_6_current_open_rate) / grind_6_current_open_rate)
            if grind_6_is_sell_found
            else profit_ratio
          )
        send_msg(
          notification_msg(
            "grinding-stop",
            tag="sg6",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
            grind_profit_stake=grind_profit * sell_amount * trade_leverage,
            grind_profit_pct=grind_profit,
            coin_amount=grind_6_total_amount,
          )
        )
        log.info(
          f"Grinding stop exit (sg6) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Coin amount: {grind_6_total_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}% | Grind profit: {(grind_profit * 100.0):.2f}%"
        )
        order_tag = "sg6"
        for grind_entry_id in grind_6_buy_orders:
          order_tag += " " + str(grind_entry_id)
        return -ft_sell_amount, order_tag, is_derisk

    # De-risk
    if (
      self.derisk_enable
      and (
        profit_stake
        < (
          slice_amount
          * (
            (self.regular_mode_derisk_futures if is_futures else self.regular_mode_derisk_spot)
            if (is_backtest or trade_open_date >= datetime(2024, 9, 13))
            else (self.regular_mode_derisk_futures_old if is_futures else self.regular_mode_derisk_spot_old)
          )
          / trade_leverage
        )
      )
      and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
    ):
      sell_amount = trade_amount * exit_rate / trade_leverage - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="d",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "d", is_derisk

    # De-risk level 1
    if (
      self.derisk_enable
      and has_order_tags
      and not is_derisk_1
      and (is_backtest or trade_open_date >= datetime(2024, 9, 13))
      and profit_stake
      < (
        slice_amount
        * (
          (self.regular_mode_derisk_1_scalp_mode_futures if is_futures else self.regular_mode_derisk_1_scalp_mode_spot)
          if is_scalp_mode
          else (
            (self.regular_mode_derisk_1_futures if is_futures else self.regular_mode_derisk_1_spot)
            if (is_backtest or trade_open_date >= datetime(2024, 9, 13))
            else (self.regular_mode_derisk_1_futures_old if is_futures else self.regular_mode_derisk_1_spot_old)
          )
        )
        / trade_leverage
      )
    ):
      sell_amount = trade_amount * exit_rate / trade_leverage - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade_stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        send_msg(
          notification_msg(
            "de-risk",
            tag="d1",
            pair=trade_pair,
            rate=exit_rate,
            stake_amount=sell_amount,
            profit_stake=profit_stake,
            profit_ratio=profit_ratio,
            stake_currency=stake_currency,
          )
        )
        log.info(
          f"De-risk (d1) [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        return -ft_sell_amount, "d1", is_derisk

    return None, "", is_derisk

  # Short Rebuy Adjust Trade Position
  # ---------------------------------------------------------------------------------------------
  def short_rebuy_adjust_trade_position(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ) -> Optional[float]:
    # Stake limits and rebuy amounts are margin, before leverage.
    config = self.config

    dp = self.dp
    is_futures_mode = self.is_futures_mode
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_leverage = trade.leverage

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)

    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_entries = trade.nr_of_successful_entries
    count_of_exits = trade.nr_of_successful_exits

    if count_of_entries == 0:
      return None

    first_filled_order = filled_orders[0]
    last_filled_order = filled_orders[-1]
    last_filled_entry = filled_entries[-1]

    has_order_tags = hasattr(first_filled_order, "ft_order_tag")

    # The first exit is de-risk (providing the trade is still open)
    # Preserve the existing grind handoff budget after de-risk.
    if (count_of_exits > 0) and (filled_exits[0].ft_order_tag == "derisk_level_3"):
      if len(df) < 2:
        return None
      return self.short_grind_adjust_trade_position_v2(
        trade,
        enter_tags,
        current_time,
        current_rate,
        current_profit,
        min_stake,
        max_stake / trade_leverage,
        current_entry_rate,
        current_exit_rate,
        current_entry_profit,
        current_exit_profit,
      )

    if dp.runmode.value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = config["exit_pricing"]["price_side"]
        if trade.is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    slice_amount = filled_entries[0].safe_filled * filled_entries[0].safe_price
    slice_profit = (exit_rate - last_filled_order.safe_price) / last_filled_order.safe_price
    slice_profit_entry = (exit_rate - last_filled_entry.safe_price) / last_filled_entry.safe_price
    if count_of_exits > 0:
      last_filled_exit_price = filled_exits[-1].safe_price
      slice_profit_exit = (exit_rate - last_filled_exit_price) / last_filled_exit_price
    else:
      slice_profit_exit = 0.0

    current_stake_amount = trade_amount * current_rate
    stake_scale_leverage = trade_leverage if is_futures_mode else 1.0

    rebuy_mode_stakes = self.rebuy_mode_stakes_futures if is_futures_mode else self.rebuy_mode_stakes_spot
    max_sub_grinds = len(rebuy_mode_stakes)
    rebuy_mode_sub_thresholds = (
      self.rebuy_mode_thresholds_futures if is_futures_mode else self.rebuy_mode_thresholds_spot
    )
    partial_sell = False
    sub_grind_count = 0
    total_amount = 0.0
    total_cost = 0.0
    current_open_rate = 0.0
    current_grind_stake = 0.0
    current_grind_stake_profit = 0.0
    for order in reversed(filled_orders):
      if (order.ft_order_side == "sell") and (order is not first_filled_order):
        sub_grind_count += 1
        total_amount += order.safe_filled
        total_cost += order.safe_filled * order.safe_price
      elif order.ft_order_side == "buy":
        if (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
        break
    if sub_grind_count > 0:
      current_open_rate = total_cost / total_amount
      current_grind_stake = total_amount * exit_rate * (1 - trade.fee_close)
      current_grind_stake_profit = current_grind_stake - total_cost

    if (len(df) >= 2) and (not partial_sell) and (sub_grind_count < max_sub_grinds):
      last_candle = df.iloc[-1]
      previous_candle = df.iloc[-2]
      if (
        (0 <= sub_grind_count < max_sub_grinds) and (-slice_profit_entry < rebuy_mode_sub_thresholds[sub_grind_count])
      ) and (
        (last_candle["RSI_3"] < 90.0)
        and (last_candle["RSI_3_15m"] < 90.0)
        # and (last_candle["RSI_3_1h"] < 90.0)
        # and (last_candle["RSI_3_4h"] < 90.0)
        and (last_candle["RSI_14"] > 60.0)
        and (last_candle["ROC_2"] < 0.0)
        and (last_candle["close"] > (last_candle["EMA_26"] * 1.012))
      ):
        buy_amount = slice_amount * rebuy_mode_stakes[sub_grind_count] / trade_leverage
        if buy_amount < (min_stake * 1.5):
          buy_amount = min_stake * 1.5
        if buy_amount <= max_stake:
          dp.send_msg(
            self.notification_msg(
              "rebuy",
              tag="r",
              pair=trade_pair,
              rate=current_rate,
              stake_amount=buy_amount,
              profit_stake=profit_stake,
              profit_ratio=profit_ratio,
              stake_currency=config["stake_currency"],
            )
          )
          log.info(
            f"Rebuy (r) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
          )
          if has_order_tags:
            return buy_amount, "r"
          else:
            return buy_amount

    if self.derisk_enable and (
      profit_stake
      < (
        slice_amount * (self.rebuy_mode_derisk_futures if is_futures_mode else self.rebuy_mode_derisk_spot)
        # / (trade.leverage if self.is_futures_mode else 1.0)
      )
    ):
      sell_amount = trade_amount * exit_rate / trade_leverage - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade.stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        grind_profit = 0.0
        dp.send_msg(
          f"❌​​ ​**Rebuy De-risk:** `Level 3`\n"
          f"🪙​ **Pair:** `{trade_pair}`\n"
          f"〽️​ **Rate:** `{exit_rate}`\n"
          f"💰 **Stake amount:** `{sell_amount}`\n"
          f"💵​ **Profit (stake):** `{profit_stake}`\n"
          f"💸 **Profit (percent):** `{(profit_ratio * 100.0):.2f}%`"
        )
        log.info(
          f"Rebuy De-risk Level 3 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount} | Profit (stake): {profit_stake} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        if has_order_tags:
          return -ft_sell_amount, "derisk_level_3"
        else:
          return -ft_sell_amount

    return None

  # Short Rebuy Adjust Trade Position v3
  # ---------------------------------------------------------------------------------------------
  def short_rebuy_adjust_trade_position_v3(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ) -> Optional[float]:
    # Stake limits and rebuy amounts are margin, before leverage.
    dp = self.dp
    is_futures_mode = self.is_futures_mode
    config = self.config
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_leverage = trade.leverage

    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_entries = trade.nr_of_successful_entries
    count_of_exits = trade.nr_of_successful_exits

    if count_of_entries == 0:
      return None

    first_filled_order = filled_orders[0]
    last_filled_order = filled_orders[-1]
    last_filled_entry = filled_entries[-1]

    has_order_tags = hasattr(first_filled_order, "ft_order_tag")

    # The first exit is de-risk (providing the trade is still open)
    # Preserve the existing grind handoff budget after de-risk.
    if (count_of_exits > 0) and (filled_exits[0].ft_order_tag == "derisk_level_3"):
      return self.short_grind_adjust_trade_position_v3(
        trade,
        enter_tags,
        current_time,
        current_rate,
        current_profit,
        min_stake,
        max_stake / trade_leverage,
        current_entry_rate,
        current_exit_rate,
        current_entry_profit,
        current_exit_profit,
      )

    if dp.runmode.value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = config["exit_pricing"]["price_side"]
        if trade.is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    slice_amount = filled_entries[0].safe_filled * filled_entries[0].safe_price
    slice_profit = (exit_rate - last_filled_order.safe_price) / last_filled_order.safe_price
    slice_profit_entry = (exit_rate - last_filled_entry.safe_price) / last_filled_entry.safe_price
    slice_profit_exit = (
      ((exit_rate - filled_exits[-1].safe_price) / filled_exits[-1].safe_price) if count_of_exits > 0 else 0.0
    )

    current_stake_amount = trade_amount * current_rate
    stake_scale_leverage = trade_leverage if is_futures_mode else 1.0

    if is_futures_mode:
      rebuy_mode_stakes = self.system_v3_rebuy_mode_stakes_futures
      rebuy_mode_sub_thresholds = self.system_v3_rebuy_mode_thresholds_futures
    else:
      rebuy_mode_stakes = self.system_v3_rebuy_mode_stakes_spot
      rebuy_mode_sub_thresholds = self.system_v3_rebuy_mode_thresholds_spot
    max_sub_grinds = len(rebuy_mode_stakes)
    partial_sell = False
    sub_grind_count = 0
    total_amount = 0.0
    total_cost = 0.0
    current_open_rate = 0.0
    current_grind_stake = 0.0
    current_grind_stake_profit = 0.0
    for order in reversed(filled_orders):
      if (order.ft_order_side == "sell") and (order is not first_filled_order):
        sub_grind_count += 1
        total_amount += order.safe_filled
        total_cost += order.safe_filled * order.safe_price
      elif order.ft_order_side == "buy":
        if (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
        break
    if sub_grind_count > 0:
      current_open_rate = total_cost / total_amount
      current_grind_stake = total_amount * exit_rate * (1 - trade.fee_close)
      current_grind_stake_profit = current_grind_stake - total_cost
    if (not partial_sell) and (sub_grind_count < max_sub_grinds):
      df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)
      if len(df) >= 1:
        last_candle = df.iloc[-1]
        if (
          (
            (0 <= sub_grind_count < max_sub_grinds)
            and (-slice_profit_entry < rebuy_mode_sub_thresholds[sub_grind_count])
          )
          and (last_candle["protections_short_global"] == True)
          and (
            (last_candle["RSI_3"] < 90.0)
            and (last_candle["RSI_3_15m"] < 90.0)
            and (last_candle["AROOND_14"] < 30.0)
            and (last_candle["AROOND_14_15m"] < 30.0)
            and (last_candle["close"] < (last_candle["EMA_26"] * 1.012))
          )
        ):
          buy_amount = slice_amount * rebuy_mode_stakes[sub_grind_count] / trade_leverage
          if buy_amount < (min_stake * 1.5):
            buy_amount = min_stake * 1.5
          if buy_amount <= max_stake:
            stake_currency = config["stake_currency"]
            stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
            send_notifications = not self.is_backtest_mode()
            if send_notifications:
              dp.send_msg(
                self.notification_msg(
                  "rebuy",
                  tag="r",
                  pair=trade_pair,
                  rate=current_rate,
                  stake_amount=buy_amount,
                  profit_stake=profit_stake,
                  profit_ratio=profit_ratio,
                  stake_currency=stake_currency,
                )
              )
            log.info(
              f"Rebuy (r) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
            )
            if has_order_tags:
              return buy_amount, "r"
            else:
              return buy_amount

    if self.derisk_enable and (
      profit_stake
      < (
        slice_amount
        * (self.system_v3_rebuy_mode_derisk_futures if is_futures_mode else self.system_v3_rebuy_mode_derisk_spot)
      )
      / trade_leverage
    ):
      sell_amount = trade_amount * exit_rate / trade_leverage - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade.stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        stake_currency = config["stake_currency"]
        stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
        send_notifications = not self.is_backtest_mode()
        grind_profit = 0.0
        if send_notifications:
          dp.send_msg(
            f"❌​​ ​**Rebuy De-risk:** `Level 3`\n"
            f"🪙​ **Pair:** `{trade_pair}`\n"
            f"〽️​ **Rate:** `{exit_rate}`\n"
            f"💰 **Stake amount:** `{sell_amount:{stake_fmt}}`\n"
            f"💵​ **Profit (stake):** `{profit_stake:{stake_fmt}}`\n"
            f"💸 **Profit (percent):** `{(profit_ratio * 100.0):.2f}%`"
          )
        log.info(
          f"Rebuy De-risk Level 3 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        if has_order_tags:
          return -ft_sell_amount, "derisk_level_3"
        else:
          return -ft_sell_amount

    return None

  # Short Rebuy Adjust Trade Position v4
  # ---------------------------------------------------------------------------------------------
  def short_rebuy_adjust_trade_position_v4(
    self,
    trade: Trade,
    enter_tags,
    current_time: datetime,
    current_rate: float,
    current_profit: float,
    min_stake: Optional[float],
    max_stake: float,
    current_entry_rate: float,
    current_exit_rate: float,
    current_entry_profit: float,
    current_exit_profit: float,
    **kwargs,
  ) -> Optional[float]:
    # Stake limits and rebuy amounts are margin, before leverage.
    dp = self.dp
    is_futures_mode = self.is_futures_mode
    config = self.config
    trade_pair = trade.pair
    trade_amount = trade.amount
    trade_leverage = trade.leverage

    # we already waiting for an order to get filled
    if trade.has_open_orders:
      return None

    min_stake = self.correct_min_stake(min_stake, trade_leverage)
    exit_rate = current_rate
    filled_orders, filled_entries, filled_exits, profit_values = self.profit_or_order_snapshot(
      trade, current_time, exit_rate
    )
    count_of_entries = trade.nr_of_successful_entries
    count_of_exits = trade.nr_of_successful_exits

    if count_of_entries == 0:
      return None

    first_filled_order = filled_orders[0]
    last_filled_order = filled_orders[-1]
    last_filled_entry = filled_entries[-1]

    has_order_tags = hasattr(first_filled_order, "ft_order_tag")

    # The first exit is de-risk (providing the trade is still open)
    # Preserve the existing grind handoff budget after de-risk.
    if (count_of_exits > 0) and (filled_exits[0].ft_order_tag == "derisk_level_3"):
      return self.short_grind_adjust_trade_position_v4(
        trade,
        enter_tags,
        current_time,
        current_rate,
        current_profit,
        min_stake,
        max_stake / trade_leverage,
        current_entry_rate,
        current_exit_rate,
        current_entry_profit,
        current_exit_profit,
      )

    if dp.runmode.value in ("live", "dry_run"):
      ticker = dp.ticker(trade_pair)
      if ("bid" in ticker) and ("ask" in ticker):
        exit_price_side = config["exit_pricing"]["price_side"]
        if trade.is_short:
          if exit_price_side in ["ask", "other"]:
            if ticker["ask"] is not None:
              exit_rate = ticker["ask"]
        else:
          if exit_price_side in ["bid", "other"]:
            if ticker["bid"] is not None:
              exit_rate = ticker["bid"]

    if profit_values is None:
      profit_values = self.calc_total_profit(trade, filled_entries, filled_exits, exit_rate)
    profit_stake, profit_ratio, profit_current_stake_ratio, profit_init_ratio = profit_values

    slice_amount = filled_entries[0].safe_filled * filled_entries[0].safe_price
    slice_profit = (exit_rate - last_filled_order.safe_price) / last_filled_order.safe_price
    slice_profit_entry = (exit_rate - last_filled_entry.safe_price) / last_filled_entry.safe_price
    slice_profit_exit = (
      ((exit_rate - filled_exits[-1].safe_price) / filled_exits[-1].safe_price) if count_of_exits > 0 else 0.0
    )

    current_stake_amount = trade_amount * current_rate
    stake_scale_leverage = trade_leverage if is_futures_mode else 1.0

    if is_futures_mode:
      rebuy_mode_stakes = self.system_v4_rebuy_mode_stakes_futures
      rebuy_mode_sub_thresholds = self.system_v4_rebuy_mode_thresholds_futures
    else:
      rebuy_mode_stakes = self.system_v4_rebuy_mode_stakes_spot
      rebuy_mode_sub_thresholds = self.system_v4_rebuy_mode_thresholds_spot
    max_sub_grinds = len(rebuy_mode_stakes)
    partial_sell = False
    sub_grind_count = 0
    total_amount = 0.0
    total_cost = 0.0
    current_open_rate = 0.0
    current_grind_stake = 0.0
    current_grind_stake_profit = 0.0
    for order in reversed(filled_orders):
      if (order.ft_order_side == "sell") and (order is not first_filled_order):
        sub_grind_count += 1
        total_amount += order.safe_filled
        total_cost += order.safe_filled * order.safe_price
      elif order.ft_order_side == "buy":
        if (order.safe_remaining * exit_rate / stake_scale_leverage) > min_stake:
          partial_sell = True
        break
    if sub_grind_count > 0:
      current_open_rate = total_cost / total_amount
      current_grind_stake = total_amount * exit_rate * (1 - trade.fee_close)
      current_grind_stake_profit = current_grind_stake - total_cost
    if (not partial_sell) and (sub_grind_count < max_sub_grinds):
      if (0 <= sub_grind_count < max_sub_grinds) and (
        -slice_profit_entry < rebuy_mode_sub_thresholds[sub_grind_count]
      ):
        df, _ = dp.get_analyzed_dataframe(trade_pair, self.timeframe)
        if len(df) >= 1:
          last_candle = df.iloc[-1]
          if (
            (last_candle["protections_short_global"] == True)
            and (last_candle["RSI_3"] < 90.0)
            and (last_candle["RSI_3_15m"] < 90.0)
            and (last_candle["AROOND_14"] < 30.0)
            and (last_candle["AROOND_14_15m"] < 30.0)
            and (last_candle["close"] < (last_candle["EMA_26"] * 1.012))
          ):
            buy_amount = slice_amount * rebuy_mode_stakes[sub_grind_count] / trade_leverage
            if buy_amount < (min_stake * 1.5):
              buy_amount = min_stake * 1.5
            if buy_amount <= max_stake:
              stake_currency = config["stake_currency"]
              stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
              send_notifications = not self.is_backtest_mode()
              if send_notifications:
                dp.send_msg(
                  self.notification_msg(
                    "rebuy",
                    tag="r",
                    pair=trade_pair,
                    rate=current_rate,
                    stake_amount=buy_amount,
                    profit_stake=profit_stake,
                    profit_ratio=profit_ratio,
                    stake_currency=stake_currency,
                  )
                )
              log.info(
                f"Rebuy (r) [{current_time}] [{trade_pair}] | Rate: {current_rate} | Stake amount: {buy_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
              )
              if has_order_tags:
                return buy_amount, "r"
              else:
                return buy_amount

    if self.derisk_enable and (
      profit_stake
      < (
        slice_amount
        * (self.system_v4_rebuy_mode_derisk_futures if is_futures_mode else self.system_v4_rebuy_mode_derisk_spot)
      )
      / trade_leverage
    ):
      sell_amount = trade_amount * exit_rate / trade_leverage - (min_stake * 1.55)
      ft_sell_amount = sell_amount * trade_leverage * (trade.stake_amount / trade_amount) / exit_rate
      if sell_amount > min_stake and ft_sell_amount > min_stake:
        stake_currency = config["stake_currency"]
        stake_fmt = ".8f" if stake_currency in ("BTC", "ETH", "BNB", "SOL") else ".3f"
        send_notifications = not self.is_backtest_mode()
        grind_profit = 0.0
        if send_notifications:
          dp.send_msg(
            f"❌​​ ​**Rebuy De-risk:** `Level 3`\n"
            f"🪙​ **Pair:** `{trade_pair}`\n"
            f"〽️​ **Rate:** `{exit_rate}`\n"
            f"💰 **Stake amount:** `{sell_amount:{stake_fmt}}`\n"
            f"💵​ **Profit (stake):** `{profit_stake:{stake_fmt}}`\n"
            f"💸 **Profit (percent):** `{(profit_ratio * 100.0):.2f}%`"
          )
        log.info(
          f"Rebuy De-risk Level 3 [{current_time}] [{trade_pair}] | Rate: {exit_rate} | Stake amount: {sell_amount:{stake_fmt}} | Profit (stake): {profit_stake:{stake_fmt}} | Profit: {(profit_ratio * 100.0):.2f}%"
        )
        if has_order_tags:
          return -ft_sell_amount, "derisk_level_3"
        else:
          return -ft_sell_amount

    return None

  ###############################################################################################

  # SHORT GRIND FUNCTIONS ENDS HERE

  ###############################################################################################


# +---------------------------------------------------------------------------+
# |                              Custom Indicators                            |
# +---------------------------------------------------------------------------+


# Range midpoint acts as Support
# ---------------------------------------------------------------------------------------------
def is_support(row_data) -> bool:
  conditions = []
  for row in range(len(row_data) - 1):
    if row < len(row_data) // 2:
      conditions.append(row_data[row] > row_data[row + 1])
    else:
      conditions.append(row_data[row] < row_data[row + 1])
  result = reduce(lambda x, y: x & y, conditions)
  return result


# Range midpoint acts as Resistance
# ---------------------------------------------------------------------------------------------
def is_resistance(row_data) -> bool:
  conditions = []
  for row in range(len(row_data) - 1):
    if row < len(row_data) // 2:
      conditions.append(row_data[row] < row_data[row + 1])
    else:
      conditions.append(row_data[row] > row_data[row + 1])
  result = reduce(lambda x, y: x & y, conditions)
  return result


# Elliot Wave Oscillator
# ---------------------------------------------------------------------------------------------
def ewo(df, ema1_length=5, ema2_length=35):
  ema1 = ta.EMA(df, timeperiod=ema1_length)
  ema2 = ta.EMA(df, timeperiod=ema2_length)
  emadiff = (ema1 - ema2) / df["close"] * 100.0
  return emadiff


# Pivot Points - 3 variants - daily recommended
# ---------------------------------------------------------------------------------------------
def pivot_points(df: DataFrame, mode="fibonacci") -> Series:
  df_high = df["high"]
  df_low = df["low"]
  df_close = df["close"]
  df_open = df["open"]

  if mode == "simple":
    hlc3_pivot = (df_high + df_low + df_close).shift(1) / 3
    res1 = hlc3_pivot * 2 - df_low.shift(1)
    sup1 = hlc3_pivot * 2 - df_high.shift(1)
    high_low_range = df_high - df_low
    res2 = hlc3_pivot + high_low_range.shift()
    sup2 = hlc3_pivot - high_low_range.shift()
    res3 = hlc3_pivot * 2 + (df_high - 2 * df_low).shift()
    sup3 = hlc3_pivot * 2 - (2 * df_high - df_low).shift()
    return hlc3_pivot, res1, res2, res3, sup1, sup2, sup3
  elif mode == "fibonacci":
    hlc3_pivot = (df_high + df_low + df_close).shift(1) / 3
    hl_range = (df_high - df_low).shift(1)
    res1 = hlc3_pivot + 0.382 * hl_range
    sup1 = hlc3_pivot - 0.382 * hl_range
    res2 = hlc3_pivot + 0.618 * hl_range
    sup2 = hlc3_pivot - 0.618 * hl_range
    res3 = hlc3_pivot + 1 * hl_range
    sup3 = hlc3_pivot - 1 * hl_range
    return hlc3_pivot, res1, res2, res3, sup1, sup2, sup3
  elif mode == "DeMark":
    demark_pivot_lt = df_low * 2 + df_high + df_close
    demark_pivot_eq = df_close * 2 + df_low + df_high
    demark_pivot_gt = df_high * 2 + df_low + df_close
    demark_pivot = np.where(
      (df_close < df_open),
      demark_pivot_lt,
      np.where((df_close > df_open), demark_pivot_gt, demark_pivot_eq),
    )
    dm_pivot = demark_pivot / 4
    dm_res = demark_pivot / 2 - df_low
    dm_sup = demark_pivot / 2 - df_high
    return dm_pivot, dm_res, dm_sup


# Heikin Ashi candles
# ---------------------------------------------------------------------------------------------
def heikin_ashi(df, smooth_inputs=False, smooth_outputs=False, length=10):
  df = df[["open", "close", "high", "low"]].copy().fillna(0)
  df_open = df["open"]
  df_high = df["high"]
  df_low = df["low"]
  df_close = df["close"]

  if smooth_inputs:
    df["open_s"] = ta.EMA(df_open, timeframe=length)
    df["high_s"] = ta.EMA(df_high, timeframe=length)
    df["low_s"] = ta.EMA(df_low, timeframe=length)
    df["close_s"] = ta.EMA(df_close, timeframe=length)

    df_open_s = df["open_s"]
    df_high_s = df["high_s"]
    df_low_s = df["low_s"]
    df_close_s = df["close_s"]

    open_ha = (df_open_s.shift(1) + df_close_s.shift(1)) / 2
    high_ha = df.loc[:, ["high_s", "open_s", "close_s"]].max(axis=1)
    low_ha = df.loc[:, ["low_s", "open_s", "close_s"]].min(axis=1)
    close_ha = (df_open_s + df_high_s + df_low_s + df_close_s) / 4
  else:
    open_ha = (df_open.shift(1) + df_close.shift(1)) / 2
    high_ha = df.loc[:, ["high", "open", "close"]].max(axis=1)
    low_ha = df.loc[:, ["low", "open", "close"]].min(axis=1)
    close_ha = (df_open + df_high + df_low + df_close) / 4

  open_ha = open_ha.fillna(0)
  high_ha = high_ha.fillna(0)
  low_ha = low_ha.fillna(0)
  close_ha = close_ha.fillna(0)

  if smooth_outputs:
    open_sha = ta.EMA(open_ha, timeframe=length)
    high_sha = ta.EMA(high_ha, timeframe=length)
    low_sha = ta.EMA(low_ha, timeframe=length)
    close_sha = ta.EMA(close_ha, timeframe=length)

    return open_sha, close_sha, low_sha
  else:
    return open_ha, close_ha, low_ha


# Peak Percentage Change
# ---------------------------------------------------------------------------------------------
def range_percent_change(self, df: DataFrame, method, length: int) -> float:
  """
  Rolling Percentage Change Maximum across interval.

  :param df: DataFrame The original OHLC df
  :param method: High to Low / Open to Close
  :param length: int The length to look back
  """
  df_high = df["high"]
  df_low = df["low"]
  df_open = df["open"]
  df_close = df["close"]

  if method == "HL":
    low_min = df_low.rolling(length).min()
    return (df_high.rolling(length).max() - low_min) / low_min
  elif method == "OC":
    close_min = df_close.rolling(length).min()
    return (df_open.rolling(length).max() - close_min) / close_min
  else:
    raise ValueError(f"Method {method} not defined!")


# Percentage distance to top peak
# ---------------------------------------------------------------------------------------------
def top_percent_change(self, df: DataFrame, length: int) -> float:
  """
  Percentage change of the current close from the range maximum Open price

  :param df: DataFrame The original OHLC df
  :param length: int The length to look back
  """
  df_open = df["open"]
  df_close = df["close"]

  if length == 0:
    return (df_open - df_close) / df_close
  else:
    return (df_open.rolling(length).max() - df_close) / df_close


def _is_entry_bool_scalar(condition) -> bool:
  return isinstance(condition, (bool, np.bool_))


def _entry_bool_array(condition):
  if isinstance(condition, np.ndarray):
    return condition.astype(bool, copy=False)
  if isinstance(condition, (pd.Series, pd.Index)):
    return condition.to_numpy(dtype=bool, copy=False)
  return np.asarray(condition, dtype=bool)


def _and_entry_conditions(conditions):
  arrays = []
  has_false = False
  for condition in conditions:
    if _is_entry_bool_scalar(condition):
      if not condition:
        has_false = True
      continue
    arrays.append(_entry_bool_array(condition))
  if not arrays:
    return not has_false
  if has_false:
    return np.zeros_like(arrays[0], dtype=bool)
  if len(arrays) == 1:
    return arrays[0]
  return np.logical_and.reduce(arrays)


def _or_entry_conditions(conditions):
  arrays = []
  has_true = False
  for condition in conditions:
    if _is_entry_bool_scalar(condition):
      if condition:
        has_true = True
      continue
    arrays.append(_entry_bool_array(condition))
  if not arrays:
    return has_true
  if has_true:
    return np.ones_like(arrays[0], dtype=bool)
  if len(arrays) == 1:
    return arrays[0]
  return np.logical_or.reduce(arrays)


def _append_entry_tag(entry_tags, mask, tag: str) -> None:
  if _is_entry_bool_scalar(mask):
    if mask:
      entry_tags[:] = entry_tags + tag
    return
  entry_tags[mask] = entry_tags[mask] + tag


# +---------------------------------------------------------------------------+
# |                              Classes                                      |
# +---------------------------------------------------------------------------+


# Cache Class
# ---------------------------------------------------------------------------------------------
class Cache:
  def __init__(self, path):
    self.path = path
    self.data = {}
    self._mtime = None
    self._previous_data = {}
    try:
      self.load()
    except FileNotFoundError:
      pass

  @staticmethod
  def rapidjson_load_kwargs():
    return {"number_mode": rapidjson.NM_NATIVE, "parse_mode": rapidjson.PM_COMMENTS | rapidjson.PM_TRAILING_COMMAS}

  @staticmethod
  def rapidjson_dump_kwargs():
    return {"number_mode": rapidjson.NM_NATIVE}

  def load(self):
    if not self._mtime or self.path.stat().st_mtime_ns != self._mtime:
      self._load()

  def save(self):
    if self.data != self._previous_data:
      self._save()

  def process_loaded_data(self, data):
    return data

  def _load(self):
    # This method only exists to simplify unit testing
    cache_path = self.path
    rapidjson_load_kwargs = self.rapidjson_load_kwargs
    process_loaded_data = self.process_loaded_data

    with cache_path.open("r") as rfh:
      try:
        data = rapidjson.load(rfh, **rapidjson_load_kwargs())
      except rapidjson.JSONDecodeError as exc:
        log.error("Failed to load JSON from %s: %s", cache_path, exc)
      else:
        self.data = process_loaded_data(data)
        self._previous_data = copy.deepcopy(self.data)
        self._mtime = cache_path.stat().st_mtime_ns

  def _save(self):
    # This method only exists to simplify unit testing
    cache_path = self.path
    cache_data = self.data
    rapidjson_dump_kwargs = self.rapidjson_dump_kwargs

    rapidjson.dump(cache_data, cache_path.open("w"), **rapidjson_dump_kwargs())
    self._mtime = cache_path.stat().st_mtime
    self._previous_data = copy.deepcopy(cache_data)


class HoldsCache(Cache):
  @staticmethod
  def rapidjson_load_kwargs():
    return {
      "number_mode": rapidjson.NM_NATIVE,
      "parse_mode": rapidjson.PM_COMMENTS | rapidjson.PM_TRAILING_COMMAS,
      "object_hook": HoldsCache._object_hook,
    }

  @staticmethod
  def rapidjson_dump_kwargs():
    return {
      "number_mode": rapidjson.NM_NATIVE,
      "mapping_mode": rapidjson.MM_COERCE_KEYS_TO_STRINGS,
    }

  def save(self):
    raise RuntimeError("The holds cache does not allow programatical save")

  def process_loaded_data(self, data):
    cache_path = self.path

    trade_ids = data.get("trade_ids")
    trade_pairs = data.get("trade_pairs")

    if not trade_ids and not trade_pairs:
      return data

    open_trades = {}
    for trade in Trade.get_trades_proxy(is_open=True):
      open_trades[trade.id] = open_trades[trade.pair] = trade

    r_trade_ids = {}
    if trade_ids:
      if isinstance(trade_ids, dict):
        # New syntax
        for trade_id, profit_ratio in trade_ids.items():
          if not isinstance(trade_id, int):
            log.error("The trade_id(%s) defined under 'trade_ids' in %s is not an integer", trade_id, cache_path)
            continue
          if not isinstance(profit_ratio, float):
            log.error(
              "The 'profit_ratio' config value(%s) for trade_id %s in %s is not a float",
              profit_ratio,
              trade_id,
              cache_path,
            )
          if trade_id in open_trades:
            formatted_profit_ratio = f"{profit_ratio * 100}%"
            log.warning(
              "The trade %s is configured to HOLD until the profit ratio of %s is met",
              open_trades[trade_id],
              formatted_profit_ratio,
            )
            r_trade_ids[trade_id] = profit_ratio
          else:
            log.warning(
              "The trade_id(%s) is no longer open. Please remove it from 'trade_ids' in %s",
              trade_id,
              cache_path,
            )
      else:
        # Initial Syntax
        profit_ratio = data.get("profit_ratio")
        if profit_ratio:
          if not isinstance(profit_ratio, float):
            log.error("The 'profit_ratio' config value(%s) in %s is not a float", profit_ratio, cache_path)
        else:
          profit_ratio = 0.005
        formatted_profit_ratio = f"{profit_ratio * 100}%"
        for trade_id in trade_ids:
          if not isinstance(trade_id, int):
            log.error("The trade_id(%s) defined under 'trade_ids' in %s is not an integer", trade_id, cache_path)
            continue
          if trade_id in open_trades:
            log.warning(
              "The trade %s is configured to HOLD until the profit ratio of %s is met",
              open_trades[trade_id],
              formatted_profit_ratio,
            )
            r_trade_ids[trade_id] = profit_ratio
          else:
            log.warning(
              "The trade_id(%s) is no longer open. Please remove it from 'trade_ids' in %s",
              trade_id,
              cache_path,
            )

    r_trade_pairs = {}
    if trade_pairs:
      for trade_pair, profit_ratio in trade_pairs.items():
        if not isinstance(trade_pair, str):
          log.error("The trade_pair(%s) defined under 'trade_pairs' in %s is not a string", trade_pair, cache_path)
          continue
        if "/" not in trade_pair:
          log.error(
            "The trade_pair(%s) defined under 'trade_pairs' in %s does not look like "
            "a valid '<TOKEN_NAME>/<STAKE_CURRENCY>' formatted pair.",
            trade_pair,
            cache_path,
          )
          continue
        if not isinstance(profit_ratio, float):
          log.error(
            "The 'profit_ratio' config value(%s) for trade_pair %s in %s is not a float",
            profit_ratio,
            trade_pair,
            cache_path,
          )
        formatted_profit_ratio = f"{profit_ratio * 100}%"
        if trade_pair in open_trades:
          log.warning(
            "The trade %s is configured to HOLD until the profit ratio of %s is met",
            open_trades[trade_pair],
            formatted_profit_ratio,
          )
        else:
          log.warning(
            "The trade pair %s is configured to HOLD until the profit ratio of %s is met",
            trade_pair,
            formatted_profit_ratio,
          )
        r_trade_pairs[trade_pair] = profit_ratio

    r_data = {}
    if r_trade_ids:
      r_data["trade_ids"] = r_trade_ids
    if r_trade_pairs:
      r_data["trade_pairs"] = r_trade_pairs
    return r_data

  @staticmethod
  def _object_hook(data):
    _data = {}
    for key, value in data.items():
      try:
        key = int(key)
      except ValueError:
        pass
      _data[key] = value
    return _data
