Most recent occurrence of LLVBars and LLV

testLLValue = llv( Close-Ref(Close,-1), 10) ;
testLLVBars = LLVBars( Ref(Close,0)-Ref(Close,-1), 10) ;

printf( "----- Close-Ref(Close,-1): " + NumToStr( Close-Ref(Close,-1) ) + "\n" ); 
printf( "----- testLLValue: " + NumToStr( testLLValue ) + "\n" ); 
printf( "----- testLLVBars: " + NumToStr( testLLVBars ) + "\n" ); 

Filter = 1; 
AddColumn ( Close, "Close" ); 
AddColumn ( Close-Ref(Close,-1), "Close-Ref(Close,-1)" ); 
AddColumn ( testLLValue, "testLLValue" ); 
AddColumn ( testLLVBars, "testLLVBars" );

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:
Capture

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)

No, it shouldn't.

Same low is NOT NEW low. NEW low is when you make low LOWER than the last one.

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???
2 Likes

Obviously I need to get my head around this whole BarsSince concept that AB uses so much.

Tomasz,

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.

Capture

My code works. Always.

The screenshot does not show my code's output, but YOUR code output. So you did something wrong.

1 Like
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???

Filter = 1;
AddColumn(input,"input");
AddColumn(llinput,"llinput");
AddColumn(condition,"condition");
AddColumn(testLLVBars,"testLLVBars");

the above code, which is yours copy and pasted, produces this output:
Capture

How can testLLVBars be greater than 10 if it is correct?

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 ):

min( LLVBars( input, 10 ), BarsSince( condition ) );
1 Like

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)