Hi everybody,
I've been using Amibroker for exploring stocks, and this software helps me so much,
I'm looking for a code that helps me know how many days since stocks reach New High,
For example, I want to know these New High were either 3 months, 6 months or more (display automatically in exploring screen without look back the charts or count by eyes)
@quangtrung1789 I think that @Tomasz code was returning the value of the High and not the number of bars since there was a higher high (just looking at the Plot and the values returned). So I tried a little modification of his code and it seems to return the number of bars since there was a higher high.
// modification of Tomasz code to get Number of Bars Since Higher High
///@link https://forum.amibroker.com/t/bars-since-higher-or-equal-value/4829/16
function BarsSinceHigherValueSelectedVal( SrcArray )
{
bi = BarIndex();
sbi = SelectedValue( bi );
hs = Reverse( HighestSinceBars( Reverse( bi == sbi ), Reverse( SrcArray ) ) ) ;
hs = Ref( bi - ValueWhen( hs == 0, bi ), -1 ) + 1;
shs = SelectedValue( hs );
return IIf( bi >= sbi - shs AND bi <= sbi, hs[ sbi ], Null );
}
// original was not returning the bars since,
// but the actual value of the High (or chosen array)??
// an exploration for debugging,
// suggest trying different "end dates" in the analysis window to illustrate what is being calculated
//Filter = Status( "lastbarinrange" );
Filter=1;
AddColumn(High, "High");
AddColumn(BarsSinceHigherValueSelectedVal( High ), "bars since higher", 1.0);