Fix trade setup generation broken by TP tightening factor
The TP floor calculations used raw min_rr (0.4) but after 20% tightening the effective RR dropped to ~0.32, failing the min_rr check and returning None for all trade setups. Pre-compensate the floor with min_rr/tf so post-tightening RR still meets the minimum.
This commit is contained in:
@@ -867,6 +867,8 @@ class SignalAggregator:
|
|||||||
is_buy = report.final_score >= 0
|
is_buy = report.final_score >= 0
|
||||||
levels = report.primary_analysis.key_levels
|
levels = report.primary_analysis.key_levels
|
||||||
min_rr = self.config.signals.min_rr_ratio
|
min_rr = self.config.signals.min_rr_ratio
|
||||||
|
tf = self.config.signals.tp_tightening_factor
|
||||||
|
pre_tight_min_rr = min_rr / tf if tf > 0 else min_rr
|
||||||
|
|
||||||
mature_move = abs(report.final_score) > 30
|
mature_move = abs(report.final_score) > 30
|
||||||
tp_mult = 1.0 if mature_move else 1.5
|
tp_mult = 1.0 if mature_move else 1.5
|
||||||
@@ -896,14 +898,14 @@ class SignalAggregator:
|
|||||||
)
|
)
|
||||||
if (swing_highs
|
if (swing_highs
|
||||||
and swing_highs[0] - price <= atr * tp_swing_cap
|
and swing_highs[0] - price <= atr * tp_swing_cap
|
||||||
and swing_highs[0] - price >= sl_distance * min_rr):
|
and swing_highs[0] - price >= sl_distance * pre_tight_min_rr):
|
||||||
tp1 = swing_highs[0]
|
tp1 = swing_highs[0]
|
||||||
else:
|
else:
|
||||||
tp1 = price + max(atr * tp_mult, sl_distance * min_rr)
|
tp1 = price + max(atr * tp_mult, sl_distance * pre_tight_min_rr)
|
||||||
if len(swing_highs) >= 2 and swing_highs[1] - price <= atr * 5.0:
|
if len(swing_highs) >= 2 and swing_highs[1] - price <= atr * 5.0:
|
||||||
tp2 = swing_highs[1]
|
tp2 = swing_highs[1]
|
||||||
else:
|
else:
|
||||||
tp2 = price + max(atr * (tp_mult + 1.5), sl_distance * min_rr * 1.5)
|
tp2 = price + max(atr * (tp_mult + 1.5), sl_distance * pre_tight_min_rr * 1.5)
|
||||||
|
|
||||||
direction = "BUY"
|
direction = "BUY"
|
||||||
entry, sl = price, sl_price
|
entry, sl = price, sl_price
|
||||||
@@ -927,14 +929,14 @@ class SignalAggregator:
|
|||||||
)
|
)
|
||||||
if (swing_lows
|
if (swing_lows
|
||||||
and price - swing_lows[0] <= atr * tp_swing_cap
|
and price - swing_lows[0] <= atr * tp_swing_cap
|
||||||
and price - swing_lows[0] >= sl_distance * min_rr):
|
and price - swing_lows[0] >= sl_distance * pre_tight_min_rr):
|
||||||
tp1 = swing_lows[0]
|
tp1 = swing_lows[0]
|
||||||
else:
|
else:
|
||||||
tp1 = price - max(atr * tp_mult, sl_distance * min_rr)
|
tp1 = price - max(atr * tp_mult, sl_distance * pre_tight_min_rr)
|
||||||
if len(swing_lows) >= 2 and price - swing_lows[1] <= atr * 5.0:
|
if len(swing_lows) >= 2 and price - swing_lows[1] <= atr * 5.0:
|
||||||
tp2 = swing_lows[1]
|
tp2 = swing_lows[1]
|
||||||
else:
|
else:
|
||||||
tp2 = price - max(atr * (tp_mult + 1.5), sl_distance * min_rr * 1.5)
|
tp2 = price - max(atr * (tp_mult + 1.5), sl_distance * pre_tight_min_rr * 1.5)
|
||||||
|
|
||||||
direction = "SELL"
|
direction = "SELL"
|
||||||
entry, sl = price, sl_price
|
entry, sl = price, sl_price
|
||||||
|
|||||||
Reference in New Issue
Block a user