scan only the specific tickers

vantduong

Member
VIP
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;
 
Solution
Assuming that I am understanding the question correctly, you can't. Thinkscript's ability to parse and manipulate text is functionally non-existent. You can not, for example, extract symbols from a comma delineated list.
Assuming that I am understanding the question correctly, you can't. Thinkscript's ability to parse and manipulate text is functionally non-existent. You can not, for example, extract symbols from a comma delineated list.
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

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;

maybe you could create a watchlist of your stocks, and use that as the source for a scan.

https://usethinkscript.com/threads/how-to-run-scans-on-your-watchlist.8755/#post-80952

https://www.hahn-tech.com/ans/run-a-scan-against-my-personal-watchlist/
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
327 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top