NexusFi: Find Your Edge


Home Menu

 





ThinkScript Portfolio Functions Broken?


Discussion in ThinkOrSwim

Updated
    1. trending_up 7,844 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
kula
Houston Texas
 
Posts: 2 since Sep 2016
Thanks Given: 0
Thanks Received: 0

Hi,

Has anyone had success with the ThinkScript Portfolio functions? GetAveragePrice(), GetQuantity(), or GetOpenPL()? TOS keeps giving me no such function errors when trying to use them.

I'm trying to make a simple script on a watchlist or marketwatch column that takes the OpenPL / Trade Price * 100 so I can easily see the % of profits for my covered calls and naked puts so I know if I should close them out if I get good gains and have plenty of DTE. Problem is that I can't seem to get any qty, price, or PL data from my current positions (though I can get all kinds of other data). Is this possible or does TOS have these functions locked down? If so, does anyone know of a clever workaround?

Any help would be greatly appreciated! Thanks!


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
White House Drops First Alien Files Today -- Market Says …
Prediction Markets & Event Contracts
Powell in 48 Hours: Word Markets Give 78% on Inflation, …
Prediction Markets & Event Contracts
Iran Airspace Contract Surges to 33.5% as Project Freedo …
Prediction Markets & Event Contracts
Ninjatrader users - good CONNECTIONs post and article fr …
NinjaTrader
CFTC Opens First COT Report Review in 20 Years -- Asks W …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Big Mike in Ecuador
205 thanks
Sober Journey With S&P
21 thanks
30 Sessions
20 thanks
Volume Indicators
8 thanks
Thanks Mike. Godspeed.
7 thanks
  #2 (permalink)
kula
Houston Texas
 
Posts: 2 since Sep 2016
Thanks Given: 0
Thanks Received: 0

Ok, I figured out that the portfolio functions only work in custom studies for the chart. I've got my percentage showing as a label on the chart, but anyone know of a way to get it into a column on the watchlist or marketwatch grids? I can't use those functions or my custom study outside of the chart for some reason. It's silly, because I can add the individual fields that I want to the MarketWatch grid, I just can't use any of those fields for calculation.


Reply With Quote
  #3 (permalink)
Alcoa1
Dallas
 
Posts: 1 since Aug 2017
Thanks Given: 0
Thanks Received: 0


As a test of the function GetAveragePrice, I generated this ThinkOrSwim script
def AP = GetAveragePrice();
plot AP_ = AP;

Here's the script.
The output for AP doesn't make any sense.
Does anyone understand it?


Attached Thumbnails
Click image for larger version

Name:	TOS_Study_GetAveragePrice.jpg
Views:	525
Size:	136.9 KB
ID:	240172  
Reply With Quote
  #4 (permalink)
 
Fi's Avatar
 Fi 
NexusFi
 


Alcoa1 View Post
The output for AP doesn't make any sense. Does anyone understand it?

@Alcoa1,

The thinkScript GetAveragePrice function is one of those portfolio functions that looks straightforward but has a bunch of hidden requirements that'll trip you up.

Here's what's likely going on with your nonsensical output:

1. You need an open position. GetAveragePrice() returns the average fill price for whatever symbol is on the chart -- but only if you're currently holding a position in it on the selected account. No position = garbage data. If you ran this on a symbol you weren't actively holding, that's your answer right there.

2. Price type matters. These thinkScript portfolio functions (GetAveragePrice, GetOpenPL, GetQuantity) only work with the LAST price type. If your chart is set to MARK, BID, or ASK, the output goes sideways.

3. Aggregation period restrictions. They only work on specific timeframes -- 1 min through 1 hour, or daily. Anything else and the function won't return valid data.

4. Chart studies only. As kula discovered earlier in this thread, these functions are restricted to chart studies. They won't work in watchlist columns or the Monitor tab.

Important update for anyone finding this thread today: Since Schwab completed the ThinkorSwim migration in May 2024, the custom scripting portfolio functions (GetAveragePrice, GetOpenPL, GetQuantity) have been deprecated. They no longer exist on the current Schwab-TOS platform. The workaround now is to use the built-in portfolio columns in your watchlist or detach the Monitor tab to track positions and P&L -- just not through custom thinkScript anymore.

For your original test, try running that script on a symbol where you have an active position, on a 5-min or daily chart, with price type set to LAST. That should give you a clean average price.

-- Fi
"The function that returns nothing is still telling you something -- you just have to know what question it's actually answering."


Learn more about Fi AI trading companion
IMPORTANT: I can make mistakes! Always verify data before relying on it.

Please leave feedback here. You can disable my ability to reply to your posts by placing me on your ignore list.

Fi provides educational information on a best-effort basis only. You are responsible for your own trading decisions and for verification of all data. This message is not trading advice.
Reply With Quote




Last Updated on February 9, 2026


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts