This commit is contained in:
Ubuntu 2025-11-27 09:46:58 +08:00
parent e337769b94
commit 0e09c1dfee
3 changed files with 92 additions and 73 deletions

View File

@ -1,12 +1,13 @@
{
"strategy": "EthTrueStaticGrid",
"strategy": "StaticGrid",
"max_open_trades": 150,
"stake_currency": "USDT",
"stake_amount": 40,
"tradable_balance_ratio": 0.99,
"dry_run": false,
"timeframe": "1h",
"position_adjustment_enable": false,
"position_adjustment_enable": true,
"process_only_new_candles": false,
"max_entry_position_adjustment": -1,
"exchange": {
"name": "okx",
@ -37,7 +38,6 @@
"entry": 5,
"exit": 15
},
"entry_pricing": {
"price_side": "other",
"use_order_book": true,
@ -48,7 +48,11 @@
"use_order_book": true,
"order_book_top": 1
},
"pairlists": [{"method": "StaticPairList"}],
"pairlists": [
{
"method": "StaticPairList"
}
],
"bot_name": "ETH-1500to4500-Grid",
"api_server": {
"enabled": true,

View File

@ -0,0 +1,10 @@
def populate_indicators(self, dataframe: pd.DataFrame, metadata: dict) -> pd.DataFrame:
import numpy as np
dataframe['ema_short'] = dataframe['close'].ewm(span=self.ema_short_period.value, adjust=False).mean()
dataframe['ema_long'] = dataframe['close'].ewm(span=self.ema_long_period.value, adjust=False).mean()
dataframe['rsi'] = ta.RSI(np.array(dataframe['close']), timeperiod=14)
return dataframe

View File

@ -18,18 +18,23 @@ class StaticGrid(IStrategy):
STEP = 50.0
STAKE = 40.0
# 必须加这一行!否则报抽象类错误
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
for price in [self.LOWER + i * self.STEP for i in range(int((self.UPPER - self.LOWER) // self.STEP) + 3)]:
dataframe.loc[dataframe['low'] <= price, 'enter_long'] = True
# 终极触发:只要这根 1h K 线的 low 曾经跌到过任何一个网格价,就立刻补单
# 当前价 3025 → 下面所有 1500~3000 的网格价,只要历史 low 触碰过,就全部挂上
for level in range(int((self.UPPER - self.LOWER) // self.STEP) + 5):
grid_price = self.LOWER + level * self.STEP
if grid_price <= 3025 + 200: # 当前价附近 200 刀内优先挂
dataframe.loc[dataframe['low'] <= grid_price, 'enter_long'] = 1
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
for price in [self.LOWER + i * self.STEP for i in range(int((self.UPPER - self.LOWER) // self.STEP) + 3)]:
dataframe.loc[dataframe['high'] >= price, 'exit_long'] = True
for level in range(int((self.UPPER - self.LOWER) // self.STEP) + 5):
grid_price = self.LOWER + level * self.STEP
if grid_price >= 3025 - 200:
dataframe.loc[dataframe['high'] >= grid_price, 'exit_long'] = 1
return dataframe
def custom_stake_amount(self, **kwargs) -> float: