# reference prev value when using double.nan ?

#### tatl

##### Member
if double.nan is spacing out your plots, how do you get the previous value that was a number?
here's the code i'm working with:

Code:
``````def lowPeak = if close[1]>close and close[-1]>close then 1 else 0;

def highPeak = if close[1]<close and close[-1]<close then 1 else 0;

plot lowPeakPlot = if lowPeak == 1 then close else double.nan;

lowPeakPlot.setPaintingStrategy(paintingstrategy.points);

plot highPeakPlot = if highPeak == 1 then close else double.nan;

highPeakPlot.setPaintingStrategy(paintingstrategy.points);

def higherHighTwo = if highPeakPlot > highPeakPlot[2] then 1 else 0;

the last two lines are the problem. it will never plot the green vertical line, even when there's a higher high, because highPeakPlot[2] isn't a number. I just want to be able to reference the second to last highPeakPlot that Was A Number . . .
not sure how.

Last edited:
Solution
if double.nan is spacing out your plots, how do you get the previous value that was a number?
here's the code i'm working with:

Code:
``````def lowPeak = if close[1]>close and close[-1]>close then 1 else 0;

def highPeak = if close[1]<close and close[-1]<close then 1 else 0;

plot lowPeakPlot = if lowPeak == 1 then close else double.nan;

lowPeakPlot.setPaintingStrategy(paintingstrategy.points);

plot highPeakPlot = if highPeak == 1 then close else double.nan;

highPeakPlot.setPaintingStrategy(paintingstrategy.points);

def higherHighTwo = if highPeakPlot > highPeakPlot[2] then 1 else 0;

the last two lines are the problem. it will never plot the green vertical line, even when...
if double.nan is spacing out your plots, how do you get the previous value that was a number?
here's the code i'm working with:

Code:
``````def lowPeak = if close[1]>close and close[-1]>close then 1 else 0;

def highPeak = if close[1]<close and close[-1]<close then 1 else 0;

plot lowPeakPlot = if lowPeak == 1 then close else double.nan;

lowPeakPlot.setPaintingStrategy(paintingstrategy.points);

plot highPeakPlot = if highPeak == 1 then close else double.nan;

highPeakPlot.setPaintingStrategy(paintingstrategy.points);

def higherHighTwo = if highPeakPlot > highPeakPlot[2] then 1 else 0;

the last two lines are the problem. it will never plot the green vertical line, even when there's a higher high, because highPeakPlot[2] isn't a number. I just want to be able to reference the second to last highPeakPlot that Was A Number . . .
not sure how.

This minor mod should allow your script to work how you want. There is an optional testbubble to help confirm

Code:
``````def lowPeak = if close[1]>close and close[-1]>close then 1 else 0;

def highPeak = if close[1]<close and close[-1]<close then 1 else 0;

plot lowPeakPlot = if lowPeak == 1 then close else double.nan;

lowPeakPlot.setPaintingStrategy(paintingstrategy.points);

plot highPeakPlot = if highPeak == 1 then close else double.nan;

highPeakPlot.setPaintingStrategy(paintingstrategy.points);

def higherHighTwo = if highPeakPlot > highPeakPlot[2] then 1 else 0;

addVerticalLine(higherHighTwo, "higher high  " + highpeakplot + " > " + highpeakplot[2], color.green);

input testbubble = yes;
addchartBubble(testbubble and higherhightwo, high, "HP1: " + highpeakplot +"\nHP2: " + highpeakplot[2], color.green);``````

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