Size as a function of equity and risk

Top  Previous  Next

 

In practice, when initially sizing positions, you will most likely want to take into consideration (a) one or more equity figures, and (b) the risk of the trade being presented for sizing.

Mechanica excels in this regard by providing you with the capability to size, reject and resize positions as a function of various measures of equity and risk.

NEWRISK

The general form of the statement that many traders use to size positions as a function of equity and initial trade risk is:

Number of Contracts = (% of Equity) / $Risk of new trade

Statements of this form are often referred to as fixed-fractional position sizing, which means simply that a fixed fraction of equity is risked on each trade. In Mechanica Basic, one way to accomplish this is with a statement like:

NEWCONTRACTS = (.01 * TOTALEQUITY) / NEWRISK 

 

The keyword NEWRISK returns the risk of the trade being presented for initial sizing, in dollars per contract, or dollars per share: 

nWhen the system enters on a stop, NEWRISK is defined as the dollar value of the difference between the entry stop price and the exit stop price.
nIn the case of a system that enters on the open, NEWRISK is defined as the dollar value of the difference between the closing price yesterday, and the exit stop today

Thus, the statement above specifies that 1% of total equity is to be risked on each trade; the number of contracts to be traded (NEWCONTRACTS), is derived by dividing 1% of total equity, by the dollar risk of the trade being presented for sizing (NEWRISK).

ThumbTack white

1.The keyword NEWCONTRACTS automatically rounds down to the nearest integer. For instance, if the statement above specified 11.83 Swiss Franc contracts, Mechanica would put on 11 contracts.
2.The Mechanica keyword NEWRISK can only be used when your systems exits employ the BUYSTOP and SELLSTOP keywords OR when risk has been user-defined, using the keyword USERDEFINEDRISK (which well cover later in this section).

       

NEWRISK and exit types

Lets look at an example:

1Open Lesson5.sig if it is not already open.
2Make sure that the Pinnacle_Futures Data Page is still selected (checked), and that JY_REV is the only symbol currently tagged (under Tag Symbols).
3Run the system.
4Open the SIZ file Lesson5.siz, if it is not already open (File menu).
5On the Initial Size page, delete the line “NEWCONTRACTS = 1” …and add the new line of code shown below:

STARTUPCASH = 25000000

NEWCONTRACTS = (.01 * TOTALEQUITY) / NEWRISK

 

6Run the Position Sizing Rules.
7Quickly look at Mechanicas status bar. You should see the following:

(If you have a blazing fast PC, you may need to tag a lot of symbols, rerun Lesson5.sig, and then run the Position Sizing Rules again, in order to see this message.)
Why the “Divide by Zero” error? Because, as we mentioned in the note above, NEWRISK only returns a non-zero  value when your system employs the BUYSTOP and SELLSTOP keywords as exits (unless USERDEFINEDRISK is employed). Otherwise, NEWRISK evaluates to zero, as it does here. Also note that the Portfolio Summary Report displays zero trades. (The Portfolio Summary report is located in the Portfolio Performance window, which grabs focus as soon as the Position Sizing Rules run is complete.)

Settings that control various aspects of the Portfolio Summary Report output (such as T-bill interest earned, assessment of management and incentive fees, risk-free-rate of return for use in calculating the Sharpe Ratio, etc.) are located under the Position Sizing menu, Portfolio Summary Report Options.

Now, look at the code on the Trade in Progress & Exit for Lesson5.sig. As you can see, were using the BUYOPEN and SELLOPEN keywords to exit on todays open, following a penetration of the SMA by yesterdays close. Hence, the error:

Trade in Progress & Exit

'IF C[1] < COL3[1] THEN SELLOPEN    'long exit signal

 IF C[1] < SMA_Exit[1] THEN SELLOPEN

'IF C[1] > COL3[1] THEN BUYOPEN     'short exit signal

 IF C[1] > SMA_Exit[1] THEN BUYOPEN

 

In circumstances like thissuch as when running the Position Sizing Rules generates a “Divide by Zero” error as it did aboveits important to look at the Grid to figure out whats going on. As you can see in the graphic on the following page, the system is entering and exiting trades OK, but there is no data in the exit column until the last day of the trade (at which point the actual exit price is displayed).
8Again, this is attributable to using the BUYOPEN and SELLOPEN keywords on the Trade in Progress & Exit page; NEWRISK will only return meaningful values when your system employs the BUYSTOP and SELLSTOP keywords as exits (unless risk has been user-defined). If it sounds like were harping on this point, its because we are! This is a common misunderstanding, and the confusion is easily avoided.

