HolidayLibrary "Holiday"
- Full Control over Holidays and Daylight Savings Time (DLS)
The Holiday Library is an essential tool for traders and analysts who engage in backtesting and live trading . This comprehensive library enables the incorporation of crucial calendar elements - specifically Daylight Savings Time (DLS) adjustments and public holidays - into trading strategies and backtesting environments.
Key Features:
- DLS Adjustments: The library takes into account the shifts in time due to Daylight Savings. This feature is particularly vital for backtesting strategies, as DLS can impact trading hours, which in turn affects the volatility and liquidity in the market. Accurate DLS adjustments ensure that backtesting scenarios are as close to real-life conditions as possible.
- Comprehensive Holiday Metadata: The library includes a rich set of holiday metadata, allowing for the detailed scheduling of trading activities around public holidays. This feature is crucial for avoiding skewed results in backtesting, where holiday trading sessions might differ significantly in terms of volume and price movement.
- Customizable Holiday Schedules: Users can add or remove specific holidays, tailoring the library to fit various regional market schedules or specific trading requirements.
- Visualization Aids: The library supports on-chart labels, making it visually intuitive to identify holidays and DLS shifts directly on trading charts.
Use Cases:
1. Strategy Development: When developing trading strategies, it’s important to account for non-trading days and altered trading hours due to holidays and DLS. This library enables a realistic and accurate representation of these factors.
2. Risk Management: Trading around holidays can be riskier due to thinner liquidity and greater volatility. By integrating holiday data, traders can better manage their risk exposure.
3. Backtesting Accuracy: For backtesting to be effective, it must simulate the actual market conditions as closely as possible. Incorporating holidays and DLS adjustments contributes to more reliable and realistic backtesting results.
4. Global Trading: For traders active in multiple global markets, this library provides an easy way to handle different holiday schedules and DLS shifts across regions.
The Holiday Library is a versatile tool that enhances the precision and realism of trading simulations and strategy development . Its integration into the trading workflow is straightforward and beneficial for both novice and experienced traders.
EasterAlgo(_year)
Calculates the date of Easter Sunday for a given year using the Anonymous Gregorian algorithm.
`Gauss Algorithm for Easter Sunday` was developed by the mathematician Carl Friedrich Gauss
This algorithm is based on the cycles of the moon and the fact that Easter always falls on the first Sunday after the first ecclesiastical full moon that occurs on or after March 21.
While it's not considered to be 100% accurate due to rare exceptions, it does give the correct date in most cases.
It's important to note that Gauss's formula has been found to be inaccurate for some 21st-century years in the Gregorian calendar. Specifically, the next suggested failure years are 2038, 2051.
This function can be used for Good Friday (Friday before Easter), Easter Sunday, and Easter Monday (following Monday).
en.wikipedia.org
Parameters:
_year (int) : `int` - The year for which to calculate the date of Easter Sunday. This should be a four-digit year (YYYY).
Returns: tuple - The month (1-12) and day (1-31) of Easter Sunday for the given year.
easterInit()
Inits the date of Easter Sunday and Good Friday for a given year.
Returns: tuple - The month (1-12) and day (1-31) of Easter Sunday and Good Friday for the given year.
isLeapYear(_year)
Determine if a year is a leap year.
Parameters:
_year (int) : `int` - 4 digit year to check => YYYY
Returns: `bool` - true if input year is a leap year
method timezoneHelper(utc)
Helper function to convert UTC time.
Namespace types: series int, simple int, input int, const int
Parameters:
utc (int) : `int` - UTC time shift in hours.
Returns: `string`- UTC time string with shift applied.
weekofmonth()
Function to find the week of the month of a given Unix Time.
Returns: number - The week of the month of the specified UTC time.
dayLightSavingsAdjustedUTC(utc, adjustForDLS)
dayLightSavingsAdjustedUTC
Parameters:
utc (int) : `int` - The normal UTC timestamp to be used for reference.
adjustForDLS (bool) : `bool` - Flag indicating whether to adjust for daylight savings time (DLS).
Returns: `int` - The adjusted UTC timestamp for the given normal UTC timestamp.
getDayOfYear(monthOfYear, dayOfMonth, weekOfMonth, dayOfWeek, lastOccurrenceInMonth, holiday)
Function gets the day of the year of a given holiday (1-366)
Parameters:
monthOfYear (int)
dayOfMonth (int)
weekOfMonth (int)
dayOfWeek (int)
lastOccurrenceInMonth (bool)
holiday (string)
Returns: `int` - The day of the year of the holiday 1-366.
method buildMap(holidayMap, holiday, monthOfYear, weekOfMonth, dayOfWeek, dayOfMonth, lastOccurrenceInMonth, closingTime)
Function to build the `holidaysMap`.
Namespace types: map
Parameters:
holidayMap (map) : `map` - The map of holidays.
holiday (string) : `string` - The name of the holiday.
monthOfYear (int) : `int` - The month of the year of the holiday.
weekOfMonth (int) : `int` - The week of the month of the holiday.
dayOfWeek (int) : `int` - The day of the week of the holiday.
dayOfMonth (int) : `int` - The day of the month of the holiday.
lastOccurrenceInMonth (bool) : `bool` - Flag indicating whether the holiday is the last occurrence of the day in the month.
closingTime (int) : `int` - The closing time of the holiday.
Returns: `map` - The updated map of holidays
holidayInit(addHolidaysArray, removeHolidaysArray, defaultHolidays)
Initializes a HolidayStorage object with predefined US holidays.
Parameters:
addHolidaysArray (array) : `array` - The array of additional holidays to be added.
removeHolidaysArray (array) : `array` - The array of holidays to be removed.
defaultHolidays (bool) : `bool` - Flag indicating whether to include the default holidays.
Returns: `map` - The map of holidays.
Holidays(utc, addHolidaysArray, removeHolidaysArray, adjustForDLS, displayLabel, defaultHolidays)
Main function to build the holidays object, this is the only function from this library that should be needed. \
all functionality should be available through this function. \
With the exception of initializing a `HolidayMetaData` object to add a holiday or early close. \
\
**Default Holidays:** \
`DLS begin`, `DLS end`, `New Year's Day`, `MLK Jr. Day`, \
`Washington Day`, `Memorial Day`, `Independence Day`, `Labor Day`, \
`Columbus Day`, `Veterans Day`, `Thanksgiving Day`, `Christmas Day` \
\
**Example**
```
HolidayMetaData valentinesDay = HolidayMetaData.new(holiday="Valentine's Day", monthOfYear=2, dayOfMonth=14)
HolidayMetaData stPatricksDay = HolidayMetaData.new(holiday="St. Patrick's Day", monthOfYear=3, dayOfMonth=17)
HolidayMetaData addHolidaysArray = array.from(valentinesDay, stPatricksDay)
string removeHolidaysArray = array.from("DLS begin", "DLS end")
܂Holidays = Holidays(
܂ utc=-6,
܂ addHolidaysArray=addHolidaysArray,
܂ removeHolidaysArray=removeHolidaysArray,
܂ adjustForDLS=true,
܂ displayLabel=true,
܂ defaultHolidays=true,
܂ )
plot(Holidays.newHoliday ? open : na, title="newHoliday", color=color.red, linewidth=4, style=plot.style_circles)
```
Parameters:
utc (int) : `int` - The UTC time shift in hours
addHolidaysArray (array) : `array` - The array of additional holidays to be added
removeHolidaysArray (array) : `array` - The array of holidays to be removed
adjustForDLS (bool) : `bool` - Flag indicating whether to adjust for daylight savings time (DLS)
displayLabel (bool) : `bool` - Flag indicating whether to display a label on the chart
defaultHolidays (bool) : `bool` - Flag indicating whether to include the default holidays
Returns: `HolidayObject` - The holidays object | Holidays = (holidaysMap: map, newHoliday: bool, holiday: string, dayString: string)
HolidayMetaData
HolidayMetaData
Fields:
holiday (series string) : `string` - The name of the holiday.
dayOfYear (series int) : `int` - The day of the year of the holiday.
monthOfYear (series int) : `int` - The month of the year of the holiday.
dayOfMonth (series int) : `int` - The day of the month of the holiday.
weekOfMonth (series int) : `int` - The week of the month of the holiday.
dayOfWeek (series int) : `int` - The day of the week of the holiday.
lastOccurrenceInMonth (series bool)
closingTime (series int) : `int` - The closing time of the holiday.
utc (series int) : `int` - The UTC time shift in hours.
HolidayObject
HolidayObject
Fields:
holidaysMap (map) : `map` - The map of holidays.
newHoliday (series bool) : `bool` - Flag indicating whether today is a new holiday.
activeHoliday (series bool) : `bool` - Flag indicating whether today is an active holiday.
holiday (series string) : `string` - The name of the holiday.
dayString (series string) : `string` - The day of the week of the holiday.
Christmas
Christmas Toolkit [LuxAlgo]It's that time of the year... and what would be more appropriate than displaying Christmas-themed elements on your chart?
The Christmas Toolkit displays a tree containing elements affected by various technical indicators. If you're lucky, you just might also find a precious reindeer trotting toward the tree, how fancy!
🔶 USAGE
Each of the 7 X-mas balls is associated with a specific condition.
Each ball has a color indicating:
lime: very bullish
green: bullish
blue: holding the same position or sideline
red: bearish
darkRed: very bearish
From top to bottom:
🔹 RSI (length 14)
rsi < 20 - lime (+2 points)
rsi < 30 - green (+1 point)
rsi > 80 - darkRed (-2 points)
rsi > 70 - red (-1 point)
else - blue
🔹 Stoch (length 14)
stoch < 20 - lime (+2 points)
stoch < 30 - green (+1 point)
stoch > 80 - darkRed (-2 points)
stoch > 70 - red (-1 point)
else - blue
🔹 close vs. ema (length 20)
close > ema 20 - green (+1 point)
else - red (-1 point)
🔹 ema (length 20)
ema 20 rises - green (+1 point)
else - red (-1 point)
🔹 ema (length 50)
ema 50 rises - green (+1 point)
else - red (-1 point)
🔹 ema (length 100)
ema 100 rises - green (+1 point)
else - red (-1 point)
🔹 ema (length 200)
ema 200 rises - green (+1 point)
else - red (-1 point)
The above information can also be found on the right side of the tree.
You'll see the conditions associated with the specific X-mas ball and the meaning of color changes. This can also be visualized by hovering over the labels.
All values are added together, this result is used to color the star at the top of the tree, with a specific color indicating:
lime: very bullish (> 6 points)
green: bullish (6 points)
blue: holding the same position or sideline
red: bearish (-6 points)
darkRed: very bearish (< -6 points)
Switches to green/lime or red/dark red can be seen by the fallen stars at the bottom.
The Last Switch indicates the latest green/lime or red/dark red color (not blue)
🔶 ANIMATION
Randomly moving snowflakes are added to give it a wintry character.
There are also randomly moving stars in the tree.
Garland rotations, style, and color can be adjusted, together with the width and offset of the tree, put your tree anywhere on your chart!
Disabling the "static tree" setting will make the needles 'move'.
Have you happened to see the precious reindeer on the right? This proud reindeer moves towards the most recent candle. Who knows what this reindeer might be bringing to the tree?
🔶 SETTINGS
Width: Width of tree.
Offset: Offset of the tree.
Garland rotations: Amount of rotations, a high number gives other styles.
Color/Style: sets the color & style of garland stars.
Needles: sets the needle color.
Static Tree: Allows the tree needles to 'move' with each tick.
Reindeer Speed: Controls how fast the deer moves toward the most recent bar.
🔶 MESSAGE FROM THE LUXALGO TEAM
It has been an honor to contribute to the TradingView community and we are always so happy to see your supportive messages on our scripts.
We have posted a total of 78 script publications this year, which is no small feat & was only possible thanks to our team of Wizard developers @alexgrover + @dgtrd + @fikira , the development team behind Pine Script, and of course to the support of our legendary community.
Happy Holidays to you all, and we'll see ya next year! ☃️
MACD + RSI + ADX Strategy (ChatGPT-powered) by TradeSmartThis is a trading strategy made by TradeSmart, using the recommendations given by ChatGPT . As an experiment, we asked ChatGPT on which indicators are the most popular for trading. We used all of the recommendations given, and added more. We ended up with a strategy that performs surprisingly well on many crypto and forex assets. See below for exact details on what logic was implemented and how you can change the parameters of the strategy.
The strategy is a Christmas special , this is how we would like to thank the support of our followers.
The strategy has performed well on Forex, tested on 43 1-hour pairs and turned a profit in 21 cases. Also it has been tested on 51 crypto pairs using the 1-hour timeframe, and turned a profit in 45 cases with a Profit Factor over 1.4 in the top-5 cases. Tests were conducted without commission or slippage, unlike the presented result which uses 0.01% commission and 5 tick slippage.
Some of the top performers were:
SNXUSDT
SOLUSDT
CAKEUSDT
LINKUSDT
EGLDUSDT
GBPJPY
TRYJPY
USDJPY
The strategy was implemented using the following logic:
Entry strategy:
Long entry:
Price should be above the Simple Moving Average (SMA)
There should be a cross up on the MACD (indicated by the color switch on the histogram, red to green)
RSI should be above the 50 level
Volume is above the selected volume-based Exponential Moving Average (EMA)
ADX should also agree to this position: below 50 and over 20, and above the Regularized Moving Average (REMA)
Short entry:
Price should be under the Simple Moving Average (SMA)
There should be a cross down on the MACD (indicated by the color switch on the histogram, red to green)
RSI should be below the 50 level
Volume is above the selected volume-based Exponential Moving Average (EMA)
ADX should also agree to this position: below 50 and over 20, and above the Regularized Moving Average (REMA)
Exit strategy:
Stop Loss will be placed based on ATR value (with 1.5 Risk)
Take profit level will be placed with a 2.5 Risk/Reward Ratio
Open positions will be closed early based on the Squeeze Momentum (Long: change to red, Short: change to green)
NOTE! : The position sizes used in the example is with 'Risk Percentage (current)', according which the position size will be determined such
that the potential loss is equal to % of the current available capital. This means that in most of the cases, the positions are calculated using leverage.
Parameters of every indicator used in the strategy can be tuned in the strategy settings as follows:
Plot settings:
Plot Signals: true by default, Show all Long and Short signals on the signal candle
Allow early TP/SL plots: false by default, Checking this option will result in the TP and SL lines to be plotted also on the signal candle rather than just the entry candle. Consider this only when manual trading, since backtest entries does not happen on the signal candle.
Entry Signal:
Fast Length: 12 by default
Slow Length: 26 by default
Source: hlcc4 by default
Signal Smoothing: 9 by default
Oscillator MA Type: EMA by default
Signal Line MA Type: EMA by default
Exit Strategy:
ATR Based Stop Loss: true by default
ATR Length (of the SL): 14 by default
ATR Smoothing (of the SL): EMA by default
Candle Low/High Based Stop Loss: false by default, recent lowest or highest point (depending on long/short position) will be used to calculate stop loss value. Set 'Base Risk Multiplier' to 1 if you would like to use the calculated value as is. Setting it to a different value will count as an additional multiplier. Please select only one active stop loss. Default value (if nothing or multiple stop losses are selected) is the 'ATR Based Stop Loss'.
Candle Lookback (of the SL): 10 by default
Base Risk Multiplier: 1.5 by default, the stop loss will be placed at this risk level (meaning in case of ATR SL that the ATR value will be multiplied by this factor and the SL will be placed that value away from the entry level)
Risk to Reward Ratio: 2.5 by default, the take profit level will be placed such as this Risk/Reward ratio is met
Force Exit based on Squeeze Momentum: true by default, a Long position will be closed when Squeeze Momentum turns red inside an open position and a Short position will be closed when Squeeze Momentum turns green inside an open position
BB Length: 20 by default
BB Mult Factor: 1.0 by default
KC Length: 20 by default
KC Mult Factor: 1.5 by default
Use True Range (KC): Yes by default
Base Setups:
Allow Long Entries: true by default
Allow Short Entries: true by default
Order Size: 1.5 by default
Order Type: Risk Percentage (current) by default, allows adjustment on how the position size is calculated: Cash: only the set cash ammount will be used for each trade Contract(s): the adjusted number of contracts will be used for each trade Capital Percentage: a % of the current available capital will be used for each trade Risk Percentage (current): position size will be determined such that the potential loss is equal to % of the current available capital Risk Percentage (initial): position size will be determined such that the potential loss is equal to % of the initial capital
Trend Filter:
Use long trend filter: true by default, only enter long if price is above Long MA
Show long trend filter: true by default, plot the selected MA on the chart
MA Type (Long): SMA by default
MA Length (Long): 100 by default
MA Source (Long): close by default
Use short trend filter: true by default, only enter long if price is under Short MA
Show short trend filter: false by default, plot the selected MA on the chart
MA Type (Short): SMA by default
MA Length (Short): 100 by default
MA Source (Short): close by default
Simple RSI Limiter:
Limit using Simple RSI: true by default, if set to 'Normal', only enter long when Simple RSI is lower then Long Boundary, and only enter short when Simple RSI is higher then Short Boundary. If set to 'Reverse', only enter long when Simple RSI is higher then Long Boundary, and only enter short when Simple RSI is lower then Short Boundary.
Simple RSI Limiter Type:
RSI Length: 14 by default
RSI Source: hl2 by default
Simple RSI Long Boundary: 50 by default
Simple RSI Short Boundary: 50 by default
ADX Limiter:
Use ADX Limiter: true by default, only enter into any position (long/short) if ADX value is higher than the Low Boundary and lower than the High Boundary.
ADX Length: 5 by default
DI Length: 5 by default
High Boundary: 50 by default
Low Boundary: 20 by default
Use MA based calculation: Yes by default, if 'Yes', only enter into position (long/short) if ADX value is higher than MA (ADX as source).
MA Type: REMA by default
MA Length: 5 by default
Volume Filter:
Only enter trades where volume is higher then the volume-based MA: true by default, a set type of MA will be calculated with the volume as source, and set length
MA Type: EMA by default
MA Length: 10 by default
Session Limiter:
Show session plots: false by default, show crypto market sessions on chart: Sidney (red), Tokyo (orange), London (yellow), New York (green)
Use session limiter: false by default, if enabled, trades will only happen in the ticked sessions below.
Sidney session: false by default, session between: 15:00 - 00:00 (EST)
Tokyo session: false by default, session between: 19:00 - 04:00 (EST)
London session: false by default, session between: 03:00 - 11:00 (EST)
New York session: false by default, session between: 08:00 - 17:00 (EST)
Date Range:
Limit Between Dates: false by default
Start Date: Jul 01 2021 00:00:00 by default
End Date: Dec 31 2022 00:00:00 by default
Trading Time:
Limit Trading Time: false by default, tick this together with the options below to enable limiting based on day and time
Valid Trading Days Global: 1234567 by default, if the Limit Trading Time is on, trades will only happen on days that are present in this field. If any of the not global Valid Trading Days is used, this field will be neglected. Values represent days: Sunday (1), Monday (2), ..., Friday (6), Saturday(7) To trade on all days use: 123457
(1) Valid Trading Days: false, 1234567 by default, values represent days: Sunday (1), Monday (2), ..., Friday (6), Saturday(7) The script will trade on days that are present in this field. Please make sure that this field and also (1) Valid Trading Hours Between is checked
(1) Valid Trading Hours Between: false, 0930-1600 by default, hours between which the trades can happen. The time is always in the exchange's timezone
Fine-tuning is highly recommended when using other asset/timeframe combinations.
Let it snow... [QuantNomad]It's almost the end of 2020. If you don't have any snow outside but still you want some Christmas mood - feel free to use my indicator.
TradingView added a possibility to use up to 500 labels, so I decided to create something fun and completely useless.
Snowflakes suppose to fall nicely, but labels are not regularly updated by TradingView. If you know how to make it better - let me know )
For the best experience use Dark Theme and play the "Let it snow" song )
Merry Christmas & Happy New Year!
Christmas Tree Theme With Open Code To See Pine ScriptI had been trying to code a predictive algorithm working with sine waves, but I got distracted and made some snow and Christmas trees lol. I'm uploading this with the source code because I'm sure someone will be able to learn from it to create something useful.
Please follow me for some actual useful pine scripts and merry Christmas! :)