Pet Macros Not Working

I often have to press my pet attack macro several times before my pet will begin attacking. When indoors, or when there is something blocking LOS, my pet sometimes will refuse to attack the target at all. I am using the same macro I used on Light’s Hope, and I never had any problems then.

/script if GetUnitName(“target”)==nil then TargetNearestEnemy() end
/script CastPetAction(2);
/script CastPetAction(10);
/script PetAttack(target)
/cast Charge
/cast Dash

Does anybody have a working macro?