PreMarket Gap from Previous Close for ThinkorSwim

Im looking for a study to identify stocks that have a price gap up from previous days close to current days open by a variable percentage.
Is there a study inside of Think or Swim for this or could someone provide a code for such?
Thanks!!
 
Im looking for a study to identify stocks that have a price gap up from previous days close to current days open by a variable percentage.
Is there a study inside of Think or Swim for this or could someone provide a code for such?
Thanks!!

The Prior Close has changed by at least X(Percent) from todays open (both up/bullish and down/bearish). Set aggregation to DAY.
For regular trading hours only. Does not include extened hours

Code:
#The Prior Close has changed by atleast X(Percent) from todays open (both up/bullish and down/bearish)
#Set aggregation to DAY
#For regular trading hours only. Does not include extened hours
#### Change Percent "2.5" to desired percent value
def percent = 2.5;

def price = open;
def length = 1;
def x = 100*(price / price[length]-1);
plot scan = x >= percent or  x <= -percent;
 
Last edited:
is there a way to find gaps from previous day's high (and low) as opposed to previous day's close ? Thanks
did you find one you'd be willing to share?
Im looking for a study to identify stocks that have a price gap up from previous days close to current days open by a variable percentage.
Is there a study inside of Think or Swim for this or could someone provide a code for such?
Thanks!!
ToS has a built in scan for this if you simply want a gap on today's daily candle above or below a point on yesterday's daily candle.

Add Filter > Study > from the drop down box = Price Performance > Gap_UP or Gap_Down
 
Pre-Market Gap from Previous Close for ThinkorSwim - can't seem to work scanner not been able to work for me..:(
 
Last edited by a moderator:
OK, OK, I am an OCD programmer. I modified it slightly to make it a bit more gooder and you don't have to delete anything. Just set the inputs in your scan.

-------------------------------------------------------------------

Code:
input percentGap = 0.5;
input direction = {default Up, Down};

def dnColor = 5;    # red
def upColor = 6;    # green

def arrowColor;
def arrowDirection;

def marketOpen    = 0930;
def marketPreOpen = 0730;
def marketClose   = 1555;

def PrevClose = if SecondsTillTime(marketClose) == 0 and
                   SecondsFromTime(marketClose) == 0
                then close
                else PrevClose[1];
def ScanActive = if SecondsTillTime(marketOpen) >= 0 and
                    SecondsFromTime(marketPreOpen) > 0
                 then 1
                 else 0;
def ll = if ScanActive and !ScanActive[1]
         then low
         else if !ScanActive
         then double.nan
         else if ScanActive and low < ll[1]
         then low
         else ll[1];
def hh = if ScanActive and !ScanActive[1]
         then high
         else if !ScanActive
         then double.nan
         else if ScanActive and high > hh[1]
         then high
         else hh[1];

def isPlot;
def gapChange;

switch (direction)
{
    case Up:
        arrowColor = upColor;
        arrowDirection = PaintingStrategy.BOOLEAN_ARROW_UP;
        gapChange = 1.0 + (percentGap / 100.0);

        isPlot = if ScanActive and ll > PrevClose * gapChange
                 then 1
                 else 0;

    case Down:
        arrowColor = dnColor;
        arrowDirection = PaintingStrategy.BOOLEAN_ARROW_DOWN;
        gapChange = 1.0 - (percentGap / 100.0);

        isPlot = if ScanActive and hh < PrevClose * gapChange
                 then 1
                 else 0;
}

plot GapPlot = (isPlot == 1);

GapPlot.SetPaintingStrategy(arrowDirection);
GapPlot.SetDefaultColor(GetColor(arrowColor));
I tried running this scan, but I am not getting back any results. Essentially I am looking for any gap up or gap down, 100,000 in volume & above $10. Would be ideal for all this to be in one scan. I ran on 5min timeframe and I did see results, but not on daily. I added volume criteria and returned nothing. Hopefully someone can help. I

Thank you
 
I tried running this scan, but I am not getting back any results. Essentially I am looking for any gap up or gap down, 100,000 in volume & above $10. Would be ideal for all this to be in one scan. I ran on 5min timeframe and I did see results, but not on daily. I added volume criteria and returned nothing. Hopefully someone can help. I

Thank you
@Stevengo By definition, this is only an intraday indicator.
 
hi,
I want to know if I can see in the pre-market gap up or down the percentage of the stocks ?
I can't see that before the market is open ? is there any formula ?
thanks
moti
 
Last edited by a moderator:
hi,
I want to know if I can see in the pre-market gap up or down the percentage of the stocks ?
I can't see that before the market is open ? is there any formula ?
thanks
moti
I moved your post here. Try the study in the top post and read how other members are using it throughout this thread
 
Open gap up from previous day close on my watchlist scan
So I wanted to know how to write a script for Open that is a gap-up over previous day Close.
I wrote out this, but I am unsure.

plot scan = open > close[1]; (with aggreation as D)
 
Last edited by a moderator:
Thank You all for these posts. I was able to get the premarket scanner to work! Can you please help me get a script to add to a custom column in the search results that will state the Gap% either up or down? I can then sort by the gap%. Thanks!
 
Thank You all for these posts. I was able to get the premarket scanner to work! Can you please help me get a script to add to a custom column in the search results that will state the Gap% either up or down? I can then sort by the gap%. Thanks!
The watchlist is the 2nd script in the 1st post of this thread
 
The watchlist is the 2nd script in the 1st post of this thread
Thanks MerryDay. But I tried that in premarket and in regular hours but in the column with the custom formula it returns the value: 9.22337203685477E16. It lists this for all stocks in my search results. I tried pasting all the formulas in this thread into my custom column (hoping to get lucky) but none of them returned the actual gap percentage.
 
