# find a valley or reversal

#### lee-I-O=coke-A

##### Member
I am trying to create a scan that will locate a valley or reversal. I have tried on a 1, 5 and 15 charts, no records found, have i coded this properly, thank you. Would appreciate your wisdom.

close is greater than close from -1 bars ago and close from -1 bars ago is greater than close from -2 bars ago and close from -3 bars ago is greater than close from -2 bars ago and close from -4 bars ago is greater than close from -3 bars ago

I am trying to create a scan that will locate a valley or reversal. I have tried on a 1, 5 and 15 charts, no records found, have i coded this properly, thank you. Would appreciate your wisdom.

close is greater than close from -1 bars ago and close from -1 bars ago is greater than close from -2 bars ago and close from -3 bars ago is greater than close from -2 bars ago and close from -4 bars ago is greater than close from -3 bars ago

are you using negative numbers ?
i think you want to use positive numbers.

negative offsets look at future bars, meaning the active bar is in the past.
scans look at values on the last bar.
so if it is on the last bar, and it looks into the future, those values don't exist yet so nothing will be true.

Code:
``````def c = close;
def v1 = c[0] > c[1];
def v2 = c[1] > c[2];
def v3 = c[3] > c[2];
def v4 = c[4] > c[3];
plot val = v1 and v2 and v3 and v4;``````

thank you halcyonguy, I was getting tired and did not pay attention.

may I ask another question, please. Can I just look at the last 5 bars only

may I ask another question, please. Can I just look at the last 5 bars only

can someone confirm this?
I think scans act on the last bar, so by default it already is doing this.

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