NEWRISK evaluates to zero, because the way the system is written, we are exiting on the open today, following a penetration of the SMA by yesterdays close. But yesterday, Mechanica has no way of knowing what todays open is. Thus:
nNEWRISK evaluates to zero, and…
nNo exit data is calculated, nor displayed in the Grid, except the actual exit price. (The light green highlight in the screen shot above indicates the cells where data would appear, if NEWRISK evaluated to a non-zero value.)
9Lets resolve the issue. Click on the Trade in Progress & Exit tab. Comment out the previous exit statements, and add the two new lines of code shown below.

Trade in Progress & Exit

'IF C[1] < COL3[1] THEN SELLOPEN       'long exit signal

'IF C[1] < SMA_Exit[1] THEN SELLOPEN

 SELLSTOP = SMA_EXIT[1]

'IF C[1] > COL3[1] THEN BUYOPEN        'short exit signal

'IF C[1] > SMA_Exit[1] THEN BUYOPEN

 BUYSTOP = SMA_EXIT[1]

 

Weve made quite a few changes, so before going further, the system as we are currently working with it is shown below, with all commented-out code removed for the sake of clarity. Please take a minute to compare it to your own code, and make sure it matches.
Note that the two new lines of code we added, BUYSTOP/SELLSTOP = SMA_EXIT[1] … are functionally equivalent to BUYSTOP/SELLSTOP = COL3[1] (see Resources page below). You can verify this by examining the Grid-column aliases associated with this SIG file, which should appear under the first three column headings in the Grid. (If they dont appear there, then you probably didnt save out Lesson3.sig to Lesson5.sig, as shown in the first exercise in this Lesson; To write and run an initial sizing file; A simple example.  If the concept isnt clear, please review the section on Grid-column aliases in Lesson 3 before proceeding).    

Resources

SYSTEM = 3

COL1 = MAX[HIGH,34,0] + TICK[1]      'long entry price

COL2 = MIN[LOW,34,0] - TICK[1]      'short entry price

COL3 = SMA[CLOSE,34]      'exit indic. (long and short) 

 

Trade Entry

BUYSTOP = Long_Entry[1]       'long entry signal 

SELLSTOP = Short_Entry[1]    'short entry signal

 

Trade in Progress & Exit

SELLSTOP = SMA_EXIT[1]         'long exit signal

BUYSTOP = SMA_EXIT[1]         'short exit signal

 

Initial Size

STARTUPCASH = 25000000

NEWCONTRACTS = (.01 * TOTALEQUITY) / NEWRISK

 

Now that were using BUYSTOP and SELLSTOP for exits on the Trade in Progress & Exit page, then NEWRISK on the Initial Size page should evaluate to a non-zero value. But in order to find out, well need to re-run the Signal Rules.
10First, save your work out to a new file name. Call it Lesson5a.sig.
11Choose Run Signal Rules (Signals menu), to re-run the system.

 

Before running the Position Sizing Rules, its important to note two things: First, since we are using the BUYSTOP / SELLSTOP keywords on the Trade in Progress & Exit page, the system is generating exit data for each trading day. Second, when we saved the SIG file out to a new filename, the Grid-column aliases were retained, as you can see in the screen shot above, or in Mechanica on your desktop, if you are following along.
Remember: the keyword NEWRISK returns the riskin dollars per contract (or dollars per share)of the trade being presented for initial sizing.
12Run the Position Sizing Rules; Click the Run arrow icon on the Position Sizing toolbar, or choose Run Position Sizing Rules under the Position Sizing menu.
This time when the Position Sizing Rules are run, the system sizes trades as instructed, and the Portfolio Performance window reports meaningful data.

 

Passing data from Signals to Sizing; 4 keywords

There are four (4) keywords in the Mechanica Basic language specifically designed to communicate sizing-related data from the Signals side to the Position Sizing side.

