fix(web): 自动刷新保留 K 线视窗;威科夫与图表增量更新
自动刷新改用 tail update 与 scrollToPosition 恢复视窗,避免 setData 后跳到最右;拆分 chart_tv 模块并扩展 analyze/recent API。同步威科夫分析、pipeline 增量构建及相关策略与配置。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
# Spring Baseline V1 — FROZEN SNAPSHOT
|
||||
|
||||
勿改本目录文件。可运行副本在:
|
||||
|
||||
- `strategies/Wyckoff_BTC_V1_BASELINE.py`
|
||||
- `config/Wyckoff_BTC_V1_BASELINE.json`
|
||||
|
||||
## Evidence (cost-adjusted)
|
||||
|
||||
| Window | Profit | n | DD | Net PF |
|
||||
|--------|--------|---|-----|--------|
|
||||
| Train | +1.66% | 12 | 3.6% | 1.17 |
|
||||
| Validate | +9.99% | 6 | 1.8% | 6.20 |
|
||||
| Test | +0.85% | 2 | 0.7% | 2.18 |
|
||||
| Full | +12.74% | 20 | 3.6% | 2.02 |
|
||||
| fee+slip 5bps | +6.78% | 20 | — | **1.45** |
|
||||
|
||||
Status: **PASS + Limited Evidence** (N=20)
|
||||
Next: Phase3 → N≥50(延历史 / 多品种),不改规则。
|
||||
@@ -0,0 +1,86 @@
|
||||
{
|
||||
"$schema": "https://schema.freqtrade.io/schema.json",
|
||||
"max_open_trades": 1,
|
||||
"stake_currency": "USDT",
|
||||
"stake_amount": "unlimited",
|
||||
"tradable_balance_ratio": 0.99,
|
||||
"fiat_display_currency": "USD",
|
||||
"dry_run": true,
|
||||
"db_url": "sqlite:///tradesv3.wyckoff_btc_v1_baseline.sqlite",
|
||||
"dry_run_wallet": 10000,
|
||||
"cancel_open_orders_on_exit": true,
|
||||
"trading_mode": "futures",
|
||||
"margin_mode": "isolated",
|
||||
"can_short": true,
|
||||
"timeframe": "1h",
|
||||
"process_only_new_candles": true,
|
||||
"unfilledtimeout": {
|
||||
"entry": 60,
|
||||
"exit": 60,
|
||||
"exit_timeout_count": 5,
|
||||
"unit": "minutes"
|
||||
},
|
||||
"entry_pricing": {
|
||||
"price_side": "same",
|
||||
"use_order_book": true,
|
||||
"order_book_top": 1,
|
||||
"price_last_balance": 0.0,
|
||||
"check_depth_of_market": {
|
||||
"enabled": false,
|
||||
"bids_to_ask_delta": 1
|
||||
}
|
||||
},
|
||||
"exit_pricing": {
|
||||
"price_side": "same",
|
||||
"use_order_book": true,
|
||||
"order_book_top": 1
|
||||
},
|
||||
"exchange": {
|
||||
"name": "binance",
|
||||
"key": "",
|
||||
"secret": "",
|
||||
"ccxt_config": {
|
||||
"proxies": {
|
||||
"http": "http://127.0.0.1:7897",
|
||||
"https": "http://127.0.0.1:7897"
|
||||
}
|
||||
},
|
||||
"ccxt_async_config": {
|
||||
"aiohttp_proxy": "http://127.0.0.1:7897"
|
||||
},
|
||||
"pair_whitelist": [
|
||||
"BTC/USDT:USDT"
|
||||
],
|
||||
"pair_blacklist": [
|
||||
"BNB/.*"
|
||||
]
|
||||
},
|
||||
"pairlists": [
|
||||
{
|
||||
"method": "StaticPairList"
|
||||
}
|
||||
],
|
||||
"telegram": {
|
||||
"enabled": false,
|
||||
"token": "",
|
||||
"chat_id": ""
|
||||
},
|
||||
"api_server": {
|
||||
"enabled": false,
|
||||
"listen_ip_address": "127.0.0.1",
|
||||
"listen_port": 8823,
|
||||
"verbosity": "error",
|
||||
"enable_openapi": false,
|
||||
"jwt_secret_key": "wyckoff-v1-baseline-change-me",
|
||||
"ws_token": "wyckoff-v1-baseline-ws-change-me",
|
||||
"CORS_origins": [],
|
||||
"username": "freqtrader",
|
||||
"password": "FreqTrade007"
|
||||
},
|
||||
"bot_name": "wyckoff_btc_v1_baseline",
|
||||
"initial_state": "running",
|
||||
"force_entry_enable": false,
|
||||
"internals": {
|
||||
"process_throttle_secs": 5
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,368 @@
|
||||
# --- Do not remove these libs ---
|
||||
"""
|
||||
Wyckoff BTC V1.0 BASELINE — FROZEN
|
||||
|
||||
Status: BASELINE FROZEN
|
||||
Evidence: PASS (+ Limited Evidence, N=20)
|
||||
Cost Adjusted: PASS (net PF 1.45 @ fee+slip 5bps)
|
||||
Risk: small sample — 目标积累 N>=50 再谈规模
|
||||
|
||||
Branch A: Spring Reversal
|
||||
8h bias + 4h structure + 1h Spring/UTAD
|
||||
Range disabled(regime_mode=trend)
|
||||
ATR + 结构止损
|
||||
setup_type: SPRING / UTAD
|
||||
|
||||
证据: user_data/Chan/scripts/wyckoff_v1_baseline_phase2.json
|
||||
LPS 是独立 Setup 研究,禁止并入本文件调参。
|
||||
"""
|
||||
from freqtrade.strategy import (
|
||||
IStrategy, IntParameter, DecimalParameter, CategoricalParameter,
|
||||
merge_informative_pair, stoploss_from_open, stoploss_from_absolute,
|
||||
)
|
||||
from freqtrade.persistence import Trade
|
||||
import talib.abstract as ta
|
||||
from pandas import DataFrame
|
||||
import pandas as pd
|
||||
import numpy as np
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# freqtrade backtesting -c ./user_data/Chan/config/Wyckoff_BTC_V1_BASELINE.json \
|
||||
# --strategy Wyckoff_BTC_V1_BASELINE --strategy-path ./user_data/Chan/strategies --timerange=20230101-
|
||||
|
||||
|
||||
class Wyckoff_BTC_V1_BASELINE(IStrategy):
|
||||
"""冻结基线:Spring 反转。禁止继续调参;对比实验请用独立分支。"""
|
||||
INTERFACE_VERSION = 3
|
||||
STRATEGY_VERSION = "V1.0_BASELINE"
|
||||
SETUP_FAMILY = "SPRING"
|
||||
|
||||
timeframe = "1h"
|
||||
structure_timeframe = "4h"
|
||||
bias_timeframe: Optional[str] = "8h"
|
||||
use_bias_filter = True
|
||||
# trend = bull|bear only(Range disabled — 理论一致性约束,非调参)
|
||||
regime_mode: str = "trend"
|
||||
|
||||
can_short = True
|
||||
process_only_new_candles = True
|
||||
startup_candle_count = 220
|
||||
|
||||
minimal_roi = {
|
||||
"0": 0.10,
|
||||
"1440": 0.05,
|
||||
"4320": 0.025,
|
||||
"10080": 0,
|
||||
}
|
||||
stoploss = -0.10
|
||||
use_custom_stoploss = True
|
||||
trailing_stop = True
|
||||
trailing_stop_positive = 0.02
|
||||
trailing_stop_positive_offset = 0.04
|
||||
trailing_only_offset_is_reached = True
|
||||
use_exit_signal = True
|
||||
exit_profit_only = False
|
||||
|
||||
# ---- 冻结默认值(optimize=False)----
|
||||
range_lookback = IntParameter(12, 48, default=24, space="buy", optimize=False)
|
||||
spring_pierce_pct = DecimalParameter(0.001, 0.012, default=0.004, decimals=3, space="buy", optimize=False)
|
||||
vol_spike_mult = DecimalParameter(1.1, 2.5, default=1.8, decimals=1, space="buy", optimize=False)
|
||||
adx_min = IntParameter(10, 28, default=14, space="buy", optimize=False)
|
||||
tr_pos_long_max = DecimalParameter(0.35, 0.55, default=0.45, decimals=2, space="buy", optimize=False)
|
||||
tr_pos_short_min = DecimalParameter(0.45, 0.65, default=0.55, decimals=2, space="buy", optimize=False)
|
||||
atr_sl_mult = DecimalParameter(1.2, 3.5, default=1.5, decimals=1, space="sell", optimize=False)
|
||||
atr_sl_min = DecimalParameter(0.012, 0.04, default=0.018, decimals=3, space="sell", optimize=False)
|
||||
atr_sl_max = DecimalParameter(0.05, 0.12, default=0.08, decimals=2, space="sell", optimize=False)
|
||||
time_stop_hours = IntParameter(48, 240, default=120, space="sell", optimize=False)
|
||||
|
||||
# Branch A:仅 Spring / UTAD
|
||||
use_spring_sig = CategoricalParameter([True, False], default=True, space="buy", optimize=False)
|
||||
use_utad_sig = CategoricalParameter([True, False], default=True, space="buy", optimize=False)
|
||||
use_sos_sig = CategoricalParameter([True, False], default=False, space="buy", optimize=False)
|
||||
use_sow_sig = CategoricalParameter([True, False], default=False, space="buy", optimize=False)
|
||||
|
||||
lev = 1.0
|
||||
|
||||
def informative_pairs(self):
|
||||
pairs = self.dp.current_whitelist() if self.dp else []
|
||||
tfs = {self.structure_timeframe}
|
||||
if self.bias_timeframe and self.use_bias_filter:
|
||||
tfs.add(self.bias_timeframe)
|
||||
return [(pair, tf) for pair in pairs for tf in tfs]
|
||||
|
||||
def _add_wyckoff_structure(self, df: DataFrame) -> DataFrame:
|
||||
lb = int(self.range_lookback.value)
|
||||
|
||||
df["atr"] = ta.ATR(df, timeperiod=14)
|
||||
df["ema50"] = ta.EMA(df, timeperiod=50)
|
||||
df["ema200"] = ta.EMA(df, timeperiod=200)
|
||||
df["adx"] = ta.ADX(df, timeperiod=14)
|
||||
df["rsi"] = ta.RSI(df, timeperiod=14)
|
||||
df["volume_ma"] = ta.SMA(df, timeperiod=20, price="volume")
|
||||
|
||||
df["tr_high"] = df["high"].rolling(lb).max()
|
||||
df["tr_low"] = df["low"].rolling(lb).min()
|
||||
df["tr_mid"] = (df["tr_high"] + df["tr_low"]) / 2.0
|
||||
df["tr_width"] = (df["tr_high"] - df["tr_low"]) / df["tr_mid"].replace(0, np.nan)
|
||||
df["tr_width_ma"] = df["tr_width"].rolling(lb).mean()
|
||||
|
||||
rng = (df["tr_high"] - df["tr_low"]).replace(0, np.nan)
|
||||
df["tr_pos"] = (df["close"] - df["tr_low"]) / rng
|
||||
|
||||
df["in_range"] = (df["tr_width"] < df["tr_width_ma"] * 1.35) & (df["adx"] < 28)
|
||||
df["ema50_slope"] = df["ema50"] - df["ema50"].shift(8)
|
||||
df["prior_down"] = df["ema50_slope"].shift(lb) < 0
|
||||
df["prior_up"] = df["ema50_slope"].shift(lb) > 0
|
||||
|
||||
down_bar = df["close"] < df["open"]
|
||||
up_bar = df["close"] > df["open"]
|
||||
vol_down = np.where(down_bar, df["volume"], np.nan)
|
||||
vol_up = np.where(up_bar, df["volume"], np.nan)
|
||||
df["vol_down_ma"] = pd.Series(vol_down, index=df.index).rolling(10, min_periods=3).mean()
|
||||
df["vol_up_ma"] = pd.Series(vol_up, index=df.index).rolling(10, min_periods=3).mean()
|
||||
df["effort_absorb"] = (
|
||||
df["vol_down_ma"].notna()
|
||||
& df["vol_up_ma"].notna()
|
||||
& (df["vol_up_ma"] > df["vol_down_ma"] * 1.05)
|
||||
)
|
||||
|
||||
df["accum_ctx"] = (
|
||||
df["in_range"]
|
||||
& (df["prior_down"] | (df["close"] < df["ema50"]))
|
||||
& (df["tr_pos"] < float(self.tr_pos_long_max.value))
|
||||
)
|
||||
df["distrib_ctx"] = (
|
||||
df["in_range"]
|
||||
& (df["prior_up"] | (df["close"] > df["ema50"]))
|
||||
& (df["tr_pos"] > float(self.tr_pos_short_min.value))
|
||||
)
|
||||
df["bull_bias"] = (df["close"] > df["ema200"]) & (df["ema50"] > df["ema200"])
|
||||
df["bear_bias"] = (df["close"] < df["ema200"]) & (df["ema50"] < df["ema200"])
|
||||
df["vol_spike"] = df["volume"] > df["volume_ma"] * float(self.vol_spike_mult.value)
|
||||
return df
|
||||
|
||||
def _merge_tf(self, dataframe: DataFrame, pair: str, tf: str) -> DataFrame:
|
||||
inf = self.dp.get_pair_dataframe(pair=pair, timeframe=tf)
|
||||
inf = self._add_wyckoff_structure(inf)
|
||||
keep = [
|
||||
"date", "atr", "ema50", "ema200", "adx", "rsi",
|
||||
"tr_high", "tr_low", "tr_mid", "tr_width", "tr_pos",
|
||||
"in_range", "accum_ctx", "distrib_ctx",
|
||||
"vol_spike", "effort_absorb", "prior_down", "prior_up",
|
||||
"bull_bias", "bear_bias",
|
||||
]
|
||||
inf = inf[[c for c in keep if c in inf.columns]].copy()
|
||||
return merge_informative_pair(dataframe, inf, self.timeframe, tf, ffill=True)
|
||||
|
||||
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
pair = metadata["pair"]
|
||||
stf = self.structure_timeframe
|
||||
dataframe = self._merge_tf(dataframe, pair, stf)
|
||||
|
||||
btf = self.bias_timeframe
|
||||
if btf and self.use_bias_filter and btf != stf:
|
||||
dataframe = self._merge_tf(dataframe, pair, btf)
|
||||
|
||||
ss = f"_{stf}"
|
||||
dataframe["atr"] = ta.ATR(dataframe, timeperiod=14)
|
||||
dataframe["ema21"] = ta.EMA(dataframe, timeperiod=21)
|
||||
dataframe["ema50"] = ta.EMA(dataframe, timeperiod=50)
|
||||
dataframe["rsi"] = ta.RSI(dataframe, timeperiod=14)
|
||||
dataframe["volume_ma"] = ta.SMA(dataframe, timeperiod=20, price="volume")
|
||||
dataframe["vol_ok"] = dataframe["volume"] > dataframe["volume_ma"] * float(self.vol_spike_mult.value)
|
||||
|
||||
tr_high = dataframe[f"tr_high{ss}"]
|
||||
tr_low = dataframe[f"tr_low{ss}"]
|
||||
pierce = float(self.spring_pierce_pct.value)
|
||||
|
||||
accum_soft = (
|
||||
dataframe[f"accum_ctx{ss}"].fillna(False).astype(bool)
|
||||
| (
|
||||
dataframe[f"in_range{ss}"].fillna(False).astype(bool)
|
||||
& dataframe[f"prior_down{ss}"].fillna(False).astype(bool)
|
||||
& (dataframe[f"tr_pos{ss}"] < float(self.tr_pos_long_max.value))
|
||||
)
|
||||
)
|
||||
distrib_soft = (
|
||||
dataframe[f"distrib_ctx{ss}"].fillna(False).astype(bool)
|
||||
| (
|
||||
dataframe[f"in_range{ss}"].fillna(False).astype(bool)
|
||||
& dataframe[f"prior_up{ss}"].fillna(False).astype(bool)
|
||||
& (dataframe[f"tr_pos{ss}"] > float(self.tr_pos_short_min.value))
|
||||
)
|
||||
)
|
||||
|
||||
if btf and self.use_bias_filter:
|
||||
bs = f"_{btf}" if btf != stf else ss
|
||||
if f"bear_bias{bs}" in dataframe.columns:
|
||||
dataframe["bias_long_ok"] = ~dataframe[f"bear_bias{bs}"].fillna(False).astype(bool)
|
||||
dataframe["bias_short_ok"] = ~dataframe[f"bull_bias{bs}"].fillna(False).astype(bool)
|
||||
else:
|
||||
dataframe["bias_long_ok"] = True
|
||||
dataframe["bias_short_ok"] = True
|
||||
else:
|
||||
dataframe["bias_long_ok"] = True
|
||||
dataframe["bias_short_ok"] = True
|
||||
|
||||
vol_mild = dataframe["volume"] > dataframe["volume_ma"] * max(1.1, float(self.vol_spike_mult.value) * 0.85)
|
||||
|
||||
dataframe["spring"] = (
|
||||
tr_low.notna()
|
||||
& (dataframe["low"] < tr_low * (1.0 - pierce))
|
||||
& (dataframe["close"] > tr_low)
|
||||
& (dataframe["close"] > dataframe["open"])
|
||||
& accum_soft
|
||||
& vol_mild
|
||||
& (dataframe["rsi"] < 58)
|
||||
& dataframe["bias_long_ok"]
|
||||
)
|
||||
dataframe["utad"] = (
|
||||
tr_high.notna()
|
||||
& (dataframe["high"] > tr_high * (1.0 + pierce))
|
||||
& (dataframe["close"] < tr_high)
|
||||
& (dataframe["close"] < dataframe["open"])
|
||||
& distrib_soft
|
||||
& vol_mild
|
||||
& (dataframe["rsi"] > 42)
|
||||
& dataframe["bias_short_ok"]
|
||||
)
|
||||
# 基线不进 SOS/SOW;保留列供 exit 参考
|
||||
dataframe["sos"] = False
|
||||
dataframe["sow"] = False
|
||||
|
||||
for col in ["spring", "utad", "sos", "sow", "vol_ok", "bias_long_ok", "bias_short_ok"]:
|
||||
dataframe[col] = dataframe[col].fillna(False).astype(bool)
|
||||
dataframe["setup_type"] = ""
|
||||
dataframe.loc[dataframe["spring"], "setup_type"] = "SPRING_LONG"
|
||||
dataframe.loc[dataframe["utad"], "setup_type"] = "UTAD_SHORT"
|
||||
return dataframe
|
||||
|
||||
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
dataframe["enter_long"] = 0
|
||||
dataframe["enter_short"] = 0
|
||||
dataframe["enter_tag"] = ""
|
||||
|
||||
vol_ok = dataframe["volume"] > 0
|
||||
|
||||
# 分开标签:禁止把 SPRING / UTAD 混成同一统计桶
|
||||
if bool(self.use_spring_sig.value):
|
||||
cond = vol_ok & dataframe["spring"]
|
||||
dataframe.loc[cond, ["enter_long", "enter_tag"]] = (1, "SPRING_LONG")
|
||||
|
||||
if bool(self.use_utad_sig.value):
|
||||
cond = vol_ok & dataframe["utad"]
|
||||
dataframe.loc[cond, ["enter_short", "enter_tag"]] = (1, "UTAD_SHORT")
|
||||
|
||||
self._apply_regime_filter(dataframe)
|
||||
return dataframe
|
||||
|
||||
def _apply_regime_filter(self, dataframe: DataFrame) -> None:
|
||||
rm = getattr(self, "regime_mode", "all")
|
||||
if rm == "all" or not self.bias_timeframe:
|
||||
return
|
||||
bs = f"_{self.bias_timeframe}"
|
||||
bc, ec = f"bull_bias{bs}", f"bear_bias{bs}"
|
||||
if bc not in dataframe.columns or ec not in dataframe.columns:
|
||||
return
|
||||
bull = dataframe[bc].fillna(False).astype(bool)
|
||||
bear = dataframe[ec].fillna(False).astype(bool)
|
||||
both = bull & bear
|
||||
bull, bear = bull & ~both, bear & ~both
|
||||
range_m = (~bull) & (~bear)
|
||||
if rm == "bull":
|
||||
mask = ~bull
|
||||
elif rm == "bear":
|
||||
mask = ~bear
|
||||
elif rm == "range":
|
||||
mask = ~range_m
|
||||
elif rm == "trend":
|
||||
mask = range_m # Range disabled
|
||||
else:
|
||||
return
|
||||
dataframe.loc[mask, ["enter_long", "enter_short"]] = (0, 0)
|
||||
dataframe.loc[mask, "enter_tag"] = ""
|
||||
|
||||
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
||||
dataframe["exit_long"] = 0
|
||||
dataframe["exit_short"] = 0
|
||||
dataframe["exit_tag"] = ""
|
||||
ss = f"_{self.structure_timeframe}"
|
||||
|
||||
exit_long = dataframe["utad"] | (
|
||||
dataframe[f"distrib_ctx{ss}"].fillna(False).astype(bool)
|
||||
& (dataframe["close"] < dataframe["ema21"])
|
||||
& (dataframe["rsi"] < 45)
|
||||
)
|
||||
exit_short = dataframe["spring"] | (
|
||||
dataframe[f"accum_ctx{ss}"].fillna(False).astype(bool)
|
||||
& (dataframe["close"] > dataframe["ema21"])
|
||||
& (dataframe["rsi"] > 55)
|
||||
)
|
||||
dataframe.loc[exit_long, ["exit_long", "exit_tag"]] = (1, "wyckoff_phase_flip")
|
||||
dataframe.loc[exit_short, ["exit_short", "exit_tag"]] = (1, "wyckoff_phase_flip")
|
||||
return dataframe
|
||||
|
||||
def custom_stoploss(
|
||||
self, pair: str, trade: Trade, current_time: datetime,
|
||||
current_rate: float, current_profit: float, after_fill: bool, **kwargs,
|
||||
) -> Optional[float]:
|
||||
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
|
||||
if dataframe.empty:
|
||||
return None
|
||||
last = dataframe.iloc[-1]
|
||||
atr = float(last["atr"]) if pd.notna(last["atr"]) else 0.0
|
||||
if atr <= 0 or trade.open_rate <= 0:
|
||||
return None
|
||||
|
||||
atr_dist = float(self.atr_sl_mult.value) * atr
|
||||
tag = trade.enter_tag or ""
|
||||
buffer = atr * 0.15
|
||||
|
||||
if after_fill and trade.get_custom_data("struct_stop") is None:
|
||||
if trade.is_short:
|
||||
trade.set_custom_data("struct_stop", float(last["high"]) + buffer)
|
||||
else:
|
||||
trade.set_custom_data("struct_stop", float(last["low"]) - buffer)
|
||||
|
||||
struct = trade.get_custom_data("struct_stop")
|
||||
if trade.is_short:
|
||||
atr_stop = trade.open_rate + atr_dist
|
||||
stop_price = min(atr_stop, float(struct)) if struct is not None else atr_stop
|
||||
else:
|
||||
atr_stop = trade.open_rate - atr_dist
|
||||
stop_price = max(atr_stop, float(struct)) if struct is not None else atr_stop
|
||||
|
||||
raw = abs(trade.open_rate - stop_price) / trade.open_rate
|
||||
raw = min(max(raw, float(self.atr_sl_min.value)), float(self.atr_sl_max.value))
|
||||
if struct is not None and tag in (
|
||||
"SPRING_LONG", "UTAD_SHORT", "SPRING", "UTAD", "wyckoff_spring", "wyckoff_utad",
|
||||
):
|
||||
sl = stoploss_from_absolute(
|
||||
stop_price, current_rate, is_short=trade.is_short, leverage=trade.leverage
|
||||
)
|
||||
return sl if sl and sl > 0 else None
|
||||
return stoploss_from_open(
|
||||
-raw, current_profit, is_short=trade.is_short, leverage=trade.leverage
|
||||
) or None
|
||||
|
||||
def custom_exit(
|
||||
self, pair: str, trade: Trade, current_time: datetime,
|
||||
current_rate: float, current_profit: float, **kwargs,
|
||||
) -> Optional[str]:
|
||||
hours = (current_time - trade.open_date_utc).total_seconds() / 3600
|
||||
if hours > float(self.time_stop_hours.value) and current_profit < 0:
|
||||
return "wyckoff_time_stop"
|
||||
if hours > float(self.time_stop_hours.value) * 2:
|
||||
return "wyckoff_time_stop_max"
|
||||
return None
|
||||
|
||||
def leverage(
|
||||
self, pair: str, current_time: datetime, current_rate: float,
|
||||
proposed_leverage: float, max_leverage: float, entry_tag: Optional[str],
|
||||
side: str, **kwargs,
|
||||
) -> float:
|
||||
return min(self.lev, max_leverage)
|
||||
@@ -0,0 +1,460 @@
|
||||
{
|
||||
"branches": {
|
||||
"Spring_V1": {
|
||||
"wfo": {
|
||||
"train": {
|
||||
"timerange": "20230101-20250101",
|
||||
"profit_pct": 1.6587295176,
|
||||
"trades": 12,
|
||||
"dd_pct": 3.644907735100005,
|
||||
"pf": 1.1700179329477578,
|
||||
"winrate": 25.0,
|
||||
"final": 10165.87295176,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"validate": {
|
||||
"timerange": "20250101-20260101",
|
||||
"profit_pct": 9.990534148400002,
|
||||
"trades": 6,
|
||||
"dd_pct": 1.797834787912851,
|
||||
"pf": 6.201791679101682,
|
||||
"winrate": 66.66666666666666,
|
||||
"final": 10999.05341484,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"test": {
|
||||
"timerange": "20260101-",
|
||||
"profit_pct": 0.8458820224000001,
|
||||
"trades": 2,
|
||||
"dd_pct": 0.7197049309999966,
|
||||
"pf": 2.175317808681236,
|
||||
"winrate": 50.0,
|
||||
"final": 10084.58820224,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"full": {
|
||||
"timerange": "20230101-",
|
||||
"profit_pct": 12.7374753063,
|
||||
"trades": 20,
|
||||
"dd_pct": 3.644907735100005,
|
||||
"pf": 2.0183507402435503,
|
||||
"winrate": 40.0,
|
||||
"final": 11273.74753063,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
}
|
||||
},
|
||||
"regimes": {
|
||||
"trend": {
|
||||
"profit_pct": 12.7374753063,
|
||||
"trades": 20,
|
||||
"dd_pct": 3.644907735100005,
|
||||
"pf": 2.0183507402435503,
|
||||
"winrate": 40.0,
|
||||
"final": 11273.74753063,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"bull": {
|
||||
"profit_pct": 8.166882314399999,
|
||||
"trades": 12,
|
||||
"dd_pct": 3.4837023928902555,
|
||||
"pf": 1.9398544482027922,
|
||||
"winrate": 33.33333333333333,
|
||||
"final": 10816.688231439999,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "bull"
|
||||
},
|
||||
"bear": {
|
||||
"profit_pct": 4.2503064875000005,
|
||||
"trades": 8,
|
||||
"dd_pct": 3.173714645599994,
|
||||
"pf": 2.084295240772406,
|
||||
"winrate": 50.0,
|
||||
"final": 10425.03064875,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "bear"
|
||||
},
|
||||
"range": {
|
||||
"profit_pct": -4.3352539371,
|
||||
"trades": 6,
|
||||
"dd_pct": 4.404162180500007,
|
||||
"pf": 0.15746188404490422,
|
||||
"winrate": 16.666666666666664,
|
||||
"final": 9566.47460629,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "range"
|
||||
},
|
||||
"all": {
|
||||
"profit_pct": 7.831216539699999,
|
||||
"trades": 26,
|
||||
"dd_pct": 7.883451762900004,
|
||||
"pf": 1.454582067425369,
|
||||
"winrate": 34.61538461538461,
|
||||
"final": 10783.12165397,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "all"
|
||||
}
|
||||
},
|
||||
"cost_stress": {
|
||||
"fee_5bps": {
|
||||
"profit_pct": 12.7374753063,
|
||||
"trades": 20,
|
||||
"dd_pct": 3.644907735100005,
|
||||
"pf": 2.0183507402435503,
|
||||
"winrate": 40.0,
|
||||
"final": 11273.74753063,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"fee_5bps+slip_5bps": {
|
||||
"profit_pct": 6.782772099999998,
|
||||
"trades": 20,
|
||||
"dd_pct": 7.851805397900007,
|
||||
"pf": 1.4511324473780693,
|
||||
"winrate": 35.0,
|
||||
"final": 10678.27721,
|
||||
"fee_used": 0.001,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"fee_10bps+slip_10bps": {
|
||||
"profit_pct": 3.182909279400001,
|
||||
"trades": 20,
|
||||
"dd_pct": 9.126146157700004,
|
||||
"pf": 1.1834520309921508,
|
||||
"winrate": 35.0,
|
||||
"final": 10318.29092794,
|
||||
"fee_used": 0.002,
|
||||
"regime_loaded": "trend"
|
||||
}
|
||||
},
|
||||
"target": {
|
||||
"pf": 1.3,
|
||||
"dd": 10.0,
|
||||
"note": "Spring: PF>1.3 DD<10%"
|
||||
},
|
||||
"verdict": {
|
||||
"full_pf": 2.0183507402435503,
|
||||
"full_dd": 3.644907735100005,
|
||||
"trades_per_year": 5.555555555555555,
|
||||
"net_mid_pf": 1.4511324473780693,
|
||||
"target_pf_ok": true,
|
||||
"target_dd_ok": true
|
||||
}
|
||||
},
|
||||
"LPS_V1": {
|
||||
"wfo": {
|
||||
"train": {
|
||||
"timerange": "20230101-20250101",
|
||||
"profit_pct": -1.2518571096,
|
||||
"trades": 1,
|
||||
"dd_pct": 1.251857109600005,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 9874.81428904,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"validate": {
|
||||
"timerange": "20250101-20260101",
|
||||
"profit_pct": -0.24613064569999998,
|
||||
"trades": 1,
|
||||
"dd_pct": 0.24613064569999552,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 9975.38693543,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"test": {
|
||||
"timerange": "20260101-",
|
||||
"profit_pct": 0.0,
|
||||
"trades": 0,
|
||||
"dd_pct": 0.0,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 10000.0,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"full": {
|
||||
"timerange": "20230101-",
|
||||
"profit_pct": -1.4952529704,
|
||||
"trades": 2,
|
||||
"dd_pct": 1.4952529703999973,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 9850.47470296,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
}
|
||||
},
|
||||
"regimes": {
|
||||
"trend": {
|
||||
"profit_pct": -1.4952529704,
|
||||
"trades": 2,
|
||||
"dd_pct": 1.4952529703999973,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 9850.47470296,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"bull": {
|
||||
"profit_pct": -1.4952529704,
|
||||
"trades": 2,
|
||||
"dd_pct": 1.4952529703999973,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 9850.47470296,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "bull"
|
||||
},
|
||||
"bear": {
|
||||
"profit_pct": 0.0,
|
||||
"trades": 0,
|
||||
"dd_pct": 0.0,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 10000.0,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "bear"
|
||||
},
|
||||
"range": {
|
||||
"profit_pct": 0.0,
|
||||
"trades": 0,
|
||||
"dd_pct": 0.0,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 10000.0,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "range"
|
||||
},
|
||||
"all": {
|
||||
"profit_pct": -1.4952529704,
|
||||
"trades": 2,
|
||||
"dd_pct": 1.4952529703999973,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 9850.47470296,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "all"
|
||||
}
|
||||
},
|
||||
"cost_stress": {
|
||||
"fee_5bps": {
|
||||
"profit_pct": -1.4952529704,
|
||||
"trades": 2,
|
||||
"dd_pct": 1.4952529703999973,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 9850.47470296,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"fee_5bps+slip_5bps": {
|
||||
"profit_pct": -1.6902037039,
|
||||
"trades": 2,
|
||||
"dd_pct": 1.6902037039000062,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 9830.97962961,
|
||||
"fee_used": 0.001,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"fee_10bps+slip_10bps": {
|
||||
"profit_pct": -2.0801051709,
|
||||
"trades": 2,
|
||||
"dd_pct": 2.080105170900006,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 9791.98948291,
|
||||
"fee_used": 0.002,
|
||||
"regime_loaded": "trend"
|
||||
}
|
||||
},
|
||||
"target": {
|
||||
"pf": 1.2,
|
||||
"dd": 15.0,
|
||||
"note": "LPS: PF>1.2, 次数增加"
|
||||
},
|
||||
"version": "LPS_V1.1",
|
||||
"verdict": {
|
||||
"full_pf": 0.0,
|
||||
"full_dd": 1.4952529703999973,
|
||||
"trades_per_year": 0.5555555555555556,
|
||||
"net_mid_pf": 0.0,
|
||||
"target_pf_ok": false,
|
||||
"target_dd_ok": true
|
||||
}
|
||||
},
|
||||
"LPS_V2": {
|
||||
"version": "LPS_V2",
|
||||
"wfo": {
|
||||
"train": {
|
||||
"timerange": "20230101-20250101",
|
||||
"profit_pct": -3.5049591933000004,
|
||||
"trades": 3,
|
||||
"dd_pct": 3.504959193300001,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 9649.50408067,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"validate": {
|
||||
"timerange": "20250101-20260101",
|
||||
"profit_pct": -1.6143743830000001,
|
||||
"trades": 2,
|
||||
"dd_pct": 1.614374382999995,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 9838.5625617,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"test": {
|
||||
"timerange": "20260101-",
|
||||
"profit_pct": 1.2174468187999996,
|
||||
"trades": 2,
|
||||
"dd_pct": 1.4924489317000007,
|
||||
"pf": 1.81573767312309,
|
||||
"winrate": 50.0,
|
||||
"final": 10121.74468188,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"full": {
|
||||
"timerange": "20230101-",
|
||||
"profit_pct": -3.9055710949000004,
|
||||
"trades": 7,
|
||||
"dd_pct": 6.479119889400008,
|
||||
"pf": 0.39720654015221873,
|
||||
"winrate": 14.285714285714285,
|
||||
"final": 9609.44289051,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
}
|
||||
},
|
||||
"regimes": {
|
||||
"trend": {
|
||||
"profit_pct": -3.9055710949000004,
|
||||
"trades": 7,
|
||||
"dd_pct": 6.479119889400008,
|
||||
"pf": 0.39720654015221873,
|
||||
"winrate": 14.285714285714285,
|
||||
"final": 9609.44289051,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"bull": {
|
||||
"profit_pct": -5.0599199851,
|
||||
"trades": 5,
|
||||
"dd_pct": 5.059919985100005,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 9494.00800149,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "bull"
|
||||
},
|
||||
"bear": {
|
||||
"profit_pct": 1.2174468187999996,
|
||||
"trades": 2,
|
||||
"dd_pct": 1.4924489317000007,
|
||||
"pf": 1.81573767312309,
|
||||
"winrate": 50.0,
|
||||
"final": 10121.74468188,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "bear"
|
||||
},
|
||||
"range": {
|
||||
"profit_pct": 0.0,
|
||||
"trades": 0,
|
||||
"dd_pct": 0.0,
|
||||
"pf": 0.0,
|
||||
"winrate": 0.0,
|
||||
"final": 10000.0,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "range"
|
||||
},
|
||||
"all": {
|
||||
"profit_pct": -3.9055710949000004,
|
||||
"trades": 7,
|
||||
"dd_pct": 6.479119889400008,
|
||||
"pf": 0.39720654015221873,
|
||||
"winrate": 14.285714285714285,
|
||||
"final": 9609.44289051,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "all"
|
||||
}
|
||||
},
|
||||
"cost_stress": {
|
||||
"fee_5bps": {
|
||||
"profit_pct": -3.9055710949000004,
|
||||
"trades": 7,
|
||||
"dd_pct": 6.479119889400008,
|
||||
"pf": 0.39720654015221873,
|
||||
"winrate": 14.285714285714285,
|
||||
"final": 9609.44289051,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"fee_5bps+slip_5bps": {
|
||||
"profit_pct": -4.5549168852,
|
||||
"trades": 7,
|
||||
"dd_pct": 7.020877735199993,
|
||||
"pf": 0.3512325585213674,
|
||||
"winrate": 14.285714285714285,
|
||||
"final": 9544.50831148,
|
||||
"fee_used": 0.001,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"fee_10bps+slip_10bps": {
|
||||
"profit_pct": -5.371762636800001,
|
||||
"trades": 7,
|
||||
"dd_pct": 8.1297357765,
|
||||
"pf": 0.33924511392759654,
|
||||
"winrate": 14.285714285714285,
|
||||
"final": 9462.82373632,
|
||||
"fee_used": 0.002,
|
||||
"regime_loaded": "trend"
|
||||
}
|
||||
},
|
||||
"target": {
|
||||
"pf": 1.2,
|
||||
"dd": 15.0,
|
||||
"note": "LPS V2: 4h SOS→1h LPS; PF>1.2; ~5-15/yr"
|
||||
},
|
||||
"verdict": {
|
||||
"full_pf": 0.39720654015221873,
|
||||
"full_dd": 6.479119889400008,
|
||||
"trades_per_year": 1.9444444444444444,
|
||||
"net_mid_pf": 0.3512325585213674,
|
||||
"target_pf_ok": false,
|
||||
"target_dd_ok": true,
|
||||
"freq_ok": false,
|
||||
"regime_logic_ok": true,
|
||||
"status": "FAIL",
|
||||
"hypothesis": "4h native SOS → 1h LPS"
|
||||
}
|
||||
}
|
||||
},
|
||||
"portfolio_note": {
|
||||
"spring_tpy": 5.555555555555555,
|
||||
"lps_tpy": 0.5555555555555556,
|
||||
"sum_tpy_approx": 6.111111111111111,
|
||||
"combined_target_tpy": "15-25",
|
||||
"lps_status": "FAIL",
|
||||
"spring_status": "PASS"
|
||||
},
|
||||
"system_status": {
|
||||
"spring": "BASELINE FROZEN / PASS + Limited Evidence",
|
||||
"lps": "FAIL",
|
||||
"spring_tpy": 5.555555555555555,
|
||||
"lps_tpy": 1.9444444444444444,
|
||||
"next": "若 LPS PASS → 组合层;否则 Spring-only"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
{
|
||||
"note": "V1 BASELINE frozen; Range disabled; Spring/UTAD only; net cost included",
|
||||
"wfo": {
|
||||
"train": {
|
||||
"timerange": "20230101-20250101",
|
||||
"profit_pct": 1.6587295176,
|
||||
"trades": 12,
|
||||
"dd_pct": 3.644907735100005,
|
||||
"pf": 1.1700179329477578,
|
||||
"winrate": 25.0,
|
||||
"final": 10165.87295176,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"validate": {
|
||||
"timerange": "20250101-20260101",
|
||||
"profit_pct": 9.990534148400002,
|
||||
"trades": 6,
|
||||
"dd_pct": 1.797834787912851,
|
||||
"pf": 6.201791679101682,
|
||||
"winrate": 66.66666666666666,
|
||||
"final": 10999.05341484,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"test": {
|
||||
"timerange": "20260101-",
|
||||
"profit_pct": 0.8458820224000001,
|
||||
"trades": 2,
|
||||
"dd_pct": 0.7197049309999966,
|
||||
"pf": 2.175317808681236,
|
||||
"winrate": 50.0,
|
||||
"final": 10084.58820224,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"full": {
|
||||
"timerange": "20230101-",
|
||||
"profit_pct": 12.7374753063,
|
||||
"trades": 20,
|
||||
"dd_pct": 3.644907735100005,
|
||||
"pf": 2.0183507402435503,
|
||||
"winrate": 40.0,
|
||||
"final": 11273.74753063,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
}
|
||||
},
|
||||
"regimes": {
|
||||
"trend": {
|
||||
"profit_pct": 12.7374753063,
|
||||
"trades": 20,
|
||||
"dd_pct": 3.644907735100005,
|
||||
"pf": 2.0183507402435503,
|
||||
"winrate": 40.0,
|
||||
"final": 11273.74753063,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"bull": {
|
||||
"profit_pct": 8.166882314399999,
|
||||
"trades": 12,
|
||||
"dd_pct": 3.4837023928902555,
|
||||
"pf": 1.9398544482027922,
|
||||
"winrate": 33.33333333333333,
|
||||
"final": 10816.688231439999,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "bull"
|
||||
},
|
||||
"bear": {
|
||||
"profit_pct": 4.2503064875000005,
|
||||
"trades": 8,
|
||||
"dd_pct": 3.173714645599994,
|
||||
"pf": 2.084295240772406,
|
||||
"winrate": 50.0,
|
||||
"final": 10425.03064875,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "bear"
|
||||
},
|
||||
"range": {
|
||||
"profit_pct": -4.3352539371,
|
||||
"trades": 6,
|
||||
"dd_pct": 4.404162180500007,
|
||||
"pf": 0.15746188404490422,
|
||||
"winrate": 16.666666666666664,
|
||||
"final": 9566.47460629,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "range"
|
||||
},
|
||||
"all": {
|
||||
"profit_pct": 7.831216539699999,
|
||||
"trades": 26,
|
||||
"dd_pct": 7.883451762900004,
|
||||
"pf": 1.454582067425369,
|
||||
"winrate": 34.61538461538461,
|
||||
"final": 10783.12165397,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "all"
|
||||
}
|
||||
},
|
||||
"cost_stress": {
|
||||
"fee_5bps": {
|
||||
"profit_pct": 12.7374753063,
|
||||
"trades": 20,
|
||||
"dd_pct": 3.644907735100005,
|
||||
"pf": 2.0183507402435503,
|
||||
"winrate": 40.0,
|
||||
"final": 11273.74753063,
|
||||
"fee_used": 0.0005,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"fee_5bps+slip_5bps": {
|
||||
"profit_pct": 6.782772099999998,
|
||||
"trades": 20,
|
||||
"dd_pct": 7.851805397900007,
|
||||
"pf": 1.4511324473780693,
|
||||
"winrate": 35.0,
|
||||
"final": 10678.27721,
|
||||
"fee_used": 0.001,
|
||||
"regime_loaded": "trend"
|
||||
},
|
||||
"fee_10bps+slip_10bps": {
|
||||
"profit_pct": 3.182909279400001,
|
||||
"trades": 20,
|
||||
"dd_pct": 9.126146157700004,
|
||||
"pf": 1.1834520309921508,
|
||||
"winrate": 35.0,
|
||||
"final": 10318.29092794,
|
||||
"fee_used": 0.002,
|
||||
"regime_loaded": "trend"
|
||||
}
|
||||
},
|
||||
"verdict": {
|
||||
"full_pf": 2.0183507402435503,
|
||||
"full_dd": 3.644907735100005,
|
||||
"trades_per_year": 5.555555555555555,
|
||||
"net_mid_pf": 1.4511324473780693,
|
||||
"target_pf_ok": true,
|
||||
"target_dd_ok": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user