@BernieTGN,

FYI, my previously posted LastDOM function is only working on EOD data (if doing **equality** checks with DateTime() array -> Datetime() **==** YourDateTime ). (Update of LastDOM is below)

If you have iEOD data (-> intraday data or Daily TF constructed from intraday data) and you do such equality check with LastDOM() there then it will **not** work.

Why? Because if having EOD data then time info is missing while on the other hand if using iEOD data then you have time info (->e.g. "00:00:00" for all daily bars).

LastDOM has this line -> DateTimeConvert(2, dn) -> default 3rd (time) argument is Null. So if you compare e.g "2018-11-30" of DateTimeConvert with intraday datetime element such as "2018-11-30 00:00:00" then it will be false despite of day being the same one.

So with a trick one can check if it is EOD data or iEOD data using DateTimeConvert:

```
// if EOD data then it returns false (0) (daily TF is applied)
// if iEOD data then it returns true (1)
tn = TimeNum();
isIEOD = tn == DateTimeConvert(1, DateTime());
// on EOD data (daily bars data) below printf returns timenum 316363
printf( "TimeNum: %g", SelectedValue(DateTimeConvert(1, DateTime())));
printf( "\nIs it iEOD? %s", StrExtract("No.,Yes.", SelectedValue(isIEOD)) );
```

So here is adjustment of LastDOM() function now working with EOD and iEOD data.

It is added Timenum() to DateTimeConvert if iEOD data and it is added Null if EOD data (if Daily TF is selected on latter one).

I have also added separate switches to Friday and Monday if Date is on weekend.

```
function LastDOM( mth, yr ) {
/// last day of month function
/// function returns datetime format
/// works in realtime as well as historically
/// mth, yr may be type array or number
/// now works on EOD and iEOD data
/// AFL function by fxshrat@gmail.com
local DIM, DIFeb, days, dn, tn;
DIM = IIf( mth % 2 == 0 AND mth < 8 OR mth == 9 OR mth == 11, 30, 31 );
/// leap year approach from:
/// @link https://stackoverflow.com/questions/3220163/how-to-find-leap-year-programatically-in-c
DIFeb = IIf( (yr & 3) == 0 AND ((yr % 25) != 0 OR (yr & 15) == 0), 29, 28 );
///
days = IIf(mth == 2, DIFeb, DIM);
dn = 10000 * (yr-1900) + 100 * mth + days;
///
tn = TimeNum();
tn = IIf(tn == DateTimeConvert(1, DateTime()), tn, Null);
return DateTimeConvert(2, dn, tn);
}
function switch_to_fri( dt ) {
local dt, result;
dow = DateTimeConvert( 9, dt );
result = IIf( dow == 6, DateTimeAdd(dt, -1, inDaily), // if date is Saturday then get FRI dt
IIf( dow == 0, DateTimeAdd(dt, -2, inDaily), // if date is Sunday then get FRI dt
dt ) );// else get input date
return result;
}
function switch_to_mon( dt ) {
local dt, result;
dow = DateTimeConvert( 9, dt );
result = IIf( dow == 6, DateTimeAdd(dt, 2, inDaily), // if date is Saturday then get MON dt
IIf( dow == 0, DateTimeAdd(dt, 1, inDaily), // if date is Sunday then get MON dt
dt ) );// else get input date
return result;
}
function LastBOM( mth, yr ) {
/// last business day of month (not including holidays check)
/// function returns datetime format
/// works in realtime as well as historically
/// mth, yr may be type array or number
/// AFL function by fxshrat@gmail.com
local ldm, result;
ldm = LastDOM( mth, yr );
result = switch_to_fri( ldm );
return result;
}
/// output 5th day before Month end
/// it does not check for holidays! But it is doable also
/// There are a few scenarios in there depending on what you actually want (so you need to study it a bit!)
/// @link https://forum.amibroker.com/t/should-i-leave-temporarily-afl/9587/17
dt = DateTime();
// Last day of month
EndOfMonth = LastDOM(Month(), Year());
// OR:
// use Last Business day of Month function
// if you do not want to count from last day of month being on weekends
// then uncomment below line
//EndOfMonth = LastBOM( Month(), Year() );
// fifth day before end of month or before last business day of month
fifth_day = DateTimeAdd(EndOfMonth, -5, inDaily);
//
// OR additionally add (or comment) below variable.
// If fifth day before EOM is on weekend and you want to get business day (FRI) before weekend
fifth_day = switch_to_fri( fifth_day );
//
// OR switch to Monday (COMMENT upper 'fifth_day' single line before uncommenting below one!)
//fifth_day = switch_to_mon( fifth_day );
//
isEntryDay = ExRem(dt >= fifth_day, dt < fifth_day);
// or if you want equality check instead then uncomment below line
//isEntryDay = dt == fifth_day;
Plot(C, "Price", colorDefault, styleCandle );
Plot(isEntryDay, "", colorRed, styleHistogram | styleOwnScale | styleNoLabel);
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} - {{DATE}} {{VALUES}}" ));
```