Wrapping Functions

During development of Automated Trading systems, “wrapping” functions (i.e., calling a standard function from a custom function) for the Interactive Brokers Controller (IBc) allows you to add debug statements to your code without making your main code difficult to read. Here is an example where the standard ibc.IsOrderPending() is wrapped by a custom afl function named IsOrderPending():

function IsOrderPending( ORderID )
{
global ibc;
IsPending = ibc.IsOrderPending( ORderID );
TRACE("# Pending Status for OrderID: " + ORderID + " is "+NumToStr(IsPending,1.0));
return IsPending;
}

Instead of calling the IBc function directly, you now call it from a function that is identically named but has the prefix ibc. removed. This allows you to attach debugging statements and utility code (such as managing OrderIDs) to your automated trading (AT) functions without increasing the length of your main code. All you have to do to restore full speed operation is to re-attach the ibc. to the wrapper function names. Other ibc. functions can be wrapped similarly.

Wrapping functions slow down AFL slightly, but the loss in speed is more than offset and justifiable by the lack of clutter in your main code with long _TRACE() statements.

Edited by Al Venosa

DebugView: Introduction and Setup

DebugView is an essential development, debugging, and trading tool.

When developing Automated Trading Systems, you need to know when orders have gone out, what their parameters were, whether they were accepted and processed, what error messages were received, etc. When you place an automated order, you cannot simply assume that your order was executed and filled. You must always verify order and system status and be able to act on irregularities.

Debugging techniques reflect personal working habits, and the examples you’ll find in the Debug Category of the Users’ Knowledge Base are intended to help you develop your own debugging strategies, not to provide the perfect debugging setup for you.

Using _TRACE() statements will slow down the speed of code executions somewhat, and you should exercise care when using them. For example, you should never permanently embed _TRACE() statements inside a loop with a thousand iterations. This would result in thousands of lines being output to DebugView and noticeably slow down your AFL execution. Another option is to selectively enable and disable _TRACE() output by using the Param() user input; this topic is covered under the heading of DebugView: _TRACE() Statements and Logging.

You can use DebugView to create a detailed logging file that will show you exactly what happened, when it happened, and in what sequence. To reject output from other programs on your computer, all _TRACE() output strings start with a “#” character. This is done so that you can set up your DebugView -> Edit -> Filter/HighLight to pass only your statements that begin with “#”:

snag-0856.jpg

To install DebugView, download, unzip, and copy the dbgview.exe program to the C:\Program Files\AmiBroker\DebugView folder. Then, in AmiBroker, go to Tools -> Customize -> Tools -> New and change MenuItem to DebugView. Next, click on the three dots inside the Command box and browse for the DebugView program, which is located at C:\Program Files\AmiBroker\DebugView\Dbgview.exe, and click on it. Finally, click the Close button, and you are finished. From now on, you can start up DebugView from AmiBroker by simply clicking Tools -> DebugView.

snag-0775.jpg

It cannot be stressed enough that DebugView is an indispensable tool in the development of Real-Time Automated trading systems.

DebugView is free, and you can download it from http://www.microsoft.com/technet/sysinternals/utilities/debugview.mspx

Edited by Al Venosa

« Previous Page