| Conditions | 4 |
| Paths | 6 |
| Total Lines | 33 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function __invoke(Collection $ohlcv, int $timePeriod = 14): int |
||
| 23 | { |
||
| 24 | $close = $ohlcv->get('close'); |
||
| 25 | $closeCount = count($close); |
||
| 26 | |||
| 27 | if ($timePeriod > $closeCount) { |
||
| 28 | $timePeriod = round($closeCount / 2); |
||
| 29 | } |
||
| 30 | |||
| 31 | $atr = trader_atr( |
||
| 32 | $ohlcv->get('high'), |
||
| 33 | $ohlcv->get('low'), |
||
| 34 | $ohlcv->get('close'), |
||
| 35 | $timePeriod |
||
| 36 | ); |
||
| 37 | |||
| 38 | throw_unless($atr, NotEnoughDataException::class); |
||
| 39 | |||
| 40 | $currentValue = array_pop($close); |
||
| 41 | $previousValue = array_pop($close); |
||
| 42 | $atrValue = array_pop($atr); |
||
| 43 | |||
| 44 | $upside = ($currentValue - ($previousValue + $atrValue)); |
||
| 45 | $downside = ($previousValue - ($currentValue + $atrValue)); |
||
| 46 | |||
| 47 | if ($upside > 0) { |
||
| 48 | return static::BUY; |
||
| 49 | } elseif ($downside > 0) { |
||
| 50 | return static::SELL; |
||
| 51 | } |
||
| 52 | |||
| 53 | return static::HOLD; |
||
| 54 | } |
||
| 55 | } |
||
| 56 |