ChangeMomentumOscillatorIndicator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 32
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0

1 Method

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