HighTick


Order Logging Strategy using Object Oriented Programming

Logging orders that a strategy generates is useful as a debugging tool during strategy creation and to monitor the operation of a fully developed strategy.

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 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:

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:

  1. Bar Date
  2. Bar Time
  3. BarNumber
  4. Computer Time (hh:mm:ss) so interval between issued and filled orders can be assessed in seconds
  5. The name of the Method generating the line of data
  6. Order Type (called StrategyOrderDirection by the object code)
  7. Order Name, which facilitates matching the fill with a specific generated order
  8. Order Size (a round lot for EURUSD is 100,000)
  9. Limit or Stop Price
  10. Order type: Limit, Stop or Market
  11. Strategy Position and Real World Position (ActualMP)
  12. Average Fill Price on filled orders.

Downloads

Initial posted version: 12/29/13

Latest Update: 12/29/13

*.ELD files are compiled for TS 9.1

All ELD and code text files packaged here:

OrderLogging.zip

 

The code may be visualized here:

OrderLogging Strategy

StrategyOrderDirection Function

StrategyOrderType Function

DateTime Function

Sample Order Log

 

Bookmark and Share