All four have one thing in common: They allow you to store numerical values created during Signal Rules operations (when Mechanica is busy processing your systems trades), that can later be referenced by the Position Sizing rules.

SYSTEM = n;   n = 1 to 254

The value assigned to the SYSTEM keyword variable (when the Signal Rules are run), is later used by the Position Sizing Rules to associate each trade with the system that generated it.

USERDEFINEDRISK

This keyword allows you to define your own measure of risk for use in Initial Sizing and Resizing operations. It is a variable that is intended to serve as a global substitute for Mechanicas internal definition of risk.

ThumbTack white

The value assigned to USERDEFINEDRISK flows through to all keywords containing the word RISK, including NEWRISK.

SIZING[n];   n = 1 to 8

You can pass any numerical value from the Signals side to the Position sizing side using this variable. SIZING[n] is often used to pass a custom measure of risk (created on the Signals side), that is later used in Sizing statements.

Unlike USERDEFINEDRISK, the value assigned to the SIZING[n] variable, when used to pass risk values, does not affect the value of any other keyword.

ThumbTack white

The SIZING[n] variable may be used to pass literally any information from the SIG side to the SIZ side. For instance, SIZING[n] may be used to pass RANK, or other market-specific information from the SIG side, for (later) use in either Initial Sizing or Resizing operations.

SORTLIST[n];  n = 1 to 4

SortList values are created when the Signal Rules are run; these values are later used by Initial Size statements when the Position Sizing rules are run. SortLists can be user-defined, on the Resources tab. A default SortList is provided.

SortList defines the order in which open trades are Initially Sized.

 

USERDEFINEDRISK

Now that weve demonstrated the circumstances under which it is appropriate to use NEWRISK in an initial sizing statement, lets look at how to go about defining your own measure of risk for use in other scenarios. You will do this by using the keyword USERDEFINEDRISK, which is intended as a global substitute for the internal definition of risk.

Remember   NEWRISK carries Mechanicas internal definition of risk (unless USERDEFINEDRISK has been assigned), and is defined as the dollar value of the difference between the entry price and the exit stop (when the system enters on a stop), and the dollar value of the difference between the closing price yesterday, and the exit price today, for a system that enters on the open.

If youll recall, the reason NEWRISK didnt work with Lesson5.sig the way it was originally written, is because the system used the BUYOPEN / SELLOPEN keywords for exits, instead of using BUYSTOP / SELLSTOP.

In this exercise, were going to look at a system that uses the BUYOPEN / SELLOPEN keywords to enter and exit on the open, following the receipt of a signal by the previous days close. (This is one of the first entry types we studied, back in Lesson 2.)

Then, well show you how using the keyword USERDEFINEDRISK in your SIG code affects position sizing when we use NEWRISK as in the previous exercises.

 

ThumbTack white

1.Assigning a value to USERDEFINEDRISK is a Signals side operation, but the value you assign is available for later use in Sizing operations.
2.After assigning a value to USERDEFINEDRISK on the Signals side, the keyword is never explicitly used in Sizing statements, because...
3.The value assigned to USERDEFINEDRISK flows through to all keywords containing the word RISK. This includes not only initial sizing keywordsincluding NEWRISKbut resizing keywords as well. Well cover this concept in detail later in this section, and again in the Resizing lesson.
4.Unlike NEWRISK, USERDEFINEDRISK does not include slippage and commission charges (unless you add them, in your definition).
1Open Lesson5a.sig if it is not already open.
2Save your work out to another filename; call it Lesson5b.sig.
Were going to skip around in the SIG file this time. Although well be modifying it shortly, the Resources page as we last left it is shown below, for reference:

Resources

SYSTEM = 3

COL1 = MAX[HIGH,34,0] + TICK[1]        'long entry price

COL2 = MIN[LOW,34,0] - TICK[1]        'short entry price

COL3 = SMA[CLOSE,34]        'exit indic. (long and short)

 

3Click on the Trade Entry tab of the Rules Editor, comment out the previous entry statements, and add the two statements shown below:

Trade Entry

IF C[1] > LONG_ENTRY[2] THEN BUYOPEN         'long entry signal

IF C[1] < SHORT_ENTRY[2] THEN SELLOPEN        'short entry signal

 

