Portfolio Functions In ThinkOrSwim

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
Having trouble using portfolio functions on your chart?
Here are the limitations of portfolio functions:
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Portfolio
WByOa8y.png

See the below thread for a myriad of ways that members use portfolio functions:
https://usethinkscript.com/threads/...labels-of-owned-equities-in-thinkorswim.7089/
 
Last edited:

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

I'd like to know this too, and also stock buying power for margin accounts. I can't seem to dig anything up.
 
Having trouble using portfolio functions on your chart?
Here are the limitations of portfolio functions:
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Portfolio

See the below thread for a myriad of ways that members use portfolio functions:
https://usethinkscript.com/threads/...labels-of-owned-equities-in-thinkorswim.7089/
@MerryDay Do you know if total cash represents "Available Funds for Trade"? I cannot locate a key or definition for these. Thank You for the reply by the way.
 
Last edited by a moderator:
@MerryDay Do you know if total cash represents "Available Funds for Trade"? I cannot locate a key or definition for these. Thank You for the reply by the way.
"Available Funds for Trade" == The amount of money available to purchase securities in your brokerage account. It includes your money market settlement fund balance, pending credits or debits, and margin cash available (if approved for margin).

"GetTotalCash" is ONLY the actual cash liquidity in the account.

In the example below the GetTotalCash == $4,161.34 The "Stock Buying Power" of $8,322.68 is not a data point that the ToS platform provides access to in our ThinkScripts.
nzfwJZ1.png


https://tlc.thinkorswim.com/center/...alCash#:~:text=total amount of cash available
hdWHkwP.png
 
# Simple Position Calculator
# Assembled by BenTen at UseThinkScript.com

def current_price = close;
def limit = GetTotalCash () / current_price;
AddLabel(yes, Concat("Shares Ava =", Round(limit)), color.orange);

I tried this. Got it to work but it is pulling from the wrong value. I guess TOS doesn't allow for me to point to Option buying Power or Available Funds for Trading (After getting advanced enabled the Available Funds for Trading is disabled) I can only use the Option Buying Power for the amount of funds I may trade.
 
Last edited by a moderator:
On a sell, in a 1st trgs seq, its easy sell 100%. But on a buy I don't know what the account buying amount will be when it is triggered. So for now I use an amount that I think should be available. I'm using studies to trigger these trades. Is there a way to get it to buy the full available amount in the account? Thanks for any help.
 
In a cash account. GetNetLiq/GetTotalCash aren't quite what I was looking for and couldn't find anything that would show 'Available Funds For Trading'. Thanks in advance.
I'd like to know this too, and also stock buying power for margin accounts. I can't seem to dig anything up.
On a sell, in a 1st trgs seq, its easy sell 100%. But on a buy I don't know what the account buying amount will be when it is triggered. So for now I use an amount that I think should be available. I'm using studies to trigger these trades. Is there a way to get it to buy the full available amount in the account? Thanks for any help.
Read through this thread to understand what choices are available on the ToS platform:
https://usethinkscript.com/threads/portfolio-functions-in-thinkorswim.11485/
 
What would happen if you used the "100%" option for "Buy"?
Would it be different for a margin account?

I'm using a 1st trgs seq conditional order. Sell 100% then buy 100%, wondering what would happen.
So far I have been using 100% for the sale and a dollar amount for the buy. But its not ideal.
I'm using studies for the trigger but not using "GetTotalCash", not sure how to. I may need to work on that.

I think you are saying it should work as long as "Use extended hours" is checked.
 
Last edited by a moderator:
What would happen if you used the "100%" option for "Buy"?
Would it be different for a margin account?

I'm using a 1st trgs seq conditional order. Sell 100% then buy 100%, wondering what would happen.
So far I have been using 100% for the sale and a dollar amount for the buy. But its not ideal.
I'm using studies for the trigger but not using "GetTotalCash", not sure how to. I may need to work on that.

I think you are saying it should work as long as "Use extended hours" is checked.
To use "GetTotalCash"
Ruby:
# Simple Position Calculator
# Assembled by BenTen at UseThinkScript.com

def current_price = close;
def limit = GetTotalCash () / current_price;
AddLabel(yes, Concat("Shares Ava =", Round(limit)), color.orange);

The trade would use 100% of the actual cash liquidity in the account.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Portfolio/GetTotalCash#:~:text=total amount of cash available
hdWHkwP.png


  • TDA does not provide the information required to calculate the balance of your margin account.
  • the documentation seems to state that extended hours must be turned on
 
Last edited:
To use "GetTotalCash"
Ruby:
# Simple Position Calculator
# Assembled by BenTen at UseThinkScript.com

def current_price = close;
def limit = GetTotalCash () / current_price;
AddLabel(yes, Concat("Shares Ava =", Round(limit)), color.orange);

