From 70eb569362caa88db7f41fa79cacef843b65cd60 Mon Sep 17 00:00:00 2001 From: "zhangkun9038@dingtalk.com" Date: Thu, 27 Nov 2025 12:37:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E6=9F=A5=E6=B2=A1=E6=9C=89n=E7=AC=94?= =?UTF-8?q?=E4=BA=A4=E6=98=93+1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- freqtrade/templates/staticgrid.py | 47 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/freqtrade/templates/staticgrid.py b/freqtrade/templates/staticgrid.py index fc8e0396..238f7875 100644 --- a/freqtrade/templates/staticgrid.py +++ b/freqtrade/templates/staticgrid.py @@ -36,40 +36,43 @@ class StaticGrid(IStrategy): def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ - Dynamic Grid Entry Logic: - - Automatically calculates grid levels based on current price - - Creates grid points with fixed percentage step (e.g., 1.5% apart) - - Works for any price range (BTC, ETH, SOL, etc.) + Static Grid Entry Logic: + - Buy at predefined grid levels: 1500, 1550, 1600, ..., 4500 (step 50) + - When price is at or below a grid level, produce buy signal + - Continuous buying at different grid levels as price moves """ dataframe['enter_long'] = False if len(dataframe) == 0: return dataframe - # Get current price current_price = dataframe['close'].iloc[-1] - print(f"[StaticGrid] Current price: {current_price:.2f}", file=sys.stderr, flush=True) + current_low = dataframe['low'].iloc[-1] + print(f"[StaticGrid] Current price: {current_price:.2f}, low: {current_low:.2f}", file=sys.stderr, flush=True) - # Dynamic grid: use percentage-based steps instead of fixed price steps - # Grid step: 1.5% (you can adjust this) - grid_step_pct = 0.015 # 1.5% + # Define static grid levels + LOWER = 1500.0 + UPPER = 4500.0 + STEP = 50.0 - # Create grid levels around current price - # Generate grid points below current price (for buying) - num_levels_below = 10 # Generate 10 levels below current price + # Generate all grid levels in the range + grid_levels = [LOWER + i * STEP for i in range(int((UPPER - LOWER) / STEP) + 1)] - for i in range(num_levels_below): - grid_price = current_price * ((1 - grid_step_pct) ** (i + 1)) - - # Buy if price drops to or below this grid level - if dataframe['low'].iloc[-1] <= grid_price * 1.01: + entry_count = 0 + + # For each grid level, check if price is at or below it + for grid_price in grid_levels: + # Buy if current low is at or below this grid level (with 0.5% tolerance) + if current_low <= grid_price * 1.005: dataframe['enter_long'] = True - print(f"[StaticGrid] Buy signal at grid level {i+1}: {grid_price:.2f}", file=sys.stderr, flush=True) - break # Only buy at one level per candle + entry_count += 1 + if entry_count <= 5: # Only print first 5 for brevity + print(f"[StaticGrid] Entry at grid {grid_price:.0f}", file=sys.stderr, flush=True) - entries = dataframe['enter_long'].sum() - if entries > 0: - print(f"[StaticGrid] Entry signals: {entries}", file=sys.stderr, flush=True) + if entry_count > 5: + print(f"[StaticGrid] ... and {entry_count - 5} more grid levels", file=sys.stderr, flush=True) + + print(f"[StaticGrid] Total entry signals: {entry_count}", file=sys.stderr, flush=True) return dataframe