AutoAT 2.0

INTRODUCTION.. 1
MAIN FEATURES. 1

CONFIGURATION.. 2
COMMAND LINE OPTIONS. 3

AutoAT OPERATION.. 3

RECEIVING ALERTS. 5

LOADING ORDER FILES. 5

EXTENDED WEALTH-LAB (C) 2.1 ALERT FILE FORMAT. 5

THE COM API6

LOG FILE. 9

SECURITY. 9

SYSTEM REQUIREMENTS. 9

KNOWN ISSUES. 9

CONTACT INFO.. 9


INTRODUCTION

IMPORTANT -  You may use AutoAT V2.0 only if you agree to the terms set forth in the AutoAT Suite License Agreement.

AutoAT 2.0 is an automatic trading application for Ameritrade and Freetrade. It works with data generated by WealthLab (C) 2.1 or 3.0, either in files or email alerts, and it also exposes a COM Automation API which can be used from applications such as Wealth-Lab, Excel, Visual Basic etc. To enable automatic trading from sources other than Wealth-Lab please contact the author.

Note that AutoAT 2.0 does not implement all the features of a complete automatic trading system application, so it will not do or enable portfolio management, tracking or canceling orders etc. Here is what it currently does: takes orders that come from a variety of sources (COM API, email, files, manual entry) and sends them to Ameritrade for execution and shows the result of sending the order to Ameritrade (such as accepted or rejected, and possibly the reason), not its status after it has been received by Ameritrade.

Currently, AutoAT can only send orders that will be routed using the Ameritrade Auto Routing option. More will be supported in future versions. Also, GTC (Good Till Cancelled orders) are not supported as of this version - all orders will expire at the end of the trading session.

Important note for Freetrade account owners: unlike Ameritrade, Freetrade accounts only supports a subset of the type of orders that AutoAT can submit. Sending of unsupported order types may have unintended consequences. Check with Freetrade  for more information.

Please note that AutoAT 2.0 is a modified version of AutoAT V1.6, which has been available as a standalone product. The changes were necessary to make it easier to adapt the software to future changes in the Ameritrade protocols. Although V1.6 has been stable for quite some time, and tests have shown 2.0 stable as well, 2.0 users may still experience unknown issues due to these changes. Please report them immediately for fixing.

MAIN FEATURES

CONFIGURATION

Before using AutoAT, the user needs to make sure that the Ameritrade or Freetrade account(s) are configured properly:

·         the Command Center should be enabled and useable

·         Express Trading should be enabled.

The user may also need to configure the network (proxy, firewall etc) to enable AutoAT to receive email alerts, to connect to Ameritrade and to send orders.

In order to use AutoAT V1.6, the user must first create and configure one or more AutoAT accounts.

If there are no accounts, the user will be prompted to create one:

Click on New and enter the name of the new account.

Once the new account name is in the list of accounts, click on Settings.

·         Start in active mode: alert receiving and sending orders are enabled at startup.

·         User name/Password: the Ameritrade login info

·         Account type: select the account type - Ameritrade or Freetrade

·         Save logon info: save the logon info and login automatically at the subsequent start-ups.

·         Don't send buy and sell short orders if...: if checked will activate the buying power limit validation whenever a buy or sell short order is in the active queue. Used in conjunction with the Buying power type. Note: the different account values that are used when the buying power limit is turned on, are updated periodically, normally once every minute (see the main window section), so these values may not be valid any more at the time an order is received and the buying power limit value is checked.

·         Buying power type: check one of the three types: Available cash, Stock buying power, and Day trading buying power. Not all these three types are present in all accounts, and they have quite different meanings. Before using this option please make sure you know exactly what type of account you have (cash or margin), if you have day tradining status, and that you understand what these values represent. As a general rule, if the user selects a type that is not available for that particular account, AutoAT will look at the next higher value. The order is: Day trading buying power, Stock buying power and Cash. So if for example the user checked Day Trading buying power but the account doesn't have day trading status and is a margin enabled account, the value that will be considered is Stock buying power. If the account were not margin enabled, AutoAT would consider the Available cash value.

·         is lower than: the buying power limit that will be checked against the actual buying power reported by the account. If this limit is equal or higher than the actual buying power, then orders that would further lower the buying power will not be sent (buy and sell short). These orders will be moved to the Inactive orders queue. 

·         Orders transformations

o        Orders are sent unchanged - no transformation is applied to the orders as they are sent

