Protective Exit Orders

This topic show how to add a protection exit price with a new order.  


It will also show how to create a volatility measure that can be used to determine how to price a protective exit for the price bar of market entry.


New Entry Order Protection:

New entry orders and active positions can have a protective price order to help the trader limit adverse price move losses.  New protective price orders are most often created during the new entry creation using a Broker Object function that provides a place where a protective exit price can be provided.  In most cases new entry orders are created in the Entry Orders script section using a Broker function with that contain "EnterLong..." or "EntryShort . . ." with the order's execution type text appended to the Broker's function name.



broker.EnterLongOnOpen( exitPrice )


Entry orders filled by the market and not closed because their protective price wasn't enabled, will appear as an active position available for the next test bar.  


Protective orders will have their protective price preserved in the instrument.unitExitStop property.  While the price is preserved there won't be a protective order for the next test bar unless the system generates a new protective price.  It can easily access the entry order's protective and use that value, or it can analyze how the market has changed and use a new protective price.  


When the test bar time ends, the system will need to generate a new protective price order when the system is dependent upon position protection to achieve its performance goals.  Maintaining protective price orders is a simple process once the system is operational because of how each active position is processed in the Exit Orders script section.  Only active position will cause Trading Blox to execute the Exit Orders script section and Long and Short trade direction orders can be contained within the same script section.


Active positions required to have a protective order in place for each bar of the trade must generate a new protective order after the close of the last trade bar.  This is needed because all orders in Trading Blox are considered "Day-Orders" which expire after the close price is printed by the exchange.


Protective Price Method:

Our example system will use a volatility based point spread for a new entry order in the Futures market.  Our approach will use the Average True Range calculation will generate a volatility estimate from a period of recent prices.  This volatility estimation is one more popular methods for estimating the offset for a protective price.  This calculation requires a period parameter to inform it how much recent price history to include in it calculation.  It in most cases also works better with a second parameter that allows the trader to adjust the size of volatility points to a larger or smaller value to fit in with the needs of a system.


To get started we will first add two parameters in the parameter section of our recently copied Entry Exit block:

First parameter will be called atrLength to our parameter section.  Our second parameter will be named atrAdjustRate to handle the volatility point adjustment.


To create this parameter, open the Blox Editor by using the menu item Blox, or pressing F4 on your keyboard:

Blox Editor Edit Menu Selection


When the Blox Editor opens locate the new copy we made of our Tutorial Entry Exit Lesson 2 and select it so we are sure it is displayed as the active module in the Blox Editor:

Blox Editor Selected Tutorial Entry Exit Lesson 2


Click on the word Parameters in the lower list area in the center section of the Blox Editor:

Tutorial Entry Exit Lesson2 - New Parameter


When the parameter dialog appears, add the atrLength variable name in the "Name for Code" textbox.


Next, in the "Name for Humans" textbox enter the description you want to see so you know the parameter is to change the length of the Avg. TrueRange calculation period length.

New atrLength Parameter Dialog

At the bottom of the dialog, enter a value that is greater than 1 or the value listed in the "Default Value" textbox field.  Value you enter into this field will be the default value displayed when this module is first added to a system list.  Once the module is displayed in the menu area the value used by the trader can be changed to another value.  When the default of any parameter will be retained by the Suite information process so that it is available the next time the software is run.


Follow the process used for our first parameter addition so we can add our second parameter,atrAdjustRate, to control the size of the protective offset points.  This second parameter will be a Floating Point type, and we will use a default value of 2.5 as the amount of adjustment we will want when we add our module to a new system.

New atrAdjustRate Floating Point Parameter


Our volatility estimation and adjustment parameters are now a part of our Tutorial System Entry Exit 2 module.  Click the Blox Editor OK button so we can see how adding a parameter to a module will appear when it appears in the parameter section of the main menu's system display area:

Tutorial System 2 Main Screen Menu after ATR Param Add

When your screen appears as shown above you will be ready to add the ATR indicator to our Entry Exit module.



Average True-Range Indicator:

Our process for adding a MACD indicator to the module in lesson 1 will be the same for this new indicator.  Indicator name and the selected calculation needed will be different, but the process will be familiar.


Start with a Right-Click on the Indicators menu item in the lower canter-section of the Blox Editor.

New AvgTrueRange Indicator Selection


A New Indicator dialog will appear where you can enter the name for the code, select the Average True Range option, assign the period length parameter, atrLength, and enable its information in the dialog's lower-right area so that after a test it can be seen below the price information chart.

New ATR Indicator Dialog


Understanding how an indicator is operating is an important towards understanding how a trading system designed.  Indicator calculation that are created by a built-in process don't allow any access to how they were designed, but we can see the data they produce.  Part of believing is seeing, and to that end this indicator will appear in a sub-graph chart area after test where the symbol generated trades using this system.


To make the protective exit process easier to see and understand when we display trade on the chart this indicator will enable the features required to display in the chart area below the displayed prices.  Enabling a built-in indicator so that it display along with its instrument prices is very easy.  Follow the details shown in the lower-right area of the dialog and then press OK


We have the new parameters appearing on our main menu screen, and now we have the details necessary to create a volatility measure for helping to determine how to price our protective exit prices.


It is also going to be visible below the Price Chart area so it can be referenced at this stage of our tutorial.  In this next image the new Average True Range (ATR) indicator and our previously created MACD indicator are shown.  Details show the ATR volatility values for each price bar, and the show the relationship of how the MACD calculation move above and below the zero basis line.

Click to Enlarge, Click to Reduce

Tutorial Lesson 2 Avg. TrueRange & MACD Graph Example


We are now ready to create the programming details in our second Entry Exit module so that we can apply a protective price order.


This completes this topic.

Edit Time: 5/10/2017 8:22:18 AM

Topic ID#: 478


Created with Help & Manual 7 and styled with Premium Pack Version 2.80 © by EC Software