Completed
Pull Request — master (#2)
by Evgenii
01:19
created

ChangeMomentumOscillatorIndicator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 32
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 21 4
1
<?php
2
3
namespace Laratrade\Indicators;
4
5
use Illuminate\Support\Collection;
6
use Laratrade\Indicators\Contracts\Indicator;
7
use Laratrade\Indicators\Exceptions\NotEnoughDataPointsException;
8
9
class ChangeMomentumOscillatorIndicator implements Indicator
10
{
11
    /**
12
     * Invoke the indicator.
13
     *
14
     * @param Collection $ohlcv
15
     * @param int        $period
16
     *
17
     * @return int
18
     */
19
    public function __invoke(Collection $ohlcv, int $period = 14): int
20
    {
21
        $cmo = trader_cmo(
22
            $ohlcv->get('close'),
23
            $period
24
        );
25
26
        if (false === $cmo) {
27
            throw new NotEnoughDataPointsException;
28
        }
29
30
        $cmoValue = array_pop($cmo);
31
32
        if ($cmoValue < -50) {
33
            return static::BUY;
34
        } elseif ($cmoValue > 50) {
35
            return static::SELL;
36
        }
37
38
        return static::HOLD;
39
    }
40
}
41