💬 Forum

FactorStrategy

🏆 League #63 / 1928

win-boom/BTCquant/user_data/strategies/factor_strat.py · first seen 2026-07-16 · repo updated 2026-06-20 · ⬇ 1 download

Basics mode: futures timeframe: 15m interface version: 3
Settings stoploss: -0.03 has minimal roi trailing process only new candles startup candle count: 500
Indicators ADX EMA MACD ROC RSI SMA talib
Concepts trailing
15 related strategies ( identical code, similar name)

Each tile is a different kind of check — from an instant code lint to full sandboxed backtests and forward tests on recent data. Not sure what a check actually proves? See the FAQ →

Source

Download Raw
 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
from pandas import DataFrame
import talib.abstract as ta
import numpy as np
from freqtrade.strategy import IStrategy


class FactorStrategy(IStrategy):
    INTERFACE_VERSION = 3
    timeframe = '15m'
    can_short = True

    stoploss = -0.03
    trailing_stop = True
    trailing_stop_positive = 0.003
    trailing_stop_positive_offset = 0.018
    trailing_only_offset_is_reached = True

    minimal_roi = {"0": 0.05, "480": 0.03, "1440": 0.02, "2880": 0}

    max_open_trades = 3
    startup_candle_count = 500
    process_only_new_candles = True
    use_exit_signal = False

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
        dataframe['ema30'] = ta.EMA(dataframe, timeperiod=30)
        dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)
        dataframe['ema200'] = ta.EMA(dataframe, timeperiod=200)

        # 15m: 192 candles = 48h = 2-day slope (same as 1h shift(48))
        dataframe['ema200_slope'] = (
            (dataframe['ema200'] - dataframe['ema200'].shift(192)) /
            dataframe['ema200'].shift(192) * 100
        )

        macd = ta.MACD(dataframe, fastperiod=12, slowperiod=26, signalperiod=9)
        dataframe['macd'] = macd['macd']
        dataframe['macd_signal'] = macd['macdsignal']

        dataframe['momentum'] = (
            ta.ROC(dataframe, timeperiod=1) * 0.1 +
            ta.ROC(dataframe, timeperiod=3) * 0.2 +
            ta.ROC(dataframe, timeperiod=6) * 0.4 +
            ta.ROC(dataframe, timeperiod=12) * 0.3
        )

        dataframe['adx'] = ta.ADX(dataframe, timeperiod=14)
        dataframe['vr'] = dataframe['volume'] / ta.SMA(dataframe['volume'], timeperiod=20)

        vwap = (dataframe['close'] * dataframe['volume']).rolling(20).sum() / dataframe['volume'].rolling(20).sum()
        dataframe['vd'] = (dataframe['close'] - vwap) / vwap * 100
        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            ((dataframe['ema200_slope'] < 2.0) &
             (dataframe['ema10'] < dataframe['ema30']) &
             (dataframe['ema30'] < dataframe['ema100']) &
             (dataframe['macd'] < dataframe['macd_signal']) &
             (dataframe['macd'] < 0) &
             (dataframe['momentum'] < -0.2) &
             (dataframe['adx'] > 25) &
             (dataframe['vr'] > 1.2) &
             (dataframe['vd'] < 3) &
             (dataframe['rsi'].between(30, 70)) &
             (dataframe['volume'] > 0)),
            ['enter_short', 'enter_tag']
        ] = (1, 'fs')
        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        return dataframe