| @@ 10-50 (lines=41) @@ | ||
| 7 | use Laratrade\Indicators\Exceptions\NotEnoughDataException; |
|
| 8 | use Throwable; |
|
| 9 | ||
| 10 | class AverageDirectionalMovementIndexIndicator implements Indicator |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * The shortcut name. |
|
| 14 | * |
|
| 15 | * @var string |
|
| 16 | */ |
|
| 17 | const SHORTCUT = 'admi'; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * Invoke the indicator. |
|
| 21 | * |
|
| 22 | * @param Collection $ohlcv |
|
| 23 | * @param int $timePeriod |
|
| 24 | * |
|
| 25 | * @return int |
|
| 26 | * |
|
| 27 | * @throws Throwable |
|
| 28 | */ |
|
| 29 | public function __invoke(Collection $ohlcv, int $timePeriod = 14): int |
|
| 30 | { |
|
| 31 | $adx = trader_adx( |
|
| 32 | $ohlcv->get('high'), |
|
| 33 | $ohlcv->get('low'), |
|
| 34 | $ohlcv->get('close'), |
|
| 35 | $timePeriod |
|
| 36 | ); |
|
| 37 | ||
| 38 | throw_unless($adx, NotEnoughDataException::class); |
|
| 39 | ||
| 40 | $adxValue = array_pop($adx); |
|
| 41 | ||
| 42 | if ($adxValue > 50) { |
|
| 43 | return static::BUY; |
|
| 44 | } elseif ($adxValue < 20) { |
|
| 45 | return static::SELL; |
|
| 46 | } |
|
| 47 | ||
| 48 | return static::HOLD; |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||
| @@ 10-50 (lines=41) @@ | ||
| 7 | use Laratrade\Indicators\Exceptions\NotEnoughDataException; |
|
| 8 | use Throwable; |
|
| 9 | ||
| 10 | class CommodityChannelIndexIndicator implements Indicator |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * The shortcut name. |
|
| 14 | * |
|
| 15 | * @var string |
|
| 16 | */ |
|
| 17 | const SHORTCUT = 'cci'; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * Invoke the indicator. |
|
| 21 | * |
|
| 22 | * @param Collection $ohlcv |
|
| 23 | * @param int $timePeriod |
|
| 24 | * |
|
| 25 | * @return int |
|
| 26 | * |
|
| 27 | * @throws Throwable |
|
| 28 | */ |
|
| 29 | public function __invoke(Collection $ohlcv, int $timePeriod = 14): int |
|
| 30 | { |
|
| 31 | $cci = trader_cci( |
|
| 32 | $ohlcv->get('high'), |
|
| 33 | $ohlcv->get('low'), |
|
| 34 | $ohlcv->get('close'), |
|
| 35 | $timePeriod |
|
| 36 | ); |
|
| 37 | ||
| 38 | throw_unless($cci, NotEnoughDataException::class); |
|
| 39 | ||
| 40 | $cciValue = array_pop($cci); |
|
| 41 | ||
| 42 | if ($cciValue < -100) { |
|
| 43 | return static::BUY; |
|
| 44 | } elseif ($cciValue > 100) { |
|
| 45 | return static::SELL; |
|
| 46 | } |
|
| 47 | ||
| 48 | return static::HOLD; |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||
| @@ 10-51 (lines=42) @@ | ||
| 7 | use Laratrade\Indicators\Exceptions\NotEnoughDataException; |
|
| 8 | use Throwable; |
|
| 9 | ||
| 10 | class MoneyFlowIndexIndicator implements Indicator |
|
| 11 | { |
|
| 12 | /** |
|
| 13 | * The shortcut name. |
|
| 14 | * |
|
| 15 | * @var string |
|
| 16 | */ |
|
| 17 | const SHORTCUT = 'mfi'; |
|
| 18 | ||
| 19 | /** |
|
| 20 | * Invoke the indicator. |
|
| 21 | * |
|
| 22 | * @param Collection $ohlcv |
|
| 23 | * @param int $timePeriod |
|
| 24 | * |
|
| 25 | * @return int |
|
| 26 | * |
|
| 27 | * @throws Throwable |
|
| 28 | */ |
|
| 29 | public function __invoke(Collection $ohlcv, int $timePeriod = 14): int |
|
| 30 | { |
|
| 31 | $mfi = trader_mfi( |
|
| 32 | $ohlcv->get('high'), |
|
| 33 | $ohlcv->get('low'), |
|
| 34 | $ohlcv->get('close'), |
|
| 35 | $ohlcv->get('volume'), |
|
| 36 | $timePeriod |
|
| 37 | ); |
|
| 38 | ||
| 39 | throw_unless($mfi, NotEnoughDataException::class); |
|
| 40 | ||
| 41 | $mfiValue = array_pop($mfi); |
|
| 42 | ||
| 43 | if ($mfiValue < -10) { |
|
| 44 | return static::BUY; |
|
| 45 | } elseif ($mfiValue > 80) { |
|
| 46 | return static::SELL; |
|
| 47 | } |
|
| 48 | ||
| 49 | return static::HOLD; |
|
| 50 | } |
|
| 51 | } |
|
| 52 | ||