| Conditions | 8 |
| Paths | 12 |
| Total Lines | 26 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 72 |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | public function __invoke(Collection $ohlcv, int $timePeriod = 200): int |
||
| 19 | { |
||
| 20 | $close = $ohlcv->get('close'); |
||
| 21 | $length = count($close); |
||
| 22 | $median = array_sum($close) / $length; |
||
| 23 | |||
| 24 | $nl = $nh = 0; |
||
| 25 | |||
| 26 | for ($a = 0; $a < $length; $a++) { |
||
| 27 | if ($close[$a] > $median && $close[$a] > @$close[$a - 1]) { |
||
| 28 | $nl++; |
||
| 29 | } elseif ($close[$a] < $median && $close[$a] < @$close[$a - 1]) { |
||
| 30 | $nh++; |
||
| 31 | } |
||
| 32 | } |
||
| 33 | |||
| 34 | $mmi = 100. * ($nl + $nh) / ($length - 1); |
||
| 35 | |||
| 36 | if ($mmi < 75) { |
||
| 37 | return static::BUY; |
||
| 38 | } elseif ($mmi > 75) { |
||
| 39 | return static::SELL; |
||
| 40 | } |
||
| 41 | |||
| 42 | return static::HOLD; |
||
| 43 | } |
||
| 44 | } |
||
| 45 |