I tried to create a bar chart showing me the duration of trades, of which the entryTime and exitTime is stored in a YAML header in each note representing a single trade.
This here works so far:
const pages = dv.pages('"00_Trades"')
.where(p => p.date == 230323 )
.sort(p => p.date, "asc");
const tradeDurations = pages.map(p => {
const entryTime = p.entryTime.split(':');
const exitTime = p.exitTime.split(':');
const entryTimestamp = new Date(0, 0, 0, entryTime[0], entryTime[1]);
const exitTimestamp = new Date(0, 0, 0, exitTime[0], exitTime[1]);
const duration = exitTimestamp.getTime() - entryTimestamp.getTime();
return Math.round(duration / 60000);
}).values;
const tradeTickers = pages.map(p => p.ticker).values;
const chartData = {
type: 'bar',
data: {
labels: tradeTickers,
datasets:[{
label: 'Duration',
data: tradeDurations,
backgroundColor: [
'rgba(255, 99, 132, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)'
],
borderWidth: 1,
}]
},
options:{
scales: {
y: {
ticks: {
callback: function(value, index, values) {
return `${value} min`;
}
}
}
},
events: ['click'],
animation: false,
},
};
window.renderChart(chartData, this.container)
Now when I extend the day range to multiple days I get an error.
const startDate = 230320;
const endDate = 230323;
const pages = dv.pages('"00_Trades"')
.where(p => p.date >= startDate && p.date <= endDate)
.sort(p => p.date, "asc");
//...
“p.entryTime.split is not a function”
Does anyone have an idea, why?