## Integrating Position Sizing with TradeStation/MultiCharts

Improve your system testing results by adding position sizing to your TradeStation™ or MultiCharts strategy. The EasyLanguage™ add-in function PSCalc implements the different position sizing methods of Market System Analyzer (MSA). The PSCalc function is called from the code of your existing TradeStation/MultiCharts trading system. It calculates and returns the number of shares/contracts based on the account equity and the selected position sizing method. This makes it possible to optimize trading system and position sizing parameters simultaneously in TradeStation/MultiCharts. As demonstrated below, this can result in better trading performance than optimizing system and position sizing parameters separately.

PSCalc can be used either to back-test trading systems or in day to day trading to determine the number of shares/contracts for the next trade. In back-testing mode, the function accumulates the account equity after each trade and bases the number of shares/contracts on the accumulated equity (or accumulated profit for fixed and generalized ratio trading). For day to day trading purposes, the function uses the input value of the trader's current account equity to calculate the number of shares/contracts for the next trade.

### An Example: Optimizing System and Position Sizing Parameters Together

To illustrate the use of the PSCalc function, the following EasyLanguage system code is provided. This system, called PSExample3, is a simple breakout system, as might be used with the E-mini S&P 500 futures. (Note: The system is for illustrative use only and is not intended to be used for live trading.)

The first two inputs to the system relate to the trading rules of the system. The remaining inputs relate to the PSCalc function. The system enters at a fraction of the prior day's range from the prior day's high. The fraction of the prior day's range is given by the first input. The second input is the size of the money management stop in dollars. The remaining inputs are the same as the parameters of PSCalc, except that the TrRisk parameter is a variable rather than an input to the system. TrRisk, the dollar value of the trade risk per contract, is set to the size of the money management stop.

{
PSExample3 strategy
This simple system is designed to illustrate the use of the PSCalc
function for position sizing.

System: Buy at a fraction of yesterday's range from yesterday's high. Hold
1 day then look to exit on the first profitable open. Use a fixed money
management stop (nominally \$1000 in the e-mini S&P).

The number of contracts for each trade is determined using function
PSCalc.

Adaptrade Software
www.Adaptrade.com

Copyright 2005 - 2009 Adaptrade Software
}

Input: EntFrac    (0.75),    { multiple of prior day's range for entering }
StopSz     (1000),    { size of money management stop in dollars }
PSMeth     (3),       { position sizing method, 1 - 14 }
Param1     (5.0),     { Position sizing parameter #1 }
Param2     (0),       { Position sizing parameter #2 }
BackTest   (true),    { true for back testing }
StEqty     (50000),   { starting account size, \$ }
CurEqty    (50000),   { current account size, \$ }
MxLoss     (1000),    { largest 1-contract/share/unit loss, \$ }
MaxDD      (2000),    { largest 1-contract/share/unitdrawdown, \$ }
Stocks     (False),   { true if trading vehicle is a stock }
UseUnits   (False),   { true for trading in even units }
UnitSize   (1),       { # shares/contracts per unit }
UseMinN    (true),    { true --> # shares/contracts at least MinN }
MinN       (1),       { Minimum # of shares/contracts }
MaxN       (1000),    { max allowable number of shares/contracts }
InitMarg   (4000),    { initial margin per contract for futures }
MargPer    (100),     { margin requirement in percent for stocks }
NATR       (10);      { period for average true range }

Var:   EntPr      (0),       { Entry target price }
XitPr      (0),       { mm stop exit price }
TrRisk     (0),       { trade risk, \$ }
NCon       (0);       { number of contracts }

TrRisk = StopSz;

{ Entry conditions }
NCon = PSCalc32(PSMeth, Param1, Param2, BackTest, StEqty, CurEqty, TrRisk,
MxLoss, MaxDD, Stocks, UseUnits, UnitSize, UseMinN, MinN,
MaxN, InitMarg, MargPer, NATR);

EntPr = H + EntFrac * (H - L);

If C > C[1] then
Buy NCon contracts next bar at EntPr Stop;

{ Exit conditions }
Sell("MMStop") next bar at EntryPrice - TrRisk/BigPointValue stop;

If BarsSinceEntry >= 1 and open of next bar > EntryPrice then
Sell("ProfOpen") next bar at market;

{ Value99 = WriteTrades32(TrRisk, 0, 0, NATR, 1, "C:\PSExample3-ES-WriteTrades3.csv");}

Placing the function parameters as inputs to the system makes it possible to optimize the position sizing within TradeStation using the built-in optimization feature of TradeStation. You can even optimize the system and position sizing parameters simultaneously. For example, in fixed fractional position sizing, the number of contracts depends on the trade risk. In this system, the trade risk is equal to the size of the money management stop. To illustrate, the size of the money management stop, StopSz, and the risk percentage, RiskPer, were optimized together using PSMeth = 3 (fixed fractional position sizing). BackTest was set to true for these tests.

The symbol was @ES (E-mini S&P 500 futures, continuous contract). The period was 1/2/2003 to 8/20/2004 with a look-back length of 1 bar. The initial account size (StEqty) was \$30,000, and \$75 was deducted per contract for slippage and commissions. For comparison, the system parameters were first optimized by themselves on a fixed contract basis. Three contracts were taken per trade. Based on net profit, the optimal parameter values were EntFrac = 0.8 and StopSz = 1700. These parameters produced the following results:

Net profit: \$14,887.50
Return on account: 49.6%
Profit factor: 2.29
Number of trades: 36
Percent profitable: 66.7%
Average trade: \$413.54
Max. consecutive losses: 2
Max. closed trade drawdown: 12.6%

Next, the stop size and the fixed risk (RiskPer) were optimized together with the entry fraction, EntFrac, set at the value of 0.8 from the prior, fixed contract optimization. In this case, a very different optimal stop size was found. With fixed risk position sizing, the best stop size was \$700 (compared to \$1700 with fixed contract position sizing) using a fixed risk percentage of 18%. The optimal results using these parameter values were:

Net profit: \$26,012.50
Return on account: 86.7%
Profit factor: 1.42
Number of trades: 39
Percent profitable: 61.5%
Average trade: \$666.99
Max. consecutive losses: 2
Max. closed trade drawdown: 40.2%

In practice, a risk percentage of 18% is far too high (notice the drawdown of 40%). However, even with smaller risk percentages, the optimal stop size was different than \$1700 using fixed risk trading. This illustrates that position sizing can interact with a system's trading rules and suggests that there may be merit in setting system parameter values and position sizing parameter values together.

In this example, the money management stop size was optimized. However, using the PSCalc function as illustrated here, any system input can be optimized together with any position sizing parameter. If you go through this type of analysis with your own trading system, it's recommended that you run the results through a Monte Carlo analysis, such as the one available in Market System Analyzer, to confirm that your chosen position sizing parameter values are reasonable.

As with any optimization, you should have a sufficient number of trades to avoid over-fitting the system to the market data. You can use the significance test feature of Market System Analyzer to help determine if this is the case. In addition, out-of-sample testing is recommended after optimization.

To use PSCalc to calculate the number of contracts for day to day trading purposes, set BackTest = false and set CurEqty to the current value of your account equity. In TradeStation, the number of shares/contracts for the next trade will be specified in the Quantity column of the Strategy Orders tab. If using fixed or generalized ratio trading, make sure that StEqty is also set correctly so that the total profit (CurEqty - StEqty) will be correct. Before each new entry, make sure CurEqty is set to the current value of your account equity.

The PSCalc add-in for TradeStation/MultiCharts is included with the licensed version of MSA. Read more about PSCalc in the appendix to the user's guide for MSA.