o        Stop market order is changed to market order - in this case the stop activation price is ignored and the order is sent as a market order. This option is intended to alleviate a current limitation with stop orders in Wealth-Lab. Ameritrade and Freetrade only accept stop orders if the activation price is under (for buy or cover orders) or above (for sell or short orders ) the current bid for a symbol. At the same time, Wealth-Lab may trigger the alert for that order only when it has already reached or exceeded the activation price. In this case, the order will be sent but not accepted by the broker. Selecting this option will allow  the order to be sent as a market order. Note: Wealth-Lab 3.0 Quote Manager has the option to set a "Trigger threshold", which if used, may send the alert before the target is reached, in which case, if this button is checked, the orders may get executed at the wrong price.

o        Stop market order is changed to stop limit order - a limit order will be sent instead of a stop market order, with the limit equal to the activation price + or - the percentage specified in the % of stop activation price edit box - the price for buy and cover orders will be above and for sell and sell short orders will be below the stop activation price. This option is intended to alleviate a current limitation in Wealth-Lab 3.0, which doesn't support stop limit orders. Also, the limit price will be rounded up for buy and cover orders and rounded down for short and limit orders, at penny level. For example, if the % of stop activation price is set to 1%, and a buy 100 shares of XYZ @ stop 2.31 is entered. The new limit price will be 2.31 + 1% which is 2.31+0.0231= 2.3331 and rounded up this will become 2.34. Similar for a short order: sell short 100 shares of XYZ @ stop 2.34 then the new limit will become 2.34-1% = 2.34-0.0234 = 2.3166, which rounded down will become 2.31.

·         Proxy server: AutoAT can connect to the Internet through a proxy server, which can be local or remote. The proxy server address and port are expressed as "server_name:port". For example "localhost:5555" identifies a proxy server running locally (on the same computer as AutoAT) and listening on port 5555. If in doubt, consult your network administrator.

·         Alert listen port: the port on which the AutoAT built-in SMTP (email) server receiving the alerts will be listening. Each account should use a different port number. Also, the port number should not be used by any other application on the same computer.

Repeat this procedure for all the accounts that need to be created and configured. Once this phase is completed, the account selected in the Accounts dialog box will become the default account, which means that if no account name is specified on the command line (see command line options section), this is the account that AutoAT will automatically select and log into at start-up.

One running instance of AutoAT can connect to only one account, but using the command line option -a (see command  line options section), multiple instances of AutoAT can be run simultaneously, and each receiving alerts on a different port and each connected to a different account.

Once all the accounts have been configured and before using AutoAT in real trading, several tests should be run in after market hours to make sure that AutoAT  is correctly configured, alerts are being received, and orders are being sent and accepted by Ameritrade. Please note that some evenings Ameritrade conducts server maintenance activity which may prevent AutoAT from entering orders, so if you see that AutoAT fails repeatedly, make sure that the server is able to accept orders.

COMMAND LINE OPTIONS

Several command line parameters can be set.

·         -f:trades_file- will automatically load an alerts file at start-up

·         -a:account_name - the name of the account which will be used as default at start-up. This will supersede the default account set in the Accounts dialog box. If the account name is not found, the Accounts dialog box will pop up asking the user to select an account or create a new one. Account names are case sensitive.

Both the trades file and account name can use quotes, in case they contain space characters.

An example of a command line: 

autoat -f:"d:\test orders.txt" -a:"My main account"

AutoAT OPERATION

Here is the main AutoAT window.

Active orders - this is the list from which orders are sent to Ameritrade, when sending orders is enabled.   

The nature of most columns is self explanatory. The "Time" column shows the local time the order was received or loaded. The "Lim Price" column contains the price for limit and for stop limit orders. The "Act Price" column shows the activation price for stop orders (market or limit) and the trailing stop parameter (percent or points) for trailing stop orders. Consult the Ameritrade online help for a complete description of different types of orders.

All orders loaded from files or received are added to this list. The user can also add orders to this list by double clicking on an empty area of the list or by clicking on the Add Order button which will bring up the Add Order dialog:

An order can be edited by double clicking on it, which will bring up the same dialog above, initialized with the type and values of the selected order. It is recommended that before editing an order, it be moved to the inactive orders list or that sending be disabled.

To delete one or more orders, select them and press the Delete key.

Inactive orders  - this is the list of inactive orders, i.e. orders that are temporarily "parked" for editing, or to be sent at a later time. Orders that have been rejected by Ameritrade are automatically moved to this list. The user can also choose to move orders from the active orders by selecting them and clicking on the button between the two lists. To move orders to the active list, first selected them and then click on the button.

Orders can also be added to the inactive orders list manually, by double clicking on an empty area of the list box which will bring up the Add Order dialog box.

