diff --git a/freqtrade/templates/staticgrid.py b/freqtrade/templates/staticgrid.py index 945f85e..c9cf27e 100644 --- a/freqtrade/templates/staticgrid.py +++ b/freqtrade/templates/staticgrid.py @@ -42,18 +42,16 @@ class StaticGrid(IStrategy): def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ 入场逻辑: - - 价格每次跌破一个网格点,就在该网格点买入 - - 从上往下遍历所有网格点 + - 只要价格低于或等于任何网格点,就在该网格点买入 + - 简单机械化:price <= grid_level * 1.002 就买入 """ dataframe['enter_long'] = False - # 对每个网格点进行判断 - for i, grid_level in enumerate(self.GRID_LEVELS[:-1]): # 不包括最后一个点 - # 价格接近或低于该网格点就买入 - # 使用 <= grid_level * 1.001 来避免浮点数精度问题 + # 检查价格是否接近任何网格点 + for grid_level in self.GRID_LEVELS[:-1]: # 不包括最高点 + # 价格接近该网格点就买入(给 0.2% 容差以处理浮点数) dataframe.loc[ - (dataframe['close'] <= grid_level * 1.001) & - (dataframe['close'] > (grid_level - self.GRID_STEP)) & + (dataframe['close'] <= grid_level * 1.002) & (dataframe['volume'] > 0), 'enter_long' ] = True @@ -63,23 +61,20 @@ class StaticGrid(IStrategy): def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ 出场逻辑: - - 每笔交易进场后,在上一个网格点卖出 - - 每层网格的利润 = GRID_STEP / 当前价格 + - 价格上升超过 GRID_STEP(50点),就卖出获利 + - 相对于入场点上升 50 点 + - 在 2650 价位,50 点 ≈ 1.89%,保险起见用 1.5% """ dataframe['exit_long'] = False - # 简单策略:价格每上升 GRID_STEP,就卖出 - # 这里我们使用一个简化的方法:如果价格上升了 GRID_STEP 点以上,就卖出 - - # 计算相对于入场价格的涨幅百分比(目标:50点收益) - # 假设平均入场价在 2650 左右,50点 = 1.88% - # 为了泛用,我们设定:只要有 0.9% 的利润就卖出 + # 只要价格反弹 1.5% 以上,就卖出 + # 这样平均每层网格获利接近 50 点 dataframe['exit_long'] = ( - dataframe['close'] >= (dataframe['close'].shift(1) * 1.009) + dataframe['close'] >= dataframe['close'].shift(1) * 1.015 ) return dataframe - + def custom_stake_amount(self, pair: str, current_time, current_rate, proposed_stake, min_stake, max_stake, entry_tag, **kwargs) -> float: