Published
Edited
May 14, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data_raw = FileAttachment("ETH-USD.csv").csv({ typed: true })
Insert cell
Insert cell
Insert cell
Inputs.table(data_raw)
Insert cell
Insert cell
Insert cell
// To use copied code replace "data" with your own variable
data_renamed = aq
.from(data_raw)
.rename({ Date: "date" })
.rename({ Open: "open" })
.rename({ High: "high" })
.rename({ Low: "low" })
.rename({ Close: "close" })
.rename({ "Adj Close": "adjustedClose" })
.rename({ Volume: "volume" })
.objects()
Insert cell
Insert cell
Insert cell
Insert cell
// ... For this, you will need to filter the dataset using the Wrangler.
// ... the filter command should specity `d["date"].getFullYear() > 2021`
// ... (.getFullYear gets the year as a number)
// ... Because the statement is not simple, it will need to be wrapped in aq.escape()

Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [Plot.barY(data_filtered, { x: "date", y: "close" }), Plot.ruleY([0])]
})
Insert cell
Insert cell
Plot.plot({
width: 1200,
marks: [
Plot.barY(data_filtered, { x: "date", y1: "open", y2: "close" }),
Plot.ruleX(data_filtered, { x: "date", y1: "high", y2: "low" })
]
})
Insert cell
Insert cell
Insert cell
Insert cell
// To use copied code replace "data" with your own variable
data_colored = aq
.from(data_filtered)
.derive({ color: (d) => (d.close < d.open ? "crimson" : "oliveDrab") })
.objects() // Uncomment to return an array of objects
Insert cell
// ... if close < open, then the color should be 'crimson', otherwise 'oliveDrab'
// ... you will need to use Wrangler's derive method for this.
Insert cell
Insert cell
Plot.plot({
width: 1200,
marks: [
Plot.barY(data_colored, {
x: "date",
y1: "open",
y2: "close",
fill: "color"
}),
Plot.ruleX(data_colored, {
x: "date",
y1: "high",
y2: "low",
stroke: "color"
})
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
width: 1200,
marks: [
Plot.ruleX(data_colored, {
x: "date",
y1: "open",
y2: "close",
stroke: "color",
strokeWidth: 8
}),
Plot.ruleX(data_colored, {
x: "date",
y1: "high",
y2: "low",
stroke: "color"
})
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// ...
Insert cell
range
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
width: 1200,
marks: [
Plot.ruleX(data_parameterized, {
x: "date",
y1: "open",
y2: "close",
stroke: "color",
strokeWidth: 8
}),
Plot.ruleX(data_parameterized, {
x: "date",
y1: "high",
y2: "low",
stroke: "color"
})
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
width: 1200,
marks: [
Plot.ruleX(data_parameterized, {
x: "date",
y1: "open",
y2: "close",
stroke: "color",
strokeWidth: 8,
strokeWidth: (d) =>
(1200 - 300) /
data_parameterized.filter((d) => d["date"].getFullYear() === range)
.length
}),
Plot.ruleX(data_parameterized, {
x: "date",
y1: "high",
y2: "low",
stroke: "color"
})
]
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import {Plot} from "@mkfreeman/plot-tooltip"
Insert cell
Insert cell
Insert cell
// ...
Insert cell
// Please uncomment
//
// makeCandleStickChartTitle = (d) => `${ d.date.toLocaleString('default', { month: 'long' }) } ${d.date.getDate()}
// Close: ${ d3.format('.3s')(d.close) }
// High: ${ d3.format('.3s')(d.high) }
// Open: ${ d3.format('.3s')(d.open) }
// Low: ${ d3.format('.3s')(d.low) }
// `
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
fc = require("d3fc")
Insert cell
Insert cell
Insert cell
Insert cell
emaColumn = fc
.indicatorExponentialMovingAverage()
.period(emaPeriode)
.value((d) => d.close)(data_parameterized)
Insert cell
Insert cell
Insert cell
Insert cell
bollingerColumn = fc
.indicatorBollingerBands()
.period(7)
.multiplier(2)
.value((d) => d.close)(data_parameterized)
Insert cell
Insert cell
Insert cell
Insert cell
macdColumn = fc
.indicatorMacd()
.signalPeriod(9)
.fastPeriod(12)
.slowPeriod(26)
.value((d) => d.close)(data_parameterized)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data_withIndicators = data_parameterized.map((d, i) => ({
ema: emaColumn[i],
macd: macdColumn[i].macd,
macdSignal: macdColumn[i].signal,
macdDivergence: macdColumn[i].divergence,
bollingerUpper: bollingerColumn[i].upper,
bollingerAverage: bollingerColumn[i].average,
bollingerLower: bollingerColumn[i].lower,
...d
}))
Insert cell
Insert cell
Insert cell
<!-- Please uncomment when chart below is completed and put a '$' sign in front of {viewof ...} -->
<!-- {viewof control_year} -->
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// ... this should be an HTML cell. You can find the embed code at the Alternative.me's Fear and Greed index website
Insert cell
Insert cell
Insert cell
// ... d3.json can be used for this
Insert cell
Insert cell
Insert cell
// ... You can use Wrangler to generate the code
Insert cell
Insert cell
Insert cell
// ... Plot.line is for the main line, Plot.ruleY is for the dotted one
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// ...
Insert cell
Insert cell
Insert cell
// ...
Insert cell
Insert cell
Insert cell
Insert cell
// ...
Insert cell
// ...
Insert cell
// ...
Insert cell
// ...
Insert cell
// ...
Insert cell
// ...
Insert cell
<!-- Once all sliders are set, please add a $ sign before {viewof ...} statements to enable this code-->

<style>
.controlPanel form{
display:inline-block;
vertical-align:top;
padding: 10px;
max-width:190px;
}
</style>
<div class="controlPanel">
<br/>
{viewof control_bollingerPeriod} {viewof control_bollingerSD}
<br/>
{viewof control_emaPeriod}
<br/>
{viewof control_macdSignalPeriod}, {viewof control_macdFastPeriod}, {viewof control_macdSlowPeriod}
<br/>
{viewof control_year}
</div>
Insert cell
Insert cell
Insert cell
// ...
Insert cell
// ...
Insert cell
// ...
Insert cell
Insert cell
Insert cell
import {toc} from "@nebrius/indented-toc"
Insert cell
import {Wrangler, op} from "@observablehq/data-wrangler"
Insert cell
Insert cell
Insert cell
import {imageToDo} from "@clokman/student-blocks"
Insert cell
imageToDo
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more