The entry statements shown above (and the exit statements were going to add below), transact on the open today following the receipt of a signal at the previous days close.
Remember: Long_Entry is a grid-column alias, and is equivalent to the value of COL1; Short_Entry is also is a grid-column alias, and is equivalent to the value in COL2.  (If this isnt clear, please review the section on grid-column aliases in Lesson 3.)
4Now, click on the Trade in Progress & Exit tab. Comment out the exits we added in the previous exercise, and activate the original exits (if the commented-out code is still in your SIG file), or simply type them in as shown:

Trade in Progress & Exit

'SELLSTOP = SMA_EXIT[1]        'long exit signal

IF C[1] < SMA_Exit[1] THEN SELLOPEN

'BUYSTOP = SMA_EXIT[1]        'short exit signal

IF C[1] > SMA_Exit[1] THEN BUYOPEN

 

These are the original exits from Lesson5.sig. Following a penetration of the SMA by yesterdays close, the system exits on todays open. (SMA_Exit is also a grid-column alias, and is equivalent to the value in COL3.)
5Click on the Resources tab, and delete the ± TICK[1] in the COL1 and COL2 definitions (assignments). Since we're requiring a close above (or below) the 34-day highest high (or lowest low), it really isnt necessary to retain the additional price tick.
6Then, add the new lines of code shown below, beginning with the COL4 assignment:

Resources

SYSTEM = 3

COL1 = MAX[HIGH,34,0]        'long entry price

COL2 = MIN[LOW,34,0]         'short entry price

COL3 = SMA[CLOSE,34]        'exit indic. (long and short)

'

COL4 = (CLOSE  SMA_EXIT)        'risk in points

COL5 = ABS[COL4]        'abs. value of risk in points

'Yesterdays risk (per contract), in dollars:

USERDEFINEDRISK = COL5[1] * POINTVALUE[1]

 

Before running the Signal Rules, lets discuss the code we just added:
COL4 yields the difference (in points) between the closing price and the exit price (SMA_EXIT).
COL5 simply takes the absolute value of COL4 in order to eliminate having to deal with the negative number that results from a pending short trade. (For a pending short trade, the close will always be below the SMA_EXIT, and the subtraction operation will yield a negative value). Thus, COL5 tells us the risk in points of a pending trade, expressed as a positive number.
In order to obtain the risk in dollars, COL5 is multiplied by the point value of the symbol (instrument), and the product is assigned to USERDEFINEDRISK. (The POINTVALUE[1] keyword returns the dollar value of a 1 point move, which, for the Japanese Yen futures contract we have been working with, is $125,000. For a share of stock, the point value is $1.00. Point values, tick sizes, and other data specifications for the Pinnacle sample data that ships with Mechanica are located under the Edit Symbol Properties tab of the Symbol Manager.)  The [1] is used here because we want to reference yesterday's value in the case we tag a foreign denominated market.  For other markets the value will be static so it does not harm to always use POINTVALUE[1].
Note that the USERDEFINEDRISK statement references COL5[1], which is the value of COL5 yesterday. Why? Because this system enters trades at the opening price today, and the best approximation of risk is the (dollar) difference between the closing price yesterday, and the exit price yesterday.
Another way to think of it is to look back at COL4 and acknowledge that it uses the CLOSE in its definition (its assignment), with no offset. Thus, if COL5, which is dependent on COL4s value, were not offset by one day COL5[1] then you would be sizing a position to enter the market at todays open, but using todays closing price to calculate risk, which is a postdictive error.
7Save your work.
8From the Data menu, choose Symbol Manager, and under the Tag Symbols tab, make sure that the Pinnacle_Futures Data Page is still selected (checked), and that JY_REV is the only symbol currently tagged.
9Run the system.
10Open the SIZ file Lesson5.siz, if it is not already open.
11Click on the Initial Size tab, and add the line, STARTDATE = 19970101, as shown below. (Well discuss this keyword in a bit.)

Initial Size

STARTUPCASH = 25000000

STARTDATE = 19970101

NEWCONTRACTS = (.01 * TOTALEQUITY) / NEWRISK

 

12Now, run the Position Sizing Rules.
For a detailed explanation of why the NEWRISK keyword worked in this exercise, but failed in an earlier exercise, please continue on to the next section in this lesson.

 

USERDEFINEDRISK and other RISK-related keywords

