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 );