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 do Pine
Em verdadeiro espírito TradingView, o autor publicou este código Pine como uma biblioteca de código aberto para que outros programadores Pine da nossa comunidade possam reutilizá-lo. Parabéns ao autor! Você pode usar esta biblioteca de forma privada ou em outras publicações de código aberto, mas a reutilização deste código em publicações é regida pelas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Biblioteca do Pine
Em verdadeiro espírito TradingView, o autor publicou este código Pine como uma biblioteca de código aberto para que outros programadores Pine da nossa comunidade possam reutilizá-lo. Parabéns ao autor! Você pode usar esta biblioteca de forma privada ou em outras publicações de código aberto, mas a reutilização deste código em publicações é regida pelas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.