IPO stocks

Is it possible to make a scan for stocks that are less than 1 years old?
maybe a function that searches for price > 1 year = n/a but price < 1 year is true
 
I don't know if you can do that in ToS but you can use the free screener on Finviz.

AWjF4bN.png
 
IPO Date or First Trading Date

Hey gang. I have been using highest(volume,365) to get the highest volume in the past year but then I hit a NaN when I looked at a stock that had not been trading a full year. I have been trying to figure out how to avoid this NaN. One way is to check the IPO date. Psedo code would be

Code:
if (today - first trading date >= 365)
then
    highest(volume,today-first trading date)
else
    highest(volume,365)

Is there a way to get the IPO date or first trading day of a stock? Do you have any other ideas on how to solve this problem?

Thanks - Matt.
 
Last edited by a moderator:
OK. Here is the relevant code:

Code:
declare lower;

plot enhancedVolume = volume;

enhancedVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

def highestVolYear = highest(volume,252);

enhancedVolume.assignValueColor(if volume == highestVolYear then COLOR.WHITE);
 
@_Merch_Man_ You'll need to refine your logic further... Below is the corrected "relevant" code as well as the results on a 2Y 1D chart... As you can see, every time there is a new 252D volume it paints the volume bar white, otherwise gray...

Ruby:
declare lower;

plot enhancedVolume = volume;

enhancedVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

def highestVolYear = highest(volume,252);

enhancedVolume.assignValueColor(if volume == highestVolYear then COLOR.WHITE else COLOR.GRAY);

dxi2ghN.png
 
Sorry @rad14733 I clearly did not do a good job explaining the problem. The code does what I want except that it does not work for stocks that have not been trading for at least 252 days. For example, if I change the symbol to SLQT then the plot goes blank because highest(volume,252) is returning a NaN.
 
Spent another hour on this and have determined that the NaN is not the problem. I am still investigating. Thanks for your help thus far.

Edit 4/2 13:47 EST - I am going to start a new thread with a new problem description.
 
Last edited:
its not a number so you must use ISNAN
remember to leave a thumbs up if you found this post useful

here is what you originally requested:

Highest Volume in the past XYZ bars (version 1.0)
Works with recently listed IPOs and Trading Instruments
Default is 252 Days which is Highest Volume in past Year
Set to Day Aggregation

Code:
## Highest Volume in the past XYZ bars v1.0
## Works with recently listed IPOs and Trading Instruments
## Default is 252 Days which is Highest Volume in past Year
## Set to Day Agreggation
## By XeoNoX via usethinkscript.com April 02,2021
declare lower;
Input BarsAgo = 252;
def hv = if volume > hv[1] then volume else hv[1];
def highestVolYear = if isnan(highest(volume,barsago)) then hv else highest(volume,barsago);
AddLabel (yes, "Highest Volume " +  (highestVolYear )  );
plot scan = highestVolYear;

explanation:
if volume is greater then the previous volume then use that volume else keep searching
def hv = if volume > hv[1] then volume else hv[1];

if the highest volume from the past 252 bars is not a number then use HV else if it is a number then use highest volume from past 252 bars
def highestVolYear = if isnan(highest(volume,barsago)) then hv else highest(volume,barsago);
 
Last edited:
its not a number so you must use ISNAN
remember to leave a thumbs up if you found this post useful

here is what you originally requested:

Highest Volume in the past XYZ bars (version 1.0)
Works with recently listed IPOs and Trading Instruments
Default is 252 Days which is Highest Volume in past Year
Set to Day Aggregation

Code:
## Highest Volume in the past XYZ bars v1.0
## Works with recently listed IPOs and Trading Instruments
## Default is 252 Days which is Highest Volume in past Year
## Set to Day Agreggation
## By XeoNoX via usethinkscript.com April 02,2021
declare lower;
Input BarsAgo = 252;
def hv = if volume > hv[1] then volume else hv[1];
def highestVolYear = if isnan(highest(volume,barsago)) then hv else highest(volume,barsago);
AddLabel (yes, "Highest Volume " +  (highestVolYear )  );
plot scan = highestVolYear;

explanation:
if volume is greater then the previous volume then use that volume else keep searching
def hv = if volume > hv[1] then volume else hv[1];

if the highest volume from the past 252 bars is not a number then use HV else if it is a number then use highest volume from past 252 bars
def highestVolYear = if isnan(highest(volume,barsago)) then hv else highest(volume,barsago);

@XeoNoX - Thanks for taking the time to reply. Did you try this code on a chart with less than 252 bars? When I try this code I see the same problem - if there are less than 252 bars on the chart then the plot does not show up.
 
Yes, I get a label, but no volume histogram. You can see where the cursor is over the NewStudy2 the value is N/A over on the right axis.
Thanks for your help on this.

BEfNyKD.jpg
 
Yes, I get a label, but no volume histogram. You can see where the cursor is over the NewStudy2 the value is N/A over on the right axis.
Thanks for your help on this.

See if this helps. This is a workaround some of thinkscript's limitations when dealing with symbols opened less than the 'barsago' days. As mentioned, there may be simpler solutions, but this may be what you are requesting. The attached chart shows the same study in both the upper and lower panes.
Code:
#Example Highest Volume within Last barsago
#Usethinkscript request
#Workaround to handle charts with less than barsago input bars
#Sleepyz

#Use at least on a 2 YEAR DAILY CHART

input barsago   = 252;
input showlabel = yes;

def lastbar = if IsNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN;
def range   = CompoundValue(1, if Between(BarNumber(), HighestAll(lastbar) - barsago, HighestAll(lastbar)) then 1 else 0, 1);

#Highest Volume on a chart with more bars than barsago
def vol       = if range[1] == 0 and range == 1
                then volume
                else if volume > vol[1]
                then volume
                else vol[1];
def volext    = if BarNumber() > HighestAll(lastbar) then volext[1] else vol;
def volb      = if range == 1 and volume == vol
                then BarNumber()
                else Double.NaN;
plot v252_end = if HighestAll(lastbar) > barsago and BarNumber() >= HighestAll(volb)
                then volext
                else Double.NaN;
          
v252_end.setdefaultColor(color.yellow);
v252_end.setpaintingStrategy(paintingStrategy.HORIZONTAL);

#Highest Volume on a chart with less bars than barsago
def r       = if HighestAll(lastbar) < barsago then 1 else 0;
def volh    = if BarNumber() == 1 and !IsNaN(range)
              then volume
              else if  volume > volh[1]
              then volume
              else volh[1];
def volhext = if BarNumber() > HighestAll(lastbar) then volhext[1] else volh;
def volb1   = if volume == volh
              then barnumber()
              else Double.NaN;
plot v1_end = if isnan(r) or r then volhext else double.nan;
v1_end.setdefaultColor(color.yellow);
v1_end.setpaintingStrategy(paintingStrategy.HORIZONTAL);

AddLabel(showlabel, "Highest Volume" + (if r==1 then " Less than "  else "  ") + barsago + " days ago == " + (if r==1 then volh else vol), Color.YELLOW);

addverticalLine(if r==1 then barnumber()==highestall(volb1) else barnumber()==highestall(volb),"",color.yellow);
Capture.jpg
 
See if this helps. This is a workaround some of thinkscript's limitations when dealing with symbols opened less than the 'barsago' days. As mentioned, there may be simpler solutions, but this may be what you are requesting. The attached chart shows the same study in both the upper and lower panes.
Code:
#Example Highest Volume within Last barsago
#Usethinkscript request
#Workaround to handle charts with less than barsago input bars
#Sleepyz

#Use at least on a 2 YEAR DAILY CHART

input barsago   = 252;
input showlabel = yes;

def lastbar = if IsNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN;
def range   = CompoundValue(1, if Between(BarNumber(), HighestAll(lastbar) - barsago, HighestAll(lastbar)) then 1 else 0, 1);

#Highest Volume on a chart with more bars than barsago
def vol       = if range[1] == 0 and range == 1
                then volume
                else if volume > vol[1]
                then volume
                else vol[1];
def volext    = if BarNumber() > HighestAll(lastbar) then volext[1] else vol;
def volb      = if range == 1 and volume == vol
                then BarNumber()
                else Double.NaN;
plot v252_end = if HighestAll(lastbar) > barsago and BarNumber() >= HighestAll(volb)
                then volext
                else Double.NaN;
         
v252_end.setdefaultColor(color.yellow);
v252_end.setpaintingStrategy(paintingStrategy.HORIZONTAL);

#Highest Volume on a chart with less bars than barsago
def r       = if HighestAll(lastbar) < barsago then 1 else 0;
def volh    = if BarNumber() == 1 and !IsNaN(range)
              then volume
              else if  volume > volh[1]
              then volume
              else volh[1];
def volhext = if BarNumber() > HighestAll(lastbar) then volhext[1] else volh;
def volb1   = if volume == volh
              then barnumber()
              else Double.NaN;
plot v1_end = if isnan(r) or r then volhext else double.nan;
v1_end.setdefaultColor(color.yellow);
v1_end.setpaintingStrategy(paintingStrategy.HORIZONTAL);

AddLabel(showlabel, "Highest Volume" + (if r==1 then " Less than "  else "  ") + barsago + " days ago == " + (if r==1 then volh else vol), Color.YELLOW);

addverticalLine(if r==1 then barnumber()==highestall(volb1) else barnumber()==highestall(volb),"",color.yellow);
Capture.jpg
Thanks for taking the time to respond @SleepyZ. I am still trying to fully understand the code and how I could use it to get the desired bar color effects. Thanks again.
 
Handling IPOs and other instruments with a gap in data
I have a situation where I'm trying to average a stock over 252 days but the stocks that have not traded for 252 days are returning isNaN. Anyone have any ideas on how to structure the code to return the appropriate average in that scenerio?
this is the code I'm using as a column inside the scanner:

Code:
input displace = 0;
input SMA3 = 252;

def MaxGain = ROUND(((Highest(high, displace+1) / open)-1),4)*100;
def MaxLoss = ROUND(((lowest(low, displace+1) / open)-1),4)*100;

def VolFactor = (MaxGain - MaxLoss);

Plot Avg = Average(VolFactor,SMA3)[1]

I spent half the day today trying to adjust it and I don't think it's possible. The issue is around ToS requiring a flat number inside the average() or sum() functions. I experimented with TotalSum() which doesn't require an integer, and then using an If statement:

Code:
def DayCount= BarNumber()
Plot test = If DayCount < 252 then TotalSum(VolFactor) / DayCount else Average(VolFactor,252)[1];

The issue is that the software makes the code inoperable even if the average is inside of the if statement. For a stock like AFRM, that hasn't been trading for 252 days, just having Average(VolFactor,252) inside of the if statement, even if it's not being used, makes it not work.
 
Last edited by a moderator:

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
451 Online
Create Post

Similar threads

Similar threads

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