I am trying to find the most recent occurrence of the largest down close from one bar to the next over the last 10 bars with the above code. See the output in this snapshot:
Where I have the blue arrow pointing, why is it saying the largest down close was 2 bars away, when that was the same -.16 as the current bar with the blue arrow? Shouldn't "testLLVBars" return a zero right here? (which is what I desire)
I have checked for decimals. They are both .160, so that’s not it. Is there any way to get LLVBars to return 0 here? Or how can i see the code to the AB LLVBars function so that i can learn how to create my own function?
Sure there is. Use BarsSince() - it is pretty much obvious. Really you need to spend some time yourself trying to solve the problem. That is the only way to progress. You need to put some effort in thinking.
The condition you are looking for is .... think a bit about it.....
input = Close - Ref( Close, -1 ); // input array
llinput = LLV( input, 10 ); // lowest low
condition = ( input == llinput ); // low is reached at this bar
testLLVBars = BarsSince( condition ); // is it THAT complicated???
After studying your solution it does not work. How can testLLVBars return 21 bars ago when I am trying to find the BarsSince largest down "close-ref(close,-1)" of the last 10 bars? Someone wrote a custom function, that does accomplish it correctly as you'll see in the testLLVBars2 column that stays within the 10bar lookback correctly.
The code works correctly. It gives you the number of bars that passed since condition was true. And it was true when current bar input was equal to N-bar LLV value. LLV is calculated correctly and condition is calculated correctly and bar since is calculated correctly. You just don't understand how it works. But I can't help you with understanding. That is something that must happen inside your brain.
It may work correctly as you see it, but it does not accomplish what I need. I specifically said it needs to accomplish this:
"I am trying to find the most recent occurrence of the largest down close from one bar to the next over the last 10 bars"
If it happened greater than 10 bars ago, that is not within the last 10 bars.
So, no matter what you have created, it does not accomplish this. That I understand.
Typically the trouble is when original poster can't clearly describe what he is after. You might be after minimum of two LLVBars( input, 10 ); and BarsSince( condition ):