added RSI crossover signals: BUY when crosses up oversold, SELL when crosses down overbought

This commit is contained in:
DiTus
2026-03-02 09:03:18 +01:00
parent 767c0bef67
commit a84a1c9091
2 changed files with 40 additions and 11 deletions

View File

@ -32,8 +32,9 @@ class BaseIndicator {
}
// Signal calculation for RSI
function calculateRSISignal(indicator, lastCandle, prevCandle, values) {
function calculateRSISignal(indicator, lastCandle, prevCandle, values, prevValues) {
const rsi = values?.rsi;
const prevRsi = prevValues?.rsi;
const overbought = indicator.params?.overbought || 70;
const oversold = indicator.params?.oversold || 30;
@ -43,13 +44,30 @@ function calculateRSISignal(indicator, lastCandle, prevCandle, values) {
let signalType, strength, reasoning;
if (rsi < oversold) {
// BUY when RSI crosses UP through oversold band (bottom band)
// RSI was below oversold, now above oversold
if (prevRsi !== undefined && prevRsi !== null && prevRsi < oversold && rsi >= oversold) {
signalType = SIGNAL_TYPES.BUY;
strength = Math.min(50 + (oversold - rsi) * 2, 100);
reasoning = `RSI (${rsi.toFixed(2)}) is oversold (<${oversold})`;
} else if (rsi > overbought) {
strength = Math.min(50 + (rsi - oversold) * 2, 100);
reasoning = `RSI (${rsi.toFixed(2)}) crossed up through oversold level (${oversold})`;
}
// SELL when RSI crosses DOWN through overbought band (top band)
// RSI was above overbought, now below overbought
else if (prevRsi !== undefined && prevRsi !== null && prevRsi > overbought && rsi <= overbought) {
signalType = SIGNAL_TYPES.SELL;
strength = Math.min(50 + (rsi - overbought) * 2, 100);
strength = Math.min(50 + (overbought - rsi) * 2, 100);
reasoning = `RSI (${rsi.toFixed(2)}) crossed down through overbought level (${overbought})`;
}
// When RSI is in oversold territory but no crossover - strong BUY
else if (rsi < oversold) {
signalType = SIGNAL_TYPES.BUY;
strength = Math.min(40 + (oversold - rsi) * 1.5, 80);
reasoning = `RSI (${rsi.toFixed(2)}) is oversold (<${oversold})`;
}
// When RSI is in overbought territory but no crossover - strong SELL
else if (rsi > overbought) {
signalType = SIGNAL_TYPES.SELL;
strength = Math.min(40 + (rsi - overbought) * 1.5, 80);
reasoning = `RSI (${rsi.toFixed(2)}) is overbought (>${overbought})`;
} else {
return null;