Closing Price for morning session Instead of midnight in Multitimeframe

Hi Everyone,

I am new to AFL programming and currently working on extracting the closing price from the futures market. The market has two sessions:

  • Morning Session : 9:45 - 16:55

  • Night Session : 18:45 - 03:00 (next day)

My formula requires:

  1. Daily ATR
  2. Closing price of the morning session for each day (at 16:55)

I attempted the following AFL code but ended up retrieving the closing price at midnight (00:00 AM) instead of the expected morning session close.

My Current Code:


TimeFrameSet(inDaily);

PVD_Cls = Ref(Close,-1); // Close price of previous day
ATR(20)
pv_xp = TimeFrameExpand(PVD_Cl , inDaily,mode=expandFirst);

TimeFrameRestore();


Issue:

The above code returns the closing price at midnight (00:00 AM), but I need the closing price at 16:55 (end of the morning session).

Question:

How can I modify my code to retrieve the daily closing price specifically at 16:55 instead of midnight?

Thanks in advance for your help!

cond = TimeNum() == 165500; // or the start time of this bar

pc = IIf( cond, C, Null );

closeArray = ValueWhen( NOT IsNull( pc ), pc ); // fill Null with prev C

printf("\n%g", SelectedValue( closeArray ) );

@NSM51

Thank you very much for the code above.
It works perfectly!

However, the standard daily ATR still recalculates at midnight. Is there a way to modify it so that ATR updates at 16:55 instead?

I’d really appreciate any guidance.
Thanks in advance for your help!

you should post your code to avoid guessing game.

What i posted is to get your custom Close. You need to use the same thing for H and L.

Then, compress those arrays to Daily, and calculate your own ATR because the built-in function does not accept custom arrays. I am not sure if there is another way.