single hurst band works OK
This commit is contained in:
@ -127,14 +127,11 @@
|
||||
|
||||
let baseCandleData1m = [];
|
||||
let displayedCandleData = [];
|
||||
let currentCandle1m = null;
|
||||
let manager;
|
||||
|
||||
const timeframeSelect = document.getElementById('timeframe-select');
|
||||
const candleTimerDiv = document.getElementById('candle-timer');
|
||||
const chartTitle = document.getElementById('chart-title');
|
||||
const analyzeButton = document.getElementById('analyzeButton');
|
||||
const analysisResultDiv = document.getElementById('analysisResult');
|
||||
const progressContainer = document.getElementById('progress-container');
|
||||
const progressBar = document.querySelector('.progress-bar');
|
||||
|
||||
@ -158,64 +155,50 @@
|
||||
low: parseFloat(k[3]), close: parseFloat(k[4])
|
||||
}));
|
||||
|
||||
updateChartForTimeframe();
|
||||
|
||||
updateChartForTimeframe(true); // Initial load, fit content
|
||||
setTimeout(() => { progressContainer.style.display = 'none'; }, 500);
|
||||
});
|
||||
|
||||
socket.on('trade', (trade) => {
|
||||
const price = parseFloat(trade.p);
|
||||
const tradeTime = Math.floor(trade.T / 1000);
|
||||
const candleTimestamp1m = tradeTime - (tradeTime % 60);
|
||||
socket.on('candle_update', (candle) => {
|
||||
candlestickSeries.update(candle);
|
||||
});
|
||||
|
||||
if (!currentCandle1m || candleTimestamp1m > currentCandle1m.time) {
|
||||
if (currentCandle1m) {
|
||||
baseCandleData1m.push(currentCandle1m);
|
||||
manager.updateIndicatorsOnNewCandle(currentCandle1m);
|
||||
}
|
||||
currentCandle1m = { time: candleTimestamp1m, open: price, high: price, low: price, close: price };
|
||||
socket.on('candle_closed', (closedCandle) => {
|
||||
const lastBaseCandle = baseCandleData1m.length > 0 ? baseCandleData1m[baseCandleData1m.length - 1] : null;
|
||||
if (lastBaseCandle && lastBaseCandle.time === closedCandle.time) {
|
||||
baseCandleData1m[baseCandleData1m.length - 1] = closedCandle;
|
||||
} else {
|
||||
currentCandle1m.high = Math.max(currentCandle1m.high, price);
|
||||
currentCandle1m.low = Math.min(currentCandle1m.low, price);
|
||||
currentCandle1m.close = price;
|
||||
baseCandleData1m.push(closedCandle);
|
||||
}
|
||||
|
||||
const selectedInterval = parseInt(timeframeSelect.value, 10) * 60;
|
||||
const displayedCandleTimestamp = tradeTime - (tradeTime % selectedInterval);
|
||||
const lastDisplayedCandle = displayedCandleData[displayedCandleData.length - 1];
|
||||
|
||||
let candleForUpdate;
|
||||
if (lastDisplayedCandle && displayedCandleTimestamp === lastDisplayedCandle.time) {
|
||||
candleForUpdate = { ...lastDisplayedCandle, high: Math.max(lastDisplayedCandle.high, price), low: Math.min(lastDisplayedCandle.low, price), close: price };
|
||||
displayedCandleData[displayedCandleData.length - 1] = candleForUpdate;
|
||||
} else {
|
||||
candleForUpdate = { time: displayedCandleTimestamp, open: price, high: price, low: price, close: price };
|
||||
displayedCandleData.push(candleForUpdate);
|
||||
}
|
||||
|
||||
if (candleForUpdate) candlestickSeries.update(candleForUpdate);
|
||||
updateChartForTimeframe(false); // Subsequent update, preserve zoom
|
||||
});
|
||||
|
||||
function updateChartForTimeframe() {
|
||||
function updateChartForTimeframe(isInitialLoad = false) {
|
||||
const selectedIntervalMinutes = parseInt(timeframeSelect.value, 10);
|
||||
if (baseCandleData1m.length === 0) return;
|
||||
|
||||
const visibleRange = isInitialLoad ? null : chart.timeScale().getVisibleLogicalRange();
|
||||
|
||||
const newCandleData = aggregateCandles(baseCandleData1m, selectedIntervalMinutes);
|
||||
|
||||
if (newCandleData.length > 0) {
|
||||
displayedCandleData = newCandleData;
|
||||
candlestickSeries.setData(displayedCandleData);
|
||||
chartTitle.textContent = `{{ symbol }} Chart (${selectedIntervalMinutes}m)`;
|
||||
manager.recalculateAllAfterHistory(displayedCandleData);
|
||||
chart.timeScale().fitContent();
|
||||
manager.recalculateAllAfterHistory(baseCandleData1m, displayedCandleData);
|
||||
|
||||
if (visibleRange) {
|
||||
chart.timeScale().setVisibleLogicalRange(visibleRange);
|
||||
} else {
|
||||
chart.timeScale().fitContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
timeframeSelect.addEventListener('change', updateChartForTimeframe);
|
||||
timeframeSelect.addEventListener('change', () => updateChartForTimeframe(true));
|
||||
|
||||
setInterval(() => {
|
||||
const selectedIntervalSeconds = parseInt(timeframeSelect.value, 10) * 60;
|
||||
// **FIX**: Corrected syntax
|
||||
const now = new Date().getTime() / 1000;
|
||||
const secondsRemaining = Math.floor(selectedIntervalSeconds - (now % selectedIntervalSeconds));
|
||||
const minutes = Math.floor(secondsRemaining / 60);
|
||||
|
||||
Reference in New Issue
Block a user