Intraday/Daily Compession

Hello,

I have tried time and again to figure out how to get my daily/intraday time compression to work the way I want it to. I want to access all the data that includes premarket and afterhours without including it in the compression for the daily time frame. I have tried playing with the settings in every which way and haven't been able to get it to work.

I have posted about this previously with no response, but I desperately want to know what it is I am doing incorrectly or if I need to synthetically develop daily bars in my code with my intraday data so I can reference the information I am trying to retrieve.

Below is a screenshot of my intraday settings window and the code I have been messing with that I initially had chatGPT write. I apologize for the messy code as I have been going back and forth trying to reference the daily data a different way.

Any help is appreciated

TimeFrameSet( inDaily );

// Daily gap condition
DailyGapPct = ((Open-Ref(Close,-1))/Ref(Close,-1)) * 100;
Cond_DailyGap = DailyGapPct >= 3;

// 20-day average volume
DailyAvgVol = Ref(MA( Volume, 20 ),1);
Cond_DailyAvgVol = DailyAvgVol >= 2000000;

// Prior day ATR
DailyATR = Ref(ATR(14),-1);
Cond_DailyATR = DailyATR >= 1;

TimeFrameRestore();

// ---------------------------------------------------------------
// 2. EXPAND DAILY VALUES INTO INTRADAY
// ---------------------------------------------------------------
GapOK      = TimeFrameExpand( Cond_DailyGap,     inDaily, expandFirst );
AvgVolOK   = TimeFrameExpand( Cond_DailyAvgVol,  inDaily, expandFirst );
ATROK      = TimeFrameExpand( Cond_DailyATR,     inDaily, expandFirst );

// ---------------------------------------------------------------
// 3. PREMARKET VOLUME (4:00–9:29am EST) -- Ignore due to filtering
// ---------------------------------------------------------------

DailyATR_i = TimeFrameExpand( DailyATR, inDaily, expandFirst );

tn = TimeNum();

NewDay = Day()!=Ref(Day(),-1);

premarket_start_time = 040000;
premarket_end_time = 093000;

regular_session_start_time = 093000;
regular_session_end_time = 160000;

after_hours_start_time = 160000;
after_hours_end_time = 200000;


PM_StartTime = 40000;
PM_EndTime = 92900;

Open_Time = 93000;
AM_Rule = 100000;
Midday_Time = 120000;
EOD_Time = 160000;

// these conditions are true when TimeNum of the bar equals startime/endtime
PM_StartBar = Cross(tn,PM_StartTime);													// Premarket Start Bar Condition
PM_EndBar = tn == PM_Endtime;															// Premarket End Bar Condition

M_StartBar = Cross(tn,PM_EndTime);														// Morning Start Bar Condition
AM_RuleBar = tn<=AM_Rule;																// 10 AM Rule Bar Condition
MD_EndBar = tn <= Midday_Time;															// Morning End Bar Condition

EOD_Bar = tn == EOD_Time;																// EOD Bar Condition
EOD_RuleBar = tn <= EOD_Time;

PM_Vol = ValueWhen( PM_EndBar, SumSince( NewDay , V ) );								// Premarket Volume

Cond_PremarketVol = PM_Vol > 200000;

// ---------------------------------------------------------------
// Daily Gap % Calculation
// ---------------------------------------------------------------

DayO_i = ValueWhen(tn==Open_Time,Open); // Todays Open

yDayC_i = Ref(ValueWhen(tn==EOD_Time,Close),-1); // Yesterdays Close

GapPct_i = ((DayO_i-yDayC_i)/yDayC_i)*100; // Gap%?

// ---------------------------------------------------------------
// ATR Calculation
// ---------------------------------------------------------------

// ---------------------------
// Calculated Highs
// ---------------------------

H1 = Ref(ValueWhen(tn==EOD_Time,HHV(High,Ref(ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)),-2))),-2); 
H2 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-2); 
H3 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-3); 
H4 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-4); 
H5 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-5); 
H6 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-6); 
H7 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-7); 
H8 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-8); 
H9 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-9); 
H10 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-10); 
H11 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-11); 
H12 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-12); 
H13 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-13); 
H14 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-14); 
H15 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-15); 

// ---------------------------
// Calculated Lows
//-----------------------------

L1 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L2 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L3 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L4 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L5 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L6 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L7 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L8 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L9 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L10 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L11 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L12 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L13 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L14 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L15 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);

// ---------------------------
// Calculated Close
//-----------------------------

yC1 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC2 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC3 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC4 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC5 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC6 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC7 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC8 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC9 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC10 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC11 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC12 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC13 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC14 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC15 = Ref(ValueWhen(tn==EOD_Time,Close),-1);


// ---------------------------
// Calculated TR
//-----------------------------

HL = (H15-L15) + (H2-L2) + (H3-L3) + (H4-L4) + (H5-L5) + (H6-L6) + (H7-L7)
	+ (H8-L8) + (H9-L9) + (H10-L10) + (H11-L11)+ (H12-L12) + (H13-L13) + (H14-L14);
	
HyC = (H1-yC1) + (H2-yC2) + (H3-yC3) + (H4-yC4) + (H5-yC5) + (H6-yC6) + (H7-yC7)
	+ (H8-yC8) + (H9-yC9) + (H10-yC10) + (H11-yC11)+ (H12-yC12) + (H13-yC13) + (H14-yC14);
	
LyC = (L1-yC1) + (L2-yC2) + (L3-yC3) + (L4-yC4) + (L5-yC5) + (L6-yC6) + (L7-yC7)
	+ (L8-yC8) + (L9-yC9) + (L10-yC10) + (L11-yC11)+ (L12-yC12) + (L13-yC13) + (L14-yC14);
	