Enable Receiving Alerts - this toggles the alert receiving enabled status. If checked, receiving email alerts is enabled, on the port specified in the active account settings.  

Enable Sending Orders - this toggles the order sending enabled status. If checked, sending orders is enabled. Please note that if a send is in progress, un-checking the button will not cancel the order currently being sent. In case of network or other error that would prevent AutoAT from sending orders, an error message box will pop up and sending will be disabled.  

Statistics - various statistics are shown: number of orders received, sent, accepted, rejected. These numbers are valid for the session. For more info open consult the log file (see below), which contains detailed information about all orders received, sent rejected and other events.

Status - shows the current status of AutoAT, such as the order being sent (if any) or the last order sent, the last server response, the login status and the active account.  

Account Info - amounts such as Cash, Available cash, Stock buying power, Day trading buying power etc are displayed in this area. These are updated periodically: every minute if the buying power limit setting is enabled, or every ten minutes if it is not set. The user can also manually force an update by clicking on the refresh button . Also in this area the status of the buying power limit setting is displayed. It can be either OFF if no limit is selected, or the limit amount, and the selected type of buying power if limit is selected.

Other commands

Under the menu File there are several other commands:

·         Open orders file - opens a file containing orders, in Wealh-Lab 3.0 or extended Wealth-Lab 2.1 format and loads their contents into the Active Orders Queue

·         Accounts- opens the Accounts dialog box, where the user can manage the AutoAT accounts.

·         Login- executes the login procedure for the active account

·         Enter Registration Code- for unregistered users, this will bring up the AutoAT registration dialog, where the user can enter the registration information he/she has received for the unlimited version.

·         About - brings up the about dialog box, where the user can see the AutoAT version and build running, and the registered/unregistered status, the hardware fingerprint and number of days left for unregistered users.

Notes

·         If an alert receive or order send error occurs, a message box pops up notifying the user and receiving and/or sending are disabled. The user has to manually dismiss the message box, fix whatever problem caused the error and re-enable receiving and/or sending. This can be a problem when AutoAT runs unattended, so make sure you minimize the risk for errors by checking all the network settings etc. A solution is being worked on that will allow recovery from transient errors such as server down or other such problems.

RECEIVING ALERTS

AutoAT contains a mini SMTP (email) server which listens for incoming email alerts. In order to receive alerts, a few things need to be done.

First, the Alerts listen port parameter in the Settings dialog should be set to a number corresponding to an available port. In general, the regular SMTP port is 25, but I suggest setting it to some other value (the default is 1111), as other SMTP proxy servers may be running and be listening on the same port.

Then Wealth-Lab will have to be configured to enable email alerts and to send them to the address of the computer where AutoAT is running and to the port set in the AutoAT settings. The EMail address can be set to any value (it should not be emtpy though or Wealth-Lab will not send alert emails) and User ID can be set to any value or no value. 

This is the Wealth-Lab Options dialog box with settings for a typical configuration, where AutoAT is on the same computer as Wealth-Lab (indicated by the "localhost" SMTP server)

In AutoAT, receiving alerts should be enabled by checking the corresponding button on the main window.

As the communication between Wealth-Lab and AutoAT is done through TCP/IP, they may reside on different computers. In this case, firewalls, proxy servers, routers etc. should be configured to allow communication between the two.

LOADING ORDER FILES

In order to load orders from a file, go to the menu File/Open orders file. Files in the format generated by both Wealth-Lab 2.1 and 3.0 are recognized, and the format is automatically detected.

If the file is in Wealth-Lab 2.1 format, extra types of orders are supported, as well as comments.

EXTENDED WEALTH-LAB (C) 2.1 ALERT FILE FORMAT

The orders file contains the data and type for each trade. Each order should be on a separate line. 
Here is the accepted format for the Wealth-Lab 2.1 alert file.

symbol;[Buy|Sell|Short|Cover];shares;[Market|Stop|Limit];price

The price field will not be present for market orders.

Here is the format for the Stop Limit and Trailing Stop type of orders, which are supported by Ameritrade:
symbol;[Buy|Sell|Short|Cover];shares;Stop Limit;stop_price;limit_price
symbol;[Buy|Sell|Short|Cover];shares;[Trailing Stop Percent|Trailing Stop Point];stop_parameter

Lines starting with "#" or "//" are interpreted as comments and their content is not parsed.

Here are some examples:

