You either need a foreground service [FREE] Pedometer with Foreground Service or a StayAwake routine. When your device goes to sleep, it cannot count the steps.
Here is how you might code a Stay Awake block routine using a Notifier
or you could use Taifun’s Tools Extension: https://puravidaapps.com/tools.php
Using either an extension or a block routine drains your device battery rapidly . These work around methods are not running the app in the Background, they force the app
screen to stay open .