2025-11-27 09:50:04 +08:00

53 lines
1.8 KiB
Python

# /freqtrade/user_data/strategies/StaticGrid.py
from freqtrade.strategy import IStrategy
from pandas import DataFrame
class StaticGrid(IStrategy):
INTERFACE_VERSION = 3
timeframe = '1h'
can_short = False
minimal_roi = {"0": 100}
stoploss = -0.99
use_exit_signal = True
position_adjustment_enable = True
max_entry_position_adjustment = -1
# 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:
"""
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:
"""
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:
return self.STAKE