HighTick


Automating Strategy Recovery

Numerous posts have dealt with the problem of "An Open Order Exists" dialog boxes appearing and demanding manual user intervention when a strategy attempts to restore itself after interruption. Failing to respond to this dialog box, such as the one below, can either halt the operation of the strategy, or result in duplicate orders executing with the result that a position size double of that desired is created.

An Open Order Exitss Dialog Box

The response to questions in this forum as to how to deal with these dialogs requiring manual intervention is usually something like:

"When you re-connect you may need to cancel old orders that were sent by automation prior to the disconnect. It is your responsibility to monitor the situation and take action as you deem necessary."

Fortunately, a solution to a more graceful and semi-automated recovery from strategy restarts can be borrowed from a technique incorporated in the companion strategy ContinuousAdoptRealWorldPositionV2. When this code detects a mismatch between the real world position and the strategy position that lasts more than a specified number of seconds, it (1) cancels all outstanding orders by issuing a RunCommand( CancelAllOrdersStr ), followed by (2) a Throw RecalculationExeption.Create("Restart strategy to enter trade"). These two commands clear all existing orders and restart the strategy. This is a relatively graceful recovery to identification of a persistent real world / strategy mismatch.

However, there are also situations where a strategy restart may be triggered that is less graceful, such as (1) data feed interruptions, (2) manually issued strategy restarts (Ctl-R), and occasionally (3) trade server disconnections. All of these may require manual intervention to either allow the strategy to continue, or to prevent duplicate orders from being issued that result in an undesirable and unintentional doubling of strategy postiion size.

The solution to a more graceful recovery in these other situations is to use the same RunCommand( CancelAllOrdersStr ) command as soon as LastBarOnChart is reached EACH TIME the chart data is reloaded by a restart, and not only when this reload occurs as a result of persistent mismatch between real world position and stategy position.

The technique is illustrated in the a re-write of ContinuousAdoptRealWorldPositionV2 called ContinuousAdoptRealWorldPositionMK, shown below.

The code modification that facilitates a smoother recovery from strategy restarts, without requiring manual intervention, is the addition of the RunCommand code in the main section:

// MAIN code

Once (_LastBarOnChart) begin
LastBar = true;
value1 = RunCommand( CancelAllOrdersStr ) ;
end;

Every time the chart is reloaded, whether because of manually initiated restart, data feed interruption, or trade server interruption, all prior active orders will be cancelled.

As a result, it is no longer necessary to manually respond to the dialog boxes stating "AN OPEN ORDER EXISTS. DO YOU WANT TO CANCEL THE ORDER?"

It will be noted when this version of ContinuousAdoptRealWorldPositionMK is used, the dialog boxes will still appear on your monitor !! However, immediately after they appear, all open orders will be cancelled in an automated fashion by the RunCommand( CancelAllOrderStr ), and the orders listed in this dialog box will no longer be active. It therefore does not matter whether you respond to this this box by selecting (1) "CANCEL ORDER", (2) "DO NOT CANCEL ORDER", or (3) fail to respond to the box at all. The effect is the same. The orders listed in this box have already been cancelled by automation and any response taken to this dialog box, including NO RESPONSE, has the same effect. The dialog boxes can be cleared at a later time at the convenience of the trader, without interfering with the smooth recovery of a triggered stategy restart from any of the conditions mentioned above.

Recommended Settings When Using ContinuousAdoptRealWorldPositionMK

  1. Format Strategies
    1. Generate strategy orders for display in TradeManager Strategy Orders tab
    2. Automate execution
    3. With Account Confirmation OFF
  2. Format Properties For All - General Tab
      1. Enable RunCommand EasyLanguage keyboard with confirmation OFF
      2. Enable order placement objects

        (Note: This checkbox respects order entry preferences confirm settings).
    1. Automation Tab
      1. Strategy will fill non-historical orders only when the TradeManager reports them filled
      2. Adopt the real-world position for the current account
      3. Wait for an UROut confirmation before sending a subsequent entry order for the same signal to the market
      4. Send stategy generated stop orders directly to the TradeStation Order Execution Network.
      5. Always hold stop orders on the Tradestation Order Execution Network’s Stop server, even if the execution destination natively supports stop orders.
  3. TradeManager Preferences
    1. Set email alerts as desired.
  4. Order Entry Preferences
    1. Confirmation for Order Bar, Macros and Order Placement Objects = OFF

 

Downloads:

Initial posted version: 12/11/13

Last Updated: 12/11/13

All Code and *.ELD Files: ContinuousAdoptRealWorldPositionMK.zip

( *.ELD files are compiled for TS 9.1 )


The code may be visualized here:


Stratregy _ContinuousAdoptRealWorldPositionMK

Function _Bar

 

 

Bookmark and Share