better vyt/sell signal proecessing/display
This commit is contained in:
@@ -3863,7 +3863,7 @@ class ChartManager {
|
||||
// Update confidence
|
||||
const confPct = (confidence * 100).toFixed(0);
|
||||
signalConf.textContent = `${confPct}%`;
|
||||
signalConf.style.color = confidence >= 0.6 ? '#10b981' : '#9ca3af';
|
||||
signalConf.style.color = confidence >= 0.5 ? '#10b981' : '#9ca3af';
|
||||
|
||||
} catch (error) {
|
||||
console.error(`Error updating signal banner for ${timeframe}:`, error);
|
||||
|
||||
@@ -1135,53 +1135,82 @@
|
||||
}
|
||||
|
||||
function updatePnLTracking(action, currentPrice, timestamp) {
|
||||
// Simple trading simulation: BUY opens long, SELL opens short, HOLD closes positions
|
||||
if (action === 'BUY' && pnlTracker.positions.length === 0) {
|
||||
// Open long position
|
||||
pnlTracker.positions.push({
|
||||
action: 'BUY',
|
||||
entryPrice: currentPrice,
|
||||
entryTime: timestamp,
|
||||
size: pnlTracker.positionSize
|
||||
});
|
||||
} else if (action === 'SELL' && pnlTracker.positions.length === 0) {
|
||||
// Open short position
|
||||
pnlTracker.positions.push({
|
||||
action: 'SELL',
|
||||
entryPrice: currentPrice,
|
||||
entryTime: timestamp,
|
||||
size: pnlTracker.positionSize
|
||||
});
|
||||
} else if (action === 'HOLD' && pnlTracker.positions.length > 0) {
|
||||
// Close all positions
|
||||
pnlTracker.positions.forEach(pos => {
|
||||
let pnl = 0;
|
||||
if (pos.action === 'BUY') {
|
||||
// Long: profit if price went up
|
||||
pnl = (currentPrice - pos.entryPrice) / pos.entryPrice * pos.size;
|
||||
} else if (pos.action === 'SELL') {
|
||||
// Short: profit if price went down
|
||||
pnl = (pos.entryPrice - currentPrice) / pos.entryPrice * pos.size;
|
||||
}
|
||||
// Paper trading simulation with proper position management
|
||||
// Rules:
|
||||
// 1. BUY: Close SHORT if exists, then open LONG
|
||||
// 2. SELL: Close LONG if exists, then open SHORT
|
||||
// 3. HOLD: Do nothing (keep existing positions)
|
||||
|
||||
const currentPosition = pnlTracker.positions.length > 0 ? pnlTracker.positions[0] : null;
|
||||
|
||||
if (action === 'BUY') {
|
||||
// Close SHORT position if exists
|
||||
if (currentPosition && currentPosition.action === 'SELL') {
|
||||
const pnl = (currentPosition.entryPrice - currentPrice) / currentPosition.entryPrice * currentPosition.size;
|
||||
|
||||
pnlTracker.closedTrades.push({
|
||||
entryPrice: pos.entryPrice,
|
||||
entryPrice: currentPosition.entryPrice,
|
||||
exitPrice: currentPrice,
|
||||
pnl: pnl,
|
||||
entryTime: pos.entryTime,
|
||||
exitTime: timestamp
|
||||
entryTime: currentPosition.entryTime,
|
||||
exitTime: timestamp,
|
||||
type: 'SHORT'
|
||||
});
|
||||
|
||||
pnlTracker.totalPnL += pnl;
|
||||
});
|
||||
pnlTracker.positions = [];
|
||||
|
||||
console.log(`[Paper Trading] Closed SHORT @ ${currentPrice.toFixed(2)}, PnL: ${pnl >= 0 ? '+' : ''}${pnl.toFixed(2)}`);
|
||||
}
|
||||
|
||||
pnlTracker.positions = [];
|
||||
// Open LONG position (if no position or just closed SHORT)
|
||||
if (pnlTracker.positions.length === 0) {
|
||||
pnlTracker.positions.push({
|
||||
action: 'BUY',
|
||||
entryPrice: currentPrice,
|
||||
entryTime: timestamp,
|
||||
size: pnlTracker.positionSize
|
||||
});
|
||||
console.log(`[Paper Trading] Opened LONG @ ${currentPrice.toFixed(2)}`);
|
||||
}
|
||||
|
||||
// Calculate win rate
|
||||
} else if (action === 'SELL') {
|
||||
// Close LONG position if exists
|
||||
if (currentPosition && currentPosition.action === 'BUY') {
|
||||
const pnl = (currentPrice - currentPosition.entryPrice) / currentPosition.entryPrice * currentPosition.size;
|
||||
|
||||
pnlTracker.closedTrades.push({
|
||||
entryPrice: currentPosition.entryPrice,
|
||||
exitPrice: currentPrice,
|
||||
pnl: pnl,
|
||||
entryTime: currentPosition.entryTime,
|
||||
exitTime: timestamp,
|
||||
type: 'LONG'
|
||||
});
|
||||
|
||||
pnlTracker.totalPnL += pnl;
|
||||
pnlTracker.positions = [];
|
||||
|
||||
console.log(`[Paper Trading] Closed LONG @ ${currentPrice.toFixed(2)}, PnL: ${pnl >= 0 ? '+' : ''}${pnl.toFixed(2)}`);
|
||||
}
|
||||
|
||||
// Open SHORT position (if no position or just closed LONG)
|
||||
if (pnlTracker.positions.length === 0) {
|
||||
pnlTracker.positions.push({
|
||||
action: 'SELL',
|
||||
entryPrice: currentPrice,
|
||||
entryTime: timestamp,
|
||||
size: pnlTracker.positionSize
|
||||
});
|
||||
console.log(`[Paper Trading] Opened SHORT @ ${currentPrice.toFixed(2)}`);
|
||||
}
|
||||
}
|
||||
// HOLD: Do nothing, keep existing positions
|
||||
|
||||
// Calculate win rate
|
||||
if (pnlTracker.closedTrades.length > 0) {
|
||||
const wins = pnlTracker.closedTrades.filter(t => t.pnl > 0).length;
|
||||
pnlTracker.winRate = pnlTracker.closedTrades.length > 0
|
||||
? (wins / pnlTracker.closedTrades.length * 100)
|
||||
: 0;
|
||||
pnlTracker.winRate = (wins / pnlTracker.closedTrades.length * 100);
|
||||
}
|
||||
|
||||
// Update PnL display
|
||||
@@ -1192,6 +1221,38 @@
|
||||
const pnlColor = pnlTracker.totalPnL >= 0 ? 'text-success' : 'text-danger';
|
||||
const pnlSign = pnlTracker.totalPnL >= 0 ? '+' : '';
|
||||
|
||||
// Update position status in trading panel
|
||||
const positionStatusEl = document.getElementById('position-status');
|
||||
if (positionStatusEl) {
|
||||
if (pnlTracker.positions.length > 0) {
|
||||
const pos = pnlTracker.positions[0];
|
||||
const posType = pos.action === 'BUY' ? 'LONG' : 'SHORT';
|
||||
const posColor = pos.action === 'BUY' ? 'text-success' : 'text-danger';
|
||||
positionStatusEl.textContent = posType;
|
||||
positionStatusEl.className = `fw-bold ${posColor}`;
|
||||
} else {
|
||||
positionStatusEl.textContent = 'NO POSITION';
|
||||
positionStatusEl.className = 'fw-bold text-info';
|
||||
}
|
||||
}
|
||||
|
||||
// Update session PnL
|
||||
const sessionPnlEl = document.getElementById('session-pnl');
|
||||
if (sessionPnlEl) {
|
||||
sessionPnlEl.textContent = `${pnlSign}$${pnlTracker.totalPnL.toFixed(2)}`;
|
||||
sessionPnlEl.className = `fw-bold ${pnlColor}`;
|
||||
}
|
||||
|
||||
// Update win rate
|
||||
const winRateEl = document.getElementById('win-rate');
|
||||
if (winRateEl) {
|
||||
const wins = pnlTracker.closedTrades.filter(t => t.pnl > 0).length;
|
||||
const total = pnlTracker.closedTrades.length;
|
||||
winRateEl.textContent = total > 0
|
||||
? `${pnlTracker.winRate.toFixed(0)}% (${wins}/${total})`
|
||||
: '0% (0/0)';
|
||||
}
|
||||
|
||||
// Update PnL metric
|
||||
const pnlElement = document.getElementById('metric-pnl');
|
||||
if (pnlElement) {
|
||||
|
||||
Reference in New Issue
Block a user