Skip to content

ivelin/thinkorswim-apps

Repository files navigation

Thinkorswim Apps

Various experimental studies and strategies written in Thinkscript for users of the Thinkorswim investment platform.

USE AT YOUR OWN RISK!

Disclaimer: In order to demonstrate the functionality of these apps, actual ticker symbols may be used. However, we do not make recommendations or determine the suitability of any security or strategy for individual traders. Any investment decision you make in your self-directed account is solely your responsibility. Be sure to backtest any strategy to determine if you understand the risks involved with each strategy.

ThinkOrSwim Position Capital Efficiency and Time Weighted Returns Study

Overview

This ThinkOrSwim chart study visualizes the performance of a trading position over time. It plots the current Invested Capital and Total Profit as lines on a lower chart panel and displays the Time-Adjusted Return (a simplified Modified Dietz Return) as a label. The study leverages real-time position data to track capital deployment and profitability, with a special emphasis on the time-averaged invested capital for assessing capital efficiency.

Features

  • Invested Capital Plot: Tracks the current cost basis of your position (in dollars) as a dark green line.
  • Total Profit Plot: Displays the combined realized and unrealized gains/losses (in dollars) as an orange line.
  • Time-Adjusted Return: A label showing the return percentage, calculated as Total Profit divided by the time-averaged invested capital, adjusted for the duration capital was deployed.
  • Labels:
    • Average Invested Capital: Shows the time-averaged invested capital (in dollars). Only bars when some capital was working count. Bars without any invested capitals are not counted for the average.
    • Total Profit: Displays the current total profit (in dollars).
    • Time-Adjusted Return: Presents the return percentage.
  • Customizable Colors: Users can adjust label colors via dropdown inputs (default: light gray).

Thinkorswim Shared Study Link

Position Capital Efficiency and Time Weighted Returns Study can be imported directly into ToS Desktop from this link

Notes on Approximations

  • Execution Price: The study approximates the sale price for realized gains using the bar’s closing price (close) because ThinkOrSwim chart studies don’t provide access to exact execution prices. This is annotated in the code where realizedPL is calculated.
  • Time-Adjusted Return: This metric simplifies the traditional Modified Dietz method by using average invested capital instead of precise cash flow timing, making it practical within ThinkScript’s limitations but less granular.

Example Chart

Example ToS Charts with Capital Efficiency Study and trades along the price chart of example stocks.

Screenshot from 2025-03-08 16-13-16

image

Source Code

Thinkscript source code is available in this repo: position-capital-efficiency.ts

Credit

This study was built in collaboration with Grok 3.

Net New Highs - Lows

Leading market trend indicator that shows whether stocks in a given period have net new 52 week highs or net new lows. Generally if periods of net new highs are more frequent than periods with net new lows, it may indicate that a bullish market trend is forming. Respectively if periods of net new lows are more frequent, that may indicate that a bear market trend is forming.

Celebrity investor Matt Caruso explains in the video below when this indicator can be helpful: Watch the video

Thinkorswim Shared Study Link

New Highs and Lows ToS Study can be imported from this link

Example Chart

Example ToS Chart for TSLA and Net New Highs / Lows studies from NYSE and NASDAQ:

Screen Shot 2023-07-31 at 1 17 11 AM

Source Code

Thinkscript source code is available in this repo: new_highs_lows_STUDY.ts

Credit

Thinkscript code is based on Melvin's work.

Notes

The study uses ToS built-in Net Highs and Net Lows symbols such as : $NYHGH, $NYLOW and others. A more complete list is available in the ToS Learning Center.

Beta Adjusted Relative Strength

This indicator is inspired by Matt Caruso 's CARS (Carusso Adaptive Relative Strength) indicator.

Relative Strength indicator is a popular tool for measuring whether a stock price is growing faster or slower relative to a base index. However when the stock is highly volatile, RS becomes a proxy for the stock price which is not very useful. This Beta Adjusted Relative Strength indicator removes the noise from RS by adjusting for the typical stock volatility relative to the index. See screenshot example below.

Example Chart: TSLA vs SPX

RS in solid gray line, and Beta Adjusted RS in dashed gray line. Notice how due to TSLA's high volatility relative to SPX (purple line), RS does not provide meaningful information at first glance. Whereas Beta Adjusted RS shows more pronounced spikes and slopes as a stock trend develops relative to the index.

Screen Shot 2023-08-15 at 8 11 39 PM

Thinkorswim Shared Study Link

Beta Adjusted Relative Strength ToS Study can be imported from this link .

Source Code

Thinkscript source code is available in this repo: relative_strength_beta_adjusted_STUDY.ts

IBD CANSLIM inspired Breakout Strategy

IBD CANSLIM is a popular system with a number of rules for recognizing and acting on leading stocks in cooperating market conditions. CANSLIM has extreme focus on True Market Leader (TML) stocks with exceptional fundamentals (IBD Composite Rating 96+).

This Thinkscript strategy is a simplified interpretation of the CANSLIM 52 week high breakout setup. It is intended to be used with pre-screened TML watchlist stocks. This strategy is NOT intended as a replacement for applying the full CANSLIM system. It is simply a tool to help spot entry opportunities within TML watchlists for further analysis.

NOT A RECOMMENDATION! NOT FINANCIAL ADVICE! USE AT YOUR OWN RISK!

NOTE: This strategy is designed and tested only for DAILY aggregation charts. Not tested for other aggregation periods.

Example Chart

Example ToS Chart applying this breakout strategy to AAPL: Screen Shot 2023-10-03 at 8 22 52 AM

Notes

This strategy seems to provide one possible answer to celebrity investor Mark Minervini's question posed on his Twitter/X account: Screen Shot 2023-10-02 at 11 10 46 PM

Thinkorswim Shared Strategy Link

Direct Thinkorswim import via this link

Source Code

Thinkscript source code is available in this repo: CANSLIM_Breakout_Strategy.ts

Contributing

Bug fixes and improvements are welcome! Please read the CONTRIBUTING GUIDE and CODE OF CONDUCT before your first contribution.

About

Experimental Thinkscript apps

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published