Help screener for exploration

Hello,

I enclose an example of my screener, but do not list it as I want.
At the end I'll give you an example in Excel.

Screener%2001

This is the code:

// Counting the actual Trading Days each month
// And just for an example exploring for the 1st trading day 
// in any given month

TradingDayThisMonth = BarsSince( Day() < Ref(Day(),-1) ) + 1;

FirstDay = TradingDayThisMonth==1;

// in AmiBroker there are many ways to arrive at the same endpoint
// the following code arrives at the same result as the above code

alternateCode = BarsSince(Month() != Ref( Month(), -1) )+1;

// another interesting day is often the first trading day of the month
isFirstOfMonth = Month() != Ref(Month(),-1);

// another method looking at Last trading day of month
LastDayOfMonth = TimeframeExpand(1, inMonthly, expandPoint);

Filter=isFirstOfMonth > 0 OR LastDayOfMonth > 0;
// Filter=1;

yr = Year();
mo = Month();
dt = DateTime();

YearChange = yr != Ref( yr, -1 );
MonChange = mo != Ref( mo, -1 );

AddColumn(IIf(isFirstOfMonth, DateTime(), null),"Fecha Inicial", formatDateTime);
AddColumn(isFirstOfMonth,"Primer Día Mes", 1.0,colorWhite, IIf(isFirstOfMonth, colorBlue,colorDefault));
AddColumn(IIf(isFirstOfMonth, C, null), "Cierre Inicial", 1.2, colorBlack);
AddColumn(IIf(LastDayOfMonth, DateTime(), null),"Fecha Final", formatDateTime);
AddColumn(LastDayOfMonth, "Ultimo Día Mes", 1.0, colorWhite, IIf(LastDayOfMonth, colorRed, colorDefault));
AddColumn(IIf(LastDayOfMonth, C, null), "Cierre Final", 1.2, colorBlack);

I need you to list on each line one month (example):
Excel%2001

Best regards,
Carlos

@carlosrodrgueznieto if you'll filter only on the last day of the month you can still print the first day of month date and is Close retaining their value in arrays using the ValueWhen() function, using the isFirstOfMonth as the condition to be applied to the DateTime() and to the Close() arrays.

(By the way, in the code as it is, there is a minor issue for the more recent month values when the month is not yet "closed").

1 Like

Use ValueWhen for isfirstmonth

// Counting the actual Trading Days each month
// And just for an example exploring for the 1st trading day 
// in any given month

TradingDayThisMonth = BarsSince( Day() < Ref(Day(),-1) ) + 1;
FirstDay = TradingDayThisMonth==1;

// in AmiBroker there are many ways to arrive at the same endpoint
// the following code arrives at the same result as the above code

alternateCode = BarsSince(Month() != Ref( Month(), -1) )+1;

// another interesting day is often the first trading day of the month
isFirstOfMonth = Month() != Ref(Month(),-1);


// another method looking at Last trading day of month
LastDayOfMonth = TimeframeExpand(1, inMonthly, expandPoint);

Filter= LastDayOfMonth;

// Filter=1;

yr = Year();
mo = Month();
dt = DateTime();

YearChange = yr != Ref( yr, -1 );
MonChange = mo != Ref( mo, -1 );

AddColumn(ValueWhen(isFirstOfMonth, DateTime()),"Fecha Inicial", formatDateTime);
AddColumn(ValueWhen(isFirstOfMonth, 1),"Primer Día Mes", 1.0,colorWhite, ValueWhen(isFirstOfMonth, colorBlue));
AddColumn(ValueWhen(isFirstOfMonth, C), "Cierre Inicial", 1.2, colorBlack);
AddColumn(IIf(LastDayOfMonth, DateTime(), null),"Fecha Final", formatDateTime);
AddColumn(LastDayOfMonth, "Ultimo Día Mes", 1.0, colorWhite, IIf(LastDayOfMonth, colorRed, colorDefault));
AddColumn(IIf(LastDayOfMonth, C, null), "Cierre Final", 1.2, colorBlack);
2 Likes

Thanks for your help, now it works correctly.

Best regards,
Carlos