PINE LIBRARY
Güncellendi MomentumResets

MomentumResets is a compact Pine Script library for detecting momentum reset events using finite-state logic.
You get three different reset models that all return one shared exported signal enum, so integration in your own scripts stays simple and consistent.
Advantages of using this library include:
• Unified signal type: All models return the same `Signal` enum (`bullish`, `bearish`, `none`).
• State-driven logic: Explicit states are more robust than brittle one-bar pattern checks.
• Input validation: Built-in runtime checks catch invalid thresholds and shoulder settings early.
• Flexible strictness: Optional `skipValidation` when you need tolerant behaviour for dynamic or partial inputs.
• Model choice: Stoch, Static Level, and Pivot variants cover different momentum structures.
🟩 RESET MODELS
Stoch Reset
Tracks Stoch around upper/lower thresholds and emits resets when momentum rotates with confirmation conditions.
Use this when you want directional reset events, not just overbought/oversold touches.
Static Level Reset
Uses a two-phase path per side around static thresholds with an optional tolerance buffer.
Use this for "break -> return -> re-break" style momentum structures around fixed levels.
Pivot Reset
Uses shoulder distances and trailed extremes to detect retrace/bounce resets after directional expansion.
Use this for swing-style turns where relative move size matters more than absolute levels.
The models are easier to grasp by seeing them than they are to explain. They all have example visualisations included.
🟩 VALIDATION & ERROR HANDLING
The library includes defensive checks with `runtime.error()` messaging for critical misconfiguration.
Examples of guarded inputs:
• Thresholds cannot be `na`.
• Lower threshold must be below upper threshold.
• Stoch thresholds must stay within 0-100.
• Tolerance must be 0 or greater.
• Shoulder distances must be greater than 0.
• Optional pivot bounds are checked for logical consistency when both are used.
Each error message is prefixed with the library + function name to make debugging easier.
🟩 HOW TO USE
Pine Script libraries contain reusable code for importing into indicators. You do not need to copy any code out of here. Just import the library and call the function you want.
For version 1, import it like this:
Pine Script®
Then call one reset function per model/series path each bar, and route the returned `Signal` enum into your entries, exits, filters, or alerts.
For more information on libraries and incorporating them into your scripts, see the Libraries section of the Pine Script User Manual.
🟩 BRING ON THE FUNCTIONS
getStochResetSignal(_stochK, _stochD, _lowerThreshold, _upperThreshold, _skipValidation)
Returns a Stoch momentum reset signal using internal FSM states (neutral, tracking, suppressed).
Parameters:
_stochK (float)
Current Stoch %K value used in state transitions.
_stochD (float)
Current Stoch %D value used for confirmation logic.
_lowerThreshold (float, default 20.0)
Lower Stoch threshold used for setup and reset detection.
_upperThreshold (float, default 80.0)
Upper Stoch threshold used for setup and reset detection.
_skipValidation (bool, default false)
If true, skips guard checks and allows tolerant execution with dynamic/partial inputs.
Returns: Signal (`Signal.bullish`, `Signal.bearish`, or `Signal.none` for this bar).
getStaticLevelResetSignal(_value, _lowerThreshold, _upperThreshold, _tolerance, _skipValidation)
Returns a reset signal when value completes the threshold/tolerance path on either side.
Parameters:
_value (float)
Current series value to evaluate.
_lowerThreshold (float)
Lower static level used by the bullish reset path.
_upperThreshold (float)
Upper static level used by the bearish reset path.
_tolerance (float, default 0.0)
Optional buffer zone around levels before a reset can complete.
_skipValidation (bool, default false)
If true, skips guard checks and allows tolerant execution with dynamic/partial inputs.
Returns: Signal (`Signal.bullish`, `Signal.bearish`, or `Signal.none` for this bar).
getPivotResetSignal(_value, _leftShoulder, _rightShoulder, _bearMinHeight, _bullMaxDepth, _skipValidation)
Returns a reset signal using shoulder-based priming and trailing extremes for pivot-style turns.
Parameters:
_value (float)
Current series value to evaluate.
_leftShoulder (float)
Relative move from anchor required to prime a directional setup.
_rightShoulder (float)
Relative retrace/bounce from the trailed extreme required to trigger a reset.
_bearMinHeight (float, optional)
Optional absolute minimum high required before bearish resets are allowed.
_bullMaxDepth (float, optional)
Optional absolute maximum low required before bullish resets are allowed.
_skipValidation (bool, default false)
If true, skips guard checks and allows tolerant execution with dynamic/partial inputs.
Returns: Signal (`Signal.bullish`, `Signal.bearish`, or `Signal.none` for this bar).
You get three different reset models that all return one shared exported signal enum, so integration in your own scripts stays simple and consistent.
Advantages of using this library include:
• Unified signal type: All models return the same `Signal` enum (`bullish`, `bearish`, `none`).
• State-driven logic: Explicit states are more robust than brittle one-bar pattern checks.
• Input validation: Built-in runtime checks catch invalid thresholds and shoulder settings early.
• Flexible strictness: Optional `skipValidation` when you need tolerant behaviour for dynamic or partial inputs.
• Model choice: Stoch, Static Level, and Pivot variants cover different momentum structures.
🟩 RESET MODELS
Stoch Reset
Tracks Stoch around upper/lower thresholds and emits resets when momentum rotates with confirmation conditions.
Use this when you want directional reset events, not just overbought/oversold touches.
Static Level Reset
Uses a two-phase path per side around static thresholds with an optional tolerance buffer.
Use this for "break -> return -> re-break" style momentum structures around fixed levels.
Pivot Reset
Uses shoulder distances and trailed extremes to detect retrace/bounce resets after directional expansion.
Use this for swing-style turns where relative move size matters more than absolute levels.
The models are easier to grasp by seeing them than they are to explain. They all have example visualisations included.
🟩 VALIDATION & ERROR HANDLING
The library includes defensive checks with `runtime.error()` messaging for critical misconfiguration.
Examples of guarded inputs:
• Thresholds cannot be `na`.
• Lower threshold must be below upper threshold.
• Stoch thresholds must stay within 0-100.
• Tolerance must be 0 or greater.
• Shoulder distances must be greater than 0.
• Optional pivot bounds are checked for logical consistency when both are used.
Each error message is prefixed with the library + function name to make debugging easier.
🟩 HOW TO USE
Pine Script libraries contain reusable code for importing into indicators. You do not need to copy any code out of here. Just import the library and call the function you want.
For version 1, import it like this:
Then call one reset function per model/series path each bar, and route the returned `Signal` enum into your entries, exits, filters, or alerts.
For more information on libraries and incorporating them into your scripts, see the Libraries section of the Pine Script User Manual.
🟩 BRING ON THE FUNCTIONS
getStochResetSignal(_stochK, _stochD, _lowerThreshold, _upperThreshold, _skipValidation)
Returns a Stoch momentum reset signal using internal FSM states (neutral, tracking, suppressed).
Parameters:
_stochK (float)
Current Stoch %K value used in state transitions.
_stochD (float)
Current Stoch %D value used for confirmation logic.
_lowerThreshold (float, default 20.0)
Lower Stoch threshold used for setup and reset detection.
_upperThreshold (float, default 80.0)
Upper Stoch threshold used for setup and reset detection.
_skipValidation (bool, default false)
If true, skips guard checks and allows tolerant execution with dynamic/partial inputs.
Returns: Signal (`Signal.bullish`, `Signal.bearish`, or `Signal.none` for this bar).
getStaticLevelResetSignal(_value, _lowerThreshold, _upperThreshold, _tolerance, _skipValidation)
Returns a reset signal when value completes the threshold/tolerance path on either side.
Parameters:
_value (float)
Current series value to evaluate.
_lowerThreshold (float)
Lower static level used by the bullish reset path.
_upperThreshold (float)
Upper static level used by the bearish reset path.
_tolerance (float, default 0.0)
Optional buffer zone around levels before a reset can complete.
_skipValidation (bool, default false)
If true, skips guard checks and allows tolerant execution with dynamic/partial inputs.
Returns: Signal (`Signal.bullish`, `Signal.bearish`, or `Signal.none` for this bar).
getPivotResetSignal(_value, _leftShoulder, _rightShoulder, _bearMinHeight, _bullMaxDepth, _skipValidation)
Returns a reset signal using shoulder-based priming and trailing extremes for pivot-style turns.
Parameters:
_value (float)
Current series value to evaluate.
_leftShoulder (float)
Relative move from anchor required to prime a directional setup.
_rightShoulder (float)
Relative retrace/bounce from the trailed extreme required to trigger a reset.
_bearMinHeight (float, optional)
Optional absolute minimum high required before bearish resets are allowed.
_bullMaxDepth (float, optional)
Optional absolute maximum low required before bullish resets are allowed.
_skipValidation (bool, default false)
If true, skips guard checks and allows tolerant execution with dynamic/partial inputs.
Returns: Signal (`Signal.bullish`, `Signal.bearish`, or `Signal.none` for this bar).
Sürüm Notları
V2Added a simple example table that shows which function is being demonstrated.
Added a new functioon `getChannelResetSignal()` that gives signals based on breaches of a channel.
Replaced `getPivotResetSignal()` with `getPivotReset()`, which now returns the reset signal together with the confirmed pivot value and pivot bar index.
NOTE: This is not backwards-compatible. If you don't want the extra info either stay on V1 or assign the returned values to an underscore.
Changed function (new version of `getPivotResetSignal`):
getPivotReset(_value, _leftShoulder, _rightShoulder, _bearMinHeight, _bullMaxDepth, _skipValidation)
Generates a confirmed pivot reset and returns the actual momentum extreme as it was on the bar where it formed. In the bearish case, the series first rises a certain distance (the "left shoulder") and then falls a certain distance (the "right shoulder") to trigger a reset. Like price pivot lengths, the shoulder values don't have to match (but often do).
Parameters:
_value (float): Current value of the series being evaluated, for example, RSI.
_leftShoulder (float): Relative move needed from wherever we start/wherever we are to prime a setup.
_rightShoulder (float): Relative retrace/bounce needed from the trailed extreme to trigger a reset.
_bearMinHeight (float): Optional absolute minimum high required for bearish resets.
_bullMaxDepth (float): Optional absolute maximum low required for bullish resets.
_skipValidation (bool): If true, input validation checks are skipped.
Returns: [Signal, pivotValue, pivotBarIndex]. The signal tells you whether the confirmed pivot is bullish or bearish, so the value is the actual trailed extreme, and the bar index is where that extreme formed.
New function:
getChannelResetSignal(_value, _width, _skipValidation)
Generates a reset signal from breaks of a ratcheting momentum channel.
Parameters:
_value (float): The momentum value to evaluate. This can be any momentum metric like RSI etc.
_width (float): Absolute channel width from the momentum value. The momentum series starts out in the centre of the channel.
_skipValidation (bool): If true, input validation checks are skipped.
Returns: Channel reset signal for the current bar. Uses our standard Signal.bullish, Signal.bearish, or Signal.none.
Removed:
getPivotResetSignal(_value, _leftShoulder, _rightShoulder, _bearMinHeight, _bullMaxDepth, _skipValidation)
Generates a reset signal when we get a pivot in the value of the series. In the bearish case, the series first rises a certain distance (the "left shoulder") and then falls a certain distance (the "right shoulder") to trigger a reset. Like price pivot lengths, the shoulder values don't have to match (but often do).
Pine kitaplığı
Gerçek TradingView ruhuyla, yazar bu Pine kodunu açık kaynaklı bir kütüphane olarak yayınladı, böylece topluluğumuzdaki diğer Pine programcıları onu yeniden kullanabilir. Yazarı tebrik ederiz! Bu kütüphaneyi özel olarak veya diğer açık kaynaklı yayınlarda kullanabilirsiniz, ancak bu kodun yayınlarda yeniden kullanılması Topluluk Kuralları tarafından yönetilir.
🆓 All my free scripts: is.gd/simplefree
🔥 Beyond Market Structure Paid Space is now live! is.gd/beyondMS
💰 Trade with me: is.gd/simpletradewithme
🔥 Beyond Market Structure Paid Space is now live! is.gd/beyondMS
💰 Trade with me: is.gd/simpletradewithme
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Pine kitaplığı
Gerçek TradingView ruhuyla, yazar bu Pine kodunu açık kaynaklı bir kütüphane olarak yayınladı, böylece topluluğumuzdaki diğer Pine programcıları onu yeniden kullanabilir. Yazarı tebrik ederiz! Bu kütüphaneyi özel olarak veya diğer açık kaynaklı yayınlarda kullanabilirsiniz, ancak bu kodun yayınlarda yeniden kullanılması Topluluk Kuralları tarafından yönetilir.
🆓 All my free scripts: is.gd/simplefree
🔥 Beyond Market Structure Paid Space is now live! is.gd/beyondMS
💰 Trade with me: is.gd/simpletradewithme
🔥 Beyond Market Structure Paid Space is now live! is.gd/beyondMS
💰 Trade with me: is.gd/simpletradewithme
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.