💬 Forum

MultiEntryStrategy

dochouyi/freqtrade_api_learning/robot/strategies/MultiEntryStrategy.py · ★1 · first seen 2026-07-19 · repo updated 2025-10-27

Basics mode: spot timeframe: 1m
Settings stoploss: -0.05 has minimal roi dca process only new candles: false
Indicators talib
Concepts dca
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from datetime import datetime, timedelta
from freqtrade.strategy import IStrategy
from freqtrade.persistence import Trade
import talib.abstract as ta
import pandas as pd


class MultiEntryStrategy(IStrategy):

    minimal_roi = {
        "0": 0.01
    }
    stoploss = -0.05
    timeframe = '1m'
    process_only_new_candles = False

    # 启用仓位调整功能
    position_adjustment_enable = True
    max_entry_position_adjustment = 9  # 额外入场 9 次,加首次共 10 次


    # # 设置市场价格订单
    # order_types = {
    #     "entry": "market",
    #     "exit": "market",
    #     "stoploss": "market",
    #     "stoploss_on_exchange": False
    # }

    entry_signal_generated = False

    def populate_indicators(self, dataframe: pd.DataFrame, metadata: dict) -> pd.DataFrame:

        return dataframe

    def populate_entry_trend(self, dataframe: pd.DataFrame, metadata: dict) -> pd.DataFrame:
        # 只在第一次生成入场信号
        if not self.entry_signal_generated:
            dataframe['enter_long'] = 0
            dataframe.at[dataframe.index[-1], 'enter_long'] = 1
            self.entry_signal_generated = True
        else:
            dataframe['enter_long'] = 0
        return dataframe

    def populate_exit_trend(self, dataframe: pd.DataFrame, metadata: dict) -> pd.DataFrame:
        """生成出场信号"""
        dataframe['exit_long'] = 0
        return dataframe

    def adjust_trade_position(
            self,
            trade: Trade,
            current_time: datetime,
            current_rate: float,
            current_profit: float,
            min_stake: float,
            max_stake: float,
            current_entry_rate: float,
            current_exit_rate: float,
            current_entry_profit: float,
            current_exit_profit: float,
            **kwargs
    ):
        # 检查是否有未完成的订单
        if trade.has_open_orders:
            return None

        # 获取已完成的入场订单数量
        count_of_entries = trade.nr_of_successful_entries

        # 如果已经达到 10 次入场,不再继续
        if count_of_entries >= 10:
            return None

        # 检查距离上次入场是否已经过了 5 秒
        filled_entries = trade.select_filled_orders(trade.entry_side)
        if filled_entries:
            last_entry_time = filled_entries[-1].order_filled_utc

            if (current_time - last_entry_time).total_seconds() < 5:
                return None

        # 返回入场金额(使用首次入场的金额)
        try:
            stake_amount = filled_entries[0].stake_amount_filled
            return stake_amount
        except Exception:
            return None