PINE LIBRARY
ONS_ForexSessionLib

Library "ONS_ForexSessionLib"
Library for DST-adjusted Forex session detection. Returns session state and timing for a given bar.
Thanks to the author of "Sessions Full Markets [TradingFinder] Forex Stocks Index 7 Time by TFlab"
DST_Detector(Start_Month, Start_Day, Start_CountDay, End_Month, End_Day, End_CountDay, TimeZone)
Detects whether DST is Active or Inactive for a given timezone.
Parameters:
Start_Month (int): Month DST begins (int)
Start_Day (int): Day-of-week DST begins (int, use dayofweek.* constants)
Start_CountDay (int): Nth occurrence of Start_Day in Start_Month (int)
End_Month (int): Month DST ends (int)
End_Day (int): Day-of-week DST ends (int)
End_CountDay (int): Nth occurrence of End_Day in End_Month (int)
TimeZone (string): IANA timezone string, use "Australia/Sydney" to invert logic (string)
Returns: "Active" or "Inactive" (string)
getDSTStates()
Returns DST state for Sydney, London and New York at the current bar.
Returns: [Sydney_DST, London_DST, NewYork_DST] — each "Active" or "Inactive" (tuple of strings)
getForexSessionStrings(Sydney_DST, London_DST, NewYork_DST)
Returns UTC session strings for all Forex sessions, DST-adjusted.
Parameters:
Sydney_DST (string): DST state string for Sydney ("Active"/"Inactive")
London_DST (string): DST state string for London ("Active"/"Inactive")
NewYork_DST (string): DST state string for New York ("Active"/"Inactive")
Returns: [Asia, Sydney, Tokyo, Shanghai, Europe, London, NewYork, NYSE] session strings (tuple of strings)
isInSession(sessionStr, tz)
Returns 1 if the bar at the current series position is inside a session, 0 otherwise.
Parameters:
sessionStr (string): Session string in "HHMM-HHMM" format (string)
tz (string): IANA or UTC offset timezone string for the session (string)
Returns: 1 if inside session, 0 if outside (int)
isBarInSession(targetIndex, sessionStr, tz)
Returns 1 if a specific bar_index is inside a session (for point-in-time lookup).
Parameters:
targetIndex (int): bar_index to test (int)
sessionStr (string): Session string "HHMM-HHMM" (string)
tz (string): IANA or UTC offset timezone string (string)
Returns: 1 if the target bar is/was inside session, 0 otherwise (int)
getAllForexSessions()
One-shot helper: given the current bar, returns open/closed state for all
DST-adjusted Forex sessions simultaneously.
Returns: [inAsia, inSydney, inTokyo, inShanghai, inEurope, inLondon, inNewYork, inNYSE]
Each value is 1 (open) or 0 (closed). (tuple of ints)
Library for DST-adjusted Forex session detection. Returns session state and timing for a given bar.
Thanks to the author of "Sessions Full Markets [TradingFinder] Forex Stocks Index 7 Time by TFlab"
DST_Detector(Start_Month, Start_Day, Start_CountDay, End_Month, End_Day, End_CountDay, TimeZone)
Detects whether DST is Active or Inactive for a given timezone.
Parameters:
Start_Month (int): Month DST begins (int)
Start_Day (int): Day-of-week DST begins (int, use dayofweek.* constants)
Start_CountDay (int): Nth occurrence of Start_Day in Start_Month (int)
End_Month (int): Month DST ends (int)
End_Day (int): Day-of-week DST ends (int)
End_CountDay (int): Nth occurrence of End_Day in End_Month (int)
TimeZone (string): IANA timezone string, use "Australia/Sydney" to invert logic (string)
Returns: "Active" or "Inactive" (string)
getDSTStates()
Returns DST state for Sydney, London and New York at the current bar.
Returns: [Sydney_DST, London_DST, NewYork_DST] — each "Active" or "Inactive" (tuple of strings)
getForexSessionStrings(Sydney_DST, London_DST, NewYork_DST)
Returns UTC session strings for all Forex sessions, DST-adjusted.
Parameters:
Sydney_DST (string): DST state string for Sydney ("Active"/"Inactive")
London_DST (string): DST state string for London ("Active"/"Inactive")
NewYork_DST (string): DST state string for New York ("Active"/"Inactive")
Returns: [Asia, Sydney, Tokyo, Shanghai, Europe, London, NewYork, NYSE] session strings (tuple of strings)
isInSession(sessionStr, tz)
Returns 1 if the bar at the current series position is inside a session, 0 otherwise.
Parameters:
sessionStr (string): Session string in "HHMM-HHMM" format (string)
tz (string): IANA or UTC offset timezone string for the session (string)
Returns: 1 if inside session, 0 if outside (int)
isBarInSession(targetIndex, sessionStr, tz)
Returns 1 if a specific bar_index is inside a session (for point-in-time lookup).
Parameters:
targetIndex (int): bar_index to test (int)
sessionStr (string): Session string "HHMM-HHMM" (string)
tz (string): IANA or UTC offset timezone string (string)
Returns: 1 if the target bar is/was inside session, 0 otherwise (int)
getAllForexSessions()
One-shot helper: given the current bar, returns open/closed state for all
DST-adjusted Forex sessions simultaneously.
Returns: [inAsia, inSydney, inTokyo, inShanghai, inEurope, inLondon, inNewYork, inNYSE]
Each value is 1 (open) or 0 (closed). (tuple of ints)
Bibliothèque Pine
Dans l'esprit TradingView, l'auteur a publié ce code Pine sous forme de bibliothèque open source afin que d'autres programmeurs Pine de notre communauté puissent le réutiliser. Bravo à l'auteur! Vous pouvez utiliser cette bibliothèque à titre privé ou dans d'autres publications open source, mais la réutilisation de ce code dans des publications est régie par nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Bibliothèque Pine
Dans l'esprit TradingView, l'auteur a publié ce code Pine sous forme de bibliothèque open source afin que d'autres programmeurs Pine de notre communauté puissent le réutiliser. Bravo à l'auteur! Vous pouvez utiliser cette bibliothèque à titre privé ou dans d'autres publications open source, mais la réutilisation de ce code dans des publications est régie par nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.