# ThinkorSwim Number of Shares Available to Buy

#### Gabrielx77

##### Active member
Here's a label that everyone can add if they quickly want to see how many shares they can buy with a certain amount of money instead of having to use the calculator; this is for the amount of shares at the 5 min. high +\$0.01. You can change your balance amount, the time frame of how long the label adjusts and the time frames of the candles by switching the number AND word 5 to 1, 10, 15, whatever you want.

Code:
``````# shares_5min

#   from the high
#   during the first 5 minutes
#   divided into an account balance number
#
#   only_first_5_minutes , if it is no, then it calculates shares all day
#   timeframe  , select desired timeframe for finding the high price, default 5 minutes

def na = Double.NaN;

input account_balance = 1000;
input only_first_5_minutes = yes;

# first 5 minutes, EST
input period_start = 0930;
input period_end = 0935;
def firstfive = SecondsFromTime(period_start) >= 0 and  SecondstillTime(period_end) >= 0;

def timeframe = aggregationperiod.five_min;
def hifive = high(period = timeframe);

def adjprice = if (only_first_5_minutes and firstfive) then (hifive + stock_price_adjust) else if !only_first_5_minutes then (hifive + stock_price_adjust) else 0;

addlabel(yes, "account: " + account_balance + "  shares: " + shares,color.yellow);``````

Last edited:
Hello, is there anything similar to this but have the indicator use the account balance as the price changes produce and give the share size? Thank You.

Hello, is there anything similar to this but have the indicator use the account balance as the price changes produce and give the share size? Thank You.
I just posted a snippet of code similar to this the other day for another member...
Code:
``````def MaxShares = Round(GetTotalCash() / close, 0);

addLabel(yes, " TotalCash = " + GetTotalCash() + "  MaxShares = " + MaxShares, Color.WHITE);``````
Edited 2020-08-21: to change GetTotalCash to GetTotalCash()...

Last edited:
Very cool, thanks.

@rad14733 For some reason it didn't add anything and when adding the script it'll highlight the GetTotalCash in red. Can you help me out with this?

Appreciate it.

@rad14733 For some reason it didn't add anything and when adding the script it'll highlight the GetTotalCash in red. Can you help me out with this?

Appreciate it.
For some reason there was a Copy & Paste issue... Change GetTotalCash to GetTotalCash() and it will work as expected...

@rad14733 Oh i see what you did. Can it be modified so that it does not use the dollar amount in the account even after a trade has been placed. We can assume if there are two positions open on two different stocks the dollar amount of one cannot be used or calculated to place another trade. I guess on thinkorswim it'll be the option buying power which is the dollar amount available at any given moment. Don't know if I'm explaining myself. Thank You.

Last edited:
I would assume that the function would take prior trades into account, hence using "Total Cash" which should be the Net Value of your account that remains available for trading... Whether it works in On Demand or Paper Trading I can't say... Something to check on I guess...

I would assume that the function would take prior trades into account, hence using "Total Cash" which should be the Net Value of your account that remains available for trading... Whether it works in On Demand or Paper Trading I can't say... Something to check on I guess...
Thank you very much this works. I understand what you're telling me. Appreciate it and appreciate the prompt reply. Stay safe.

@Gabrielx77 I use something smart to this but I will check this one out. Is it compatible with options?

@Gabrielx77 I use something smart to this but I will check this one out. Is it compatible with options?
I don't believe so, but most likely if you open up the option you want to trade on a chart, it will work the same as shares.

Is it possible to
Modify this so it also divides by the ADR of the previous 7 days?

I just posted a snippet of code similar to this the other day for another member...
Code:
``````def MaxShares = Round(GetTotalCash() / close, 0);

addLabel(yes, " TotalCash = " + GetTotalCash() + "  MaxShares = " + MaxShares, Color.WHITE);``````
Edited 2020-08-21: to change GetTotalCash to GetTotalCash()...
can you please provide the code for getting the total # of outstanding shares for any stock?

can you please provide the code for getting the total # of outstanding shares for any stock?

As in total shares in your portfolio, or the total company float for a symbol...???

87k+ Posts
232 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?