# Plot curve (recursion) from anchor date

#### RandyP

##### New member
VIP
I’m looking to plot a curve (recursion) starting at a specific date.

How do I plot something like this: y = y[1] * 1.005

Thank you, Randy.

Code:
``````input startDate = 20240305;
input price = high;

def date = getyyyymmdd();

def x = if startDate == date then BarNumber() else x[1];
def y = if startDate == date then price else y[1];

# Plot a line starting at startDate.
def slope = 2;
plot line = if x != 0 then y + (BarNumber()- x) * slope else double.nan;

# How do I plot a curve (recursion) starting at startDate?
# y = y[1]  * 1.005``````

Solution
I’m looking to plot a curve (recursion) starting at a specific date.

How do I plot something like this: y = y[1] * 1.005

Thank you, Randy.

Code:
``````input startDate = 20240305;
input price = high;

def date = getyyyymmdd();

def x = if startDate == date then BarNumber() else x[1];
def y = if startDate == date then price else y[1];

# Plot a line starting at startDate.
def slope = 2;
plot line = if x != 0 then y + (BarNumber()- x) * slope else double.nan;

# How do I plot a curve (recursion) starting at startDate?
# y = y[1]  * 1.005``````

Code:
``````#diaglinefromdate

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

input startDate = 20240305;
input price = high;
input slope = 0.005;

def y = if bn == 1 then 0...``````
I’m looking to plot a curve (recursion) starting at a specific date.

How do I plot something like this: y = y[1] * 1.005

Thank you, Randy.

Code:
``````input startDate = 20240305;
input price = high;

def date = getyyyymmdd();

def x = if startDate == date then BarNumber() else x[1];
def y = if startDate == date then price else y[1];

# Plot a line starting at startDate.
def slope = 2;
plot line = if x != 0 then y + (BarNumber()- x) * slope else double.nan;

# How do I plot a curve (recursion) starting at startDate?
# y = y[1]  * 1.005``````

Code:
``````#diaglinefromdate

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

input startDate = 20240305;
input price = high;
input slope = 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] + slope
else 0;

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

#``````

Code:
``````#diaglinefromdate

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

input startDate = 20240305;
input price = high;
input slope = 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] + slope
else 0;

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

#``````

Nice! Thank you!

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

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 approximately match up with SPY for the past three decades.

Last edited by a moderator:
Nice! Thank you!

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

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 approximately match up with SPY for the past three decades.

another example of plotting formulas

87k+ Posts
300 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?