The code below is from the previous exercise, and is shown to facilitate discussion:

Resources

SYSTEM = 3

COL1 = MAX[HIGH,34,0]        'long entry price

COL2 = MIN[LOW,34,0]         'short entry price

COL3 = SMA[CLOSE,34]        'exit indic. (long and short)

'

COL4 = (CLOSE  SMA_EXIT)        'risk in points

COL5 = ABS[COL4]        'abs. value of risk in points

'Risk per contract, in dollars:

USERDEFINEDRISK = COL5[1] * POINTVALUE 

 

Trade Entry

IF C[1] > LONG_ENTRY[2] THEN BUYOPEN         'long entry signal

IF C[1] < SHORT_ENTRY[2] THEN SELLOPEN        'short entry signal

 

Trade in Progress & Exit

IF C[1] < SMA_Exit[1] THEN SELLOPEN        'long exit signal

IF C[1] > SMA_Exit[1] THEN BUYOPEN        'short exit signal 

 

Initial Size

STARTUPCASH = 25000000

STARTDATE = 19970101

NEWCONTRACTS = (.01 * TOTALEQUITY) / NEWRISK

 

In the previous exercise, we were able to successfully employ the NEWRISK keyword in the initial sizing statement, even though we were no longer using BUYSTOP / SELLSTOP keywords in the exit statements. (We were using BUYOPEN / SELLOPEN instead.)

Yet the sizing statement executed as instructed, and the Portfolio Performance window reported valid resultsinstead of rejecting all tradeswhich is what happened the first time we attempted to use NEWRISK with the BUYOPEN / SELLOPEN keywords in the exit statements.

Why? Because the value assigned to the keyword USERDEFINEDRISK on the Resources page flows through to all keywords on the Sizing side containing the word RISK, including the keyword NEWRISK.

To reiterate: The value assigned to USERDEFINEDRISK flows through not only to NEWRISK, but to all the Initial Sizing and Resizing keywords containing the word RISK, such as SECTORISK, SYMBOLRISK, SECTORLONGRISK, SYSTEMSHORTRISK, TOTALRISK and RISK to name a few.

ThumbTack white

1.The Mechanica keyword NEWRISK can only be used when your systems exits employ the BUYSTOP and SELLSTOP keywords, UNLESS ... risk has been user-defined to accommodate other exit types, by using the keyword USERDEFINEDRISK in the SIG code (in which case NEWRISK will return that value, instead).
2.The same rule applies to all Initial Sizing and Resizing keywords that contain the word RISK: If you are employing an exit type that causes NEWRISK to return a value of zero (and remember, the Rules Editor status bar displayed a Divide by Zero error in this circumstance), then the Initial Sizing and Resizing keywords containing the word RISK will not work as intended, since they, too, will return a value of zero under these circumstances.

       

SIZING[n] 

SIZING[n] is one of the four variables Mechanica provides (along with SYSTEM USERDEFINEDRISK and SORTLIST), that can be used to pass information from the SIG to the SIZ side. Now that weve covered USERDEFINEDRISK, understanding SIZING[n] is a simple matter. In this exercise, well show you how to define a new measure of risk on the Signals side and store it in SIZING[n]. Later we'll reference that assigned value in an Initial Sizing statement. 

1Open Lesson5b.sig, if it is not already open.
Note on the Trade in Progress & Exit page (below), that our exits are still using the BUYOPEN / SELLOPEN keywords.
2Modify the statement at the bottom of the Resources page as shown below, using the keyword SIZING[n]   …and save your work. 
Please note that the actual definition of risk is unchanged from the previous exercise. But now, instead of using USERDEFINEDRISK to carry the risk definition, were using the SIZING[n] variable.
Dont confuse the numbers in the brackets!
nThe “n” in SIZING[n] can assume a value of from 1 to 8, which means that Mechanica allows you to simultaneously assign (and later pass up to eight different SIZING variables. Thus, in the statement below, SIZING[1] simply identifies which of the eight possible SIZING[n] variables is being used, so that Mechanica can keep track of the corresponding value. This is not a day offset!
nAs weve discussed previously, the [1] notation in COL5[1] is an offset that tells Mechanica to look at the value of COL5 yesterday. The SIZING[1] definition, or assignment, uses COL5[1] to avoid creating a postdictive error when SIZING[1] is later referenced on the SIZ side.
3From the Data menu, choose Symbol Manager. Under Tag Symbols, make sure that the Pinnacle_Futures Data Page is still selected (checked), and that JY_REV is the only symbol currently tagged.

Resources

SYSTEM = 3

COL1 = MAX[HIGH,34,0]        'long entry price

COL2 = MIN[LOW,34,0]         'short entry price

COL3 = SMA[CLOSE,34]        'exit indic. (long and short)

'

COL4 = (CLOSE  SMA_Exit)        'risk in points

COL5 = ABS[COL4]        'abs. value of risk in points

'Yesterdays risk per contract, in dollars:

SIZING[1] = COL5[1] * POINTVALUE[1] 

 

Trade Entry

IF C[1] > LONG_ENTRY[2] THEN BUYOPEN         'long entry signal

IF C[1] < SHORT_ENTRY[2] THEN SELLOPEN        'short entry signal

 

Trade in Progress & Exit

IF C[1] < SMA_Exit[1] THEN SELLOPEN        'long exit signal

IF C[1] > SMA_Exit[1] THEN BUYOPEN        'short exit signal 

 

4Run the system.
5Open the SIZ file Lesson5.siz, if it is not already open.
6Replace the statement at the bottom of the Initial Size page with the code shown below, using the keyword SIZING[n], as shown.
7Save your work. 

Initial Size

STARTUPCASH = 25000000

STARTDATE = 19970101

NEWCONTRACTS = (.01 * TOTALEQUITY) / SIZING[1]

 

Note that the NEWCONTRACTS statement is unchanged from the previous exercise...with the exception of our use of the keyword SIZING[n].

We are still sizing new positions at 1% of total equity. We have simply replaced the USERDEFINEDRISK / NEWRISK combination with SIZING[n] ...both on the Resources page, and on the Initial Sizing page.

8Now, run the Position Sizing Rules        

ThumbTack white

1.In the previous exercise, SIZING[n] was used to pass a custom measure of risk defined on the Signals side, to (later) be used in Initial Sizing and Resizing statements.

The SIZING[n] variable may be used to pass literally any information from the SIG side to the SIZ side. For instance, SIZING[n] may be used to pass RANK, or other market-specific information from the SIG side, for (later) use in either Initial Sizing or Resizing operations.

2.The parameter [n] in the variable SIZING[n] can assume the values 1 to 8. Thus, there are 8 different SIZING[n] numerical values that can be passed.
3.There are many circumstance where you will use more than one SIZING[n] variable. One example of this is when you define a custom measure of risk, as we did above, with SIZING[1], and use SIZING[2] to pass RANK information from the SIG side to the SIZ side.
4.Unlike USERDEFINEDRISK, whose value flows through to all keywords containing the word RISK, values assigned to the SIZING[n] variable do not affect the value of any other keyword.

ThumbTack2

Important

5.Anytime you pass values from the SIG side to the SIZ side using either SIZING[n] or USERDEFINEDRISK, be sure that they always reference yesterdays information in the SIG file...just like we did in the previous exercise with COL5[1] ...so that you do not create a postdictive error.

 

SIZING[n] in conjunction with USERDEFINEDRISK

At the end of the previous exercise we mentioned some circumstances under which you might wish to employ USERDEFINEDRISK and SIZING[n] together. The following exercise demonstrates one possible such use; it also introduces the concept of measuring risk based on volatility, for use in initial sizing.

1Open Lesson5b.sig if it is not already open.
2Save this file (Save As) …Lesson5c.sig.
3Modify the Resources page, as shown:

Resources

SYSTEM = 3

COL1 = MAX[HIGH,34,0]        'long entry price

COL2 = MIN[LOW,34,0]         'short entry price

COL3 = SMA[CLOSE,34]        'exit indic. (long and short)

'

COL4 = ATR[34]        '34-day Average True Range

'Yesterdays volatility (risk) 

'per contract, in dollars:

SIZING[1] = COL4[1] * POINTVALUE[1] 

'

COL5 = (CLOSE  SMA_Exit)        'risk in points

COL6 = ABS[COL5]        'abs. value of risk in points

'Yesterdays risk per contract, in dollars:

USERDEFINEDRISK = COL6[1] * POINTVALUE[1] 

 

SIZING[1] has been assigned a measure of (dollar) volatility, which is a commonly used proxy for risk. This value will later be used on the Initial Size page as the risk component of the NEWCONTRACTS statement.
USERDEFINEDRISK has been assigned the value of actual risk, in dollars. This value now flows through to all keywords containing RISK, which are available for use on the Initial Size page for controlling risk (and which well explore later in this lesson), and on the Resize page.
Lets look a little closer at our new code; COL4 is assigned the value of the 34-day Average True Range, which is a measure of volatility, expressed in points. Click ATR for more information.
Next, yesterday's COL4 value COL4[1] is multiplied by yesterday's point value of the currently processing symbol in order to obtain the volatility in dollars;  the product is then assigned to the variable SIZING[1].

Discussion

Why did we use volatility? Its simply another way of looking at risk, and some traders prefer to use volatility, rather than actual risk, to size positions.

It is a common misconception that, "position sizing depends on the stop you pick." That's not necessarily true. Allowing stop placement to define the risk on a trade for the purpose of sizing positions is only one way to view the world.

There are many systems that don't use stops at all. For instance, how would you size positions for a moving average crossover system? You could calculate the magnitude of price movement that would cause the moving averages to cross over, but more likely (and more conveniently), you'd probably size trades by some measure of volatility. At this point, a lot of traders scream, "But that's not the same as actual risk!"  Well, thats true; They're not the same…and that's exactly the point.

While the actual risk of a trade is generally defined as the distance between two pricesin the case of NEWRISK, the entry price to the exit stop (for systems entering on a stop), or yesterdays close to the exit price today (systems entering on the open), or the close yesterday to the exit price yesterday, in the case of our current systemactual risk does not necessarily have an impact on how positions are sized. In most cases, it comes down to a matter of preference.

 

Back to the code; COL5 yields the difference in points between the closing price and the exit price, SMA_EXIT (a grid-column alias defined in Lesson 3).
COL6 takes the absolute value of COL5, so that the point difference (the risk in points), is always expressed as a positive number.
In the next line, yesterday's value of COL6 is multiplied by the point value of the currently processing symbol (instrument) to obtain the risk in dollars, and the product is assigned to USERDEFINEDRISK.

Why bother to calculate risk in this manner, when the keyword NEWRISK already exists for this very purpose? Remember, in order for NEWRISK to return a non-zero value, it is must be used in conjunction with the keywords BUYSTOP / SELLSTOP. But our current system exits trades on the open, using BUYOPEN / SELLOPEN:

Trade Entry

IF C[1] > LONG_ENTRY[2] THEN BUYOPEN         'long entry signal

IF C[1] < SHORT_ENTRY[2] THEN SELLOPEN        'short entry signal

 

Trade in Progress & Exit

IF C[1] < SMA_Exit[1] THEN SELLOPEN        'long exit signal

IF C[1] > SMA_Exit[1] THEN BUYOPEN        'short exit signal 

 

4Thus, we simply approximated a similar measure of risk, and assigned it to the variable USERDEFINEDRISK.
5Review:
NEWRISK is a function that can return Mechanicas internal definition of risk. It is the dollar risk per contract (or per share) of the trade being presented for initial sizing. For systems that enter on a stop, it is defined as the dollar value of the difference between the entry stop price and exit stop price. For systems that enter on the open, it is defined as the dollar value of the difference between the closing price yesterday, and the exit (stop) price today.
NEWRISK includes slippage and commission, unless USERDEFINEDRISK has been assigned a value (the value of USERDEFINEDRISK flows through to NEWRISK, and USERDEFINEDRISK excludes slippage and commission).
The measure of risk that we defined and subsequently assigned to USERDEFINEDRISK differs, in that it is the dollar value of the difference between the closing price yesterday, and the exit price yesterday. So in this regard, it serves as a reasonable approximation of the value NEWRISK would return had we used exit stops and relied on Mechanica's internal definition of risk.
6Save your work.
7From the Data menu, choose Symbol Manager, and under the Tag Symbols tab, make sure that the Pinnacle_Futures Data Page is still selected (checked), and that JY_REV is the only symbol currently tagged.
8Now, run the system.