Thank you for the help!
I read the article “Using New Analysis window”, but I don’t understand how this can be applied to real trading. This window seems to be about back-testing the AFL with various time intervals. To trade for real, do I need to do a “walk forward”? Can you please explain? So far I have been testing directly on the chart window by applying my AFL on the chart, for one symbol. Of course at some point I will want to run the same AFL over multiple symbols to trade for real, so the question is how do I do that? (Links accepted)
Regarding the code snippet: I am also trading manually in TWS, but ibc.GetPositionSize(fSymbol) is returning the cumulative position (as shown in TWS), isn’t it? So this won’t work.
Yesterday I also had an issue with the ibc.GetPendingList(…) part. In effect, I placed a short sell order, and the IB controller displayed it with error 404, which translates to “Shares for this order are not immediately available for short sale. The order will be held while we attempt to locate the shares.” (<-- this is from the IB documentation)
To my greatest surprise, ibc.GetPendingList(…) did not return this order, and ibc.IsOrderPending(orderId) returned false! I noticed that only after the order was released by IB did it appear in the controller as a pending order. As a result, I ended up sending double orders. What I had to do was to use ibc.GetLastError(orderId) to check the last error on this order, and handle this special case, and it worked (that is, no double orders). What is worrisome though is that IB has lots of error codes and I am not sure which ones will affect the controller’s behavior. And what is more worrisome is that in fact this situation is not an error at all and I am not sure why IB controller changes the order’s status to “Error”, whereas in TWS the order is not displayed with an error.
For making my AFL not to interfere with manual trading in TWS I still have to think of a solution.
Just out of curiosity: Roughly how many lines of code should I expect that I have to write to make a bulletproof order entry system? So far I have written over 100 and it only handles a few IB errors. I just want to know the magnitude: 100s of lines, 1000s?