Find Your Edge...
If you're still looking for an edge in the markets, mechanical trading systems are the best way to get it. Learn more.
Software for TradeStation
Improve your system testing results by adding position sizing to your TradeStation™ system. 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 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. 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 intended primarily for the E-mini S&P 500 futures.
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.
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. The number of shares/contracts for the next trade will be specified in the Quantity column of the Strategy Orders tab in TradeStation 8. 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 is included with the licensed version of MSA, a money management software application that includes many other features to improve your trading results.
Read more about PSCalc in the appendix of the user's guide for MSA.
To return to the main page for Market System Analyzer, click on the Next button at the bottom of the page or go to the online store below to purchase your own copy of MSA including the PSCalc function.
Download a fully functional trial version of Market System Analyzer. Evaluate MSA for up to 30 days. Click here to download now without obligation.
Did you know?
The PSCalc EasyLanguage add-in is included with Market System Analyzer, a stand-alone money management application. When you purchase Market System Analyzer, you'll get the code for the PSCalc function as both a text file and a .eld file. The code is open (unlocked) and commented. The PSCalc function is described in the user's guide for Market System Analyzer.
If you'd like to be informed of new developments, news, and special offers from Adaptrade Software, please join our email list. Thank you.
For Email Marketing you can trust
Copyright (c) 2004-2019 Adaptrade Software. All rights reserved.