To quote Dulrik from the stickied
Reminder:Botting is Illegal thread
Dulrik wrote:
If your trigger is changing the alias for you, then that would be illegal. Client side triggers should be limited to highlighting information or presenting it in alternate windows (if desired).
In my opinion that means that if, as a result of a single input, your command not only looks at the amount you have, but also determines the number of things to buy without any extra manual input, then it would be illegal as that's basically automating your character.
A legal version of your script would be two commands: One that highlights or even prompts you how many "things" you need, and then another command that requires you to manually type the number of times to perform whatever action you want to perform.