In this code snippet, I manually entered 7 stock symbols as conditions for scanning only those 7 symbols. Every time I want to change or add/remove these symbols, I have to manually adjust the conditions in the scan command, which is very inconvenient. Can anyone help me find a way to enter the symbols only once manually, and the program will scan according to the entered set?
Code:
input Day_Session_From_Open = 0400;
input Day_Session_End = 0929;
# Define input variables for each stock symbol
input Stock1 = "TSLA";
input Stock2 = "NVDA";
input Stock3 = "AAPL";
input Stock4 = "AMZN";
input Stock5 = "MSFT";
input Stock6 = "SPY";
input Stock7 = "QQQ";
def v = volume;
def na = Double.NaN;
def Is_Session_From_Open = SecondsFromTime(Day_Session_From_Open) >= 0 && SecondsTillTime(Day_Session_End) > 0;
def New_Session_From_Open = Is_Session_From_Open && !Is_Session_From_Open[1];
def Cum_Vol = if New_Session_From_Open
then v
else if Is_Session_From_Open
then Cum_Vol[1] + v
else Cum_Vol[1];
def count = count[1] + if New_Session_From_Open
then 1
else 0;
def Session_Volume1;
def Session_Volume2;
def Session_Volume3;
def Session_Volume4;
if (New_Session_From_Open and count > 1) {
Session_Volume1 = Cum_Vol[1];
Session_Volume2 = Session_Volume1[1]; # Corrected typo here
Session_Volume3 = Session_Volume2[1]; # Corrected Typo Here
Session_Volume4 = Session_Volume3[1]; # Corrected typo here
} else {
Session_Volume1 = Session_Volume1[1];
Session_Volume2 = Session_Volume2[1];
Session_Volume3 = Session_Volume3[1];
Session_Volume4 = Session_Volume4[1];
}
def avgs = (Session_Volume1 + Session_Volume2 + Session_Volume3 + Session_Volume4) / 4;
# Check which stock symbol is selected from the dropdown menu
def IsStock1 = GetSymbol() == Stock1;
def IsStock2 = GetSymbol() == Stock2;
def IsStock3 = GetSymbol() == Stock3;
def IsStock4 = GetSymbol() == Stock4;
def IsStock5 = GetSymbol() == Stock5;
def IsStock6 = GetSymbol() == Stock6;
def IsStock7 = GetSymbol() == Stock7;
def avg = Round(number = (Cum_Vol / avgs));
# Only scan the selected stock symbol
plot scan = (IsStock1 or IsStock2 or IsStock3 or IsStock4 or IsStock5 or IsStock6 or IsStock7) and avg >= 1.2 and Cum_Vol > Session_Volume1 and close >= 100;