Pre-refactor: commit before converting indicators to self-contained files

This commit is contained in:
DiTus
2026-03-01 19:37:07 +01:00
parent e457ce3e20
commit fdab0a3faa
22 changed files with 96 additions and 2726 deletions

View File

@ -236,18 +236,16 @@ function calculateMASignal(indicator, lastCandle, prevCandle, values) {
let signalType, strength, reasoning;
if (close > ma * 1.02) {
if (close > ma) {
signalType = SIGNAL_TYPES.BUY;
strength = Math.min(60 + ((close - ma) / ma) * 500, 100);
reasoning = `Price (${close.toFixed(2)}) is strongly above ${maLabel} (${ma.toFixed(2)}), bullish trend`;
} else if (close < ma * 0.98) {
reasoning = `Price (${close.toFixed(2)}) is above ${maLabel} (${ma.toFixed(2)})`;
} else if (close < ma) {
signalType = SIGNAL_TYPES.SELL;
strength = Math.min(60 + ((ma - close) / ma) * 500, 100);
reasoning = `Price (${close.toFixed(2)}) is strongly below ${maLabel} (${ma.toFixed(2)}), bearish trend`;
reasoning = `Price (${close.toFixed(2)}) is below ${maLabel} (${ma.toFixed(2)})`;
} else {
signalType = SIGNAL_TYPES.HOLD;
strength = 30;
reasoning = `Price (${close.toFixed(2)}) is near ${maLabel} (${ma.toFixed(2)}), sideways/consolidating`;
return null;
}
console.log('[calculateMASignal] Result:', signalType, strength);
@ -406,6 +404,36 @@ export function calculateAllIndicatorSignals() {
const signal = calculateIndicatorSignal(indicator, candles, values);
let currentSignal = signal;
let lastSignalDate = indicator.lastSignalTimestamp || null;
let lastSignalType = indicator.lastSignalType || null;
if (!currentSignal || !currentSignal.type) {
console.log('[Signals] No valid signal for', indicator.type, '- Using last signal if available');
if (lastSignalType && lastSignalDate) {
currentSignal = {
type: lastSignalType,
strength: 50,
value: candles[candles.length - 1]?.close,
reasoning: `No crossover (price equals MA)`
};
} else {
console.log('[Signals] No previous signal available - Skipping');
continue;
}
} else {
const currentCandleTimestamp = candles[candles.length - 1].time;
if (currentSignal.type !== lastSignalType || !lastSignalType) {
console.log('[Signals] Signal changed for', indicator.type, ':', lastSignalType, '->', currentSignal.type);
lastSignalDate = currentCandleTimestamp;
lastSignalType = currentSignal.type;
indicator.lastSignalTimestamp = lastSignalDate;
indicator.lastSignalType = lastSignalType;
}
}
const label = indicator.type?.toUpperCase();
const params = indicator.params && typeof indicator.params === 'object'
? Object.entries(indicator.params)
@ -420,11 +448,12 @@ export function calculateAllIndicatorSignals() {
label: label,
params: params || null,
type: indicator.type,
signal: signal.type,
strength: Math.round(signal.strength),
value: signal.value,
reasoning: signal.reasoning,
color: SIGNAL_COLORS[signal.type]
signal: currentSignal.type,
strength: Math.round(currentSignal.strength),
value: currentSignal.value,
reasoning: currentSignal.reasoning,
color: SIGNAL_COLORS[currentSignal.type],
lastSignalDate: lastSignalDate
});
}