Our Average True Range (ATR) indicator is now operating and reporting a volatility measure for each price in the data file after the calculation priming period has primed.

 

When we create orders they are always based upon the values of price bars that have an Open, High, Low and Close price value that considers that price record ready to use.  After the last available price bar is provided Trading Blox can use that new information to what if had previously and update the calculations of its indicators.

 

To apply the last bar's volatility measure, we will take the last ATR value and then adjust in a way that should help us reduce losses during difficult trading time, and allow a position to stay in place during favorable market periods.  In this next section we will program our module to use this new ATR information to generate a point estimation of how much of a distance we should use to place our protective exit prices.  Our offset distance will be controlled by a new Instrument Permanent Variable (IPV) we will add to our module so that the process can be seen in more clear terms.

 

Add a Working Variable:

Open the Blox Editor and click on the Entry Orders script section and select the New menu item to create a new Block Permanent Variable (BPV) Floating Point type variable:

New BPV variable creation selection

When the new BPV dialog appears fill in the details as shown:

New BPV exit Points floating variable

Our new BPV is created for a stand alone calculation so that the results of the calculation can easily be seen when needed.  For example, in the beginning of your experience you might want to see how the value in this BPV changes with each instrument when Trading Blox Debugger mode is active.

 

For this lesson a BPV variable was chosen because this is just a temporary working variable.  A local variable could have been declared and used, but a BPV variables execute a little faster, and their values can seen from other script sections when needed.  It was also chosen to create a variable that improves readability, which often helps to improve understanding. BPV variables are intended to not retain a specific value that is only correct for one instrument.  Instead they are intended to be used a working variable or a blox specific that can be used with any instrument.  In this case the working value in the BPV is only good until it is passed to the Broker Object EnterOnOpen function, and is updated before it is used with another instrument.

 

A value specific to an instrument would be an actual unit entry price, or a unit exit price.  These types of values would be placed in an Instrument Permanent Variable (IPV) because they only are valid for a specific instrument at a specific time.

 

Adding Volatility Results:

All the parameters, variables and indicator details we need to add a protective price to our entry orders are in place.  To make them work we just need to add two additional lines of programming code, and modify our two Broker functions so the orders are generated with a protective price for the price bar of entry.

 

Code Changes:

'  Calculate Current Protective Offset Points                     <- Add
exitPoints = avgTrueRange * atrAdjustRate                         <- Add

 
 
  '  Generate a LONG Entry with a Protective Exit below prices   <- Modify
  broker.EnterLongOnOpen( instrument.close - exitPoints )       <- Modify
 

 
  '  Generate a SHORT Entry with a Protective Exit above prices <- Modify
  broker.EnterShortOnOpen( instrument.close + exitPoints )     <- Modify

 

 

Use the above code details to modify your new Entry Exit module's Entry Orders script area so that your Entry Orders script section looks like this next image:

Add Entry Order Protection Changes

When you get your source code to match the changes suggested, orders generated with this module will contain an exit price that will provide an Exit Order for the price bar where your Entry Order was enabled.

 

As our code is currently written the protective exit order will not be active after the bar of entry, but that can be changed by adding additional instruction into the Exit Orders script section.  We will also add script rules to the Exit Orders script section to enable the position to carry the protective price forward for each price bar on which the position is active.

 

Understanding Chart Display Details:

Image notations point out how the indicators influence the trade action.  It also shows how our last change of adding a protective price sits below the current market price and how that protective value establishes the risk this order assumes on entry.

Click on image to expand, Click on image to reduce.

Click Image

At this stage of the tutorial we are showing the plot values of the instruments below the chart so their values can be seen.  With then in a parallel visual display it is easy to relate how the indicator values relate to what is shown in the price area of the chart.  It should also be possible with the aid of the cross-hair cursor data display on the right side of the chart area to see the actual values of everything displayed on the chart.  

 

With the actual indicator and price values available it should be easy to understand how the rules are creating the timing and price values shown for each trade listed in the trade's table below the chart.

 

All the orders generated with out new system now show an entry date protective initial stop price.  This stop price protection is only available on the bar of entry because all orders in Trading Blox are "Day" orders.  In our next tutorial topic we'll create the script so that the initial protective prices are available for the active orders after the bar of entry.

 

Links:

Operator Reference

 

This completes this topic.


Edit Time: 9/25/2017 09:09:54 AM


Topic ID#: 297

 

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