Volume below Average Volume only for selected bar

Hello, i am trying to code the condition where the volume would be below its average volume(10days) but only in the last 2 to 5 bars.

the start should be similar to this:

AverageVolume = MA(Volume, 10);
Filter = Volume < AverageVolume; // this would be for today's volume below the average volume
// but how to put the volume of the last 2 to 5 bars below the Average volume?

Thanks for your help

Try this

/// @link https://forum.amibroker.com/t/volume-below-average-volume-only-for-selected-bar/9389
bi = BarIndex();
lbr = Status("lastbarinrange");
bi2 = LastValue(ValueWhen(lbr, bi-2));
bi5 = LastValue(ValueWhen(lbr, bi-5));

AverageVolume = MA(Volume, 10);
Filter = Volume < AverageVolume AND bi >= bi5 AND bi <= bi2; 

AddColumn(bi, "bi", 1);
AddColumn(bi2, "bi-2", 1);
AddColumn(bi5, "bi-5", 1);
AddColumn(V, "V", 1);
AddColumn(AverageVolume, "AverageVolume", 1);
1 Like

Thanks a lot for your help and quick reply. I am trying to plot to check the signal .The code seems to be working but it is only showing on the right side of the chart. Is there any way to have the condition plot when the condition is met? not only today's signal?

Your first post has Filter = Volume < AverageVolume; and you have got a proper reply in kind.
Post your plotting code and elaborate on that.

1 Like