Position Size Calculator for ThinkorSwim

@bottomphishing and others - Thinkscript portfolio functions will not work if "advanced features" is not enabled for the account. I'd contact TD support through the support chat to turn it on.

Also -
GetNetLiq() " . . . will return N/A if chart property Show Extended-Hours Trading session is de-activated. To make sure this property is activated, navigate to Style -> Settings and then choose the tab that corresponds to the type of security you are currently analyzing: Equities, Options, or Futures. The Show Extended-Hours Trading session checkbox is located in the Axis area in the lower half of each of these tabs."
- taken from ThinkorSwim instructions
 
Last edited:
Thank you @Pensar
I added % targets to the labels on the chart. Instead of showing $0.00 when there is no position in the ticker how can I get the AddLabel to be "off"
I tried doing an if / then for color making it BLACK but its not working:

#Position Targets
def GetAveragePrice = GetAveragePrice();
def TargetPrice = Round((GetAveragePrice * .05) + GetAveragePrice); # Change Percent to 1 to 1
def TargetPrice2 = Round((GetAveragePrice * .20) + GetAveragePrice);
def TargetPrice3 = Round((GetAveragePrice * .50) + GetAveragePrice);
def TargetPrice4 = Round((GetAveragePrice * 1.00) + GetAveragePrice);


AddLabel(yes, " Targets- 5%: " + AsDollars(TargetPrice) + " | 20%: " + AsDollars(TargetPrice2) + " | 50%: " + AsDollars(TargetPrice3) + " | 100%: " + AsDollars(TargetPrice4), if GetAveragePrice <= 0 then Color.Black else Color.LIGHT_GREEN);
 
@bottomphishing Change the "yes" in the label to if Entry_ then 1 else 0. "Yes" simply is a boolean on/off switch for the label - for instance, if you were to put "no" the label would disappear. Using "1" in place of "yes" and "0" in place of "no" works as well, they're interchangeable. Just like using a light switch to turn on or cut off the lights.
 
I reverse engineered what I think the two labels show.

This is the output of that work.

X8Lk7qK.png


thinkScript Code

Code:
#
# PositionSizingCalculator
#
# Author: Kory Gill, @korygill
#
#

input RiskUnit = 100;
input AggregationPeriod = AggregationPeriod.FIFTEEN_MIN;

def highVal = high(period = AggregationPeriod);
def lowVal = low(period = AggregationPeriod);

AddLabel(
    yes,
    "High: " + highVal + " Low: " + lowVal,
    Color.Gray
    );

def diff = highVal-LowVal;

AddLabel(
    yes,
    AsDollars(RiskUnit) + " risk with " + AsDollars(diff) + " stop = " + Floor(Round(RiskUnit/diff)) + " shares",
    Color.Gray
    );

Link to the study

https://tos.mx/HwObLl

Thanks,
Kory Gill, @korygill

HI Kory. can you confirm this Risk Study , the High and LOW is based of the previous closed candle ?
 
@ronaknathwani the study shows values on the current candle using the specified aggregation period. set your chart to the same setting as the study and will display same values as the last bar on your chart.
 
@ronaknathwani the study shows values on the current candle using the specified aggregation period. set your chart to the same setting as the study and will display same values as the last bar on your chart.
ok ill take a look at it Monday, so what you saying is if i set both the study agg 10min and time frame 10min with a risk is $100, the previous bar (last bar) will be the high and low of what i what i will be risking off ?
 
This morning I executed a trade with a $.04 stop. Unfortunately, the trade turned against me and I was stopped out. While I was in the position, the stock wasn't volatile at all. No surges and no flash crashes. Despite that, when I was stopped out, my P/L showed a loss that was twice what it should have been based on what I entered into the Active Trader order entry window.

When I went back to review my order, it showed that a $.08 stop loss was submitted. For a moment I thought that I may have made a typo. I knew this was highly unlikely though, because I use a position sizer that automatically calculates my share size, limit offset, stop offset and entry price based on my max risk per trade. All I have to do is type what the tool calculates into the Active Trader Ladder. But even still, it's possible that I could make a typo.

After reviewing the trade execution details under the Monitor tab, I went back to my chart to review the Active Trader Ladder. And what do you know... My stop offset was indeed set to $.04. Since I hadn't taken any additional trades after this loss, it would be impossible for the stop offset to be set to $.04 if that wasn't what I submitted in my order.

After reviewing all of this I got on chat with TD Ameritrade to explain what happened, and of course... The said that there is nothing they can do to credit my account since there's no way for them to verify that an error was made on their behalf.

