Need help checking if price has not dipped below level


New member

I am trying to create a scan that can be used to find stocks which have opened and then gone up to a high and retraced but haven't crossed back over the midpoint between the low and high. I have tried a number of things but I keep getting strange results.

I want to be able to run this scan throughout the day, and after hours to look for setups both intraday and setups to prepare for the next trading day.

Below is what I have right now:

input marketOpen = 0930;
input marketClose = 1600;

def OpenCounter =  SecondsFromTime(marketOpen);
def CloseCounter = SecondsTillTime(marketClose);

def MarketHours = if OpenCounter >= 0 and CloseCounter >= 0 then 1 else 0;

def beforeMidnight = OpenCounter >= 0 and CloseCounter <= 0;
def afterMidnight = OpenCounter <= 0 and CloseCounter >= 0;

def Today;
rec DailyHigh;
rec DailyLow;
rec LowSinceHigh;

Today = if GetDay() != GetDay()[1] then 1 else 0;

DailyHigh = if Today then high else if MarketHours then if high > DailyHigh[1] then high else DailyHigh[1] else high;
DailyLow = if Today then low else if MarketHours then if low < DailyLow[1] then low else DailyLow[1] else low;

def bNum = if high == DailyHigh then 1 else bNum[1] + 1;
def lNum = if low == DailyLow then 1 else lNum[1] + 1;

LowSinceHigh = if MarketHours then if low < LowSinceHigh[1] and high != DailyHigh then low else LowSinceHigh[1] else low;

def midpoint = DailyLow + ((DailyHigh - DailyLow) / 2);
plot scan =
    lNum < bNum
    LowSinceHigh > midpoint;

the lNum < bNum is to ensure that the high comes after the low.

It looks like LowSinceHigh is always = 0 which is why it isn't working. Another problem I noticed is that right now it is after hours and yet SecondsTillTime(marketClose) reports 300 instead of 0 like I would expect.

Any help on these problems would be greatly appreciated!

Similar threads