To share a bit of my secret in this, Is a process I do when I develop macros.
First sim your character. Assuming you are using sim C
then scroll through the detailed information, until you see something called an Action priority list.
which should show a table with a bunch of stuff but below that look for Sample sequence table.
this dropdown shows what abilites were used and timestamped when during the sim essentially its a combat log of the sim.
from here you need to study it and look for a pattern that you can replicate in a macro. depending on the class it won’t be a perfect fit but it should give you an idea of ability order and frequency.
from there you script and test your macro first on a training dummy while doing so run two add-ons first details damage metres. second is something like Hero rotation or Hekili,
don’t look at you DPS at this point, use detail to look at the charts and graphs to compare with the ones in the sim, so you can see it abilities are firing as often as the sim, running watching hero rotation addon as you hit the dummy you can see if your abilites are firing when the addon thinks it should be.
FYI the APL or information to determine that ability to press is often the same as whats used to sim your character, so should result in a similar rotation.
from this point its a matter of back and forth testing and tuning until things match up as close as possible.
it seems a lot to do but yeah a lot of thought and time goes into some of these macros many cant grasps. as its often not simple fits to just throw commands at a wall and see what sticks. personally i am happy with a 5% leeway trying to match your sim results. as the sim results demonstrate a perfect scenario which often cant be achieved. heck even if you have set the siim up wrong can skew things also.