#this is a comment line
// this is another comment line
#buying 1000 shares of IBM at market
IBM;Buy;1000;Market;
#selling 1000 shares of IBM at limit $88.05
IBM;Sell;1000;Limit;$88.05
#cover 1000 shares of IBM at stop $85.55
IBM;Cover;1000;Stop;$85.55
#sell 1000 shares of IBM at Stop Limit - stop at $88.05 and sell at limit $89.00
IBM;Sell;1000;Stop Limit;88.05;89
#sell 1000 shares of IBM at trailing stop 0.5 points
IBM;Sell;1000;Trailing Stop Point;0.05
#sell 1000 shares of IBM at trailing stop 1%
IBM;Sell;1000;Trailing Stop Percent;1



Please note that Ameritrade has specific rules regarding entering Short and Trailing Stop orders, so make sure you understand exactly how they work before you place them.

Make sure you check the program output for any errors or events that may have occurred during its execution, such as trades not accepted and the reason for that.

For Wealth-Lab 3.1 alert file format, please refer to the Wealth-Lab 3.0 documentation.

THE COM API

The COM API enables programmatic access to some of the functionality implemented by AutoAT: adding orders to the active orders queue, re-logging in and checking the login status.

Before the COM API can be used, AutoAT must be run at least once as a standalone application in order to register itself with the system.

When AutoAT is instantiated from an external application, it starts up, loads the default settings and then waits for commands. Using the COM APIs the client application can login or re-login, check the login status and send orders to the active orders queue. In addition, AutoAT can still receive email alerts and load orders from files concurrently with the COM API.

A future version will allow loading different settings for each instance, in order to enable multiple simultaneous connections.

The COM API is accessible from a variety of applications such as Excel, Visual Basic, Wealth-Lab etc. The type id of the interface, needed to load and access the API is "AutoAT.AutoATBroker". 

These are the available methods:


 

//********************
// login or re-login
//   no parameters, 
//   no return value

Login

// checks the logged in status
//   no parameters
//   returns 0 if not logged in, non-zero if logged in

integer IsLoggedIn

// adds a market order to the active orders queue
//   Side - integer value: 0 - Buy, 1 - Sell, 2 Sell short, 3 - Buy to cover
//   Symbol - string:
//   Shares - integer: number of shares
//   Comment - string: reserved. Can be any string
//   no return value
MarketOrder( integer Side, string Symbol, integer Shares, string Comment )

// adds a limit order to the active orders queue
//   Side - integer value: 0 - Buy, 1 - Sell, 2 Sell short, 3 - Buy to cover
//   Symbol - string:
//   Shares - integer: number of shares
//   LimitPrice - float
//   Comment - string: reserved. Can be any string

//   no return value
LimitOrder( integer Side, string Symbol, integer Shares, float LimitPrice, string Comment )

// adds a stop market order to the active orders queue
//   Side - integer value: 0 - Buy, 1 - Sell, 2 Sell short, 3 - Buy to cover
//   Symbol - string:
//   Shares - integer: number of shares
//   ActivationPrice - float
//   Comment - string: reserved. Can be any string

//   no return value
StopOrder( integer Side, string Symbol, integer Shares, float ActivationPrice, string Comment )

// adds a stop limit order to the active orders queue
//   Side - integer value: 0 - Buy, 1 - Sell, 2 Sell short, 3 - Buy to cover
//   Symbol - string:
//   Shares - integer: number of shares
//   ActivationPrice: float
//   LimitPrice: float
//   Comment - string: reserved. Can be any string

//   no return value
StopLimitOrder( integer Side, string Symbol, integer Shares, float ActivationPrice, float LimitPrice, string Comment )

// adds a trailing stop order to the active orders queue
//   Side - integer value: 0 - Buy, 1 - Sell, 2 Sell short, 3 - Buy to cover
//   Symbol - string:
//   Shares - integer: number of shares
//   Type - integer: 0 - points, 1 - percent
//   ActivationPrice - float
//   Comment - string: reserved. Can be any string

//   no return value
TrailingStopOrder( integer Side, string Symbol, integer Shares, integer Type, float ActivationValue, string Comment)

// indicates whether the active orders queue is empty
// used to determine if there are any more orders to be submitted, for example when
// closing the application
integer ActiveOrdersQueueEmpty

Depending on the users’ feedback, other methods to control AutoAT could be added in the future.

Here is a sample code for Wealth-Lab which starts AutoAT, tests the login status and sends several orders. Note: sending trailing stop orders will only work for Ameritrade accounts.

// define a few constants to make the code more legible
const _BUY = 0;
const _SELL = 1;
const _SHORT = 2;
const _COVER = 3;

const POINTS = 0;
const PERCENT = 1;

// declare a variable of type ComVariant
var lib: ComVariant;

// instantiate the AutoAT interface and application
lib := CreateOleObject( 'AutoAT.AutoATBroker' );

