input lookbackBars = 7;
def c = close;
def liquidityOk =
c > 20 and
Average(volume, 50) > 1000000;
def ema10 = ExpAverage(c, 10);
def ema21 = ExpAverage(c, 21);
def trendOk =
c > ema10 and
c > ema21 and
ema10 > ema21 and
ema10 > ema10[3] and
ema21 > ema21[3];
def h63 = Highest(high, 63);
def l63 = Lowest(low, 63);
def l20 = Lowest(low, 20);
def range63 = h63 - l63;
def rangePos63 = if range63 != 0 then (c - l63) / range63 else 0;
def pctOff20Low = if l20 != 0 then (c / l20) - 1 else 0;
def pctBelow63High = if h63 != 0 then (h63 - c) / h63 else 0;
def locationOk =
pctOff20Low > 0.10 and
pctBelow63High > 0.06 and
pctBelow63High < 0.20 and
rangePos63 > 0.45 and
rangePos63 < 0.78;
def repairSetup =
liquidityOk and
trendOk and
locationOk;
def lowestLow = Lowest(low, 4);
def highestHigh = Highest(high, 4);
def rangeA = highestHigh - lowestLow;
def kRaw =
if rangeA != 0
then 100 * (c - lowestLow) / rangeA
else 0;
def kSlow = WildersAverage(kRaw, 10);
def dLine = WildersAverage(kSlow, 10);
def turnUpNow =
dLine > dLine[1] and
dLine[1] <= dLine[2];
def recentTurnUp =
Highest(if turnUpNow then 1 else 0, lookbackBars) > 0;
plot scan =
repairSetup and
recentTurnUp;