ATR_Calc = (((HL/14)*13)+(H1-L1))/14;

// ---------------------------------------------------------------
// 20D Avg Volume Calculation
// ---------------------------------------------------------------

// ---------------------------
// Calculate EOD Bar and Sum Vol
//-----------------------------


EODBar = HHV(tn,tn>=195000);
VolT = SumSince( NewDay , V );

// ---------------------------
// Calculate Vol for 20 Days
//-----------------------------

yDV1  = ValueWhen(tn==EODBar,VolT);
yDV2  = Ref(ValueWhen(tn==EODBar,VolT),-1);
yDV3  = Ref(ValueWhen(tn==EODBar,VolT),-2);
yDV4  = Ref(ValueWhen(tn==EODBar,VolT),-3);
yDV5  = Ref(ValueWhen(tn==EODBar,VolT),-4);
yDV6  = Ref(ValueWhen(tn==EODBar,VolT),-5);
yDV7  = Ref(ValueWhen(tn==EODBar,VolT),-6);
yDV8  = Ref(ValueWhen(tn==EODBar,VolT),-7);
yDV9  = Ref(ValueWhen(tn==EODBar,VolT),-8);
yDV10 = Ref(ValueWhen(tn==EODBar,VolT),-9);
yDV11  = Ref(ValueWhen(tn==EODBar,VolT),-10);
yDV12  = Ref(ValueWhen(tn==EODBar,VolT),-11);
yDV13  = Ref(ValueWhen(tn==EODBar,VolT),-12);
yDV14  = Ref(ValueWhen(tn==EODBar,VolT),-13);
yDV15 = Ref(ValueWhen(tn==EODBar,VolT),-14);
yDV16 = Ref(ValueWhen(tn==EODBar,VolT),-15);
yDV17 = Ref(ValueWhen(tn==EODBar,VolT),-16);
yDV18 = Ref(ValueWhen(tn==EODBar,VolT),-17);
yDV19 = Ref(ValueWhen(tn==EODBar,VolT),-18);
yDV20 = Ref(ValueWhen(tn==EODBar,VolT),-19);


AvgVol20D = (yDV1 + yDV2 + yDV3 + yDV4 + yDV5 + yDV6 + yDV7 + yDV8 + yDV9 + yDV10 
	+ yDV11 + yDV12 + yDV13 + yDV14 + yDV15 + yDV16 + yDV17 + yDV18 + yDV19 + yDV20)/20;

// ---------------------------------------------------------------
// 4. FIRST 30 MINUTES LOGIC (9:30–10:00am)
// ---------------------------------------------------------------
SessionOpen = 093000;
Session10 = 094000;
Session30   = 100000;
Session11am = 110000;

IsFirst30 = tn >= SessionOpen AND tn <= Session30;



// High of first 30 minutes
First30High = HighestSince( tn == SessionOpen, High );

// Condition: First 30-min high >= Open + 0.5 ATR
Cond_First30_ATR = First30High >= ( Open + 0.5 * DailyATR_i );

// Detect the bar where the first-30-min high is set
HighHit = High == First30High AND IsFirst30;

BarsSinceHigh = BarsSince(HighHit);

// Track lowest low AFTER the high is set
LowAfterHigh = LLV(Low,BarsSinceHigh);

//VWAP Calc
VWAP = SumSince( NewDay, Avg * Volume) / SumSince( NewDay, Volume );


// Condition: lowest low after high < VWAP
Cond_LowBelowVWAP = Cross(VWAP, LowAfterHigh) AND tn >= Session10 AND tn <= Session11am;

// Bars Since VWAP Touch

High_Entry_Cond = BarsSince(Cond_LowBelowVWAP) == 11; //Minimum 10 bars after VWAP is touched

Entry_High_Find = HighestSince(Cond_LowBelowVWAP,High); //Find high value after crossing vwap

Entry_High = ValueWhen(High_Entry_Cond,Entry_High_Find); //High value for entry price

Entry_Signal = Cross(High,Entry_High); //Enter when consolidation high is broken

Risk_Low_Find = LowestSince(Cond_LowBelowVWAP,High); //Find Risk

Risk_Low = ValueWhen(High_Entry_Cond,Risk_Low_Find); //Risk Value

Sell_Signal = Cross(Risk_Low,Low); //Sell when consolidation low is broken

EC2 = tn >= Session10 AND tn <= Session11am;

EC3 = ValueWhen(Cond_LowBelowVWAP,DateTime()) < ValueWhen(Entry_Signal, DateTime()); //Only enter after vwap is crossed first

// 6. FINAL TRADE CONDITION
// ---------------------------------------------------------------


Filter = 1;//Entry_Signal AND EC2 AND Cond_PremarketVol AND GapPct_i>=3;

AddColumn( GapPct_i,        "Gap %", 1.2 );
//AddColumn(Avg20Vol,        "20D Avg Vol", 1.2);
AddColumn( H1 ,"Prior ATR", 1.2 );
AddColumn( PM_Vol,       "Premarket Vol", 1.2 );
AddColumn( First30High,        "First 30 High", 1.2 );
AddColumn( LowAfterHigh,       "Low After High", 1.2 );
AddColumn( vwap,               "VWAP", 1.2 );
AddColumn( Entry_High,          "High Entry", 1.2 );
AddColumn( Entry_Signal,          "High Signal", 1.2 );
//AddColumn( TradeSignal,        "Signal", 1.0 );
//AddColumn( BarsSinceHigh,        "BarsSince high", 1.0 );

