排查没有n笔交易+1
This commit is contained in:
parent
c8e91eb760
commit
70eb569362
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user