niver code

This commit is contained in:
olli 2024-07-15 17:10:48 +02:00
parent 2bdc7d3ab2
commit e06b575e46

View File

@ -2,8 +2,6 @@ const urlParams = new URLSearchParams(window.location.search);
const symbol = urlParams.get('symbol');
const time = urlParams.get('time');
//window.dispatchEvent(new Event('resize'));
function timeToLocal(originalTime) {
const d = new Date(originalTime * 1000);
return Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds()) / 1000;
@ -41,6 +39,22 @@ function timeToLocal(originalTime) {
return result;
}
function getCrosshairDataPoint(series, param) {
if (!param.time) {
return null;
}
const dataPoint = param.seriesData.get(series);
return dataPoint || null;
}
function syncCrosshair(chart, series, dataPoint) {
if (dataPoint) {
chart.setCrosshairPosition(dataPoint.value, dataPoint.time, series);
return;
}
chart.clearCrosshairPosition();
}
// Create the Lightweight Chart within the container element
const chart = LightweightCharts.createChart(document.getElementById('container'),
{
@ -50,13 +64,16 @@ function timeToLocal(originalTime) {
},
height: 500,
crosshair: {
mode: 0,
},
timeScale: {
timeVisible: true,
secondsVisible: false,
},
layout: {
background: {
type: 'solid',
@ -64,10 +81,12 @@ function timeToLocal(originalTime) {
},
textColor: '#DDD',
},
grid: {
vertLines: { color: '#444' },
horzLines: { color: '#444' },
},
});
chart.applyOptions({
@ -78,8 +97,8 @@ function timeToLocal(originalTime) {
vertAlign: 'left',
color: '#DDD',
text: symbol + " " + time,
}});
}
});
// define chart
const candleSeries = chart.addCandlestickSeries();
@ -100,9 +119,11 @@ function timeToLocal(originalTime) {
borderVisible: false
},
height: 200,
timeScale: {
visible: false,
},
layout: {
background: {
type: 'solid',
@ -110,6 +131,7 @@ function timeToLocal(originalTime) {
},
textColor: '#DDD',
},
grid: {
vertLines: { color: '#444' },
horzLines: { color: '#444' },
@ -124,7 +146,8 @@ function timeToLocal(originalTime) {
vertAlign: 'left',
color: '#DDD',
text: 'RSI 5,14,21',
}});
}
});
const lineSeriesRSI5 = chartrsi.addLineSeries({ color: 'orange', lineWidth: 1, lineStyle: 2, priceLineVisible: false});
const lineSeriesRSI14 = chartrsi.addLineSeries({ color: 'yellow', lineWidth: 2, priceLineVisible: false});
@ -139,10 +162,12 @@ function timeToLocal(originalTime) {
},
height: 200,
timeScale: {
timeVisible: true,
secondsVisible: false,
},
layout: {
background: {
type: 'solid',
@ -150,6 +175,7 @@ function timeToLocal(originalTime) {
},
textColor: '#DDD',
},
grid: {
vertLines: { color: '#444' },
horzLines: { color: '#444' },
@ -164,7 +190,8 @@ function timeToLocal(originalTime) {
vertAlign: 'left',
color: '#DDD',
text: 'MACD 12 26',
}});
}
});
const lineSeriesMACD = chartmacd.addLineSeries({ color: 'blue', lineWidth: 1, lineStyle: 0, priceLineVisible: false});
const lineSeriesMACDSignal = chartmacd.addLineSeries({ color: 'orange', lineWidth: 1, lineStyle: 0, priceLineVisible: false});
@ -173,11 +200,9 @@ function timeToLocal(originalTime) {
type: 'volume',
color: 'orange',
},
//priceScaleId: '', // set as an overlay by setting a blank priceScaleId
});
fetch("/botdata/asset-histories/" + symbol + ".history." + time + ".csv")
.then(response => response.text())
.then(data => {
@ -304,22 +329,6 @@ function timeToLocal(originalTime) {
chart.timeScale().setVisibleLogicalRange(timeRange);
});
function getCrosshairDataPoint(series, param) {
if (!param.time) {
return null;
}
const dataPoint = param.seriesData.get(series);
return dataPoint || null;
}
function syncCrosshair(chart, series, dataPoint) {
if (dataPoint) {
chart.setCrosshairPosition(dataPoint.value, dataPoint.time, series);
return;
}
chart.clearCrosshairPosition();
}
chart.subscribeCrosshairMove(param => {
const dataPoint = getCrosshairDataPoint(lineSeriesEMA50, param);
syncCrosshair(chartrsi, lineSeriesRSI14, dataPoint);
@ -331,7 +340,6 @@ chartrsi.subscribeCrosshairMove(param => {
syncCrosshair(chart, lineSeriesEMA50, dataPoint);
const dataPointmacd = getCrosshairDataPoint(lineSeriesRSI14, param);
syncCrosshair(chartmacd, lineSeriesMACD, dataPointmacd);
});
chartmacd.subscribeCrosshairMove(param => {
const dataPoint = getCrosshairDataPoint(lineSeriesMACD, param);
@ -339,4 +347,3 @@ chartmacd.subscribeCrosshairMove(param => {
const dataPointrsi = getCrosshairDataPoint(lineSeriesMACD, param);
syncCrosshair(chartrsi, lineSeriesRSI14, dataPointrsi);
});