Files
winterfail/js/indicators/index.js

69 lines
2.5 KiB
JavaScript

// Indicator registry and exports for self-contained indicators
// Import all indicator classes and their signal functions
export { MAIndicator, calculateMASignal } from './moving_average.js';
export { MACDIndicator, calculateMACDSignal } from './macd.js';
export { HTSIndicator, calculateHTSSignal } from './hts.js';
export { RSIIndicator, calculateRSISignal } from './rsi.js';
export { BollingerBandsIndicator, calculateBollingerBandsSignal } from './bb.js';
export { StochasticIndicator, calculateStochSignal } from './stoch.js';
export { ATRIndicator, calculateATRSignal } from './atr.js';
export { HurstBandsIndicator, calculateHurstSignal } from './hurst.js';
// Import for registry
import { MAIndicator as MAI, calculateMASignal as CMA } from './moving_average.js';
import { MACDIndicator as MACDI, calculateMACDSignal as CMC } from './macd.js';
import { HTSIndicator as HTSI, calculateHTSSignal as CHTS } from './hts.js';
import { RSIIndicator as RSII, calculateRSISignal as CRSI } from './rsi.js';
import { BollingerBandsIndicator as BBI, calculateBollingerBandsSignal as CBB } from './bb.js';
import { StochasticIndicator as STOCHI, calculateStochSignal as CST } from './stoch.js';
import { ATRIndicator as ATRI, calculateATRSignal as CATR } from './atr.js';
import { HurstBandsIndicator as HURSTI, calculateHurstSignal as CHURST } from './hurst.js';
// Signal function registry for easy dispatch
export const SignalFunctionRegistry = {
ma: CMA,
macd: CMC,
hts: CHTS,
rsi: CRSI,
bb: CBB,
stoch: CST,
atr: CATR,
hurst: CHURST
};
// Indicator registry for UI
export const IndicatorRegistry = {
ma: MAI,
macd: MACDI,
hts: HTSI,
rsi: RSII,
bb: BBI,
stoch: STOCHI,
atr: ATRI,
hurst: HURSTI
};
/**
* Get list of available indicators for the UI catalog
*/
export function getAvailableIndicators() {
return Object.entries(IndicatorRegistry).map(([type, IndicatorClass]) => {
const instance = new IndicatorClass({ type, params: {}, name: '' });
const meta = instance.getMetadata();
return {
type,
name: meta.name || type.toUpperCase(),
description: meta.description || ''
};
});
}
/**
* Get signal function for an indicator type
* @param {string} indicatorType - The type of indicator (e.g., 'ma', 'rsi')
* @returns {Function|null} The signal calculation function or null if not found
*/
export function getSignalFunction(indicatorType) {
return SignalFunctionRegistry[indicatorType] || null;
}