BarsSinceCompare returns Empty values

Hello,

BarsSinceCompare returns "Empty" values for all bars which are higher that the Highest bar since Bar 1
Am I using it correctly?
Do I need to intrude an additional check for this condition?

tBarsSinceH = BarsSinceCompare( Close, ">", Close );

Plot( C, "Candles", colorBlack, styleCandle, Null, Null, 0, 0, 1);
Plot(BarsSinceH, "BarsSinceH", colorBlack, styleLine|styleStaircase|styleOwnScale, Null, Null, 0, 0, 2);

Kind Regards
Richard

getting total bars coded by FXshart

https://forum.amibroker.com/t/how-to-find-the-number-of-bars-in-a-given-day/11057/2?u=needhelp

dt = DateTime();
dn = DateNum();
newday = dn != Ref( dn, -1);

bars_of_today = BarsSince(newday) + 1;

tBarsSinceH = BarsSinceCompare( Close, ">", Close );

// check if the current array is not the highest value in the remaining data  then use BarsSince Compare , if the current array is the highest then use current array 

tBarsSinceH_close = IIf ( C < HHV( C , bars_of_today ), tBarsSinceH  , BarsSince(HHV( C , bars_of_today )) ) ; 
// or
 tBarsSinceH_close = IIf ( C < HHV( C , bars_of_today ), tBarsSinceH  , 0 ) ;

reference for reading

https://forum.amibroker.com/t/bars-since-higher-or-equal-value/4829/2?u=needhelp

https://forum.amibroker.com/t/duplicate-bars-since-price-was-this-high-low/28355/14

I hope it is help .

Thank you very much for your help.
Unfortunately, I could not make any of the suggestions work.
I was probably doing something wrong.

tBarsSinceH_close array is equal 0 for all bars.

However, you gave me an idea on how to make it work and I think, I have solved the problem with this approach;

bi = BarIndex();
BarsSinceH = BarsSinceCompare( Close, ">", Close );
BarsSinceH = IIf(BarsSinceH > 0, BarsSinceH, bi + 1);
Plot( C, "Candles", colorBlack, styleCandle, Null, Null, 0, 0, 1);
Plot(BarsSinceH, "BarsSinceH", colorBlack, styleLine|styleStaircase|styleOwnScale, Null, Null, 0, 0, 2);

Now for all time high it shows BarIndex() + 1 values.

Thanks Again.
Richard

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.