Some people like to make things a lot more difficult than they need to be. The problem with your original code was that you were using the wrong methods. You should have been using CTrade::BuyLimit and CTrade::SellLimit instead. If I were you I wouldn't muck about with the low-level functions as others suggest and instead use the standard library classes as they were intended to be used. Here is a working example you can run on history data with the debugger.