How to get Close Price 20 Seconds prior to high Volume tick

How to get Close Price 20 Seconds prior to Volume ticks greater than 10000 in exploration.
I have tried following :

Time0 =ValueWhen(Volume > 10000,TimeNum());
Price0 = ValueWhen(TimeNum() == Time0, Close);

Time1 = Time0 - 20; //Also tried: Time1 =ValueWhen(Volume > 10000,TimeNum()-200,1);
Price1 = ValueWhen(TimeNum() == Time1, Close);

Filter = Volume > 10000 ;
AddColumn(Time0, "Time0",1);
AddColumn(Price0, "Price0",1);

AddColumn(Time1, "Time1",1);
AddColumn(Price1, "Price1",1); // Does not show any value.
Screenshot%20(408)

Welcome @jdeep1983,

Use </> code tag whenever you share codes. Please refer to:


Coming to what you want to procure, before anything else you need a database with Tick data or at the very least 1-sec snapshot data. Then from File > Database Settings you would need to set the Base time interval to 1-second or Tick.

On the basis of the code that you have shared, it is vague to subtract a value (20 secs) from TimeNum() in order to capture that bars Close. What if there was no tick 20 seconds ago!

Also refer to Understanding how AFL works.

Run below AFL as Exploration with Periodicity set to 1-Second:

SetOption( "NoDefaultColumns", 1 );
VolCap = Param( "High Volume level", 10000, 1000, 10000000, 1 );
LkBkBars = Param( "No. of bars to look back", 20, 1, 60, 1 ); // N-Bars ago

DT = DateTime();

Cond = V >= VolCap;
dtNbarsAgo = ValueWhen( Cond, Ref( DT, -LkBkBars ) );
CloseNbarsAgo = ValueWhen( Cond, Ref( C, -LkBkBars ) );

//Filter = Cond;
Filter = 1;

AddTextColumn( Name(), "Symbol" );
AddColumn( DT, "Date/Time", formatDateTimeISO, FntClr = IIf( Cond, colorWhite, colorDefault ), BkClr = IIf( Cond, colorDarkBlue, colorDefault ), 118 );
AddColumn( V, "Volume", 1.0, FntClr, BkClr );
AddColumn( C, "Close", 1.2, FntClr, BkClr );

AddColumn( IIf( Cond, dtNbarsAgo, Null ), "N-Bars ago High Volume bar - Time", formatDateTimeISO );
AddColumn( IIf( Cond, CloseNbarsAgo, Null ), "N-Bars ago High Volume bar - Close", 1.2 );

Thank you Cougar for prompt response.
The problem with considering no. of preceding bars is that no. of bars are different in each minute for each symbol. For some symbol 20th preceding bar may be 60 second ago and for other script it may be 20 second ago. So I want to get value at predefined time before the condition. If there is no tick at that time (Say 20 second before condition), then the value of previous available tick(Say 27 seconds before condition) should appear. I have tried Exploration with Periodicity set to 1-Second , but still not getting desired result as at many instances no. of ticks are less 60 in one minute in most cases. Please let me know if there is way to get last close value 20 seconds before condition.
Thanks,
Jagdeep

Also, is there any setting in Amibroker 6.30.5 to include bars with which do not have value. There are 22500 seconds in a trading day in India. If there are 22500 ticks are available then Periodicity set to 1-Second can work, but Indian data providers (Truedata and GDFL) provides less than 22500 ticks for each symbol.
Thanks,
Jagdeep