## Integrating Position Sizing with TradeStation/MultiCharts

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.

}

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;

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
Percent profitable: 66.7%
Max. consecutive losses: 2

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
Percent profitable: 61.5%