find holidays on a chart (missing days) for ThinkOrSwim

halcyonguy

Moderator - Expert
VIP
Lifetime
find holidays, missing trading days, on a chart.
..draw a vertical line and/or a bubble
..the text includes the name of the missing day and the date after it.
..works on any timeframe. on smaller times, will need the expansion area set to a big number.


sometimes i forget about a holiday and end up holding a trade over it.
i wanted somthing on the chart, to remind me about future holidays.
i have been working on and off on some ideas for awhile. but they involve typing in dates, which gets messy and long, with all of the comparisons.

then today i was using dayofweek for something and i came up with this.

if references the first bar of the day.
now that it is done, i see i could have referenced the dayend variable and compared to a future value [-1] , and probably come up with the date of the missing day... but it's late and this will work for me.


Ruby:
# dow_holidays_01
# halcyonguy
# 22-04-06
# check if a trading day is skipped, holidays
# compare 2 day of week #'s  to see if a date was skipped
# dow 1 = monday , 5 = friday

# mobius
def data = getYYYYMMDD();
def year = Round(data/10000, 0);
def month = Round((data % 10000) / 100, 0);
def day = (data % 100);
#addLabel(1, "date: " + month + "/" + day + "/" + AsPrice(year), color.white);

def bn = barnumber();
def lastbar = !isnan(close[0]) and isnan(close[-1]);
def lastcls = if !isnan(close) and !lastbar then close else if lastbar then close else lastcls[1];

def DOW = GetDayOfWeek(GetYYYYMMDD());
def daystart = if GetDay() != GetDay()[1] then 1 else 0;
#def dayend = if GetDay() != GetDay()[-1] then 1 else 0;

# if no skip  = 99
def dayskipped;
if bn == 1 then {
  dayskipped = 99;
} else if (daystart and dow == 2 and dow[1] != 1) then {
  dayskipped = 1;
} else if (daystart and dow == 3 and dow[1] != 2) then {
  dayskipped = 2;
} else if (daystart and dow == 4 and dow[1] != 3) then {
  dayskipped = 3;
} else if (daystart and dow == 5 and dow[1] != 4) then {
  dayskipped = 4;
} else if (daystart and dow == 1 and dow[1] != 5) then {
  dayskipped = 5;
} else {
  dayskipped = 99;
}

input show_bubble = yes;
addchartbubble(show_bubble and dayskipped != 99, lastcls,
(if dayskipped == 1 then "Monday"
else if dayskipped == 2 then "Tuesday"
else if dayskipped == 3 then "Wednesday"
else if dayskipped == 4 then "Thursday"
else if dayskipped == 5 then "Friday"
else "") + "\n" +
"skipped\n" +
"before\n" +
( month + "/" + day + "/" + AsPrice(year) )
, color.cyan, no);

input show_vertical_line = yes;
addverticalline(show_vertical_line and dayskipped != 99,
(if dayskipped == 1 then "Monday"
else if dayskipped == 2 then "Tuesday"
else if dayskipped == 3 then "Wednesday"
else if dayskipped == 4 then "Thursday"
else if dayskipped == 5 then "Friday"
else "") + "  skipped before  " + ( month + "/" + day + "/" + AsPrice(year)) , color.cyan);

# ---------------------------------------------------------
input test1_dow = no;
AddChartBubble( test1_dow, lastcls, dow , color.yellow, no);
#

WMT day chart expansion area = 300
ORCF6J7.jpg

hal_hol
 

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

def na = Double.NaN;
def bn = BarNumber();
def lastbar = (!IsNaN(close) and IsNaN(close[-1]));
def newday = GetDay() <> GetDay()[1];
def currentday = GetDay() == GetLastDay();

# 0 = current day , 1 = prev day, 2 = 2 days ago
input days_back_date = 1;
def dayx = (GetDay() + days_back_date) == GetLastDay();



Hello, this is a part of a code I use it to draw yesterdays lows. It woek perfectly expets the days after market holidays ( it does not work on mondays because the day before is sundays and also it does not work the day just after holidays). Can someone help me. Thanks in advance.
 
@Doubbi
Use the difference between the values of GetDay() and GetDay()[1].
If it is greater than 1, the previous day is not charted(i.e. Sundays and Holidays).
So you would look back whatever the difference between GetDay()[1] and GetDay() number of days further to pull the previous trading day low.
 
@Doubbi
Use the difference between the values of GetDay() and GetDay()[1].
If it is greater than 1, the previous day is not charted(i.e. Sundays and Holidays).
So you would look back whatever the difference between GetDay()[1] and GetDay() number of days further to pull the previous trading day low.
Thank you very much.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
549 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