I would like to count the number of high-volume bars within a range and display the result.
Below is my AFL code.
function count_high_volume_bars(starting_bar, ending_bar)
{
high_volume = IIf( Volume >= MA(Volume, 50), True_part=True, False_part=False);
high_volume_in_range = Ref(high_volume, -(LAST_BAR - ending_bar) );
if (ending_bar < starting_bar)
{
num_bars_in_range = 0;
}
else if (ending_bar >= starting_bar)
{
num_bars_in_range = ending_bar-starting_bar+1;
}
num_high_volume_bars = Sum(high_volume_in_range, num_bars_in_range );
return num_high_volume_bars;
}
START_BAR = BeginValue( BarIndex() );
SELECTED_BAR = SelectedValue( BarIndex() );
number_of_high_volume_bars_in_range = count_high_volume_bars(START_BAR, SELECTED_BAR)
Something is not right as I am not able to get the right result. Can someone help spot what is wrong? I looked at the code a few times and I can't spot what went wrong.
Thank you.