Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 38cdffc2b9 |
2
app.py
2
app.py
@ -46,7 +46,7 @@ def stream_historical_data(sid):
|
||||
all_klines = client.get_historical_klines(
|
||||
SYMBOL,
|
||||
Client.KLINE_INTERVAL_1MINUTE,
|
||||
start_str="8 weeks ago UTC" # Fetches data starting from 8 weeks ago until now
|
||||
start_str="1 week ago UTC" # Fetches data starting from 8 weeks ago until now
|
||||
)
|
||||
|
||||
# --- ORIGINAL SOLUTION COMMENTED OUT ---
|
||||
|
||||
File diff suppressed because one or more lines are too long
60
static/hts.js
Normal file
60
static/hts.js
Normal file
@ -0,0 +1,60 @@
|
||||
/**
|
||||
* HTS (High-Tech SMAs) - Combined Fast and Slow SMA Indicator
|
||||
* This indicator displays both Fast SMA and Slow SMA on the same chart
|
||||
*/
|
||||
const HTS_INDICATOR = {
|
||||
name: 'HTS',
|
||||
label: 'HTS (Fast & Slow SMA)',
|
||||
usesBaseData: false, // This indicator uses the chart's currently displayed data
|
||||
params: [
|
||||
{ name: 'fastPeriod', type: 'number', defaultValue: 33, min: 2, label: 'Fast SMA Period' },
|
||||
{ name: 'slowPeriod', type: 'number', defaultValue: 133, min: 2, label: 'Slow SMA Period' },
|
||||
],
|
||||
calculateFull: calculateFullHTS,
|
||||
};
|
||||
|
||||
function calculateFullHTS(data, params) {
|
||||
const fastPeriod = params.fastPeriod;
|
||||
const slowPeriod = params.slowPeriod;
|
||||
|
||||
if (!data || data.length < Math.max(fastPeriod, slowPeriod)) {
|
||||
return {
|
||||
fastSMA: [],
|
||||
slowSMA: []
|
||||
};
|
||||
}
|
||||
|
||||
// Calculate Fast SMA
|
||||
const fastSMA = calculateSMA(data, fastPeriod);
|
||||
|
||||
// Calculate Slow SMA
|
||||
const slowSMA = calculateSMA(data, slowPeriod);
|
||||
|
||||
return {
|
||||
fastSMA: fastSMA,
|
||||
slowSMA: slowSMA
|
||||
};
|
||||
}
|
||||
|
||||
function calculateSMA(data, period) {
|
||||
if (!data || data.length < period) return [];
|
||||
|
||||
let smaData = [];
|
||||
let sum = 0;
|
||||
|
||||
// Calculate initial sum for the first period
|
||||
for (let i = 0; i < period; i++) {
|
||||
sum += data[i].close;
|
||||
}
|
||||
|
||||
// Add the first SMA point
|
||||
smaData.push({ time: data[period - 1].time, value: sum / period });
|
||||
|
||||
// Calculate remaining SMA points using sliding window
|
||||
for (let i = period; i < data.length; i++) {
|
||||
sum = sum - data[i - period].close + data[i].close;
|
||||
smaData.push({ time: data[i].time, value: sum / period });
|
||||
}
|
||||
|
||||
return smaData;
|
||||
}
|
||||
@ -24,6 +24,12 @@ function createIndicatorManager(chart, baseCandleDataRef, displayedCandleDataRef
|
||||
bb3_lower: 'rgba(6, 95, 6, 1.0)',
|
||||
},
|
||||
hurst: { topBand: '#787b86', bottomBand: '#787b86', topBand_h: '#673ab7', bottomBand_h: '#673ab7' },
|
||||
hts: {
|
||||
fastSMA: '#00bcd4', // Cyan blue for Fast SMA
|
||||
slowSMA: '#ff5252' // Red for Slow SMA
|
||||
},
|
||||
fast_sma: '#00bcd4',
|
||||
slow_sma: '#ff5252',
|
||||
default: ['#00BCD4', '#FFEB3B', '#4CAF50', '#E91E63']
|
||||
};
|
||||
|
||||
@ -138,8 +144,10 @@ function createIndicatorManager(chart, baseCandleDataRef, displayedCandleDataRef
|
||||
slot.series.push(series);
|
||||
});
|
||||
} else {
|
||||
const indicatorNameLower = slot.definition.name.toLowerCase();
|
||||
const indicatorColor = colors[indicatorNameLower] || slot.definition.color || colors.default[slot.id - 1];
|
||||
const series = chart.addLineSeries({
|
||||
color: colors.default[slot.id - 1],
|
||||
color: indicatorColor,
|
||||
lineWidth: 1,
|
||||
title: '',
|
||||
lastValueVisible: false,
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
* 3. Add the indicator's definition object (e.g., RSI_INDICATOR) to this array.
|
||||
*/
|
||||
const AVAILABLE_INDICATORS = [
|
||||
SMA_INDICATOR,
|
||||
HTS_INDICATOR,
|
||||
EMA_INDICATOR,
|
||||
BB_INDICATOR, // Added the new Bollinger Bands indicator
|
||||
HURST_INDICATOR // Added the new Hurst Bands indicator
|
||||
|
||||
@ -1,14 +1,29 @@
|
||||
/**
|
||||
* Indicator Definition Object for SMA.
|
||||
* Indicator Definition Object for Fast SMA.
|
||||
*/
|
||||
const SMA_INDICATOR = {
|
||||
name: 'SMA',
|
||||
label: 'Simple Moving Average',
|
||||
const FAST_SMA_INDICATOR = {
|
||||
name: 'FAST_SMA',
|
||||
label: 'Fast SMA',
|
||||
usesBaseData: false, // This simple indicator uses the chart's currently displayed data
|
||||
params: [
|
||||
{ name: 'period', type: 'number', defaultValue: 20, min: 2 },
|
||||
{ name: 'period', type: 'number', defaultValue: 33, min: 2 },
|
||||
],
|
||||
calculateFull: calculateFullSMA,
|
||||
color: '#00bcd4',
|
||||
};
|
||||
|
||||
/**
|
||||
* Indicator Definition Object for Slow SMA.
|
||||
*/
|
||||
const SLOW_SMA_INDICATOR = {
|
||||
name: 'SLOW_SMA',
|
||||
label: 'Slow SMA',
|
||||
usesBaseData: false, // This simple indicator uses the chart's currently displayed data
|
||||
params: [
|
||||
{ name: 'period', type: 'number', defaultValue: 133, min: 2 },
|
||||
],
|
||||
calculateFull: calculateFullSMA,
|
||||
color: '#ff5252',
|
||||
};
|
||||
|
||||
function calculateFullSMA(data, params) {
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
<!-- NOTE: These 'url_for' will not work in a static HTML file. -->
|
||||
<!-- They are placeholders for a Flask environment. For a standalone file, you would link directly to the JS files. -->
|
||||
<script src="{{ url_for('static', filename='candle-aggregator.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='sma.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='hts.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='ema.js') }}"></script>
|
||||
<script src="{{ url_for('static',filename='bb.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='hurst.js') }}"></script>
|
||||
|
||||
Reference in New Issue
Block a user