ChangeMomentumOscillatorIndicator::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 11
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 2
crap 12
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