The trade would use 100% of the actual cash liquidity in the account.
https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Portfolio/GetTotalCash#:~:text=total amount of cash available
hdWHkwP.png


  • TDA does not provide the information required to calculate the balance of your margin account.
  • the documentation seems to state that extended hours must be turned on
I don't understand how that gets into my conditional order.
 
I don't understand how that gets into my conditional order.
Without seeing your conditional order, it is not possible to answer your question.
Above is an example of the syntax using GetCash() in a script.
 
Anyone know why GetNetLiq would be returning NAN? Both the built in AccountNetLiq indicator and my own custom indicator are broken because of it.

Here is my custom indicator code.

input DollarAmountx = -100;
input NumberBar = 40;

def PLTodayx = If isNaN(GetNetLiq()) then 0 else GetNetLiq() - GetNetLiq()[NumberBar] ;

AddLabel(yes, " P:" + AsDollars(PLTodayx), if PLTodayx > 0 then Color.LIGHT_GREEN else if PLTodayx < 0 then Color.LIGHT_RED else Color.LIGHT_GRAY);

AddLabel(yes, "Goal" , if PLTodayx > 100 then Color.LIGHT_GREEN else if PLTodayx < -50 then Color.LIGHT_RED else Color.LIGHT_GRAY);

Alert(PLTodayx crosses below DollarAmountx, "********************************************************* --------MAX Loss reached! SELL!!!!!!!!!!! - NOW!!!!!!!!!!!------- ********************************************************", Alert.BAR, Sound.Chimes);

AssignBackgroundColor(if (PLTodayx < DollarAmountx) then Color.DARK_RED else Color.BLACK);
 
Anyone know why GetNetLiq would be returning NAN? Both the built in AccountNetLiq indicator and my own custom indicator are broken because of it.
Your code does not throw a 'Not A Number' syntax error.
You didn't provide enough information about what you are attempting to do, to provide any additional assistance.
7V0SU8d.png
 
I'm stumped trying to resolve these errors below... hope someone can spot my error...

16| Input CashInput = 100000.00;
17| def PrTy = getpricetype();
18| def Cash = if PrTy == last
19| then Cash == GetTotalCash()
20| else Cash == CashInput;

[The bold items were red-highlighted in the editor]

ThinkScript editor squawks as follows...
Expected double at 16:5
Expected double
No such variable: last at 17:23
Expected double at 16:5
No such variable: last at 17:23
 
I'm stumped trying to resolve these errors below... hope someone can spot my error...

16| Input CashInput = 100000.00;
17| def PrTy = getpricetype();
18| def Cash = if PrTy == last
19| then Cash == GetTotalCash()
20| else Cash == CashInput;

[The bold items were red-highlighted in the editor]

ThinkScript editor squawks as follows...
Expected double at 16:5
Expected double
No such variable: last at 17:23
Expected double at 16:5
No such variable: last at 17:23

i'm guessing that mashume was on the right track...

Whistlerr
a few things...

------
try to describe things better. your title suggests something completely different than what your code does. title should mention price type , not last candle. last candle infers the last candle on the chart, the right most candle.

-------
don't reuse the main variable within an if then, set equal to a value. just list the desired value

not this
then Cash == GetTotalCash()

just this
then GetTotalCash()

-------

if checking a type value, append that value to the end of the main variable with a period
pricetype.last

and compare it to something
if getpricetype() == pricetype.last then


when i set my chart to day, i get values.
i am not familiar with these functions and have no other advice for this.


Code:
Input CashInput = 100000.00;

def Cash = if getpricetype() == pricetype.last then GetTotalCash()
 else CashInput;

addlabel(1, "cash start " + CashInput , color.cyan);
addlabel(1, "cash " + cash, color.cyan);

input test1 = yes;
addchartbubble(test1, low,
cash
, color.yellow, no);
#
 
I find that I am only able to use these functions in chart studies. When I try to use them for custom columns, they are not available. Is this per design or does my particular installation have a bug? I'd like to be able to at least use GetQuantity() for a custom column on my Activity and Positions subtab.
 
I find that I am only able to use these functions in chart studies. When I try to use them for custom columns, they are not available. Is this per design or does my particular installation have a bug? I'd like to be able to at least use GetQuantity() for a custom column on my Activity and Positions subtab.

Correct. The thinkscript portfolio functions are not available in custom columns.
Instead of GetQuantity() ; you can use Position QTY watchlist field

Here are the portfolio functions available for watchlists
https://tlc.thinkorswim.com/center/...=Nuts and Bolts-,Position Data,-in Watchlists
To see all the portfolio watchlist fields available:
1. click on the down arrow (to the right of the search box)
2. scroll down to Portfolio
RDGUs1g.png
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
502 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