Build Your Own Trading System: Part Two
Teresa, February 8, 2008 @ 3:38PM ET | Link | RSS | Read via Email | Start a Discussion
The Greek mathematician Archimedes once said, “Give me a place to stand on, and I can move the earth.” Apparently many traders believe they can do the same.
In Part One, we made a checklist of the factors that must be addressed by any trading program:
- leverage
- position sizing (and pyramiding)
- security/time frame selection
- entry criteria
- exit criteria/stop placement
Leverage is at the top of my list because it is the defining factor that determines how long a trader can expect to stay alive. Leverage undermines traders, both big and small:
[Long Term Capital Management]’s trading strategies were secret. …One thing was disclosed. LTCM used a lot of leverage. That was how they were able to obtain better-than-market returns from a nearly efficient market.
…In 1996 one of LTCM’s investors spoke by phone with several of the partners. …[he] learned that the fund was using leverage of about thirty times. For every dollar of investor money, the fund borrowed $29 more. — Fortune’s Formula
Hedge funds employing 20:1 leverage routinely go bust. Failure is typically not due to lack of skill; it happens because the higher the leverage, the smaller the adverse price move needs to be in order to wipe out the capital in an account.
A minimum of US$25,000 is required for active stock trading. Switching to options, futures, Forex or CFDs for the sole purpose of circumventing this capital requirement makes little sense. The reason is leverage. The higher the leverage, the larger the position size.
If you are trading Forex at 1:100 or can barely make intraday margin for e-mini futures, pray for a miracle that you will succeed where hedge funds failed. But you don’t have to believe me: code it up and see for yourself.
Doing it Right
By default, TradeStation allows users to select a fixed number of shares/contracts per trade (assumes that you can come up with the money necessary to buy X shares every time, regardless of stock price) or a fixed amount of money to deploy per trade (assumes unlimited funds, no margin). These are not real-world conditions.
NOTE: Tharp’s “R” and The Turtles “N” suffer from the same problem: the amount of capital required is open-ended and does not address the leverage issue.
One way to solve the problem is to turn the amount of capital the trader contributes and the amount of leverage he plans to use into inputs. This can be accomplished with a few lines of code. This approach also allows the trader to calculate return on capital.
The Code

How much leverage are you using?
Inputs: OwnCapital(25000), PercentOwnCapital(50);
Variables: nMarginFactor(0), Num_initial(0);
OwnCapital = the amount of cash the trader contributes
PercentOwnCapital = Buying Power/OwnCapital
For example, if OwnCapital = 25000 and PercentOwnCapital = 50, the trader would have buying power of $50,000 for the first trade. Another example: A pattern day-trader with OwnCapital = 25000 using 3:1 intraday margin would have $100,000 buying power, hence PercentOwnCapital = 25.
Next, since TradeStation keeps track of the account equity, we can use the reserved word NetProfit in our calculations. For example:
nMarginFactor = PercentOwnCapital * .01;
If Close > 0 Then
Num_initial = (OwnCapital + NetProfit) * (1/nMarginFactor) / (Close * BigPointValue)
Else Num_initial = 0;
I then add a couple more lines to perform a sanity check to make sure that the system never deploys more than margin allows.
Pyramiding can get a little tricky because several ducks must be lined up before adding to an existing position. First, the existing position must be profitable, or else there is no increase in account equity to play with. Second, the account must make use of margin in order to tap into the increase in equity. Third, traders may wish to impose additional conditions (above and beyond a simple increase in equity) before pyramiding.
TradeStation reserved word OpenPositionProfit becomes part of the equation. The way I do it is to calculate the maximum allowable position based on the account equity:
If Close > 0 Then
Num_max = (OwnCapital + NetProfit + OpenPositionProfit) * (1/nMarginFactor) / (Close * BigPointValue)
Else Num_max = 0;
Once again, I add a couple more lines to perform a sanity check to make sure that the system never deploys more than margin allows. Once Num_max is known, we use the TradeStation reserved word CurrentShares OR CurrentContracts to calculate the number of shares/contracts we can add:
Num_add = Num_max - CurrentShares;
The first pyramid is pretty easy; repeat pyramids may require a bit more code. Don’t forget to add Num_max(0) and Num_add(0) to the list of variables.
It’s all pretty simple; to think that commercial vendors refuse to add this is an indictment of their business practices. But then again, it pays to ignore the issue since “assumption of unlimited capital” guarantees that their systems will never go bankrupt like their users.
More Articles from Our Blog
- Trading Ideas for Thursday
- Trading Ideas for Wednesday
- Portfolio Strategy for July 1
- Trading Ideas for Tuesday
- Portfolio Strategy for June 30
- Trading Ideas for Monday
- Trading Ideas for Friday
- Trading Ideas for Thursday
- Podcast: The Prophets of Gloom
- Trading Ideas for Wednesday
Recent Comments and Discussion
- Mark @ 5:54 AM 07/02/2008 (Read More...)
Richard- $TRAN action has not been good. T, yesterday’s action had the feel of “short squeezing” to me. Not that rallies... - Richard @ 12:31 AM 07/01/2008 (Read More...)
The Plywood Indicator. I note the BNSF RR cars that travel from Canada to the US along my Pacific Coast bike... - Richard @ 12:28 AM 06/25/2008 (Read More...)
The “Official Head & Sholders” has reappeared on Marketwatch.com - Teresa @ 2:29 PM 06/23/2008 (Read More...)
No, the conditions for the swings are laid out in advance, and once they are satisfied, then the line is... - Teresa @ 1:56 PM 06/23/2008 (Read More...)
Dennis: I use the TWS Portfolio Trader to rebalance; it gets the job done at (I set it to) “market”....
Join the Discussion
Portfolio Strategy clients: Please log in and the text box will automatically appear right here for you to join the discussion.