Paragraphs are 16-byte increments of memory. To figure out your program size dynamically as your program runs will depend in part on the language used for programming, model of the program and the segment structure in use. Generally what you would do is to arrange your link map to place a nearly empty (maybe a 1 byte allocated) segment at the end of your total program image. The the single unused but allocated byte is given a symbol that you can reference at run time.
Since, when programming in a 16-bit environment, segment addresses increment on paragraph boundaries the process to figure out your programs run time size is to subtract the segment of our programs load time PSP (program segment prefix) from the "segment" part of the address of the unused byte variable mentioned above. The difference is the number of paragraphs to ask DOS to keep loaded when you go TSR.
Note it can be very useful to carefully study the map file produced by the linker when your program is built. At least you need to check that the marker segment that you setup at the end of the image is indeed the last thing in image.
Note also that some programming environments may already have marker segments setup for just this purpose within their programming template.