Published
Edited
May 13, 2022
1 fork
1 star
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() // Uncomment to return an array of objects
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
// To use copied code replace "data" with your own variable
data_filtered = aq
.from(data_renamed)
.filter(aq.escape((d) => d["date"].getFullYear() === 2022))
.objects()
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [Plot.barY(data_filtered, { x: "date", y: "close" }), Plot.ruleY([0])]
})
Insert cell
Insert cell
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
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
range
Insert cell
// To use copied code replace "data" with your own variable
data_parameterized = aq
.from(data_renamed)
.derive({ color: (d) => (d.close < d.open ? "crimson" : "oliveDrab") })
.filter(aq.escape((d) => d["date"].getFullYear() === range))
.objects()
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
viewof range = Inputs.range([2017, 2022], { label: "Year", step: 1 })
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { Plot } from "@mkfreeman/plot-tooltip"
Insert cell
Insert cell
Insert cell
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(emaPeriod)
.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
//Please uncomment to merge the indicators with the data after they are calculated
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
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