You are requesting to program the pending orders at the exact same time you are checking for both buy/sell conditions. This is why only buys are programmed, because that is the only condition that can be true. The sell condition cannot be true at that exact time. You need to check those conditions BEFORE the moment those conditios are checked, not at the exact one.