zhangkun9038@dingtalk.com 5e1f966b6d staticgrid update
2025-11-26 23:01:36 +08:00

47 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# user_data/strategies/EthTrueStaticGrid.py ← 复制整个文件
from freqtrade.strategy import IStrategy
from pandas import DataFrame
class StaticGrid(IStrategy):
INTERFACE_VERSION = 3
timeframe = '1h' # 1h 或 4h 都行,建议 1h 更灵敏
can_short = False
minimal_roi = {"0": 100}
stoploss = -0.99
use_exit_signal = True
position_adjustment_enable = True
max_entry_position_adjustment = -1
# ================== 永续静态网格参数 ==================
LOWER = 1500.0
UPPER = 4500.0
GRID_STEP = 50.0 # 每格 50 USDT
GRID_COUNT = int((UPPER - LOWER) / GRID_STEP) # = 60 格
STAKE_PER_ORDER = 40 # 每张单 40 USDT60格 × 40 × 2 ≈ 4800 USDT 吃满)
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
price = dataframe['close'].iloc[-1]
# 从 1500 到 4450 每 50 USDT 一个价位,只要价格跌到或跌破这个价,就买入
for level in range(self.GRID_COUNT):
buy_price = self.LOWER + level * self.GRID_STEP
if price <= buy_price:
dataframe.loc[dataframe['low'] <= buy_price, 'enter_long'] = True
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
price = dataframe['close'].iloc[-1]
# 从 1550 到 4500 每 50 USDT 一个价位,只要价格涨到或超过这个价,就卖出
for level in range(1, self.GRID_COUNT + 1):
sell_price = self.LOWER + level * self.GRID_STEP
if price >= sell_price:
dataframe.loc[dataframe['high'] >= sell_price, 'exit_long'] = True
return dataframe
def custom_stake_amount(self, **kwargs) -> float:
return self.STAKE_PER_ORDER