Skip to content

Commit

Permalink
Adds close price to trend result
Browse files Browse the repository at this point in the history
  • Loading branch information
jensscherbl committed Jul 20, 2023
1 parent 99bcb42 commit 262ed49
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 29 deletions.
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
// ],
// ...
```
Expand Down
30 changes: 16 additions & 14 deletions src/Chart/Chart.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,29 @@ 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);
$ADXRounded = $this->round($ADXResult);
}

$result[$date] = new Trend(
$closeRounded,
$SMARounded,
$EMARounded,
$DIpRounded,
Expand Down
1 change: 1 addition & 0 deletions src/Trend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 262ed49

Please sign in to comment.