From 262ed49b9b57d71ecc0b71ab9577c9b348478d14 Mon Sep 17 00:00:00 2001 From: Jens Scherbl Date: Thu, 20 Jul 2023 21:36:38 +0200 Subject: [PATCH] Adds close price to trend result --- README.md | 33 ++++++++++++++++++--------------- src/Chart/Chart.php | 30 ++++++++++++++++-------------- src/Trend.php | 1 + 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index a2772c9..42ea7c0 100644 --- a/README.md +++ b/README.md @@ -137,27 +137,30 @@ $EMAPeriod = 10; $result = $chart->getTrend($SMAPeriod, $EMAPeriod); // '2023-01-25' => [ -// 'SMA' => null, -// 'EMA' => null, -// 'DIp' => null, -// 'DIm' => null, -// 'ADX' => null, +// 'close' => '141.8600', +// 'SMA' => null, +// 'EMA' => null, +// 'DIp' => null, +// 'DIm' => null, +// 'ADX' => null, // ], // ... // '2023-02-07' => [ -// 'SMA' => null, -// 'EMA' => '148.8578', -// 'DIp' => '45.1810', -// 'DIm' => '1.8100', -// 'ADX' => null, +// 'close' => '154.6500', +// 'SMA' => null, +// 'EMA' => '148.8578', +// 'DIp' => '45.1810', +// 'DIm' => '1.8100', +// 'ADX' => null, // ], // ... // '2023-02-22' => [ -// 'SMA' => '149.8000', -// 'EMA' => '151.0938', -// 'DIp' => '28.7024', -// 'DIm' => '18.6931', -// 'ADX' => '67.8187', +// 'close' => '148.9100', +// 'SMA' => '149.8000', +// 'EMA' => '151.0938', +// 'DIp' => '28.7024', +// 'DIm' => '18.6931', +// 'ADX' => '67.8187', // ], // ... ``` diff --git a/src/Chart/Chart.php b/src/Chart/Chart.php index de6300a..d14fd3c 100644 --- a/src/Chart/Chart.php +++ b/src/Chart/Chart.php @@ -122,20 +122,21 @@ public function getTrend(int $SMAPeriod, int $EMAPeriod): array $result = []; foreach ($this->candles as $date => $candle) { - $close = $candle->close; - $SMAResult = $SMA->calculate($close); - $SMARounded = $this->round($SMAResult); - $EMAResult = $EMA->calculate($close); - $EMARounded = $this->round($EMAResult); - $DMp = $candle->DMp; - $DMm = $candle->DMm; - $TR = $candle->TR; - $DIResult = $DI->calculate($DMp, $DMm, $TR); - $DIpResult = $DIResult->DIp; - $DIpRounded = $this->round($DIpResult); - $DImResult = $DIResult->DIm; - $DImRounded = $this->round($DImResult); - $ADXRounded = null; + $close = $candle->close; + $closeRounded = $this->round($close); + $SMAResult = $SMA->calculate($close); + $SMARounded = $this->round($SMAResult); + $EMAResult = $EMA->calculate($close); + $EMARounded = $this->round($EMAResult); + $DMp = $candle->DMp; + $DMm = $candle->DMm; + $TR = $candle->TR; + $DIResult = $DI->calculate($DMp, $DMm, $TR); + $DIpResult = $DIResult->DIp; + $DIpRounded = $this->round($DIpResult); + $DImResult = $DIResult->DIm; + $DImRounded = $this->round($DImResult); + $ADXRounded = null; if ($DIpResult !== null && $DImResult !== null) { $ADXResult = $ADX->calculate($DIpResult, $DImResult); @@ -143,6 +144,7 @@ public function getTrend(int $SMAPeriod, int $EMAPeriod): array } $result[$date] = new Trend( + $closeRounded, $SMARounded, $EMARounded, $DIpRounded, diff --git a/src/Trend.php b/src/Trend.php index 373eb22..756e8a6 100644 --- a/src/Trend.php +++ b/src/Trend.php @@ -8,6 +8,7 @@ final readonly class Trend { public function __construct( + public string|null $close, public string|null $SMA, public string|null $EMA, public string|null $DIp,