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

# calculate shares to buy
#   from the high
#   during the first 5 minutes
#   with an adjustment added to the price
#   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 stock_price_adjust = 0.01;
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;

def shares = if adjprice > 0 then round(account_balance/adjprice,1) 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:
@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.
 
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?
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
434 Online
Create Post

Similar threads

Similar threads

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