double short SMAs auto TF
This commit is contained in:
@ -75,27 +75,72 @@ function createIndicatorManager(chart, baseCandleDataRef, displayedCandleDataRef
|
||||
if (!definition) return;
|
||||
|
||||
slot.definition = definition;
|
||||
|
||||
// Special case for HTS: hide avgType/fast controls, show only Auto TF checkbox
|
||||
if (indicatorName === 'HTS') {
|
||||
const label = document.createElement('label');
|
||||
label.textContent = 'Auto TF';
|
||||
label.style.fontSize = '12px';
|
||||
const checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.className = 'input-field';
|
||||
// initialize params
|
||||
// default HTS params
|
||||
slot.params.autoTF = false;
|
||||
slot.params.avgType = definition.params.find(p => p.name === 'avgType').defaultValue;
|
||||
slot.params.fast = definition.params.find(p => p.name === 'fast').defaultValue;
|
||||
checkbox.addEventListener('change', () => {
|
||||
slot.params.autoTF = checkbox.checked;
|
||||
updateIndicator(slot.id, true);
|
||||
});
|
||||
const controlGroup = document.createElement('div');
|
||||
controlGroup.style.display = 'flex';
|
||||
controlGroup.style.flexDirection = 'column';
|
||||
controlGroup.appendChild(label);
|
||||
controlGroup.appendChild(checkbox);
|
||||
controlsContainer.appendChild(controlGroup);
|
||||
// initial draw
|
||||
updateIndicator(slot.id, true);
|
||||
return;
|
||||
}
|
||||
// Default controls for other indicators
|
||||
definition.params.forEach(param => {
|
||||
const label = document.createElement('label');
|
||||
label.textContent = param.label || param.name;
|
||||
label.style.fontSize = '12px';
|
||||
|
||||
const input = document.createElement('input');
|
||||
input.type = param.type;
|
||||
input.value = param.defaultValue;
|
||||
if (param.min !== undefined) input.min = param.min;
|
||||
if (param.step !== undefined) input.step = param.step;
|
||||
input.className = 'input-field';
|
||||
slot.params[param.name] = input.type === 'number' ? parseFloat(input.value) : input.value;
|
||||
// Create select for dropdowns, input for numbers
|
||||
let input;
|
||||
if (param.type === 'select') {
|
||||
input = document.createElement('select');
|
||||
input.className = 'input-field';
|
||||
// populate options
|
||||
param.options.forEach(opt => {
|
||||
const option = document.createElement('option');
|
||||
option.value = opt;
|
||||
option.textContent = opt;
|
||||
if (opt === param.defaultValue) option.selected = true;
|
||||
input.appendChild(option);
|
||||
});
|
||||
slot.params[param.name] = input.value;
|
||||
} else {
|
||||
input = document.createElement('input');
|
||||
input.type = param.type;
|
||||
input.value = param.defaultValue;
|
||||
if (param.min !== undefined) input.min = param.min;
|
||||
if (param.step !== undefined) input.step = param.step;
|
||||
input.className = 'input-field';
|
||||
slot.params[param.name] = parseFloat(input.value);
|
||||
}
|
||||
|
||||
input.addEventListener('input', () => {
|
||||
// --- FIX: --- Use the slot's `debounceTimerId` property to manage the timeout.
|
||||
// debounce param changes
|
||||
clearTimeout(slot.debounceTimerId);
|
||||
slot.debounceTimerId = setTimeout(() => {
|
||||
slot.params[param.name] = input.type === 'number' ? parseFloat(input.value) : input.value;
|
||||
// update param value
|
||||
const val = input.value;
|
||||
slot.params[param.name] = (param.type === 'number') ? parseFloat(val) : val;
|
||||
updateIndicator(slot.id, true);
|
||||
slot.debounceTimerId = null; // Clear the ID after the function has run.
|
||||
slot.debounceTimerId = null;
|
||||
}, 500);
|
||||
});
|
||||
const controlGroup = document.createElement('div');
|
||||
@ -113,7 +158,13 @@ function createIndicatorManager(chart, baseCandleDataRef, displayedCandleDataRef
|
||||
const slot = indicatorSlots.find(s => s.id === slotId);
|
||||
if (!slot || !slot.definition) return;
|
||||
|
||||
const candleDataForCalc = (slot.definition.usesBaseData) ? baseCandleDataRef : displayedCandleDataRef;
|
||||
// for HTS autoTF, always use base data for aggregation; else follow definition flag
|
||||
let candleDataForCalc;
|
||||
if (slot.definition.name === 'HTS' && slot.params.autoTF) {
|
||||
candleDataForCalc = baseCandleDataRef;
|
||||
} else {
|
||||
candleDataForCalc = (slot.definition.usesBaseData) ? baseCandleDataRef : displayedCandleDataRef;
|
||||
}
|
||||
if (candleDataForCalc.length === 0) return;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user