better vyt/sell signal proecessing/display
This commit is contained in:
@@ -316,7 +316,14 @@ class RealTrainingAdapter:
|
||||
return None
|
||||
|
||||
def _create_pivot_training_batch(self, model_inputs: Dict, pivot_event, inference_ref) -> Optional[Dict]:
|
||||
"""Create training batch from inference inputs and pivot event"""
|
||||
"""
|
||||
Create training batch from inference inputs and pivot event
|
||||
|
||||
Strategy: Train to execute trades on L2 pivots that align with upper trend
|
||||
- L2L (support) in UPTREND → BUY
|
||||
- L2H (resistance) in DOWNTREND → SELL
|
||||
- Misaligned pivots → HOLD (don't trade against trend)
|
||||
"""
|
||||
try:
|
||||
import torch
|
||||
|
||||
@@ -327,15 +334,29 @@ class RealTrainingAdapter:
|
||||
# Get device
|
||||
device = next(iter(batch.values())).device if batch else torch.device('cpu')
|
||||
|
||||
# Determine action from pivot type
|
||||
# L2L, L3L, etc. -> BUY (support levels)
|
||||
# L2H, L3H, etc. -> SELL (resistance levels)
|
||||
if pivot_event.pivot_type.endswith('L'):
|
||||
action = 1 # BUY
|
||||
elif pivot_event.pivot_type.endswith('H'):
|
||||
action = 2 # SELL
|
||||
else:
|
||||
action = 0 # HOLD
|
||||
# Get trend direction from pivot event (if available)
|
||||
trend_direction = getattr(pivot_event, 'trend_direction', 'sideways')
|
||||
pivot_type = pivot_event.pivot_type
|
||||
|
||||
# Determine action based on pivot type AND trend alignment
|
||||
# Only trade when pivot aligns with trend
|
||||
action = 0 # Default: HOLD
|
||||
|
||||
if pivot_type in ['L2L', 'L3L']: # Support levels (lows)
|
||||
# BUY only if in UPTREND (buying at support in uptrend)
|
||||
if trend_direction in ['up', 'uptrend', 'UPTREND']:
|
||||
action = 1 # BUY
|
||||
logger.info(f"Pivot training: BUY signal at {pivot_type} (aligned with {trend_direction})")
|
||||
else:
|
||||
logger.debug(f"Pivot training: HOLD at {pivot_type} (not aligned with {trend_direction})")
|
||||
|
||||
elif pivot_type in ['L2H', 'L3H']: # Resistance levels (highs)
|
||||
# SELL only if in DOWNTREND (selling at resistance in downtrend)
|
||||
if trend_direction in ['down', 'downtrend', 'DOWNTREND']:
|
||||
action = 2 # SELL
|
||||
logger.info(f"Pivot training: SELL signal at {pivot_type} (aligned with {trend_direction})")
|
||||
else:
|
||||
logger.debug(f"Pivot training: HOLD at {pivot_type} (not aligned with {trend_direction})")
|
||||
|
||||
batch['actions'] = torch.tensor([[action]], dtype=torch.long, device=device)
|
||||
|
||||
@@ -4824,7 +4845,7 @@ class RealTrainingAdapter:
|
||||
Execute trade based on signal, respecting position management rules
|
||||
|
||||
Rules:
|
||||
1. Only execute if confidence >= 0.6
|
||||
1. Only execute if confidence >= 0.5 (lowered for more learning opportunities)
|
||||
2. Only open new position if no position is currently open
|
||||
3. Close position on opposite signal
|
||||
4. Track all executed trades for visualization
|
||||
@@ -4836,8 +4857,8 @@ class RealTrainingAdapter:
|
||||
confidence = signal['confidence']
|
||||
timestamp = signal['timestamp']
|
||||
|
||||
# Rule 1: Confidence threshold
|
||||
if confidence < 0.6:
|
||||
# Rule 1: Confidence threshold (lowered to 0.5 for more learning opportunities)
|
||||
if confidence < 0.5:
|
||||
return None # Rejected: low confidence
|
||||
|
||||
# Rule 2 & 3: Position management
|
||||
@@ -4962,8 +4983,8 @@ class RealTrainingAdapter:
|
||||
confidence = signal['confidence']
|
||||
position = session.get('position')
|
||||
|
||||
if confidence < 0.6:
|
||||
return f"Low confidence ({confidence:.2f} < 0.6)"
|
||||
if confidence < 0.5:
|
||||
return f"Low confidence ({confidence:.2f} < 0.5)"
|
||||
|
||||
if action == 'HOLD':
|
||||
return "HOLD signal (no trade)"
|
||||
|
||||
Reference in New Issue
Block a user