| Conditions | 6 |
| Paths | 6 |
| Total Lines | 29 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | public function __invoke(Collection $ohlcv): int |
||
| 18 | { |
||
| 19 | $high = $ohlcv->get('high'); |
||
| 20 | $low = $ohlcv->get('low'); |
||
| 21 | |||
| 22 | $data = []; |
||
| 23 | foreach ($high as $key => $value) { |
||
| 24 | $data[$key] = ($high[$key] + $low[$key]) / 2; |
||
| 25 | } |
||
| 26 | |||
| 27 | $sma1 = trader_sma($data, 5); |
||
| 28 | $sma2 = trader_sma($data, 34); |
||
| 29 | |||
| 30 | array_pop($data); // take most recent off |
||
| 31 | |||
| 32 | $sma3 = trader_sma($data, 5); |
||
| 33 | $sma4 = trader_sma($data, 34); |
||
| 34 | |||
| 35 | $last = (array_pop($sma3) - array_pop($sma4)); |
||
| 36 | $current = (array_pop($sma1) - array_pop($sma2)); |
||
| 37 | |||
| 38 | if ($last <= 0 && $current > 0) { |
||
| 39 | return static::BUY; |
||
| 40 | } elseif ($last >= 0 && $current < 0) { |
||
| 41 | return static::SELL; |
||
| 42 | } |
||
| 43 | |||
| 44 | return static::HOLD; |
||
| 45 | } |
||
| 46 | } |
||
| 47 |