PINE LIBRARY
SequencerLibrary

Library "SequencerLibrary"
SequencerLibrary v1 is a Pine Script™ library for identifying, tracking, and visualizing
sequential bullish and bearish patterns on price charts.
It provides a complete framework for building sequence-based trading systems, including:
• Automatic detection and counting of setup and countdown phases.
• Real-time tracking of completion states, perfected setups, and exhaustion signals.
• Dynamic support and resistance thresholds derived from recent price structure.
• Customizable visual highlighting for both setup and countdown sequences.
method doSequence(s, src, config, condition)
Updates the sequence state based on the source value, and user configuration.
Namespace types: Sequence
Parameters:
s (Sequence): <Sequence> The sequence object containing bullish and bearish setups.
src (float): <float> The source value (e.g., close price) used for evaluating sequence conditions.
config (SequenceInputs): <SequenceInputs> The user-defined settings for sequence analysis.
condition (bool): <bool> When true, executes the sequence logic.
Returns: <void>
highlight(s, css, condition)
Highlights the bullish and bearish sequence setups and countdowns on the chart.
Parameters:
s (Sequence): <Sequence> The sequence object containing bullish and bearish sequence states.
css (SequenceCSS): <SequenceCSS> The styling configuration for customizing label appearances.
condition (bool): <bool> When true, the function creates and displays labels for setups and countdowns.
Returns: <void>
SequenceState
A type representing the configuration and state of a sequence setup.
Fields:
setup (series int): <int> Current count of the setup phase (e.g., how many bars have met the setup criteria).
countdown (series int): <int> Current count of the countdown phase (e.g., bars meeting countdown criteria).
threshold (series float): <float> The price threshold level used as support/resistance for the sequence.
priceWhenCompleted (series float): <float> The closing price when the setup or countdown phase is completed.
indicatorWhenCompleted (series float): <float> The indicator value when the setup or countdown phase is completed.
setupCompleted (series bool): <bool> Indicates if the setup phase has been completed (i.e., reached the required count).
countdownCompleted (series bool): <bool> Indicates if the countdown phase has been completed (i.e., reached exhaustion).
perfected (series bool): <bool> Indicates if the setup meets the "perfected" condition (e.g., aligns with strict criteria).
highlightSetup (series bool): <bool> Determines whether the setup phase should be visually highlighted on the chart.
highlightCountdown (series bool): <bool> Determines whether the countdown phase should be visually highlighted on the chart.
Sequence
A type containing bullish and bearish sequence setups.
Fields:
bullish (SequenceState): <SequenceState> Configuration and state for bullish sequences.
bearish (SequenceState): <SequenceState> Configuration and state for bearish sequences.
SequenceInputs
A type for user-configurable input settings for sequence-based analysis.
Fields:
showSetup (series bool): <bool> Enables or disables the display of setup sequences.
showCountdown (series bool): <bool> Enables or disables the display of countdown sequences.
setupFilter (series string): <string> A comma‐separated string containing setup sequence counts to be highlighted (e.g., "1,2,3,4,5,6,7,8,9").
countdownFilter (series string): <string> A comma‐separated string containing countdown sequence counts to be highlighted (e.g., "1,2,3,4,5,6,7,8,9,10,11,12,13").
lookbackSetup (series int): <int> Defines the lookback period for evaluating setup conditions (default: 4 bars).
lookbackCountdown (series int): <int> Defines the lookback period for evaluating countdown conditions (default: 2 bars).
lookbackSetupPerfected (series int): <int> Defines the lookback period to determine a perfected setup condition (default: 6 bars).
maxSetup (series int): <int> The maximum count required to complete a setup phase (default: 9).
maxCountdown (series int): <int> The maximum count required to complete a countdown phase (default: 13).
SequenceCSS
A type defining the visual styling options for sequence labels.
Fields:
bullish (series color): <color> Color used for bullish sequence labels.
bearish (series color): <color> Color used for bearish sequence labels.
imperfect (series color): <color> Color used for labels representing imperfect sequences.
SequencerLibrary v1 is a Pine Script™ library for identifying, tracking, and visualizing
sequential bullish and bearish patterns on price charts.
It provides a complete framework for building sequence-based trading systems, including:
• Automatic detection and counting of setup and countdown phases.
• Real-time tracking of completion states, perfected setups, and exhaustion signals.
• Dynamic support and resistance thresholds derived from recent price structure.
• Customizable visual highlighting for both setup and countdown sequences.
method doSequence(s, src, config, condition)
Updates the sequence state based on the source value, and user configuration.
Namespace types: Sequence
Parameters:
s (Sequence): <Sequence> The sequence object containing bullish and bearish setups.
src (float): <float> The source value (e.g., close price) used for evaluating sequence conditions.
config (SequenceInputs): <SequenceInputs> The user-defined settings for sequence analysis.
condition (bool): <bool> When true, executes the sequence logic.
Returns: <void>
highlight(s, css, condition)
Highlights the bullish and bearish sequence setups and countdowns on the chart.
Parameters:
s (Sequence): <Sequence> The sequence object containing bullish and bearish sequence states.
css (SequenceCSS): <SequenceCSS> The styling configuration for customizing label appearances.
condition (bool): <bool> When true, the function creates and displays labels for setups and countdowns.
Returns: <void>
SequenceState
A type representing the configuration and state of a sequence setup.
Fields:
setup (series int): <int> Current count of the setup phase (e.g., how many bars have met the setup criteria).
countdown (series int): <int> Current count of the countdown phase (e.g., bars meeting countdown criteria).
threshold (series float): <float> The price threshold level used as support/resistance for the sequence.
priceWhenCompleted (series float): <float> The closing price when the setup or countdown phase is completed.
indicatorWhenCompleted (series float): <float> The indicator value when the setup or countdown phase is completed.
setupCompleted (series bool): <bool> Indicates if the setup phase has been completed (i.e., reached the required count).
countdownCompleted (series bool): <bool> Indicates if the countdown phase has been completed (i.e., reached exhaustion).
perfected (series bool): <bool> Indicates if the setup meets the "perfected" condition (e.g., aligns with strict criteria).
highlightSetup (series bool): <bool> Determines whether the setup phase should be visually highlighted on the chart.
highlightCountdown (series bool): <bool> Determines whether the countdown phase should be visually highlighted on the chart.
Sequence
A type containing bullish and bearish sequence setups.
Fields:
bullish (SequenceState): <SequenceState> Configuration and state for bullish sequences.
bearish (SequenceState): <SequenceState> Configuration and state for bearish sequences.
SequenceInputs
A type for user-configurable input settings for sequence-based analysis.
Fields:
showSetup (series bool): <bool> Enables or disables the display of setup sequences.
showCountdown (series bool): <bool> Enables or disables the display of countdown sequences.
setupFilter (series string): <string> A comma‐separated string containing setup sequence counts to be highlighted (e.g., "1,2,3,4,5,6,7,8,9").
countdownFilter (series string): <string> A comma‐separated string containing countdown sequence counts to be highlighted (e.g., "1,2,3,4,5,6,7,8,9,10,11,12,13").
lookbackSetup (series int): <int> Defines the lookback period for evaluating setup conditions (default: 4 bars).
lookbackCountdown (series int): <int> Defines the lookback period for evaluating countdown conditions (default: 2 bars).
lookbackSetupPerfected (series int): <int> Defines the lookback period to determine a perfected setup condition (default: 6 bars).
maxSetup (series int): <int> The maximum count required to complete a setup phase (default: 9).
maxCountdown (series int): <int> The maximum count required to complete a countdown phase (default: 13).
SequenceCSS
A type defining the visual styling options for sequence labels.
Fields:
bullish (series color): <color> Color used for bullish sequence labels.
bearish (series color): <color> Color used for bearish sequence labels.
imperfect (series color): <color> Color used for labels representing imperfect sequences.
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Pine library
In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in publications is governed by House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.