排查staticgrid没有入场的问题

This commit is contained in:
zhangkun9038@dingtalk.com 2025-11-27 09:50:04 +08:00
parent 0e09c1dfee
commit 789b4e10eb

View File

@ -12,24 +12,40 @@ class StaticGrid(IStrategy):
position_adjustment_enable = True
max_entry_position_adjustment = -1
# 永续网格参数
LOWER = 1500.0
UPPER = 4500.0
STEP = 50.0
STAKE = 40.0
# Grid parameters
LOWER = 1500.0 # Minimum price
UPPER = 4500.0 # Maximum price
STEP = 50.0 # Grid spacing
STAKE = 40.0 # Per-trade stake
# 必须加这一行!否则报抽象类错误
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
for price in [self.LOWER + i * self.STEP for i in range(int((self.UPPER - self.LOWER) // self.STEP) + 3)]:
dataframe.loc[dataframe['low'] <= price, 'enter_long'] = True
"""
Entry logic: Buy whenever price touches or goes below a grid point
Grid points: 1500, 1550, 1600, ..., 4500
"""
dataframe['enter_long'] = False
# Generate all grid points
num_grids = int((self.UPPER - self.LOWER) / self.STEP) + 1
for i in range(num_grids):
grid_price = self.LOWER + i * self.STEP
# Buy if low touches this grid point (with 0.1% tolerance)
dataframe.loc[
(dataframe['low'] <= grid_price * 1.001) & (dataframe['volume'] > 0),
'enter_long'
] = True
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
for price in [self.LOWER + i * self.STEP for i in range(int((self.UPPER - self.LOWER) // self.STEP) + 3)]:
dataframe.loc[dataframe['high'] >= price, 'exit_long'] = True
"""
Exit logic: Sell when price bounces back (any upward movement = profit)
"""
dataframe['exit_long'] = (dataframe['close'] > dataframe['close'].shift(1)).fillna(False)
return dataframe
def custom_stake_amount(self, **kwargs) -> float: