Welcome to NexusFi: the best trading community on the planet, with over 200,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- discounts are available after registering.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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!
Can you help answer these questions from other members on NexusFi?
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.
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."
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.