Thanks MerryDay. But I tried that in premarket and in regular hours but in the column with the custom formula it returns the value: 9.22337203685477E16. It lists this for all stocks in my search results. I tried pasting all the formulas in this thread into my custom column (hoping to get lucky) but none of them returned the actual gap percentage.
You are right. That scripts seems to be fubar :(
 
This indicator adds a custom column to your watchlist of stocks that show when a gap has formed on the daily chart.
  • Red = Gap down
  • Green = Gap up
  • White = No gap

xYJalTL.png

RSsgb9w.png


thinkScript Code

Code:
# Billy Bob's Better Gap Indicator for Column alert
input Detect_Gaps_By = {default "percent", "dollars"};
input Min_Gap_Size = 1.0;

# Define Candle Body
def bodyTop = Max(open, close);
def bodyBottom = Min(open, close);

# Define a gap and its direction
def MinGapSize;
switch (Detect_Gaps_By) {
case "percent":
MinGapSize = Min(close[1] * (Min_Gap_Size/100),5);
case "dollars":
MinGapSize = Min_Gap_Size;
};

def GapUp = bodyBottom - bodyTop[1] >= MinGapSize;
def GapDown = bodyTop - bodyBottom[1] <= -MinGapSize;

plot isGap = if GapUp then 1 else if GapDown then 2 else 0;
isgap.AssignValueColor(if isgap ==1 then color.green else if isgap == 2 then color.red else color.white);

AssignBACKGROUNDColor(if isgap ==1 then color.green else if isgap == 2 then color.red else color.white);

Shareable Link

https://tos.mx/wMCwUM
Credit:
Hi, Can I request help with this code. I'm trying to get this column to show before/after market hours. I tried a couple of scenarios but could not get it working.

input closing_time = 1559;
input open_time = 0930;
input price = close;
input percent_change = 1.00;

def time_until_close = SecondsTillTime(closing_time);
def time_until_open = SecondsTillTime(open_time);
def closing_bell = time_until_close == 0;
rec closing_price = CompoundValue(1, if closing_bell then price else closing_price[1], price);
def after_closing_bell = time_until_close <= 0;
def before_opening_bell = time_until_open >= 0 ;
def afterhours_percent_change = 100 * (price / closing_price - 1);

input Detect_Gaps_By = {default "percent", "dollars"};
input Min_Gap_Size = 1.0;

# Define Candle Body
def bodyTop = Max(open, close);
def bodyBottom = Min(open, close);

# Define a gap and its direction
def MinGapSize;
switch (Detect_Gaps_By) {
case "percent":
MinGapSize = Min(close[1] * (Min_Gap_Size/100),5);
case "dollars":
MinGapSize = Min_Gap_Size;
};

def GapUp = (bodyBottom - bodyTop[1] >= MinGapSize) and afterhours_percent_change >= percent_change;
def GapDown = (bodyTop - bodyBottom[1] <= -MinGapSize) and afterhours_percent_change <= percent_change;

plot isGap = if gapUp then 1 else if gapDown then 2 else 0;
isgap.AssignValueColor(if isgap ==1 then color.green else if isgap == 2 then color.red else color.white);

AssignBACKGROUNDColor(if isgap ==1 then color.green else if isgap == 2 then color.red else color.white);
 
Hello. I found Mobius's scan (script below). Can someone help me change it?
I want a gap scanner (yesterday's close to premarket price). I want to find stocks that Gap Up and down. I ran it during regular mkt hours and I get too many results. How can I modify this script?
Changes
#1. compare current close to yesterdays close. Current close should be up until the market opens at 9:30. So, after 9:30 the list becomes static it does not change.
#2. include stocks that are gapping up and down. it would be nice to have the ability to change the gap percentage threshold from 1% to 3% or any % i want to look for.

Thanks for any tips you can offer.
Here's the script.
# Premarket Scan
# Mobius
# Scan looks for premarket price to be above previous day close and premarket volume to be above 1000
def ExtHrs = getTime() >= RegularTradingEnd(getYYYYMMDD());
def c = if ExtHrs and !ExtHrs[1]
then close[1]
else c[1];
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def vol = if isRollover and beforeStart
then volume
else if beforeStart
then vol[1] + volume
else vol[1];
def PreMarketVol = if IsNaN(vol)
then PreMarketVol[1]
else vol;
plot scan = if between(c, 1, 100) and PreMarketVol > 1000 and close > c then 1 else 0;
 
Last edited by a moderator:
Hello. I found Mobius's scan (script below). Can someone help me change it?
I want a gap scanner (yesterday's close to premarket price). I want to find stocks that Gap Up and down. I ran it during regular mkt hours and I get too many results. How can I modify this script?
Changes
#1. compare current close to yesterdays close. Current close should be up until the market opens at 9:30. So, after 9:30 the list becomes static it does not change.
#2. include stocks that are gapping up and down. it would be nice to have the ability to change the gap percentage threshold from 1% to 3% or any % i want to look for.

Thanks for any tips you can offer.
Here's the script.
# Premarket Scan
# Mobius
# Scan looks for premarket price to be above previous day close and premarket volume to be above 1000
def ExtHrs = getTime() >= RegularTradingEnd(getYYYYMMDD());
def c = if ExtHrs and !ExtHrs[1]
then close[1]
else c[1];
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def vol = if isRollover and beforeStart
then volume
else if beforeStart
then vol[1] + volume
else vol[1];
def PreMarketVol = if IsNaN(vol)
then PreMarketVol[1]
else vol;
plot scan = if between(c, 1, 100) and PreMarketVol > 1000 and close > c then 1 else 0;
Did you ever figure this out?
 

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
359 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