Currently, I'm using a bit of code consisting of a finditem, and an /if statement to sell the item if the result isn't null. The problem is, and I'm not sure if this is due to lag or my bad coding, that not all the arrows always get sold. So /finditem(foo) is returning null when there are still foo in my inventory. My buy macro is also similiarly simple, looping through a series of /merchant find and /click left merchant buy commands, incrementing a variable so I can buy X sets of ingredients. But once again, I seem to occasionally skip one or two. I've tried adding lengthy delays throughout, but the problem perseveres. If I let it run, the mismatched ingredient amounts fill up my bags and kill the macro.
I've tossed together a rather kludgy fix by selling back all the ingredients that were left unused due to this problem every round, but that hurts my skill-up rate.
I was thinking of using variables to keep track of the various quantities of items bought. How can I iterate through my inventory and total up the items with a given name? Finditem seems to just select the same one every time?
Does anyone else have a really good merchant buy or sell macro they could post, so I could try to figure out where mine is going wrong and where to improve it?

