GymStrategy_2
♡15 related strategies (⧉ identical code, ≈ similar name)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 | import numpy as np from pandas import DataFrame from freqtrade.strategy.interface import IStrategy import talib.abstract as ta import freqtrade.vendor.qtpylib.indicators as qtpylib from stable_baselines3 import PPO class GymStrategy_2(IStrategy): stoploss = -0.20 trailing_stop = False ticker_interval = '5m' process_only_new_candles = False startup_candle_count: int = 20 model = None def __init__(self, config: dict) -> None: super().__init__(config) self._load_model() def _load_model(self): try: self.model = PPO.load('/freqtrade/user_data/model.gym') except FileNotFoundError: pass def informative_pairs(self): pairs = self.dp.current_whitelist() informative_pairs = [(pair, self.informative_timeframe) for pair in pairs] return informative_pairs def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: dataframe['adx'] = ta.ADX(dataframe) dataframe['plus_dm'] = ta.PLUS_DM(dataframe) dataframe['plus_di'] = ta.PLUS_DI(dataframe) dataframe['minus_dm'] = ta.MINUS_DM(dataframe) dataframe['minus_di'] = ta.MINUS_DI(dataframe) aroon = ta.AROON(dataframe) dataframe['aroonup'] = aroon['aroonup'] dataframe['aroondown'] = aroon['aroondown'] dataframe['aroonosc'] = ta.AROONOSC(dataframe) dataframe['ao'] = qtpylib.awesome_oscillator(dataframe) dataframe['uo'] = ta.ULTOSC(dataframe) dataframe['cci'] = ta.CCI(dataframe) dataframe['rsi'] = ta.RSI(dataframe) rsi = 0.1 * (dataframe['rsi'] - 50) dataframe['fisher_rsi'] = (np.exp(2 * rsi) - 1) / (np.exp(2 * rsi) + 1) dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1) stoch = ta.STOCH(dataframe) dataframe['slowd'] = stoch['slowd'] dataframe['slowk'] = stoch['slowk'] stoch_fast = ta.STOCHF(dataframe) dataframe['fastd'] = stoch_fast['fastd'] dataframe['fastk'] = stoch_fast['fastk'] stoch_rsi = ta.STOCHRSI(dataframe) dataframe['fastd_rsi'] = stoch_rsi['fastd'] dataframe['fastk_rsi'] = stoch_rsi['fastk'] macd = ta.MACD(dataframe) dataframe['macd'] = macd['macd'] dataframe['macdsignal'] = macd['macdsignal'] dataframe['macdhist'] = macd['macdhist'] dataframe['mfi'] = ta.MFI(dataframe) dataframe['roc'] = ta.ROC(dataframe) bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_middleband'] = bollinger['mid'] dataframe['bb_upperband'] = bollinger['upper'] dataframe["bb_percent"] = ( (dataframe["close"] - dataframe["bb_lowerband"]) / (dataframe["bb_upperband"] - dataframe["bb_lowerband"]) ) dataframe["bb_width"] = ( (dataframe["bb_upperband"] - dataframe["bb_lowerband"]) / dataframe["bb_middleband"] ) dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9) """ if self.dp: if self.dp.runmode in ('live', 'dry_run'): ob = self.dp.orderbook(metadata['pair'], 1) dataframe['best_bid'] = ob['bids'][0][0] dataframe['best_ask'] = ob['asks'][0][0] """ return dataframe def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: action, nan_list = self.rl_model_redict(dataframe) dataframe.loc[action == 1, 'buy'] = 1 dataframe.loc[nan_list == True, 'buy'] = 0 return dataframe def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: action, nan_list = self.rl_model_redict(dataframe) dataframe.loc[action == 2, 'sell'] = 1 dataframe.loc[nan_list == True, 'sell'] = 0 return dataframe def rl_model_redict(self, dataframe): data = np.array([ dataframe['adx'], dataframe['plus_dm'], dataframe['plus_di'], dataframe['minus_dm'], dataframe['minus_di'], dataframe['aroonup'], dataframe['aroondown'], dataframe['aroonosc'], dataframe['ao'], dataframe['uo'], dataframe['cci'], dataframe['rsi'], dataframe['fisher_rsi'], dataframe['slowd'], dataframe['slowk'], dataframe['fastd'], dataframe['fastk'], dataframe['fastd_rsi'], dataframe['fastk_rsi'], dataframe['macd'], dataframe['macdsignal'], dataframe['macdhist'], dataframe['mfi'], dataframe['roc'], ], dtype=np.float) data = data.reshape(-1, 24) nan_list = np.isnan(data).any(axis=1) data = np.nan_to_num(data) action, _ = self.model.predict(data, deterministic=True) return action, nan_list |
Strategy League — fixed backtest that feeds the ranking
🤖 Machine-learning strategies can't be sandbox-tested for now — they need model libraries, trained model files and (for FreqAI) hours of training compute per run — so this strategy isn't League-ranked. Its code analysis, tags and bias checks above still apply.
Backtests — over a market period
Backtest this strategy over a chosen crypto-cycle period. These don't affect the League ranking, and need that period's candle data downloaded.
🤖 Not available for FreqAI/ML strategies for now — the sandbox has no model libraries or trained model files (see the Strategy League tab).
Log in or sign up to run backtests.
| Period | Range | Total % | Win % | Max DD | Trades | |
|---|---|---|---|---|---|---|
| 2020 · DeFi Summer & Pre-Halving Rally | 20200101-20210101 | not run | ||||
| 2021 · Institutional Bull Market | 20210101-20220101 | not run | ||||
| 2022 · Post-Bull Crash & Macro Tightening | 20220101-20230101 | not run | ||||
| 2023–2024 · Recovery & ETF Anticipation | 20230101-20250101 | not run | ||||
| 2025–2026 · Current Cycle | 20250101-20260101 | not run | ||||
Walk forward
🤖 Not available for FreqAI/ML strategies for now — the sandbox has no model libraries or trained model files (see the Strategy League tab).
Backtest trust check
Static source analysis — instant, does not run the strategy. Flags future-data leaks, backtest-realism problems, and indicators worth a second look.
Lookahead analysis
freqtrade lookahead-analysis: detects strategies peeking at future candles.