Plot Previous Day Close in ThinkorSwim

BenTen

Administrative
Staff
VIP
A thinkscript code to help you plot previous close to your ThinkorSwim chart. The previous day's close level is important to determine intraday directional bias.

Code:
# Previous Day Closing Price (PCL)
input aggregationPeriod = AggregationPeriod.DAY;
def close = close(period = aggregationPeriod)[1];
plot previous_close = close;
 

Playstation

Active member
VIP
This is a really simple indicator code by me, Playstation, using Mr Yen's aka realBrianWatt method of trading within the zones of 40 handles on /ES.
Warning: Only use this on /ES, not for any other products. Change deviation according to what you want. 20 each side is the suggested value.

Code:
# Previous Day Close Made By Playstation using MrYen aka realBrianWatt method.
# This remains free for all to use.

input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
input deviation = 20;

plot PreviousDayClose;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) { PreviousDayClose = Double.NaN;}
else { PreviousDayClose = Highest(close(period = aggregationPeriod)[-displace], length);}

PreviousDayClose.SetLineWeight(3);
PreviousDayClose.SetDefaultColor(Color.GREEN);


def TC = PreviousDayClose + deviation;
def BC = PreviousDayClose - deviation;

def TC2 = TC+40;
def BC2 = BC-40;

AddCloud(TC, TC2, Color.RED, Color.RED);
AddCloud(BC, BC2, Color.GREEN, Color.GREEN);

Totally forgot about the Discord and here. Yes, please follow Mr Yen, aka realbrianwatt on twitter for understanding of his method. He does have a youtube channel where he does his live sessions, so it would be good to learn there on his methods of trading.

**fair warning, he cusses and rants alot...but what he teaches is golden.
 
Last edited:

lrc11239

Member
VIP
Would you be able to plot the price labels for the previous close and the clouds/boxes?? Many thanks
 

BenTen

Administrative
Staff
VIP
@lrc11239 Here's the chart bubble. Just add it to the end of your script.

Code:
input showBubble = yes;
def SR = showBubble and !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());
AddChartBubble(SR, PreviousDayClose, "PrevClose", Color.Dark_Orange);
 

jay_charting

New member
Daily Bias Statistics (Notes by JQ)

Code:
# Daily Bias Statistics
# Mobius
# Study tracks the open vs previous close and current days closing bias
# V01.07.2015

def RTHopen = open(period = AggregationPeriod.Day);  #    Today's Open     RTH is Regular Trading Hours 
def prevRTHclose = close(period = AggregationPeriod.Day)[1];    # Previous Day's close of regular trading hours
def RTHclose = close(period = AggregationPeriod.Day);    #    Today's Close     RTH is Regular Trading Hours

def countUp = if RTHopen < prevRTHclose and
                 RTHclose < RTHopen
              then countUp[1] + 1
              else countUp[1];

def countDn = if RTHopen > prevRTHclose and
                 RTHclose > RTHopen
              then countDn[1] + 1
              else countDn[1];

def barCount = compoundValue(1, barCount[1] + 1, 0);
def Pup = (barCount - countUp) / barNumber();
def Pdn = (barCount - countDn) / barNumber();
AddLabel(1, "%O < PC and C < O = " + AsPercent(Pup) +
          "  %O > PC and C > O = " + AsPercent(Pdn),
            if RTHopen < prevRTHclose and RTHclose < RTHopen
            then color.red
            else if RTHopen < prevRTHclose and RTHclose > RTHopen
                 then color.yellow
                 else color.white);
# End Code Daily Bias
 

BenTen

Administrative
Staff
VIP
I think this give you what you need, I'm guessing it's not exactly what you think you want. It took a bit of analysis of the Gap Zone Map before I understood that the zones aren't plotted, only the previous day's close. The gap analysis is watching how the next day's price open moves vis-a-vis the previous day's close. The Gap Zone Map delineates the probably of movement when the previous day's close is a down day or an up day. That can't be plotted, if you're going to trade this system, 1) print out the Gap Zone Map and stick it up somewhere close to your trading station so you see it every time you look up, 2) memorize the Gap Zone Map so you understand the probabilities of moving from the current day's open based on the previous day's close, and 3) buy the $14.95 book so you learn everything you can about gap analysis in the Master The Gap system. Why so harsh? I'm seeing a trend that folks, for whatever reason, aren't putting much effort into helping themselves before posting a request to the forum. So for instance, the real chart study here was the previous day close plot, I wouldn't hazard a guess as to how many requests we've gotten here for a previous day close study.

So following time honored tradition I offer yet another previous day's close study. In order to give this some value above and beyond previous such studies this one plot's the previous day's close in a big, bold orange, medium dashed line. It will plot correctly on any timeframe day or less, in other words it won't plot on weekly or monthly charts. Additionally, on intraday charts it will also plot a cloud between the previous day's close and the current price, that way you can see the progress of the gap fade, if any. This doesn't work on daily charts as the AddCloud function needs more than two days, yesterdays and today's bars to paint a cloud. But I'm betting that you're not looking to use this on daily charts. The cloud makes it easy to see the gap fade, if it occurs.

Link http://www.masterthegap.com/public/...b0ac90c5bf1f704b888f23d3fc48da92eaf9c2dfbb87a

Richard Houser

5ratG8M.png

h8jmlPx.png


thinkScript Code

Code:
# RH_PreviousDayCloseGapAnalysisSTUDY.ts
# Code by rhouser
# copyright 4/23/2013 All rights reserved.
# Permission granted to use, copy, modify to members of the Yahoo TOS_thinkscript Group