I'm really concerned about trading with Thinkorswim now, and I am only going to continue trading with them while video recording my screen during all trading sessions. Had I had that proof, I could have gotten them to credit my account for the $.04 difference (slippage) in the Stop loss they executed vs. what I submitted multiplied by the number of shares I purchased.

Thankfully, I was trading with a small risk/trade, so even though my loss was doubled, I didn't blow up my account or have a major setback.

Please, please, please protect yourself. There are several free screen recording programs you can use. I'm using Debut by NCH. They have a 30 day free trial, and then after 30 days it's still free, but it has a watermark on it, which doesn't really matter, since I won't be posting these videos publicly anywhere.
that's a LOT of slippage! yeah I trade with as little as a 5c STOP INTRADAY and tell you what I'm concerned about this amount of slippage that you discussed here. now I'm trading at 2:1 thus the same thing could occur on the LIMIT side. yeah THAT is a LOT of slippage because it can cost you on the PROFIT side as well. now if you're strategy still wins (my strategy takes more loser trades than winning ones but I win because Its a 2:1 trade) then you might be ok but I don't like it as this is huge amount of slippage. however say I take 4 losers and 2 winners.. do I come out even? well I better come damn close to even or this is not gonna work for me.
 
I'm looking for a position sizing calculator for ThinkorSwim that can calculate how many shares I can buy and define my risk level with stop losses.

ryAiY4P.jpg

vkolSK4.jpg


I've purchased stuff like this before from other developers in the past and they stopped working after awhile. I'm burned out from paying for poorly supported scripts, nst amount ot to say that the one from easycators is.
I find this easier, I can reference with a glance on my chart the first amount of shares to use, changes can be made in the code for amount considered.... Post#33 https://usethinkscript.com/threads/position-size-calculator-for-thinkorswim.588/page-2#post-25983
 
Last edited by a moderator:
I got an idea to spice things up.
You would enter how much you want to profit for each trade in the study settings, and it would draw an position entry line that moves with the price & a position exit line that also automatically adjusts. The study would tell you how much of you balance you would be risking if you were to enter that trade.

For instance if you want to make 100 or 200 dollars per trade the indicator would tell you how much would would the underlining price would have to move. With those price line you should quickly see if you're being too greedy because those lines could be used in conjunction with a auto trend drawer study.
 
I got an idea to spice things up.
You would enter how much you want to profit for each trade in the study settings, and it would draw an position entry line that moves with the price & a position exit line that also automatically adjusts. The study would tell you how much of you balance you would be risking if you were to enter that trade.

For instance if you want to make 100 or 200 dollars per trade the indicator would tell you how much would would the underlining price would have to move. With those price line you should quickly see if you're being too greedy because those lines could be used in conjunction with a auto trend drawer study.

Alright, I'll now create such a study, or attempt to do so.
 
The blue lines is how much the stock would have to move to reach 100 dollars of profit with a shares bought with a purchasing budget of 10,000 dollars.


I have another study up that adds three lines. - https://usethinkscript.com/threads/...price-to-existing-thinkscript.5705/post-58122

The 3 white lines indicate the current price & how much a stock would have to increase to make a 1 % move.
  • I would really like to know how to get that blue line indicator ("how much the stock would have to move to reach $100 profit with shares bought).
  • Thank you for posting the indicator for the 3 white lines.
  • I am having trouble understanding how this script (https://tos.mx/c8K389v) works. I understand how your "blue lines" indicator is supposed to work, but this script (https://tos.mx/c8K389v) is not that. Unless there is something I am missing. Thank you for your help.
 
I reverse engineered what I think the two labels show.

This is the output of that work.

X8Lk7qK.png


thinkScript Code

Code:
#
# PositionSizingCalculator
#
# Author: Kory Gill, @korygill
#
#

input RiskUnit = 100;
input AggregationPeriod = AggregationPeriod.FIFTEEN_MIN;

def highVal = high(period = AggregationPeriod);
def lowVal = low(period = AggregationPeriod);

AddLabel(
    yes,
    "High: " + highVal + " Low: " + lowVal,
    Color.Gray
    );

def diff = highVal-LowVal;

AddLabel(
    yes,
    AsDollars(RiskUnit) + " risk with " + AsDollars(diff) + " stop = " + Floor(Round(RiskUnit/diff)) + " shares",
    Color.Gray
    );

Link to the study

https://tos.mx/HwObLl

Thanks,
Kory Gill, @korygill
OK I've downloaded and installed this script. But how do I implement it in my TOS trading? How do I change amounts? Sorry I'm very new at this.
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
419 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.
Back
Top