number of days a position has been held WATCHLIST COLUMN

Solution
Portfolio functions are available in the watchlist
vKKTFXj.png

Go to customize
Scroll down to portfolio


Those are all that are available.
HivrjYS.png

They are only available as watchlist columns.
ToS does not provide the ability to interact with them in a watchlist script

@markallenwilson1016 @mashume @rad14733
Something like this might work:

Code:
def qty = GetQuantity();
def counter = if qty != 0 then counter[1] + 1 else 0;
plot open_position_duration = counter;

The reason I didn't use a sum() is that I only want to know the duration of the most recent open position, not some total of days in a position over the last year or whatever.

I don't use watch lists, so I'm not sure I remember how to make a column, but this should get you some of the way there.

-mashume

https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Portfolio/GetQuantity
 

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

I appreciate the reply and help. Tired the code but I could not figure out why it red flagged the first line. Understand you don't use watchlists, but any idea what the issue may be. Also, begs the question, what do you use to manage your potential trades, investments, etc.
 
I appreciate the reply and help. Tired the code but I could not figure out why it red flagged the first line. Understand you don't use watchlists, but any idea what the issue may be. Also, begs the question, what do you use to manage your potential trades, investments, etc.
I don't have any active positions these days that I manage... actively. When I did trade, I traded futures, and even then mostly /ES or /MES and /6E or /M6E. Occasionally others, but mostly those two. You don't need much of a watch list if you're just making trades on the same futures over and over. ;-)

As for why the red on the first line:
Jr43soB.png

I hadn't realized that thinkScript Portfolio functions aren't always available. See this post:
https://usethinkscript.com/threads/...thinkorswim-are-now-working.18808/post-141972
for the sad realization that this has been an issue for a while.

Oh well.

happy trading,
-mashuma
 
@mashume While the results of some Portfolio functions may not be available you should never get a syntax error within a script due to unavailability... Your code should remain error-free and only a lack of results from a function call should occur...
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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