I believe that the subject is covered here:

and also some here: AmiBroker Knowledge Base » Time compression of data retrieved from another symbol

Note that these settings affect "DAILY" interval selected from UI, not anything that you do inside your AFL code.

I have reviewed that link quite a bit and maybe I am just not understanding or not doing something right.

To be clear with my goal/intentions. I would like to compress to a daily bar from intraday data without losing access to premarket data, but still calculate the data required correctly.

Here is what I get when with my current filtering:


**

**
With the settings shown below, I get what I am looking for with the chart compression, but it restricts access to the premarket data


When I show day/night filtering, the calculation for the daily values is not correct. I did have mixed data on for this so the chart appears as I expect, but the calculation from the code does not give me similar values.

It is also worth noting that I got the daily data from a different vendor as my intraday so I expect it not to be exact, but it is a much larger difference than I anticipated.



Below is a slightly updated but still messy code. All I really added was a variable to view the ATR

I am a bit lost on what I am not doing correctly or not understanding to get my desired outcome. All help is appreciated. Thank you

TimeFrameSet( inDaily );

// Daily gap condition
DailyGapPct = ((Open-Ref(Close,-1))/Ref(Close,-1)) * 100;
Cond_DailyGap = DailyGapPct >= 3;

// 20-day average volume
DailyAvgVol = Ref(MA( Volume, 20 ),1);
Cond_DailyAvgVol = DailyAvgVol >= 2000000;

// Prior day ATR
DailyATR = Ref(ATR(14),-1);
Cond_DailyATR = DailyATR >= 1;

TimeFrameRestore();

// ---------------------------------------------------------------
// 2. EXPAND DAILY VALUES INTO INTRADAY
// ---------------------------------------------------------------
GapOK      = TimeFrameExpand( Cond_DailyGap,     inDaily, expandFirst );
AvgVolOK   = TimeFrameExpand( Cond_DailyAvgVol,  inDaily, expandFirst );
ATROK      = TimeFrameExpand( Cond_DailyATR,     inDaily, expandFirst );

DailyATR_i = TimeFrameExpand(DailyATR, inDaily);
// ---------------------------------------------------------------
// 3. PREMARKET VOLUME (4:00–9:29am EST) -- Ignore due to filtering
// ---------------------------------------------------------------

DailyATR_i = TimeFrameExpand( DailyATR, inDaily, expandFirst );

tn = TimeNum();

NewDay = Day()!=Ref(Day(),-1);

premarket_start_time = 040000;
premarket_end_time = 093000;

regular_session_start_time = 093000;
regular_session_end_time = 160000;

after_hours_start_time = 160000;
after_hours_end_time = 200000;


PM_StartTime = 40000;
PM_EndTime = 92900;

Open_Time = 93000;
AM_Rule = 100000;
Midday_Time = 120000;
EOD_Time = 160000;

// these conditions are true when TimeNum of the bar equals startime/endtime
PM_StartBar = Cross(tn,PM_StartTime);													// Premarket Start Bar Condition
PM_EndBar = tn == PM_Endtime;															// Premarket End Bar Condition

M_StartBar = Cross(tn,PM_EndTime);														// Morning Start Bar Condition
AM_RuleBar = tn<=AM_Rule;																// 10 AM Rule Bar Condition
MD_EndBar = tn <= Midday_Time;															// Morning End Bar Condition

EOD_Bar = tn == EOD_Time;																// EOD Bar Condition
EOD_RuleBar = tn <= EOD_Time;

PM_Vol = ValueWhen( PM_EndBar, SumSince( NewDay , V ) );								// Premarket Volume

Cond_PremarketVol = PM_Vol > 200000;

// ---------------------------------------------------------------
// Daily Gap % Calculation
// ---------------------------------------------------------------

DayO_i = ValueWhen(tn==Open_Time,Open); // Todays Open

yDayC_i = Ref(ValueWhen(tn==EOD_Time,Close),-1); // Yesterdays Close

GapPct_i = ((DayO_i-yDayC_i)/yDayC_i)*100; // Gap%?

// ---------------------------------------------------------------
// ATR Calculation
// ---------------------------------------------------------------

// ---------------------------
// Calculated Highs
// ---------------------------

