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;

addVerticalLine(higherHigh, "higher high", color.green);

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;

addVerticalLine(higherHigh, "higher high", color.green);

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;

addVerticalLine(higherHigh, "higher high", color.green);

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

Screenshot-2023-04-09-093854.png
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);
 
Solution

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
594 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