Code Duplication    Length = 25-28 lines in 3 locations

src/AverageDirectionalMovementIndexIndicator.php 1 location

@@ 27-53 (lines=27) @@
24
 *     50-75    Very Strong Trend
25
 *     75-100    Extremely Strong Trend
26
 */
27
class AverageDirectionalMovementIndexIndicator implements Indicator
28
{
29
30
    public function __invoke(Collection $ohlcv, int $period = 14): int
31
    {
32
        $adx = trader_adx(
33
            $ohlcv->get('high'),
34
            $ohlcv->get('low'),
35
            $ohlcv->get('close'),
36
            $period
37
        );
38
39
        if (false === $adx) {
40
            throw new NotEnoughDataPointsException('Not enough data points');
41
        }
42
43
        $adx = array_pop($adx); //[count($adx) - 1];
44
45
        if ($adx > 50) {
46
            return static::BUY; // overbought
47
        } elseif ($adx < 20) {
48
            return static::SELL;  // underbought
49
        } else {
50
            return static::HOLD;
51
        }
52
    }
53
}
54

src/CommodityChannelIndexIndicator.php 1 location

@@ 18-42 (lines=25) @@
15
 * determine when an investment vehicle is reaching a condition of being overbought or oversold.
16
 *
17
 */
18
class CommodityChannelIndexIndicator implements Indicator
19
{
20
21
    public function __invoke(Collection $ohlcv, int $period = 14): int
22
    {
23
24
        # array $high , array $low , array $close [, integer $timePeriod ]
25
        $cci = trader_cci($ohlcv->get('high'), $ohlcv->get('low'), $ohlcv->get('close'), $period);
26
27
        if (false === $cci) {
28
            throw new NotEnoughDataPointsException('Not enough data points');
29
        }
30
31
        $cci = array_pop($cci); #[count($cci) - 1];
32
33
        if ($cci > 100) {
34
            return static::SELL; // overbought
35
        } elseif ($cci < -100) {
36
            return static::BUY;  // underbought
37
        } else {
38
            return static::HOLD;
39
        }
40
    }
41
}
42

src/MoneyFlowIndexIndicator.php 1 location

@@ 22-49 (lines=28) @@
19
 * volume to the relative strength index (RSI), it's sometimes referred to as volume-weighted RSI.
20
 *
21
 */
22
class MoneyFlowIndexIndicator implements Indicator
23
{
24
    public function __invoke(Collection $ohlcv, int $period = 14): int
25
    {
26
        $mfi = trader_mfi(
27
            $ohlcv->get('high'),
28
            $ohlcv->get('low'),
29
            $ohlcv->get('close'),
30
            $ohlcv->get('volume'),
31
            $period
32
        );
33
34
        if (false === $mfi) {
35
            throw new NotEnoughDataPointsException('Not enough data points');
36
        }
37
38
        $mfiValue = array_pop($mfi);
39
40
        if ($mfiValue < -10) {
41
            return static::BUY;
42
        } elseif ($mfiValue > 80) {
43
            return static::SELL;
44
        }
45
46
        return static::HOLD;
47
    }
48
}
49