Enable OTG with a shell command
Note: the solution is tested on a rooted OnePlus 6 running OxygenOS (Android 8, 9, 10).

The command I use is:
adb shell su -c 'setprop persist.sys.oem.otg_support true'

Some folks on some  forums suggested to toggle the value for the global settings key oneplus_otg_auto_disable, but it never worked out for me. My solution survives reboot and OTG would work even when decryption password is not supplied.
I automate the solution for fail-safe scenario (in case something disable the OTG)  using Tasker app. My task is:
Code → Run Shell:

setprop persist.sys.oem.otg_support true
enable Use Root

I then assign the task to a boot event profile so that the task runs during startup.