// wait for the login process to complete
// note that this is not necessary as the active queue operates asynchronously
// so it is ok to start adding orders immediately
// but it is here to illustrate the concept
while not lib.IsLoggedIn do
begin
end;

// add a variety of orders to the active orders queue
lib.MarketOrder( _BUY, 'xyz', 100, 'comment' );
lib.MarketOrder( _SELL, 'xyz', 150, 'comment' );
lib.MarketOrder( _SHORT, 'xyz', 200, 'comment' );
lib.MarketOrder( _COVER, 'xyz', 250, 'comment' );

lib.LimitOrder( _BUY, 'xyz', 300, 1.55, 'comment' );
lib.LimitOrder( _SELL, 'xyz', 350, 1.55, 'comment' );
lib.LimitOrder( _SHORT, 'xyz', 400, 1.55, 'comment' );
lib.LimitOrder( _COVER, 'xyz', 450, 1.55, 'comment' );

lib.StopOrder( _BUY, 'xyz', 300, 1.55, 'comment' );
lib.StopOrder( _SELL, 'xyz', 350, 1.55, 'comment' );
lib.StopOrder( _SHORT, 'xyz', 400, 1.55, 'comment' );
lib.StopOrder( _COVER, 'xyz', 450, 1.55, 'comment' );

lib.StopLimitOrder( _BUY, 'xyz', 300, 1.55, 3.00, 'comment' );
lib.StopLimitOrder( _SELL, 'xyz', 350, 1.55, 3.00, 'comment' );
lib.StopLimitOrder( _SHORT, 'xyz', 400, 1.55, 3.00, 'comment' );
lib.StopLimitOrder( _COVER, 'xyz', 450, 1.55, 3.00, 'comment' );

lib.TrailingStopOrder( 0, 'xyz', 500, 0, 4, 'comment' );
lib.TrailingStopOrder( 1, 'xyz', 600, 1, 5, 'comment' );

And here is a Visual Basic sample:

Private Sub Form_Load()

' create the AutoAT variable and instantiate the interface and AutoAT
Dim AutoAT As Object
Set AutoAT = CreateObject("AutoAT.AutoATBroker")

' wait for the login process to complete
’ note that this is not necessary as the active queue operates asynchronously
’ so it is ok to start adding orders immediately
’ but it is here to illustrate the concept
Do
Loop While Not AutoAT.IsLoggedIn

' add several orders to the active orders queue
AutoAT.MarketOrder 0, "xyz", 555, "comment"
AutoAT.LimitOrder 1, "xyz", 555, 1.5, "comment"
' and so on....

Set AutoAT = Nothing
End Sub

LOG FILE

Each time AutoAT starts, it will create a new log file with the name "the current date and time.log". All log files are stored in the "logs" subdirectory, under the AutoAT installation directory.

AutoAT writes all activity into these log files. You will find there all significant events of the session: the active account, orders received, sent, the result of sending them and the server message, various errors etc. These log files are never deleted by AutoAT, so make sure you clean this directory periodically.

SECURITY

AutoAT is as secure as the browser based Ameritrade application. communication between AutoAT and the broker is encrypted using SSL and orders can be sent only after logging in to Ameritrade.

If the user chooses to save the login info (in the Accounts/Settings dialog box), it will be stored in the registry in clear text. This will be fixed in a future release - the user info will be stored in the registry in encrypted form. If this is a concern, in the meantime the user can choose not to save the login info, and instead enter it when prompted . 

SYSTEM REQUIREMENTS

AutoAT V1.6 has been tested and used on Windows XP Pro, Windows 2000 Server and Windows 98SE, with most recent patches and updates. The memory, disk space and CPU speed requirements are very low by current standards, so pretty much any computer will do.

It has been tested and can receive email alerts from Wealth-Lab 2.1 and Wealth-Lab 3.0 up to the most recent build.

KNOWN ISSUES

AutoAT cannot relogin if the accounts are switched during the same session. In this case the user should restart AutoAT after selecting the new default account and AutoAT will login  automatically the next time.

All types of orders are sent regardless of the account type, Ameritrade or Freetrade. This can pose a problem for Freetrade accounts, if the order is not recognized or misinterpreted by the server, as Freetrade does not support all types that AutoAT can send. Please check with Freetrade for the allowed orders.

CONTACT INFO

Email me at info@amichel.com  for bug reports, enhancement requests etc.
Also, if you want to be on a mailing list for future releases please let me know. I will never, for any reason, sell or give away your contact info - I am as bothered by spam and concerned for my privacy as most other people are.


Copyright (C) Adrian Michel 2003, 2004