Run explore between two dates from afl

I want to run explore on two dates dynamically calculated (StartDate , EndDate )
to see stocks that meet the criteria
Is the method i am trying to implement is not feasible? if not what are the alternatives to achieve what i want?

// Find stocks that have gapped down in last 3 months

// Calculate EndDate as today
EndDate = Now(5);

// Calculate StartDate as 180 days ago from today
StartDate = DateTimeAdd( EndDate, -180, inDaily ); // Subtract 180 days

aGapDn = ( H < 0.95 * Ref(L, -1) ); // Identify GapDown bars
GapDate = ValueWhen(aGapDn, DateTime());
GapLow = ValueWhen(aGapDn, Ref(Low, -1));
GapHigh = ValueWhen(aGapDn, High);

latestClose = LastValue(Close);
latestDate = LastValue(DateTime());

//Filter = aGapDn AND latestClose > 0.9 * GapLow;
Filter = aGapDn AND Close > 0.9 * GapLow AND DateTime() >= StartDate AND DateTime() <= EndDate;



AddColumn(GapHigh, "GapHigh");
AddColumn(GapLow, "Gap Low");
AddColumn(Close, "Close");
AddColumn(latestClose, "latestClose");
AddColumn(GapDate, "GapDate", formatDateTime);
//AddColumn(latestClose, "Latest Close");
//AddColumn(latestDate, "Latest Date", formatDateTime);
AddColumn(StartDate, "StartDate", formatDateTime);
AddColumn(EndDate, "EndDate", formatDateTime);


Yes, it is totally possible. And your code is pretty much working fine. Just remove those extra checks and make Filter simple:

// Find stocks that have gapped down in last 3 months

// Calculate EndDate as today
EndDate = Now(5);

// Calculate StartDate as 180 days ago from today
StartDate = DateTimeAdd( EndDate, -180, inDaily ); // Subtract 180 days

aGapDn = ( H < 0.95 * Ref(L, -1) ); // Identify GapDown bars
GapDate = ValueWhen(aGapDn, DateTime());
GapLow = ValueWhen(aGapDn, Ref(Low, -1));
GapHigh = ValueWhen(aGapDn, High);

latestClose = LastValue(Close);
latestDate = LastValue(DateTime());

//Filter = aGapDn AND latestClose > 0.9 * GapLow;
Filter =  DateTime() >= StartDate AND DateTime() <= EndDate;



AddColumn(GapHigh, "GapHigh");
AddColumn(GapLow, "Gap Low");
AddColumn(Close, "Close");
AddColumn(latestClose, "latestClose");
AddColumn(GapDate, "GapDate", formatDateTime);
//AddColumn(latestClose, "Latest Close");
//AddColumn(latestDate, "Latest Date", formatDateTime);
AddColumn(StartDate, "StartDate", formatDateTime);
AddColumn(EndDate, "EndDate", formatDateTime);
1 Like

Thanks, but in many cases GapDate is out of range of the Filter given. How can i address it?

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.