I have written the following exploration as a learning exercise.
However, when a stock does NOT meet the listing condition the Exploration still lists every quote for that stock (ticker)in the Date Range - Ticker & (Quote) date.
When I run the code using the Debugger for a stock NOT meeting the condition, the AddColumn code (dependent on If & Filter condition) is not executed but appears to be being generated as the code Exits the While loop.....I am mystified as to how/why the list is being generated for those stocks.
Would someone please explain?
//List those stocks which Closed <= 52 week Low +10%
//within the last 31 days
Liquidity = MA(C*V,21);
Filter = Liquidity >= 1000000;
LastX = LastValue(BarIndex()); //is number
StartX = (LastX - 31); //is number //set index for 1 month earlier than BarCount -1
if (StartX < 0)
StartX =0;
// get the 52 week (260 days) Low
Low52 = LLV(Low,260); //is array
//Add 10% to the 52 week Low
Low5210 = Low52 + ((Low52 * 10) / 100); //is array
//Now get the Index of the 52 week Low
BarsSinceLow52 = LLVBars(Low,260); //is array
//Get the index of the 52 week Low
Low52X = LastX - BarsSinceLow52[LastX];
LowDate = ValueWhen(Low[Low52X],DateTime()); //is array //get date of 52 week low
L52X = NumToStr(Low52X,1.0);
// get the lowest Close in the last 31 days
CloseLow = LLV(Close,31); //is array
BarsSinceLowClose = LLVBars(Close,31); //is array
//Get the Index of the 31 day lowest Close
CloseLowX = LastX - BarsSinceLowClose[LastX];
CloseLowDate = ValueWhen(Close[CloseLowX],DateTime()); //is array //get the date of the lowest Close
CLX = NumToStr(CloseLowX,1.0);
StartDate = ValueWhen(Close[StartX],DateTime());//is array //get the period start date
EndDate = ValueWhen(Close[LastX], DateTime()); //is array //get the date of the last Close
//List the most recent Close which is <= 52 week Low + 10%
X = LastX;
Ok = 0;
while (X >= StartX)
{
Ok = IIf(Close[X] <= Low5210[LastX],1,0);
if (Ok==1)
{
Filter = (X == BarIndex());
AddColumn(Close[X],"Close",format = 1.2);
AddColumn(LowDate[Low52X],"Low52Dte",formatdateTime);
AddColumn(Low52[Low52X],"52Wk$",format=1.2);
AddColumn(Low5210[Low52X], "+10%$", format = 1.2);
AddTextColumn(L52X,"Low52X",1.0);
AddColumn(CloseLowDate[CloseLowX],"CloseLowDte",formatdateTime);
AddColumn(CloseLow[LastX],"CloseLow",format = 1.2);
AddTextColumn((NumToStr(BarsSinceLowClose)),"BarsSinceCloseLow");
AddTextColumn(CLX,"CloseLowX",1.0);
AddColumn(X,"X",format = 1.0);
AddColumn(StartDate[StartX],"StartDte",formatdateTime);
AddColumn(StartX,"StartX",format = 1);
AddColumn(EndDate[LastX],"EndDte",formatdateTime);
AddColumn(LastX,"LastX",format = 1.0);
AddColumn(BarIndex(),"BarIndex",format = 1);
X = -1;
}
else
{
X = X -1;
}
if (X == 198) //this If for debugging
Y = 0;
}
Y = 1; //this for debugging
//AddColumn(BarIndex(),"BarIndex-NBG",format=1); //This for debugging
Moderator comment: The post was missing required CODE TAGS. Added them