This Python script is designed to retrieve market holiday data for a variety of global stock exchanges and format them into PineScript arrays. These arrays can then be used within TradingView indicators and strategies to account for non-trading days.
- Retrieves market holiday data for multiple stock exchanges around the globe.
- Formats the holiday data into PineScript arrays.
- Outputs the arrays to a text file for easy integration into TradingView scripts.
The script uses the pandas_market_calendars
(https://pandas-market-calendars.readthedocs.io) library to directly obtain the non-trading days (holidays) for each specified exchange. Each set of non-trading days is formatted as a PineScript array and saved to an output file.
Ensure you have Python installed on your system.
Install the required libraries using pip:
pip install pandas pandas_market_calendars
Run the script:
python PineScript_MarketHolidays.py
Check the output file market_holidays_pinescript.txt
for the PineScript arrays.
The script includes a comprehensive list of global stock exchange identifiers. For example:
XNYS
: New York Stock Exchange, USAXCBF
: CBOE Futures, USAXTSE
: Toronto Stock Exchange, CanadaXJPX
: Tokyo Stock Exchange, Japan- ... and many more.
Each exchange's non-trading days are outputted as a PineScript array with a naming convention of <EXCHANGE_CODE>_<COUNTRY_CODE>_nonTradingDays
. For example:
// New York Stock Exchange, US
XNYS_US_nonTradingDays = array.from(
timestamp("2023-01-01T00:00:00"),
timestamp("2023-07-04T00:00:00"),
// ... more dates
)
In addition to this Python script, a complementary PineScript library will be available for further integration and usage within TradingView scripts on my TradingView profile.
You can customize the list of exchanges by editing the exchange_codes
array and the exchange_descriptions
mapping.
Contributions are welcome! If you'd like to add more features or suggest improvements, please feel free to fork this repository and submit a pull request.
This project is open-source and available under the MIT License.