H1 = Ref(ValueWhen(tn==EOD_Time,HHV(High,Ref(ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)),-2))),-2); 
H2 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-2); 
H3 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-3); 
H4 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-4); 
H5 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-5); 
H6 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-6); 
H7 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-7); 
H8 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-8); 
H9 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-9); 
H10 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-10); 
H11 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-11); 
H12 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-12); 
H13 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-13); 
H14 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-14); 
H15 = Ref(ValueWhen(tn==EOD_Time,HHV(High,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-15); 

// ---------------------------
// Calculated Lows
//-----------------------------

L1 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L2 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L3 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L4 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L5 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L6 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L7 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L8 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L9 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L10 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L11 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L12 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L13 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L14 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);
L15 = Ref(ValueWhen(tn==EOD_Time,LLV(Low,ValueWhen(tn==EOD_Time,BarsSince(tn==Open_Time)))),-1);

// ---------------------------
// Calculated Close
//-----------------------------

yC1 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC2 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC3 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC4 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC5 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC6 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC7 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC8 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC9 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC10 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC11 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC12 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC13 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC14 = Ref(ValueWhen(tn==EOD_Time,Close),-1);
yC15 = Ref(ValueWhen(tn==EOD_Time,Close),-1);


// ---------------------------
// Calculated TR
//-----------------------------

HL = (H15-L15) + (H2-L2) + (H3-L3) + (H4-L4) + (H5-L5) + (H6-L6) + (H7-L7)
	+ (H8-L8) + (H9-L9) + (H10-L10) + (H11-L11)+ (H12-L12) + (H13-L13) + (H14-L14);
	
HyC = (H1-yC1) + (H2-yC2) + (H3-yC3) + (H4-yC4) + (H5-yC5) + (H6-yC6) + (H7-yC7)
	+ (H8-yC8) + (H9-yC9) + (H10-yC10) + (H11-yC11)+ (H12-yC12) + (H13-yC13) + (H14-yC14);
	
LyC = (L1-yC1) + (L2-yC2) + (L3-yC3) + (L4-yC4) + (L5-yC5) + (L6-yC6) + (L7-yC7)
	+ (L8-yC8) + (L9-yC9) + (L10-yC10) + (L11-yC11)+ (L12-yC12) + (L13-yC13) + (L14-yC14);
	
ATR_Calc = (((HL/14)*13)+(H1-L1))/14;

// ---------------------------------------------------------------
// 20D Avg Volume Calculation
// ---------------------------------------------------------------

// ---------------------------
// Calculate EOD Bar and Sum Vol
//-----------------------------


EODBar = HHV(tn,tn>=195000);
VolT = SumSince( NewDay , V );

// ---------------------------
// Calculate Vol for 20 Days
//-----------------------------

yDV1  = ValueWhen(tn==EODBar,VolT);
yDV2  = Ref(ValueWhen(tn==EODBar,VolT),-1);
yDV3  = Ref(ValueWhen(tn==EODBar,VolT),-2);
yDV4  = Ref(ValueWhen(tn==EODBar,VolT),-3);
yDV5  = Ref(ValueWhen(tn==EODBar,VolT),-4);
yDV6  = Ref(ValueWhen(tn==EODBar,VolT),-5);
yDV7  = Ref(ValueWhen(tn==EODBar,VolT),-6);
yDV8  = Ref(ValueWhen(tn==EODBar,VolT),-7);
yDV9  = Ref(ValueWhen(tn==EODBar,VolT),-8);
yDV10 = Ref(ValueWhen(tn==EODBar,VolT),-9);
yDV11  = Ref(ValueWhen(tn==EODBar,VolT),-10);
yDV12  = Ref(ValueWhen(tn==EODBar,VolT),-11);
yDV13  = Ref(ValueWhen(tn==EODBar,VolT),-12);
yDV14  = Ref(ValueWhen(tn==EODBar,VolT),-13);
yDV15 = Ref(ValueWhen(tn==EODBar,VolT),-14);
yDV16 = Ref(ValueWhen(tn==EODBar,VolT),-15);
yDV17 = Ref(ValueWhen(tn==EODBar,VolT),-16);
yDV18 = Ref(ValueWhen(tn==EODBar,VolT),-17);
yDV19 = Ref(ValueWhen(tn==EODBar,VolT),-18);
yDV20 = Ref(ValueWhen(tn==EODBar,VolT),-19);


AvgVol20D = (yDV1 + yDV2 + yDV3 + yDV4 + yDV5 + yDV6 + yDV7 + yDV8 + yDV9 + yDV10 
	+ yDV11 + yDV12 + yDV13 + yDV14 + yDV15 + yDV16 + yDV17 + yDV18 + yDV19 + yDV20)/20;

// ---------------------------------------------------------------
// 4. FIRST 30 MINUTES LOGIC (9:30–10:00am)
// ---------------------------------------------------------------
SessionOpen = 093000;
Session10 = 094000;
Session30   = 100000;
Session11am = 110000;

IsFirst30 = tn >= SessionOpen AND tn <= Session30;



// High of first 30 minutes
First30High = HighestSince( tn == SessionOpen, High );

// Condition: First 30-min high >= Open + 0.5 ATR
Cond_First30_ATR = First30High >= ( Open + 0.5 * DailyATR_i );

// Detect the bar where the first-30-min high is set
HighHit = High == First30High AND IsFirst30;

BarsSinceHigh = BarsSince(HighHit);

// Track lowest low AFTER the high is set
LowAfterHigh = LLV(Low,BarsSinceHigh);

//VWAP Calc
VWAP = SumSince( NewDay, Avg * Volume) / SumSince( NewDay, Volume );


// Condition: lowest low after high < VWAP
Cond_LowBelowVWAP = Cross(VWAP, LowAfterHigh) AND tn >= Session10 AND tn <= Session11am;

// Bars Since VWAP Touch

High_Entry_Cond = BarsSince(Cond_LowBelowVWAP) == 11; //Minimum 10 bars after VWAP is touched

Entry_High_Find = HighestSince(Cond_LowBelowVWAP,High); //Find high value after crossing vwap

Entry_High = ValueWhen(High_Entry_Cond,Entry_High_Find); //High value for entry price

Entry_Signal = Cross(High,Entry_High); //Enter when consolidation high is broken

Risk_Low_Find = LowestSince(Cond_LowBelowVWAP,High); //Find Risk

Risk_Low = ValueWhen(High_Entry_Cond,Risk_Low_Find); //Risk Value

Sell_Signal = Cross(Risk_Low,Low); //Sell when consolidation low is broken

EC2 = tn >= Session10 AND tn <= Session11am;

EC3 = ValueWhen(Cond_LowBelowVWAP,DateTime()) < ValueWhen(Entry_Signal, DateTime()); //Only enter after vwap is crossed first

// 6. FINAL TRADE CONDITION
// ---------------------------------------------------------------


Filter = 1;//Entry_Signal AND EC2 AND Cond_PremarketVol AND GapPct_i>=3;

AddColumn( GapPct_i,        "Gap %", 1.2 );
//AddColumn(Avg20Vol,        "20D Avg Vol", 1.2);
AddColumn( DailyATR_i ,"Prior ATR", 1.2 );
AddColumn( PM_Vol,       "Premarket Vol", 1.2 );
AddColumn( First30High,        "First 30 High", 1.2 );
AddColumn( LowAfterHigh,       "Low After High", 1.2 );
AddColumn( vwap,               "VWAP", 1.2 );
AddColumn( Entry_High,          "High Entry", 1.2 );
AddColumn( Entry_Signal,          "High Signal", 1.2 );
//AddColumn( TradeSignal,        "Signal", 1.0 );
//AddColumn( BarsSinceHigh,        "BarsSince high", 1.0 );

For your goal with intraday data, you will need to use "no filtering" that way you access all your pre/post data

this block of code here.

You cannot do this, from the KB article, it is very clear how daily compression is controlled using Filtering/Trading hours. But you are setting requirements which are opposing this logic.
AB will use all the data available after the selected filtering option for daily compression.

this is the way to go, so while your trailing code should work, your start is wrong using TimeFrameSet( inDaily )

You programmatically do something like:

regular_session_start_time = 093000; // move lines to the top
regular_session_end_time = 160000;

mask_for_daily = IIf( tn >= regular_session_start_time,
					  tn < regular_session_end_time,
					  1, 0 );

daily_C = C AND mask_for_daily;
// same for O,H,L,V

// NOW, dont Compress + Expand, instead use
// HHV, LLV, SUMSINCE etc
// So you skip the TimeFrame functions

so you will be using your own created daily data expanded to your intraday timeframe.

Note: Alternate way (untested by me but theoretically doable)
IF you understand well enough, you could do a swap of standard OHLC also after applying the daily_mask. AB is very versatile.

Then use TimeFrame* functions on this data.
AmiBroker Knowledge Base » Indicators based on user values rather than standard OHLC prices
Dont forget to restore original arrays afterwards.

edited a typo

regular_session_start_time = 093000; // move lines to the top
regular_session_end_time   = 160000;

mask_for_daily = IIf( tn >= regular_session_start_time AND
					  tn < regular_session_end_time,
					  1, null );

AmiBroker default time compression works as explained in the Knowledge Base and in the Users' Guide. The level of detail that KB provides is super high and there is really nothing more to add to it.

If you want something different, like compression that is "yours" done "your way", AmiBroker has dedicated functions that can compress/expand data based on user-provided points: SparseCompress/SparseExpand

These functions can be used to create completely custom compressions not limited by any rules or restrictions.

Nice thing is that once data are compressed by SparseCompress they can be used exactly the same way as data compressed by TimeFrameCompress. So everything written about TimeFrame functions apply to sparse-compressed data, as these functions do pretty much same thing, just Sparse* functions allow you to provide your own "pick points/bars".

One thing to understand that is already described in the Users' Guide is that if you apply global filtering and/or change interval to compressed one, you can't magically unfilter that in AFL.
If you want to apply your OWN compressions, you have to operate on UNFILTERED data with BASE interval so you can compress it to desired points. Compressing already compressed data doesn't work.

And you need to understand that View-> menu settings (both compression and filtering) compress/filter data BEFORE they are fed into your AFL. If you want to have your OWN filtering and OWN compression solely in AFL alone, you need to feed your AFL with uncompressed/unfiltered data (by selecting View menu options appropriately).

I appreciate the insight as I was not aware of SparseCompress/SparseExpand.

I am desperately trying not to be handheld completely through this code, but I am not understanding how the SparseCompress is working. To my understanding based on the code below, it should compress only the bars between 093000 and 160000, but for whatever reason it I am not getting the values I expect.

Here are the settings I have to start before continuing:

I started a new code so I can just focus on getting the compression correct. I had ChatGPT assist with writing this and then I experimented from there.

I had it compress the closes first and used a ValueWhen function to spit out the close at the end of day bar. This worked as expected.

tn = TimeNum();

regular_session_start_time = 093000;
regular_session_end_time   = 160000;

// RTH mask
isRTH = tn >= regular_session_start_time AND tn <= regular_session_end_time;

// Last RTH bar of each day = in RTH and next bar is NOT in RTH
isLastRTH = isRTH == 1;

// Compress: one value per day (the close of last RTH bar)
dailyCloseCompressed = SparseCompress( isLastRTH, C );

// Expand back to sparse series (values only on last RTH bars)
dailyCloseSparse = SparseExpand( isLastRTH, dailyCloseCompressed );

// Optional: forward-fill so every bar in the day sees that daily close
dailyCloseAllBars = ValueWhen( isLastRTH AND tn==regular_session_end_time, dailyCloseSparse );

prevclose = Ref(dailycloseallbars, -1);

Filter = 1;
AddColumn( dailyCloseAllBars, "Daily Close", 1.2 );
AddColumn( isLastRTH, "Last RTH", 1.0 );

Below leads me to believe that I am not going about it correctly. This only seems to work when I call out specific datapoints, otherwise it will just give me the requested value of the bar rather than the compressed value between 093000 and 160000.

tn = TimeNum();
regular_session_start_time = 093000;
regular_session_end_time   = 160000;

// RTH mask
isRTH = IIf(tn >= regular_session_start_time AND tn <= regular_session_end_time,1,0);

// Compress: one value per day (the close of last RTH bar)

//--------------------------------------------------------------------------------------------------------
// Daily Values
//--------------------------------------------------------------------------------------------------------

dailyOpenCompressed = SparseCompress( isRTH, O );
dailyHighCompressed = SparseCompress( isRTH, H );
dailyLowCompressed = SparseCompress( isRTH, L );
dailyCloseCompressed = SparseCompress( isRTH, C );

dailyOpenSparse = SparseExpand(isRTH, dailyOpenCompressed );
dailyHighSparse = SparseExpand(isRTH, dailyHighCompressed );
dailyLowSparse = SparseExpand(isRTH, dailyLowCompressed );
dailyCloseSparse = SparseExpand(isRTH, dailyCloseCompressed );


// Optional: forward-fill so every bar in the day sees that daily close

dailyOpenAllBars = ValueWhen( isRTH AND tn==regular_session_start_time, dailyOpenSparse);
dailyHighAllBars = ValueWhen( isRTH, dailyHighSparse);
dailyLowAllBars = ValueWhen( isRTH, dailyLowSparse);
dailyCloseAllBars = ValueWhen( isRTH AND tn==regular_session_end_time, dailyCloseSparse );

HOD = HHV(H,1);

Filter = 1;
AddColumn( dailyOpenAllBars, "Daily Open", 1.2 );
AddColumn( dailyHighAllBars , "Daily High", 1.2 );
AddColumn( dailyLowAllBars, "Daily Low", 1.2 );
AddColumn( dailyCloseSparse, "Daily Close", 1.2 );
AddColumn( isRTH, "Last RTH", 1.0 );


I have tried code like below just toying with the idea of TimeFrame functionality thinking that might be the correct way to achieve this, but it is not working as expected and only gave 1 correct value (High)

tn = TimeNum();
regular_session_start_time = 093000;
regular_session_end_time   = 160000;

// RTH mask
isRTH = IIf(tn >= regular_session_start_time AND tn <= regular_session_end_time,1,0);

// Compress: one value per day (the close of last RTH bar)

//--------------------------------------------------------------------------------------------------------
// Daily Values
//--------------------------------------------------------------------------------------------------------

dailyOpenCompressed = SparseCompress( isRTH, O );

Day_O = TimeFrameGetPrice("O",inDaily);

dailyOpenSparse = SparseExpand(isRTH, dailyOpenCompressed );


dailyHighCompressed = SparseCompress( isRTH, H );

Day_H = TimeFrameGetPrice("H",inDaily);

dailyHighSparse = SparseExpand(isRTH, dailyHighCompressed );

dailyLowCompressed = SparseCompress( isRTH, L );

Day_L = TimeFrameGetPrice("L",inDaily);

dailyLowSparse = SparseExpand(isRTH, dailyLowCompressed );

dailyCloseCompressed = SparseCompress( isRTH, C );

Day_C = TimeFrameGetPrice("C",inDaily);

dailyCloseSparse = SparseExpand(isRTH, dailyCloseCompressed );


// Optional: forward-fill so every bar in the day sees that daily close

dailyOpenAllBars = ValueWhen( isRTH AND tn==regular_session_start_time, dailyOpenSparse);
dailyHighAllBars = ValueWhen( isRTH, dailyHighSparse);
dailyLowAllBars = ValueWhen( isRTH, dailyLowSparse);
dailyCloseAllBars = ValueWhen( isRTH AND tn==regular_session_end_time, dailyCloseSparse );

HOD = HHV(H,1);

Filter = 1;
AddColumn( Day_O, "Daily Open", 1.2 );
AddColumn( Day_H , "Daily High", 1.2 );
AddColumn( Day_L, "Daily Low", 1.2 );
AddColumn( Day_C, "Daily Close", 1.2 );
AddColumn( isRTH, "Last RTH", 1.0 );

I have tried a lot of other combinations both with and without timeframe functions included as well as scoured the forums/KB for other information on SparseCompress/SparseExpand.

Again I appreciate the help. I just want to figure out what I am not getting. Thanks


Try increase number of bars to minimum 10,000.

Local DB unaffected by # of bars field

see this if it helps, it was a similar case like yours that I recalled.

You have this code:

isRTH = IIf(tn >= regular_session_start_time AND tn <= regular_session_end_time,1,0); // WRONG
dailyOpenSparse = SparseExpand(isRTH, dailyOpenCompressed );

Sparse* function needs IMPULSE, you are passing STATE (range), that is incorrect.

What you are passing now (incorrectly) is this::
0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0 (state or 'range')

What you really need is something like:
0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 (impulse)

To get better understanding, you have to write SIMPLE CODE. Don't write tens of lines. Write few lines and use advice given here: How do I debug my formula?

It should be like

impulseWhen = tn == 93000; // exactly WHEN (the point in time, NOT range!)
dailyOpenCompressed = SparseCompress( impulseWhen, Open );

Did you try to COPY-PASTE ready-to-use examples from the Users' Guide:

They PRECISELY shown what is done inside and how to use.

You can also copy-paste Users' Guide to AI and ask it to explain.

With TimeframeSet() I was loosing bars due to nulls.

This approach is better, no?
Using this code:
AmiBroker Knowledge Base » High-Low of certain hours of the day
Then just SParseCompress() at the tn == regular_session_end_time for range H and L.

similarly,
For range O, SParseCompress() for tn == regular_session_start_time
For range C, SParseCompress() for tn == regular_session_end_time

After that, SParseExpand()

see if you can wrap your head around this. real code :slight_smile:

I have removed bars during the "day" period just for plot otherwise the variables have continuous data.


Plot( C, "Close", IIf( O < C, colorGreen,colorRed), styleCandle, Null,Null,0,5);

tn = TimeNum();

StartTime = 110000;
Endtime   = 130000;

StartBar = tn == StartTime;
EndBar   = tn == Endtime;
inRange  = tn >= StartTime AND tn <= Endtime;

myH = ValueWhen( EndBar, HighestSince( StartBar, High ) );
myL = ValueWhen( EndBar, LowestSince( StartBar, Low ) );
myO = ValueWhen( StartBar, Open );
myC = ValueWhen( EndBar, Close );

/* verify by plotting */
myO1=IIf( inRange, Null, myO );
myH1=IIf( inRange, Null, myH );
myL1=IIf( inRange, Null, myL );
myC1=IIf( inRange, Null, myC );

PlotOHLC( myO1, myH1, myL1, myC1, "", IIf(myO<myC,colorBlue,colorYellow), styleCandle ); 

/* For Time Compress Calculations Eg. one bar per day */

compO = SparseCompress( StartBar, O );
compH = SparseCompress( EndBar, myH );
compL = SparseCompress( EndBar, myL );
compC = SparseCompress( EndBar, C );

/* Calculate on compressed data here */

x = MA( compC, 5 ); 				// regular calculation

/* Expand to periodicity */
y = SparseExpand( StartBar, x ); 	// expand sparse data

/* Fill expanded data zeros */
z = ValueWhen( y > 0, y );

/* plot */
Plot( y, "Sparse", colorWhite );
Plot( z, "filled", colorDarkBlue );

I appreciate all the responses and assistance on this.

I started the code over based on the information that Tomasz provided.

I started with code shown below which funny enough is pretty much what you provided for the initial arguments.

tn = TimeNum();
Session_Open = 093000;
Session_Close   = 160000;

Session = tn>= Session_Open AND tn<= Session_Close;
SessionStart = tn == Session_Open;
SessionEnd = tn == Session_Close;

You responded as I was trying to wrap my head around what I should be doing to get the values for OHLC which you seem to have mapped out.

Before I start running with all the information provided, let me dissect your code so I can make sure I understand what you provided and figure out how I can apply it directly to what I am trying to do. Feel free to correct me if I am not understanding fully.

Here you are defining the OHLC of the current bar in the range you provided previously.

Here you are setting up the OHLC to be plotted by the OHLC where if the close is greater than the open it would be a blue candle (green typically) and yellow if is close is lower than open (red typically)

So far this makes sense. I am under the impression that the bars you're showing in the picture are 1min bars and the bars that are blue/yellow overlay them as the "compressed daily candle", if you will.

This is the part where I think I get confused. You are calculating a closing moving average over 5 bars as value 'x' (in what I assume is the calculated daily close due to the compression). With this you expand this to overlay over the 1min data where you then plot both the y/z variables. (this part I don't seem to get from what you've provided)

When you compress and calculate something, you cannot plainly plot on lower timeframe from daily.
So when you SParseExpand(), the values are expanded at only 1 bar for the day. (because that is where true condition is passed )

like 100000001000000010000000, these are the white tiny dots
so to fill those zeros, I copy the value overwriting the 0's so it can be plotted like a line. ie. dark blue line

Gotcha, I didn't notice the white dots, and I guess that makes sense.

I accidentally wrote the code for compO_C and compO_E and found it calculating the OHLC perfectly (in this case, a previous open). Which I was struggling to do correctly yesterday with other combinations of using Ref('OHLC Value function', -1);

compO = SparseCompress( SessionStart, O );
compH = SparseCompress( SessionEnd, myH );
compL = SparseCompress( SessionEnd, myL );
compC = SparseCompress( SessionEnd, C );

compO_C = Ref(compO,-1); 
compO_E = SparseExpand(sessionStart, compo_C);

Filter = 1;

AddColumn(myO,"Open",1.2);
AddColumn(myH,"High",1.2);
AddColumn(myL,"Low",1.2);
AddColumn(myC,"Close",1.2);
AddColumn(compO_E, "test",1.2);

Also, I was expecting the sparsecompress to essentially generate the bar as a daily candle. I think your explanation about the white dots being points is helpful in seeing it as more of a point in time rather than a condensed candle like I was initially imagining.

However, when applying an out of box function like ATR(14), and expanding it back to the intraday time frame with sparesexpand, I would expect it to be referring to the synthetically created daily candles made from the sparsecompress, seeing as these would be the closing points, but it still refers to the intraday time frame. This I don't necessarily understand.

Here's my whole code including the ATR function calc and it's result:

tn = TimeNum();
Session_Open = 093000;
Session_Close   = 160000;

Session = tn>= Session_Open AND tn<= Session_Close;
SessionStart = tn == Session_Open;
SessionEnd = tn == Session_Close;

myH = ValueWhen( SessionEnd, HighestSince( SessionStart, High ) );
myL = ValueWhen( SessionEnd, LowestSince( SessionStart, Low ) );
myO = ValueWhen( SessionStart, Open );
myC = ValueWhen( SessionEnd, Close );

myO1=IIf( Session, Null, myO );
myH1=IIf( Session, Null, myH );
myL1=IIf( Session, Null, myL );
myC1=IIf( Session, Null, myC );

compO = SparseCompress( SessionStart, O );
compH = SparseCompress( SessionEnd, myH );
compL = SparseCompress( SessionEnd, myL );
compC = SparseCompress( SessionEnd, C );

compO_C = Ref(compO,-1); 
compO_E = SparseExpand(sessionStart, compo_C);

myATR_C = ATR(14);

myATR_E =SparseExpand(sessionend,myATR_C);

Filter = 1;

AddColumn(myO,"Open",1.2);
AddColumn(myH,"High",1.2);
AddColumn(myL,"Low",1.2);
AddColumn(myC,"Close",1.2);
AddColumn(compO_E, "Previous Open",1.2);
AddColumn(myATR_E, "ATR",1.2);

I will keep playing around with it in the meantime, because I'm sure it is something I am doing incorrectly like I was previously with finding OHLC referencing.

posted this above.
You cant use ATR() just like that, either use swap method or actually write the formula(code) for calculating ATR on those compressed arrays.

search the forum, for how to use custom arrays. Some indicators directly access ohlcv etc like ATR() unlike MA() which takes an array parameter.

in this case, you dont use TimeFrame* funcs, because you have derived daily bars. just save original ohlcv to temp variables, calculate what you need and restore them. (it is in the KB article)

Just following up. I think I got it now. Posting what I got to close the loop. I'm sure there are more efficient ways to write this, but its got me where I need to go for the time being. The only thing that was giving me issues was the MA(myV,20) with the sparseexpand, but the timeframeset/expansion seemed to work fine for getting me that information. I might circle back and figure it out at a later date, but for now I should be able to carry on as is. I appreciate all the help on this. Thanks!

//-------------------------------------------------------------------------------
// 1. Daily Parameter Calculations
//-------------------------------------------------------------------------------


//Date and time conditions

tn = TimeNum();
NewDay = Day()!=Ref(Day(),-1);

// Define Times for Premarket / Market / Afterhours Session

PM_Session_Open = 040000;
Session_Open = 093000;
Session_Close   = 160000;
AH_Session_Close = 195900;

// Define Conditions for Premarket / Market / Afterhours Sessionhh

PM_SessionStart = tn == PM_Session_Open;
SessionStart = tn == Session_Open;
SessionEnd = tn == Session_Close;
AH_SessionEnd = tn == AH_Session_Close;

All_Sessions = tn>=PM_Session_Open AND tn <=AH_Session_Close;
Session = tn>= Session_Open AND tn<= Session_Close;

// Define OHLCV

myH = ValueWhen( SessionEnd, HighestSince( SessionStart, High ) );
myL = ValueWhen( SessionEnd, LowestSince( SessionStart, Low ) );
myO = ValueWhen( SessionStart, Open );
myC = ValueWhen( SessionEnd, Close );
myV = ValueWhen( AH_SessionEnd, HighestSince(NewDay,SumSince( NewDay, V ,True) ));

// Prepare OHLC for Plotting

myO1=IIf( Session, Null, myO );
myH1=IIf( Session, Null, myH );
myL1=IIf( Session, Null, myL );
myC1=IIf( Session, Null, myC );
myV1=IIf( Session, Null, myV );

// Sparse Compress OHLC values

compO = SparseCompress( SessionStart, myO );
compH = SparseCompress( SessionEnd, myH );
compL = SparseCompress( SessionEnd, myL );
compC = SparseCompress( SessionEnd, myC );
compV = SparseCompress( AH_SessionEnd, myV );

// Calculate Gap%

Gap_Pct = (((myO-Ref(myC,-1))/Ref(myC,-1)))*100;

// Calculate 20D Average Volume

TimeFrameSet(inDaily);

Prev20DAvgVol_D = MA(V,20);

TimeFrameRestore();

Prev20DAvgVol_E = TimeFrameExpand(Prev20DAvgVol_D, inDaily,expandFirst);

CompV_Calc = MA(CompV,20);
CompV_E = SparseExpand(AH_SessionEnd,CompV_Calc);

// Calculate Previous ATR

True_range = Max(compH-compL, Max(abs(compH-Ref(compC,-1)),abs(compL-Ref(compC,-1))));
ATR_Calc = Wilders(True_range,14);
ATR_E = SparseExpand(SessionEnd, ATR_Calc);

// Allow ATR to be plotted during session hours
ATR_inAM = ValueWhen(Session,ATR_E);

//-------------------------------------------------------------------------------
// 2. Intraday Parameter Calculations
//-------------------------------------------------------------------------------

// Premarket Volume Calculation

PM_Vol = ValueWhen( Cross(tn,092900), SumSince( NewDay , V ) );

//-------------------------------------------------------------------------------
// 3. Conditional Filtering
//-------------------------------------------------------------------------------

// Gap up or down +/-3%

C1 = Gap_Pct >= 3 OR Gap_Pct <= -3;

// Previous ATR > 1

C2 = ATR_inAM >= 1;

// 20D average Vol > 2,000,000

C3 = Prev20DAvgVol_E >= 2000000;

// Premarket Volume > 200,000

C4 = PM_Vol >= 200000;

//Filter for conditions at open to 

OnRadar = IIf(C1 AND C2 AND C3 AND C4 AND SessionStart,1,0);

Filter = 1;

AddColumn(myO,"Open",1.2);
AddColumn(myH,"High",1.2);
AddColumn(myL,"Low",1.2);
AddColumn(myC,"Close",1.2);
AddColumn(myV, "Volume",1.2);
AddColumn(Gap_Pct, "Gap%",1.2);
AddColumn(Prev20DAvgVol_E, "20D Avg Vol",1.2);
AddColumn(ATR_E, "Prev ATR", 1.2);
AddColumn(PM_Vol, "PM Vol", 1.2);
AddColumn(OnRadar, "OnRadar at Open", 1.2);