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)
Biblioteca Pine
Fiel al espíritu de TradingView, el autor ha publicado este código de Pine como biblioteca de código abierto, para que otros programadores de nuestra comunidad puedan reutilizarlo. ¡Enhorabuena al autor! Puede usar esta biblioteca de forma privada o en otras publicaciones de código abierto, pero su reutilización en publicaciones está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.
Biblioteca Pine
Fiel al espíritu de TradingView, el autor ha publicado este código de Pine como biblioteca de código abierto, para que otros programadores de nuestra comunidad puedan reutilizarlo. ¡Enhorabuena al autor! Puede usar esta biblioteca de forma privada o en otras publicaciones de código abierto, pero su reutilización en publicaciones está sujeta a nuestras Normas internas.
Exención de responsabilidad
La información y las publicaciones no constituyen, ni deben considerarse como, asesoramiento o recomendaciones financieras, de inversión, de trading u otro tipo, proporcionadas o respaldadas por TradingView. Obtenga más información en Condiciones de uso.