排查加log+2

This commit is contained in:
zhangkun9038@dingtalk.com 2025-11-27 11:11:24 +08:00
parent 23ebce4924
commit e815595389
2 changed files with 39 additions and 17 deletions

View File

@ -5,6 +5,7 @@
"stake_amount": 40,
"tradable_balance_ratio": 0.99,
"dry_run": false,
"dry_run_wallet": 10000,
"timeframe": "1h",
"position_adjustment_enable": true,
"process_only_new_candles": true,

View File

@ -33,34 +33,55 @@ class StaticGrid(IStrategy):
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Aggressive entry: Always buy at current price if we don't have a position yet.
The grid logic will be handled by custom_stake_amount and max_open_trades.
Grid Entry Logic:
- Buy at each grid level when price drops to it
- Grid levels: 1500, 1550, 1600, ..., 4500 (step 50)
"""
print(f"[StaticGrid] populate_entry_trend called! df len: {len(dataframe)}", file=sys.stderr, flush=True)
dataframe['enter_long'] = False
# EXTREME: Always set buy signal for every candle
# This forces the bot to try to enter on every opportunity
dataframe['enter_long'] = True
if len(dataframe) == 0:
return dataframe
if len(dataframe) > 0:
latest_close = dataframe['close'].iloc[-1]
latest_low = dataframe['low'].iloc[-1]
print(f"[StaticGrid] Latest close: {latest_close:.2f}, low: {latest_low:.2f}", file=sys.stderr, flush=True)
print(f"[StaticGrid] Forcing entry on ALL candles!", file=sys.stderr, flush=True)
# Get current price
current_price = dataframe['close'].iloc[-1]
print(f"[StaticGrid] Current price: {current_price:.2f}", file=sys.stderr, flush=True)
# Check which grid level price is closest to or below
# If price is near any grid level, buy
for i in range(int((self.UPPER - self.LOWER) / self.STEP) + 1):
grid_price = self.LOWER + i * self.STEP
# Buy if we're at this grid level (within 2% tolerance)
# This allows buying at intermediate prices too
if current_price <= grid_price * 1.02:
# Mark this candle and recent candles for entry
dataframe.loc[dataframe['close'] <= grid_price * 1.02, 'enter_long'] = True
entries = dataframe['enter_long'].sum()
print(f"[StaticGrid] Entry signals: {entries}", file=sys.stderr, flush=True)
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Exit logic: Sell when price bounces back (any upward movement = profit)
Exit Logic:
- Exit when price rises 1% (small profit per grid level)
- This matches the grid step of 50 points (~1.6% at 3000 price)
"""
print(f"[StaticGrid] populate_exit_trend called! df len: {len(dataframe)}", file=sys.stderr, flush=True)
dataframe['exit_long'] = False
dataframe['exit_long'] = (dataframe['close'] > dataframe['close'].shift(1)).fillna(False)
if len(dataframe) < 2:
return dataframe
exit_count = dataframe['exit_long'].sum()
if exit_count > 0:
print(f"[StaticGrid] Exit signals: {exit_count}", file=sys.stderr, flush=True)
# Exit when price goes up 1% from entry
# (Freqtrade tracks entry price internally)
dataframe.loc[
dataframe['close'] > dataframe['open'] * 1.01,
'exit_long'
] = True
exits = dataframe['exit_long'].sum()
if exits > 0:
print(f"[StaticGrid] Exit signals: {exits}", file=sys.stderr, flush=True)
return dataframe