# Dollar Amount divided by Share Price Label

#### 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:

#### betogmgf

##### New member
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.

##### Well-known member
VIP
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:

#### RickAns

##### Active member
VIP
Very cool, thanks.

#### betogmgf

##### New member
@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.

##### Well-known member
VIP
@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...

#### betogmgf

##### New member
@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:

##### Well-known member
VIP
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...

#### betogmgf

##### New member
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.

#### stockscouter87

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

#### Gabrielx77

##### Active member
@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.