Implement Strategy tab with Ping-Pong backtesting and crossover-based signal logic

- Add 'Strategy' tab to sidebar for backtesting simulations
- Create strategy-panel.js for Ping-Pong and Accumulation mode simulations
- Refactor all indicators (MA, HTS, RSI, MACD, BB, STOCH, Hurst) to use strict crossover-based signal calculation
- Update chart.js with setSimulationMarkers and clearSimulationMarkers support
- Implement single-entry rule in Ping-Pong simulation mode
This commit is contained in:
DiTus
2026-03-03 13:15:29 +01:00
parent 73f325ce19
commit d92af6903d
13 changed files with 626 additions and 104 deletions

View File

@ -32,33 +32,38 @@ class BaseIndicator {
}
// Signal calculation for Stochastic
function calculateStochSignal(indicator, lastCandle, prevCandle, values) {
function calculateStochSignal(indicator, lastCandle, prevCandle, values, prevValues) {
const k = values?.k;
const d = values?.d;
const prevK = prevValues?.k;
const prevD = prevValues?.d;
const overbought = indicator.params?.overbought || 80;
const oversold = indicator.params?.oversold || 20;
if (!k || !d) {
if (k === undefined || d === undefined || prevK === undefined || prevD === undefined) {
return null;
}
if (k < oversold && d < oversold) {
// BUY: %K crosses UP through %D while both are oversold
if (prevK <= prevD && k > d && k < oversold) {
return {
type: SIGNAL_TYPES.BUY,
strength: Math.min(50 + (oversold - k) * 2, 100),
strength: 80,
value: k,
reasoning: `Stochastic %K (${k.toFixed(2)}) and %D (${d.toFixed(2)}) oversold (<${oversold})`
reasoning: `Stochastic %K crossed UP through %D in oversold zone`
};
} else if (k > overbought && d > overbought) {
}
// SELL: %K crosses DOWN through %D while both are overbought
else if (prevK >= prevD && k < d && k > overbought) {
return {
type: SIGNAL_TYPES.SELL,
strength: Math.min(50 + (k - overbought) * 2, 100),
strength: 80,
value: k,
reasoning: `Stochastic %K (${k.toFixed(2)}) and %D (${d.toFixed(2)}) overbought (>${overbought})`
reasoning: `Stochastic %K crossed DOWN through %D in overbought zone`
};
} else {
return null;
}
return null;
}
// Stochastic Oscillator Indicator class