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)
Pine腳本庫
秉持TradingView一貫精神,作者已將此Pine代碼以開源函式庫形式發佈,方便我們社群中的其他Pine程式設計師重複使用。向作者致敬!您可以在私人專案或其他開源發表中使用此函式庫,但在公開發表中重用此代碼須遵守社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。
Pine腳本庫
秉持TradingView一貫精神,作者已將此Pine代碼以開源函式庫形式發佈,方便我們社群中的其他Pine程式設計師重複使用。向作者致敬!您可以在私人專案或其他開源發表中使用此函式庫,但在公開發表中重用此代碼須遵守社群規範。
免責聲明
這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。