Refactor dashboard JS to ES modules; fix collector strategy loading and add auto-backfill
- Split inline JS into separate ES module files (indicators/, strategies/, ui/, utils/) - Fix brain.py strategy registry to use MAStrategy directly instead of missing modules - Add auto-backfill for detected data gaps in collector monitoring loop - Fix chart resize on sidebar toggle - Fix chart scrollToTime -> setVisibleLogicalRange
This commit is contained in:
36
src/api/dashboard/static/js/indicators/atr.js
Normal file
36
src/api/dashboard/static/js/indicators/atr.js
Normal file
@ -0,0 +1,36 @@
|
||||
import { BaseIndicator } from './base.js';
|
||||
|
||||
export class ATRIndicator extends BaseIndicator {
|
||||
calculate(candles) {
|
||||
const period = this.params.period || 14;
|
||||
const results = new Array(candles.length).fill(null);
|
||||
const tr = new Array(candles.length).fill(0);
|
||||
|
||||
for (let i = 1; i < candles.length; i++) {
|
||||
const h_l = candles[i].high - candles[i].low;
|
||||
const h_pc = Math.abs(candles[i].high - candles[i-1].close);
|
||||
const l_pc = Math.abs(candles[i].low - candles[i-1].close);
|
||||
tr[i] = Math.max(h_l, h_pc, l_pc);
|
||||
}
|
||||
|
||||
let atr = 0;
|
||||
let sum = 0;
|
||||
for (let i = 1; i <= period; i++) sum += tr[i];
|
||||
atr = sum / period;
|
||||
results[period] = atr;
|
||||
|
||||
for (let i = period + 1; i < candles.length; i++) {
|
||||
atr = (atr * (period - 1) + tr[i]) / period;
|
||||
results[i] = atr;
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
getMetadata() {
|
||||
return {
|
||||
name: 'ATR',
|
||||
inputs: [{ name: 'period', label: 'Period', type: 'number', default: 14, min: 1, max: 100 }],
|
||||
plots: [{ id: 'value', color: '#795548', title: 'ATR' }]
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user