Skip to content

Commit

Permalink
better formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
micahkendall committed Sep 5, 2024
1 parent 0e5aa5c commit c2bbcf3
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions ema.typ
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,38 @@ This visual representation demonstrates how the Simple EMA (red line) closely fo


=== Pseudocode

#figure([
#set text(font: "New Computer Modern Mono")

*Input:* prices, period \
*Output:* ema

ema \<\- [prices[0]] \
multiplier \<\- 2 / (period + 1)

*for* price *in* prices[1:] \
#h(20pt)*if* price < ema[-1] \
#h(40pt)ema.append(price) \
#h(20pt)*else* \
#h(40pt)new_ema \<\- (price - ema[-1]) \* multiplier + ema[-1] \
#h(40pt)ema.append(new_ema) \
#h(20pt)*end if* \
*end for*

*return* ema
], caption: "Simple EMA Algorithm")
#figure(
align(left)[
#set text(font: "New Computer Modern Mono")
#set par(leading: 0.65em)
#let prices = [...price values]

#table(
columns: (auto, auto),
inset: 0pt,
stroke: none,
align: left + horizon,
[*Input:*], [prices, period],
[*Output:*], [ema],
)

#v(0.5em)
$"ema" arrow.l [prices[0]]$\
$"multiplier" arrow.l 2 / ("period" + 1)$\
#v(0.5em)
*for* $"price"$ *in* $"prices"[1:]$ *do*\
#h(1em) *if* $"price" < "ema"[-1]$ *then*\
#h(2em) $"ema"."append"("price")$\
#h(1em) *else*\
#h(2em) $"new_ema" arrow.l ("price" - "ema"[-1]) dot "multiplier" + "ema"[-1]$\
#h(2em) $"ema"."append"("new_ema")$\
#h(1em) *end if*\
*end for*
#v(0.5em)
*return* $"ema"$
],
caption: "Simple EMA Algorithm"
)

== Notes
1. The algorithm initializes the EMA with the first price in the series.
Expand Down

0 comments on commit c2bbcf3

Please sign in to comment.