Non Trading days

Continuing the discussion from DayofWeek issues in a Rotation strategy:
@portfoliobuilder could you offer any advice how to deal with non trading days as you've highlighted?
In the circumstance, for example;
C < MA(C,50) AND DayOfWeek() ==5
Sell next open

Welcome to the forum @wverney . In AmiBroker most issues can be solved in multiple different ways. If you have a strategy that you are backtesting and need to identify the last trading day of the week you can ….

If using daily data, looking forward so OK for backtesting

EndOfWeek = DayOfWeek() > Ref( DayOfWeek(), 1 ); //looks ahead so can't use in realtime


Use some of the many different multitimeframe functions that AmiBroker has to offer, for example

EndOfWeek = TimeFrameExpand(1, inWeekly, expandPoint); // also looks ahead


Run your backtest / analysis in the Weekly settings and use appropriate parameters for your strategy based upon weekly data. So your daily MA(C, 50) might become a weekly MA(C, 10)

In most equity markets (I should say in the U.S.), having a holiday closure on Friday only happens once a year on Good Friday. But occasionally Christmas and New Year's day fall on a Friday, and in the U.S. when their Independence Day is on a Friday or a Saturday the market is closed on the Friday (actually if Christmas falls on a Saturday I think they close the markets on the Friday).

Good luck.

1 Like

I once coded a system that needed to predict which day would be the last trading day prior to a ex-dividend date (if the day prior to ex-div date happened to be a weekend or public holiday then the entire premise of holding the position was invalidated).

The way I made this work then was to go visit the trading calendar of the asx and type up the no trading days in DN notation, shove this list in the top of my file and then update it once a year. Yes, you could probably use Beautiful Soup and automate it all, but for the 10 minutes it takes to update the dates once a year, it just wasn't worth it for a quick test ...

asx link: no trading days for a 2020

asxNTDN = 	"1100101,1100126,1100402,1100405,1100426,1100614,1101227,1101228," +
			"1110103,1110126,1110422,1110425,1110426,1110613,1111226,1111227," +
			"1120102,1120126,1120406,1120409,1120425,1120611,1121225,1121226," +
			"1130101,1130128,1130329,1130401,1130425,1130610,1131225,1131226," +
			"1140101,1140127,1140418,1140421,1140425,1140609,1141225,1141226," +
			"1150101,1150126,1150403,1150406,1150525,1150608,1151225,1151228," +
// later on, when you need to check if a DN in the future is a no trading day:
function NoTradingDay(DN)
   DnStr = NumToStr(DN,1.0,False);
   return StrFind( asxNTDN, DNStr);

FWIW, there exist formulas for Public Holidays.

1 Like

Larry, thanks for the warm welcome, and the advice. It gives me something to progress my idea with, although I'm still trying to complete coding the basic strategy.

Many thanks.

1 Like

@jani, really appreciate the input. Will explore this avenue as well.

Many thanks.


fxshrat, thank you. As a new user, I've become innately aware, that knowing who to ask is the first part of any solution, and, virtually every problem has been addressed at some point.

Many thanks.