S&P 500 Logarithmic Chart For ThinkOrSwim

RandyP

New member
VIP
With these inputs:
SPY Monthly Max Available
startDate 19940103
rate .0065 (happens to be close to 8% annual return)

You get these charts. One chart is log price axis, the other is non-log. The log chart is nearly identical to the Wikipedia S&P 500, best-fit logarithmic chart:
https://en.wikipedia.org/wiki/File:S&P_500_Index_Logarithmic_Chart_through_Jan_2021.svg

wiki states:
While S&P 500 data to linear plot scale is good for analysis of a span of 2 or 3 years, beyond that a logarithmic S&P 500 chart is best. This is because it gives the same Y or vertical displacement for a certain percentage move up or down regardless of date.

IMPORTANT:
Please note that this script does not calculate a best-fit line or curve (that's complicate math). The math here draws a curve based on a simple, non-linear equation with user inputted values. When the right values for the variables are chosen, the curve HAPPENS to match up with SPY for the past three decades.
s_and_p_best_fit_log.png
s_and_p_best_fit_non_log.png

Code:
#diaglinefromdate

def na = double.nan;
def bn = barnumber();
def date = getyyyymmdd();

input startDate = 20240305;
input price = close;
input rate = 0.005;

def y = if bn == 1 then 0
 else if startDate == date then price
 else if y[1] > 0 and !isnan(close) then y[1] + (y[1] * rate)
 else 0;

plot z = if y > 0 then y else na;

#addverticalline(startDate == date, "-");
#

Thank you To @halcyonguy code from here:
https://usethinkscript.com/threads/plot-curve-recursion-from-anchor-date.18616/
I tweaked a couple of things:
- modified the y calculation on the line starting "else if y[1] . . . . . ."
-changed a couple of variable names/input values
 
Last edited by a moderator:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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