Dollar Amount divided by Share Price Label

G

Gabrielx77

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

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.
 
rad14733

rad14733

Active 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:
B

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.
 
rad14733

rad14733

Active 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...
 
B

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

rad14733

Active 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...
 
B

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.
 

Similar threads

Top