Yes, stain or dye first normally, then polish or sealer. Avoid, if you can using a dye or stain that uses the same solvent as the sealing coat. For example, ready made spirit dye is alcohol based, as is shellac. Applying the shellac over the dye with a brush will redissolve the underlying dye which, if you work the shellac too much with the brush, can result in patchy colouring job. If you do have to brush on a sealing coat of shellac, it's best to get it on fast and thin with one pass of the brush, and move on to the next strip that needs coverage. After the dye has been sealed in like this subsequent coats shouldn't (I won't say can't) affect the underlying dye base.
However, pine has a real tendency to "blotchiness" when dyed because of the reverses in the grain pattern, so a trick might be to apply a thin coat of sealer, let this dry thoroughly, sand back pretty hard, then apply the colour. The idea here is that the applied sealer partially seals the grain, especially the short grain which, if not partially blocked, will take up the dye more thoroughly than long grain. Sanding back the sealer leaves the short grain partially blocked, but re-exposes the longer smoother grain leading to a more even colouring job.
I suggest a few experiments with some offcuts to see what I mean. Slainte.