#hint:<b>RH_PreviousDayCloseGapAnalysis</b>\n
declare upper;

def lastDayToday    = if GetLastDay() == GetDay() and GetLastYear() == GetYear() then yes else no;

plot PrevDayClose   = HighestAll( if lastDayToday then close( period = "DAY" )[1] else Double.NaN );
def CurrentClose   = if lastDayToday then close else Double.NaN;

AddCloud( PrevDayClose, CurrentClose, Color.PINK, Color.LIME );

#===============================[ Look & Feel ]================================
PrevDayClose.SetDefaultColor( Color.ORANGE );
PrevDayClose.SetLineWeight( 2 );
PrevDayClose.SetStyle( Curve.MEDIUM_DASH );

Shareable Link: https://tos.mx/CgUxAS
 

airsakuragi

New member
Hi Guys, I'm trying to make a scanner that shows stock crossing previous day close. Let say it opens -1% and then it will come out on the scanner when it goes +.01%. I have a script of previous day close but its on Day time frame and it goes error when I change it to 5 min.
 

jngy2k

Member
VIP
FKS6Nan.png


Code:
def agPeriod = AggregationPeriod.DAY;

def cod = close(period=agPeriod);

def prevcl= cod[1];

plot PCl= prevcl;

Is there a way to get rid of the connecting line from one day to the next? I only want the display to show the price line and not the vertical movement in post market.
 

usa10

New member
Active break above Previous Close scanner:

Code:
# Scan forActive break above Previous Close
# Mobius
def prevClose = if getTime() crosses above RegularTradingEnd(getYYYYMMDD())
                then close
                else prevClose[1];
def Active = if SecondsTillTime(0830) > 0 and
                SecondsFromTime(0915) <= 0
             then 1
             else 0;
plot Break = Active and close crosses above prevClose;
#plot BreakoutDn = Active and close crosses below prevClose;

Percentage away from previous close:

Code:
# Scan for 1 Percent gap from Previous Close
# Scan at 5 min aggregation
# Mobius
# Chat Room Request

def PrevClose = if SecondsTillTime(1555) == 0 and
                   SecondsFromTime(1555) == 0
                then close
                else PrevClose[1];
def ScanActive = if SecondsTillTime(0930) >= 0 and
                    SecondsFromTime(0730) > 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];
# Comment out (#) Plot NOT wanted
plot gapUP = if ScanActive and ll > PrevClose * 1.01
             then 1
             else 0;
#plot gapDN = if ScanActive and hh < PrevClose * .99
#             then 1
#             else 0;
 

BenTen

Administrative
Staff
VIP
For this to work, you must have extended hours enabled, and the data is only accurate once the market is open.

Code:
# GlobeX or Overnight High / Low v.07.2017
# Mobius
# V01.2012
# V07.2017 Replaced Time Brackets with GetTime() function which works better with Mobile
# Modified by BenTen at UseThinkScript.com

input PlotOverNightExtremes = yes;

def h = high;
def l = low;
def bar = BarNumber();
def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
def ONhigh = if GlobeX and !Globex[1]
             then h
             else if Globex and
                     h > ONhigh[1]
                  then h
                  else ONhigh[1];
def ONhighBar = if GlobeX and h == ONhigh
                then Bar
                else double.nan;
def ONlow = if GlobeX and !GlobeX[1]
            then l
            else if GlobeX and
                    l < ONlow[1]
                 then l
                 else ONlow[1];
def ONlowBar = if GlobeX and l == ONlow
               then Bar
               else double.nan;
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
                    then ONhigh
                    else OverNightHigh[1];
def ONH = if OverNightHigh > 0
           then OverNightHigh
           else Double.NaN;

def prev_close = close(period = "day" )[1];

def Range = prev_close - ONH;

AddLabel(yes, Concat("Range = ", Range), color.orange);
 

Cribbage

New member
I'm interested in a study that paints a bar if it runs 20% above the close of the previous par. If it matters, I'd be using this exclusively on a daily time frame. This would capture stocks that gap up then selloff but still are 20% above previous day's close. Any help is appreciated.

Edit: This study got me close to what I was looking for: https://usethinkscript.com/threads/percent-range-flags-turning-points-for-thinkorswim.1310/ . I just set up the PctAbove to 20% and set it to a 2-bar length. Good enough.
 
Last edited:

shahgols

New member
Hi all, I have been trying and trying to put together two scripts and am frustrated...I just don't have a programmer's instincts I guess. Would you kindly help me with these two scripts?

1. Script that shows stocks that opened a certain percentage (let's say 5% or more) lower than yesterday's close.

2. Script that shows how many percent the stocks is down from yesterday's close at any time that I run the script. So if at 9:40 the stock is down 1%, and it shows 1% and if I run it again at 9:45 and it's down 2%, it shows 2%.

Many thanks in advance!
 

shahgols

New member
Hi Generic, thanks for your input, but I am trying to set up a scanner that shows me the list of stocks that match those criteria.
 

generic

Active member
@shahgols There's a gap up and gap down scanner. You should also have a %change column to compare current price to previous close.

Here is the scanner code I set up.
Code:
#Wizard text: Current bar's
#Wizard input: price1
#Wizard text: gaps 
#Wizard input: percentage
#Wizard text: % or more below the previous
#Wizard input: price2

input price1 = high;
input percentage = 5.0;
input price2 = low;
def x = 1-percentage/100;
def term = x*price2[1];
plot scan = price1 <= term;
 

Similar threads

Top