Object Based Advanced Order Handling

This topic contains 0 replies, has 1 voice, and was last updated by Seer Seer 8 years, 3 months ago.

Viewing 1 post (of 1 total)
  • Author
  • #607

    Some trading systems need to manipulate orders once they have been placed. A simple example is a system that needs to change an active stop order based upon price changes (perform a dynamic trailing stop). Often it is necessary to add information to an order so it’s possible to track the order during it’s life, this is especially important when there are many orders active at any point in time. Adding data to an order can be performed on order creation by the PlaceOrder function with the UserData parameter. Once data is set, it can be queried via the UserData method during the life of the order.

    To manipulate active orders (during backtesting and live orders at the broker) you’ll need to call functions that return order(s) that are active at that point in time:


    Fetching Order Objects

    Orders - returns all orders for the current symbol
    SystemOrders - returns all the orders for the current system
    AccountOrders - returns all the orders for the current account

    Multiple orders can be returned by the above functions. So it’s often necessary to process orders within loops. The returned order(s) are objects that then can be manipulated by method calls.


    Order Methods

    The following methods can effect the state of the order and have separate documentation:

    Approve - Approve the order
    Cancel - Cancel the order
    Change - Change the order
    UserData - Access any user data that is associated with the order.

    The following methods return information about the order (no separate documentation):

    LastUpdated – the last time this order was updated (via the broker)
    TransactionCost – any transaction costs for this order
    SlippageCost – any slippage cost for this order
    OrderTypeID – the order type (buylimit, selllimit etc. See the PlaceOrder function for codes)
    Quantity – the quantity of units for the order
    Filled – how many units have been filled
    DateTimeFilled – the last date time that a fill has happened
    FillPrice – the fill price of the order
    StopPrice – the stop price of the order
    NBOStopPrice – the NextBarOpen stop price
    LimitPrice – the limit price of the order
    StatusID – the status code of the order (see broker documentation for these codes)
    NBOLimitPrice – the NextBarOpen limit price
    Label – the label on the order
    SystemName – the system in which the order came from
    Symbol – the symbol for the order
    OCA – any OCA group on the order (not broker OCA)
    TypeDescription – the order type description
    StatusDescription – the status type description
    Message – any (broker) message associated with this order



    #Loop around all active orders, printing them out.
    foreach my $order (Orders) {
      Output $order;
    #Loop around all active orders and then cancel any order with a specific stop price
    foreach my $order (Orders) {
      $order->Cancel if $order->StopPrice == 12.00;
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.