Add Automatic Order Logging to Any EasyLanguage Strategy.
You can add automatic order logging code to any Tradestation EasyLanguage strategy in minutes with this custom strategy code. This code is a self-contained strategy in itself and is inserted on any chart along with your trading strategy. It is useful as a debugging tool during strategy creation and to monitor the operation of a fully developed strategy. It can be easily disabled or removed when order logging is no longer needed.
Traditionally, to debug strategy order generation it was necessary to create additional unique lines of code that document the exact order sent as a text string so that it could be printed to the Easylanguage Print Log, such as follows:
Fig. 1. Traditional Order Logging/Debugging Code
Since this type of unique code must be created for each order, the task is both tedius and not re-usable for other strategies.
A second problem with order debugging is that there is no convenient way to log orders as they are filled, identifying which order was filled and at what price.
Fortunately, object oriented programming code makes it easy to add Order Logging to any strategy, reporting every order generated and every order as it is filled, along with it’s fill price.
Order Logging Strategy may be used as a stand alone utility, added to any chart containing a strategy, or the code may be incorporated into the main strategy code, which is somewhat more efficient if the strategy already uses StrategyHost or PositionProvider objects.
An image of this code is as follows:
Fig. 2. Order Logging Strategy Code
What is the Code Doing?
Method InitializeComponent() initializes a PositionProvider and StrategyHost object. In this section, the methods NewOrder, OrderFill and PositionUpdated are only assigned if the strategy is NOT undergoing optimization. Order logging is thereby disabled during optimization to increase optimization speed.
Method NewOrder() is called each time a new order is created. In addition to logging the order, the strategy position and real world position (ActualMP) is also reported on the same line in the log, as this is useful for debugging purposes and to ensure the correct order was issued for the current strategy status.
Custom functions StrategyOrderDirection and StrategyOrderType convert the integer values of StrategyOrderDirection and StrategyOrderType to string descriptions so they may be logged as text following the syntax of the Easylanguage code that created the order.
Method OrderFill() is called each time an order is filled and logs the details of this event, along with the fill price.
Method PositionUpdate() is triggered once for every historical bar and when real time data is available once every time the position or the bid/ask price changes. It is used to calculate the Real World Position and the Strategy Position so this information may be included in the Order Log with each order generated or filled.
The Order Log Example link at the bottom will open a separate full size window and displays all orders generated and all orders filled in the Easylanguage Print Log. This example is for FOREX symbol EURUSD, and therefore shows order quantities in units of 100,000, which is the round lot size for FOREX. Since this sample was created from historical bars, no real world position (ActualMP) exists in this portion of the log. An image of the log is as follows:
Fig. 2 Sample Order Log from a EURUSD Strategy
Items displayed in each line of the above log are:
- Bar Date
- Bar Time
- Computer Time (hh:mm:ss) so interval between issued and filled orders can be assessed in seconds
- The name of the Method generating the line of data
- Order Type (called StrategyOrderDirection by the object code)
- Order Name, which facilitates matching the fill with a specific generated order
- Order Size (a round lot for EURUSD is 100,000)
- Limit or Stop Price
- Order type: Limit, Stop or Market
- Strategy Position and Real World Position (ActualMP)
- Average Fill Price on filled orders.
Initial posted version: 12/19/13
Latest Update: 10/21/21
*.ELD FILES ARE COMPILED FOR v. 9.5
Users of earlier versions of Tradestation may compile the code from the text files included in the above *.zip file.
The code may be visualized here: