| Conditions | 6 |
| Paths | 4 |
| Total Lines | 25 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | public function __invoke(Collection $ohlcv, int $period = 14): int |
||
| 21 | { |
||
| 22 | |||
| 23 | $obv = trader_obv($ohlcv->get('close'), $ohlcv->get('volume')); |
||
| 24 | |||
| 25 | if (false === $obv) { |
||
| 26 | throw new NotEnoughDataPointsException('Not enough data points'); |
||
| 27 | } |
||
| 28 | |||
| 29 | $current_obv = array_pop($obv); |
||
| 30 | $prior_obv = array_pop($obv); |
||
| 31 | $earlier_obv = array_pop($obv); |
||
| 32 | |||
| 33 | /** |
||
| 34 | * This forecasts a trend in the last three periods |
||
| 35 | * TODO: this needs to be tested more, we might need to look closer for crypto currencies |
||
| 36 | */ |
||
| 37 | if (($current_obv > $prior_obv) && ($prior_obv > $earlier_obv)) { |
||
| 38 | return static::BUY; // upwards momentum |
||
| 39 | } elseif (($current_obv < $prior_obv) && ($prior_obv < $earlier_obv)) { |
||
| 40 | return static::SELL; // downwards momentum |
||
| 41 | } else { |
||
| 42 | return static::HOLD; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 |