Portfolio and Risk Management


Although this site is focused on thinkScript, I would like to open a discussion on Portfolio and Risk Management. We all trade, or plan to. Even though these topics are not directly related to thinkScript, I strongly believe that it is critically important for an intraday trader, swing trader or long-term investor to be aware of. thinkScript does offer us tools to assist in these areas.

I am a swing trader, with holding periods from a few days to a few weeks to 2 – 3 years. I trade Intraday to Weekly charts. I trade stocks, options and have traded futures and have been trading since 1992. I am also an engineer and a certified Lean Six Sigma belt holder. This history and training drives me to continuously improve, and this means constantly learning and analyzing.

I believe that the turning point in my trading career was when I started thinking about all my existing positions, not just where I was going to find the next one. That prompted me to learn more about diversification, risk management (trade exposure), sector analysis and balance, and method analysis.

I hope that this doesn't sound teachy.

It doesn't matter how much you have to trade. You just need to apply sound Portfolio Management as the professionals do. (disclosure - I am not a Professional trader.) Position size is one of the keys to managing my portfolio. The number of positions and position size is governed by individual trade risk, maximum desired portfolio risk and account size. Understanding and applying these concepts improved the overall performance of my portfolio.

Here are my rules: (no implied recommendation)

1. Diversification

Work up to a targeted number of positions. Many theorists say that an optimum portfolio contains 16 positions or more, across many sectors. More than 30 - 35 positions gain little in overall diversification.

Here is an example:

If one starts with $1000, trade 1 or 2 positions. When balance = $2000, trade 2 positions. When balance = $5000, trade 4 positions. When balance = $10,000 trade 8 positions, balance = $20,000 trade 16, balance = $50,000 trade 30.

Keep in mind that there is nothing wrong starting with one position, just follow the other rules.

2. Risk Management / Trade Exposure

Don't let a single trade lose so much that you “go out of business”. You manage your overall exposure through proper Trade Sizing and discipline following your exit methodology.

Maximum portfolio risk per trade should be 1% to 2% of the account balance. For accounts less than $ 20,000 you can use 2% if you want to be aggressive. As your account grows larger, move toward limiting your risk per trade to less than 1%.

For example: acct size = $20,000, 1% = $200 risk per trade, 2% = $400 risk per trade. If your account is only $1000, risk $20 per trade. This may mean only trading 1 share.

I determine Trade Size this way:

Trade risk: (Entry Price - Logical Stop) * #Shares

Trade Size (#Shares) = $Trade Amount / (Entry Price - Logical Stop)

For example: Acct Size = 20,000, desired # positions = 16 then max position value = 20,000/16 = $1250 per trade

If Entry Price = $40/share, Logical Stop = $35/share.
Therefore, Max Shares based on Trade Exposure = $1250 / (40-35) = 250 Shares

- Maximum position size

Your maximum position amount is $1250 so, Max Shares based on Diversification = Position Amt / Entry Price = $1250 / $40 = 31 Shares

Trade Size is the lesser of Max Shares based on Trade Exposure or Max Shares based on Diversification. This is 31 Shares, set by Diversification.

If you were trading $12,000 per position, then Max Shares based on Diversification = $12000/$40 = 300 Shares. The lesser of this or the Max Shares base on Trade Exposure is 250 Shares set by Trade Exposure, not 300.

In this day of zero commissions, there is no reason for you not to trade 1 or 4 shares of a stock if that is what your trade sizing says is correct.

3. Sector Analysis and Balance

This is more related to longer term swing traders and investors, but affects short term traders too. Over-exposure to one sector can have unintended consequences. At the time of writing this, the Tech sector is strongly outperforming all other sectors. This was the case in 1998 through 2000 while the .com bubble was inflating. One of my colleagues had loaded up on internet and data center companies and pretty much ignored other sectors and industry groups. When the bubble burst, he kept saying “But PSI Net is worth more than this! It can't go down any more!!” PSI Net went bankrupt, as did more than ¾ of the companies that he owned. Not only does this speak to diversification, but to knowing when you will exit a trade – AND DOING IT!

I try to have holdings in all 11 S&P Sectors, but not in equal portions. Everyone's preferred sector allocation will be different. Sometimes, I don’t have 1 or 2 of them represented, but I look for the right opportunity to add them. The % sector allocation varies based on their overall performance. As a sector’s relative balance grows, I trim deadwood to get back to targeted allocation. When a security has a big run, I typically take 20% - 30% of the position off to book profit and help balance allocation.

Even if you are a very short-term trader, it is easier to make money if the stock’s sector is trending in the same direction as the stock that you are trading. Keep an eye on how sectors are performing. There are some tremendous studies on this site that makes it easy to see which sectors are more bullish or more bearish than others.

@markos created this great study: https://usethinkscript.com/threads/sector-rotation-indicator-for-thinkorswim.845/

Here are a couple that I use daily: https://usethinkscript.com/threads/alternate-sector-analysis-study-for-thinkorswim.2974/#post-27782

4. Method Analysis

Do you have an edge? Unless you are a buy-and-hold, long term investor, you need to know if you have an edge when you make trade decisions based on your methodology or system. Do you know what your system is? Have you defined trade size, entry strategy, and exit strategy? Do you know how your trade method performs? What is the win/loss ratio? What is the Expectancy Ratio or Profit Factor? What is the maximum draw-down over an extended period? What is longest losing streak?

This sounds daunting, and it is if you have to manually do the backtesting that is required to know your system. Now, there are some fantastic tools that help you test and understand your system. Note that it is best if you keep the same data about your actual trades as you do on the backtested trades. You can see if your results match what the system generates. This gives you an idea if you are truly following your system or if the market conditions have changed and the system may not be working as well as it once did. I have thousands of trades documented for each of my strategies across the years.

The best tool for those of us on this website is the ToS strategy. When you create strategies, you are forced to define your entry and exit rules explicitly. I strongly encourage you to design your strategies so each trade is for the same $ amount, not the same number of shares. This ensures that a trade from 10 years ago at $25/share can be compared to a trade from last week at $280/share. (same $ invested, same risk taken)

Don’t just focus on how you get into a trade. Arguably, exits are more important than entries. Exits allow you to control your current, real risks. Look at a variety of exit types to find one that matches your trading personality. It can be a simple trailing stop, or something more complex such as Chandelier or Swing Highs and Lows.

There are 2 major benefits that I see using strategies. The first is that you are forced to explicitly define your system, entries and exits. What I think is equally important, is that you can get a strategy report for the system directly from ToS which shows the trades taken and their results..

Accessing this report is simple. ‘Right Click’ a strategy entry or exit arrow or description. Select ‘Show Report.’


...and this is the report that you receive:


This gives you all the data you need – entry signal name, exit signal name, size, entry and exit price, trade P/L and time in the trade. You can export this in .csv format so you can start your analysis.

Thanks to @Zachc, this is now so much easier to process. See the fantastic set of tools that he created here:

The Stats page from Zach’s spreadsheet is shown here. I have highlighted a few fields. Note that I changed the name of one of Zach’s fields to “Expectancy Ratio” in my copy, as I have been using that term for many years. Yours will be called "Profit Factor", and is in the same place on the report.


This report answers the questions you need answered.

I first look at Expectancy Ratio (ER). If ER is less than 1, you will lose money trading this strategy. The higher the number, the more profitable the strategy. I believe that Expectancy Ratio (ER) is the single most important statistic about your system.

In Tharpe’s book “Trade Your Way to Financial Freedom” he suggests that a strategy’s ER should define the amount of margin that you should use, as follows:


In Deel’s book "Trading the Plan - Build Wealth, Manage Money, Control Risk" he proposes that your system’s performance must also be factored into how much you are investing or trading in the market altogether.


Next, take a look at “Worst Losing Streak” in the stats. In this example, even though you have a pretty good expectancy ratio, could you handle 12 losing trades in a row? Would that cause you to stop trading this system, just before the 8 winning trades come? Can you cope with a 30% drawdown? If not, keep working on your system before you trade it.

5. Method Improvement

Use these tools to understand and improve your system.

You may find that a strategy that you are trading doesn’t make money over time. You may find that you make more money actually trading the method than the strategy is making. If this is the case, are you passing on some of the trades that the strategy takes? Is there something that you see in real life that tells you to pass on a trade? Are you changing where you exit trades compared to the strategy? Can you code that into the strategy to improve its results?

As I mentioned earlier, it is important to find the best exit rules as possible. You may find that a wider stop makes you more money. I have found this to be true for me when swing trading. You may also find that a tighter stop saves you money. This may be optimum if your system has a lot of losses and a few very large wins. Are you using the best kind of stop? I test at least three of my favorite stops on each entry method that I use to see which is best suited for that system.

Be very careful not to over-customize study settings. If you chase the 'perfect' settings you may find yourself with a system that only works for the past 10 years (the period tested) but then can't perform over the next few years. Unless you have found a unique way to use an indicator, I would suggest using them with the default settings +/- 1.

Trading the market is tough. We are all very small fish in a very large pond. Institutional investors and programmed trading pushes stocks up and down. It is our job to identify and be on the right side of the market and to protect our capital.

Hopefully some of the ideas presented here give you something to think about.

I always welcome comments.

Trade Well!
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Wow, this is great post... as somebody new to trading this is great to establish portfolio and risk managements strategy. Will definitely use above notes /steps and frameworks to manage and establish risk management strategy.
These are the kind of post's that bring balance and perspective to the forum. Very well thought out....I appreciate you sharing!
Hey I am curious if anyone knows how to essentially accumulate shares while backtesting. Like if I started with 1000 dollars, I can buy x amount of shares of some stock. I then sell the shares at a profit/loss, and use that new cash value for the next purchase. In regular code this is simple because variables can be initialized as well as conditional statements not needing an "else". I am kind of newer to think script. All I can really think of is to somehow create a counter variable that would start at zero, and become higher if a buy is ordered, but because of the "else" statement being mandatory. I keep trying to create overly complex counters but since I can't initialize any variables I can't start with a "if counter = 0" argument. Any help would be appreciated. Thanks everyone.
@zindahl If you want to auto-increment trade size based on current assets you would need to use a state variable, start with however many shares that $1,000 bought, increment or decrement the total assets based on selling price, calculate and store total assets complete with remaining balance, rinse, repeat, always buying as many shares as Total assets can afford... So, to answer your question, Yes, it can be done... It would require a substantial amount of code... Perhaps the easiest way to do this might be to potentially tweak the FloatingPL Study... Perhaps not... Just food for thought... Heck, there might even be code written already that I'm not currently aware of...

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
403 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.