Items can be on the Dock in one of three ways.
- you have dragged them onto it
- the applications are currently running
- new to Catalina - they are recently used but not running. These will always appear on the right side of the Dock if it is on the bottom of the display or on the bottom of the Dock if it is on the right or left
Icons that are dragged onto the Dock should always appear in the same location whether they are running or not. Icons of applications that haven't been dragged onto the Dock will appear essentially in the order in which they were launched. This, I would expect, is why your icons change position. And if you are running Catalina the #3 would add to that confusion.
If I'm correct, your solution is to drag the icons of programs you run frequently onto the Dock so they remain in the location you want them.