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
        if (false === $adx) {
39
            throw new NotEnoughDataPointsException('Not enough data points');
40
        }
41
42
        $adx = array_pop($adx); //[count($adx) - 1];
43
44
        if ($adx > 50) {
45
            return static::BUY; // overbought
46
        } elseif ($adx < 20) {
47
            return static::SELL;  // underbought
48
        } else {
49
            return static::HOLD;
50
        }
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
}
43

src/MoneyFlowIndexIndicator.php 1 location

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