Hi all, I want to create a single scan that will return all stocks above the 200 daily SMA. The scan should also return recent IPOs (where there is no data for 200 daily SMA). Here is the scan I have but it always excludes IPOs (like RDDT). What am I doing wrong?
Code:
input minPrice = 0.10;
def stockPrice = close;
# Determine if the stock has enough data for a 200-day SMA
def hasEnoughData = BarNumber() >= 200;
# Calculate the 200-day SMA (only if enough data is available)
def SMA200 = if hasEnoughData then Average(close, 200) else Double.NaN;
# Include stocks based on SMA200 or recent IPOs
def isAbove200DSMA = hasEnoughData and stockPrice > SMA200;
def isRecentIPO = !hasEnoughData;
# Basic price condition
def isPriceGreaterThanMin = close > minPrice;
# Combine conditions to include stocks with sufficient data or recent IPOs
plot scan = isPriceGreaterThanMin and (isAbove200DSMA or isRecentIPO);