Portfolio Functions In ThinkOrSwim

In my watchlist I'd like to add a column for the P/L % but have it in a specific color based on what the percentage is at. For example, if my % is higher than 75 then I'd like to change the color to green.

In theory it should be something like
def avg = GetAveragePrice();
def mark = GetMark();

then I'd do the calculations.

My problem is simply starting off. I cannot figure out how to get my average price and the mark. Does anyone know the function for that?? Thanks!
I wasn't able to make that work.
 

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

Hi, I am new to ThinkScript and can't find a way to do this. I would like to put a calculation in a custom column in the Position Statement section of the Monitor Tab that simply calculates 20% of the trade price. I think I've learned that I can use GetAveragePrice() in my calculation as the Trade Price. But I entered def TradePrice = GetAveragePrice() and got an error saying there is no such function. It also said I need at least one plot, but I'm not suing this for a chart.

Can anyone point me in the right direction. Also, where is the best place to learn thinkscript syntax, such as tutorials, websites, etc.

Appreciate your help.

Dave
 
Hey hey!

Would a script like this one be expected to work in terms of ThinkScript API syntax ?

Code:
def PLPercent = ((close - AveragePrice()) / AveragePrice()) * 100;

AddLabel(yes, AsText(PLPercent, NumberFormat.TWO_DECIMAL_PLACES) + "%",
    if PLPercent > 0 then Color.GREEN
    else if PLPercent < 0 then Color.RED
    else Color.GRAY);

I put this script into a Custom Column in the Column configuration model dialog.

My result under Monitor::Activity and Position::Equities and Equity Options"
In the new column "myPL%" I see "loading" on every position row.

Basically no result. Just says loading forever.

I am sure that I must be doing something wrong. Please ask me questions. :)
 
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.
In TOS, they have something called "Settled Funds". That will tell you how much you have left to trade with in your accounts.

Hope this helps!
 
Hey hey!

Would a script like this one be expected to work in terms of ThinkScript API syntax ?

Code:
def PLPercent = ((close - AveragePrice()) / AveragePrice()) * 100;

AddLabel(yes, AsText(PLPercent, NumberFormat.TWO_DECIMAL_PLACES) + "%",
    if PLPercent > 0 then Color.GREEN
    else if PLPercent < 0 then Color.RED
    else Color.GRAY);

I put this script into a Custom Column in the Column configuration model dialog.

My result under Monitor::Activity and Position::Equities and Equity Options"
In the new column "myPL%" I see "loading" on every position row.

Basically no result. Just says loading forever.

I am sure that I must be doing something wrong. Please ask me questions. :)

next time , make a lower study and test it.
that way you can see what is wrong.

ThinkScript is not the API . they are 2 separate things

AveragePrice() is not a valid function. next time if things don't work , look it up
https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Portfolio/GetAveragePrice
GetAveragePrice() is the function

if average price is 0, then you get an error.
i added a check to get around that.

Code:
#col_avgpr_color_lower

declare lower;

#def PLPercent = ((close - AveragePrice()) / AveragePrice()) * 100;
#def PLPercent = ((close - getAveragePrice()) / getAveragePrice()) * 100;

def ap = getAveragePrice();
def PLPercent = if ap > 0 then ((close - ap) / ap) * 100 else 0;

AddLabel(yes, AsText(PLPercent, NumberFormat.TWO_DECIMAL_PLACES) + "%",
    if PLPercent > 0 then Color.GREEN
    else if PLPercent < 0 then Color.RED
    else Color.GRAY);


addchartbubble(0, 0,
 getAveragePrice()
, color.yellow, no);
#
 
Zt51fad.png

The above are the portfolio script functions.
They are not available for use in watchlists, or as custom columns in the Monitor Tab or Positions or Activity Statements
read more about the other limitations with these functions:
https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Portfolio

The ONLY portfolio columns available are:
huzGf4r.png

Sadly no. These watchlist columns are not customizable or modifiable.


@yolo4theyacht @chewie76 @dhatpc @halcyonguy @dhatpc
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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