I read Tomasz’s code sample in “How to Generate Backtest Statistics from a List of Historical Trades Stored in a File”. I want to modify it to process InteractiveBrokers’ trade fill file, which has fill time stamps and signed trade quantities – the sign being designed in the “Action” column by “BOT” or “SLD”. There appears to be a number of changes I need to make and I need some help to figure out the best way to achieve this:
- Process fills that all happen in the same intraday bar. Do I need to aggregate these fills in my code or is there already an built-in facility in Amibroker to do this?
- The scale-in, scale-out sample code in “Pyramiding” seems to suggest that one has to be able to figure out if a trade is “Buy”, “Short”, “Sell”, or “Cover”. Given the trade list only has signed trade quantity, do I need to keep a running position which processing the file to figure out, for example, whether a positive quantity fill is a “Buy” (scale-in) or “Cover” (scale-out), by either doing it in a pre-processing stage (e.g. using Python) or in AFL?
- Related to 2 above, there may be “stop and reverse” trades in which a long position is changed to a short position in a single fill – allowed in IB TWS but not necessarily in other platforms such as Tradestation. How do I handle these trades? Do I need to manually break the single fill into 2 trades, one closing the long position and the other opening the short position?
- As the symbology used by IB is not necessarily the same as that of the backtest database, what is the best way to do the ticker mapping, assuming I use an “exception”-based dictionary, e.g. if the IB symbol is in the dictionary, use the dictionary entry to translate to the target database symbol; Otherwise, use the IB symbol. I know how to do this cleanly in Python, but I hope to minimize non-AFL code to benefit all in the Amibroker community when I upload my solution into this Forum.
Thanks in advance for your thoughts.