single hurst band works OK

This commit is contained in:
2025-07-14 22:34:49 +02:00
parent 0c3c9ecd81
commit 80e3875abe
4 changed files with 63 additions and 88 deletions

View File

@ -1,11 +1,11 @@
/**
* Creates and manages all indicator-related logic for the chart.
* @param {Object} chart - The Lightweight Charts instance.
* @param {Array<Object>} baseCandleData - A reference to the array holding the chart's BASE 1m candle data.
* @param {Array<Object>} displayedCandleData - A reference to the array with currently visible candles.
* @param {Array<Object>} baseCandleDataRef - A reference to the array holding the chart's BASE 1m candle data.
* @param {Array<Object>} displayedCandleDataRef - A reference to the array with currently visible candles.
* @returns {Object} A manager object with public methods to control indicators.
*/
function createIndicatorManager(chart, baseCandleData, displayedCandleData) {
function createIndicatorManager(chart, baseCandleDataRef, displayedCandleDataRef) {
const indicatorSlots = [
{ id: 1, cellId: 'indicator-cell-1', series: [], definition: null, params: {} },
{ id: 2, cellId: 'indicator-cell-2', series: [], definition: null, params: {} },
@ -96,9 +96,11 @@ function createIndicatorManager(chart, baseCandleData, displayedCandleData) {
function updateIndicator(slotId) {
const slot = indicatorSlots.find(s => s.id === slotId);
const candleDataForCalc = (slot.definition.usesBaseData) ? baseCandleData : displayedCandleData;
const candleDataForCalc = (slot.definition.usesBaseData) ? baseCandleDataRef : displayedCandleDataRef;
if (!slot || !slot.definition || candleDataForCalc.length === 0) return;
if (!slot || !slot.definition || candleDataForCalc.length === 0) {
return;
}
slot.series.forEach(s => chart.removeSeries(s));
slot.series = [];
@ -131,21 +133,16 @@ function createIndicatorManager(chart, baseCandleData, displayedCandleData) {
}
}
function recalculateAllAfterHistory(newDisplayedCandleData) {
displayedCandleData = newDisplayedCandleData;
function recalculateAllAfterHistory(baseData, displayedData) {
baseCandleDataRef = baseData;
displayedCandleDataRef = displayedData;
indicatorSlots.forEach(slot => {
if (slot.definition) updateIndicator(slot.id);
});
}
// This function is not currently used with the new model but is kept for potential future use.
function updateIndicatorsOnNewCandle(newCandle) {
// Real-time updates would go here.
}
return {
populateDropdowns,
recalculateAllAfterHistory,
updateIndicatorsOnNewCandle
};
}