OPEN-SOURCE SCRIPT
AI Trend Strength Meter [algotim]

Overview
EMA Cloud Trend Retest Signals is a trend-continuation indicator built around a state-based pullback and retest process.
The purpose of the script is to distinguish an ordinary moving-average touch from a structured retest. Instead of generating a signal simply because price crosses an EMA, the script first requires an established directional regime, then tracks a pullback into the EMA cloud and evaluates how deeply price retraces before attempting to resume the prevailing direction.
The result is a selective retest workflow rather than a standalone moving-average crossover signal.
Problem Statement
A basic EMA crossover can identify direction, but it does not describe what happens after the trend has started. Likewise, a simple moving-average touch can occur repeatedly during sideways markets and can produce many low-quality signals.
This script addresses that problem by separating trend identification from retest validation.
A trend must first establish itself for a configurable number of bars. Price must then interact with the EMA cloud. The script tracks the deepest part of that pullback and can require the depth to exceed a configurable fraction of ATR. Optional volume confirmation adds another condition at the retest candle.
This makes the signal dependent on the sequence of events rather than on one indicator crossing another.
Methodology
The trend engine uses a fast EMA and a slow EMA calculated from the selected price source.
When the fast EMA is above the slow EMA, the regime is bullish. When it is below the slow EMA, the regime is bearish.
The script also measures the percentage distance between the two EMAs:
Spread % = abs(Fast EMA - Slow EMA) / Close x 100
This value is normalized and used primarily to control the visual strength of the EMA cloud rather than to create an independent trading signal.
Trend age is tracked as the number of bars since the EMA regime last changed. A configurable minimum trend age prevents an immediate EMA flip from being treated as an established trend.
Retest Detection
Once a bullish regime is active, the script monitors for price interaction with the EMA cloud. For bearish regimes, the same process is applied in the opposite direction.
Depending on the selected setting, a retest can be recognized using either:
* A wick entering the EMA cloud.
* A candle close entering the EMA cloud.
Once the cloud is touched, a pullback state becomes active.
The script then tracks the most extreme price reached during that active pullback.
For bullish retests:
Pullback depth = Cloud top - Pullback low
For bearish retests:
Pullback depth = Pullback high - Cloud bottom
This allows the depth of the retracement to be compared with current volatility.
ATR Validation
The pullback-depth filter uses ATR as the volatility reference.
A bullish retest must satisfy:
Pullback depth >= ATR x Minimum Depth
A bearish retest uses the corresponding distance from the lower cloud boundary.
Because the threshold is expressed in ATR units, the filter adapts to the current volatility of the instrument instead of relying on a fixed price distance.
Volume Validation
When enabled, the retest candle is compared with a moving average of volume.
Volume confirmation requires:
Current volume >= Average volume x Volume multiplier
This filter is optional and can be disabled when volume data is unsuitable for the instrument.
Signal Workflow
1. Calculate the fast and slow EMAs.
2. Establish the bullish or bearish EMA regime.
3. Reset the signal lock when the EMA regime changes.
4. Count how many bars the current regime has remained active.
5. Ignore retests until the minimum trend-age requirement is satisfied.
6. Detect price interaction with the EMA cloud.
7. Activate a pullback state.
8. Track the deepest price reached during that pullback.
9. Compare pullback depth with the ATR-based minimum.
10. Optionally verify above-average volume.
11. Require price to close back through the appropriate cloud boundary.
12. Generate the retest signal.
13. Lock further signals until the EMA regime changes.
The one-signal-per-trend lock is an important part of the workflow. It prevents repeated cloud interactions during the same EMA regime from continuously producing identical signals.
Signal Strength
When enabled, the script classifies the retest using a simple three-point strength model.
One point is added when the trend has persisted for at least twice the minimum trend-age requirement.
One point is added when current volume reaches 1.5 times the average volume.
One point is added when the measured pullback depth reaches twice the configured minimum ATR depth.
A score of two or more is displayed as a stronger retest classification.
This score is a classification of the conditions present at the retest; it is not a probability or performance estimate.
Why This Indicator Is Different
A conventional EMA indicator normally answers one question: which EMA is above the other?
A basic pullback indicator may add a moving-average touch condition.
This script instead treats the retest as a sequence with persistent state:
EMA regime -> trend age -> cloud interaction -> pullback tracking -> ATR depth validation -> volume validation -> recovery through the cloud -> signal lock.
The distinction is therefore not the use of EMAs, ATR or volume individually. Those are standard analytical tools. The main contribution is the way they are used as sequential validation layers around a tracked pullback state.
The script also prevents multiple signals from the same trend regime by maintaining a signal-fired state until the EMA direction changes.
Inputs
EMA Cloud Settings
* Fast EMA Length
* Slow EMA Length
* Price Source
* EMA Line Width
* Candle coloring
* Cloud opacity and visual options
* ATR Length
Retest Settings
* Minimum Trend Age
* Wick-based or close-based cloud interaction
* Buy/Sell signal visibility
* Volume confirmation
* Volume moving-average length
* Volume multiplier
* Minimum pullback depth in ATR
* Signal-strength display
Risk and Target Settings
The script also provides configurable risk-reward reference levels where enabled, including target multipliers and a selectable stop-loss basis.
Alerts
The indicator provides alert functionality for the retest conditions according to the enabled alert settings.
Alerts should be interpreted as notifications that the defined sequence has completed, not as guarantees of future price movement.
Practical Usage
The indicator is intended primarily for trend-continuation analysis.
For bullish conditions, users can focus on periods where the fast EMA remains above the slow EMA, the trend has established for the required number of bars, and price pulls back into the EMA cloud before recovering above it.
For bearish conditions, the inverse process applies.
The ATR depth filter can be increased when shallow pullbacks generate excessive signals. The volume filter can be enabled when volume data provides useful participation information.
Signals should preferably be evaluated in the context of the broader market structure, timeframe and current volatility rather than treated as automatic entries.
Limitations
EMA-based regimes are lagging by construction and can change frequently during sideways markets.
A cloud interaction does not guarantee continuation. Ranging conditions can produce repeated pullbacks and failed retests.
ATR normalization adjusts the depth requirement to volatility but does not eliminate market noise.
Volume confirmation depends on the quality and meaning of the volume data available for the instrument.
The signal-strength score is a rule-based classification, not a statistical probability of success.
Trend age and pullback depth depend on historical bars and the selected settings, so results can vary substantially between instruments and timeframes.
Signals should be evaluated after bar close and should not be interpreted as guaranteed future price direction.
Notes
This indicator is an analytical framework for identifying structured EMA-cloud retests. It is not a trading strategy with guaranteed performance and should not be treated as financial advice.
The EMA, ATR and volume calculations used by the script are standard technical-analysis concepts. The intended distinction is the state-based workflow that combines them to qualify a single retest within an established trend regime.
EMA Cloud Trend Retest Signals is a trend-continuation indicator built around a state-based pullback and retest process.
The purpose of the script is to distinguish an ordinary moving-average touch from a structured retest. Instead of generating a signal simply because price crosses an EMA, the script first requires an established directional regime, then tracks a pullback into the EMA cloud and evaluates how deeply price retraces before attempting to resume the prevailing direction.
The result is a selective retest workflow rather than a standalone moving-average crossover signal.
Problem Statement
A basic EMA crossover can identify direction, but it does not describe what happens after the trend has started. Likewise, a simple moving-average touch can occur repeatedly during sideways markets and can produce many low-quality signals.
This script addresses that problem by separating trend identification from retest validation.
A trend must first establish itself for a configurable number of bars. Price must then interact with the EMA cloud. The script tracks the deepest part of that pullback and can require the depth to exceed a configurable fraction of ATR. Optional volume confirmation adds another condition at the retest candle.
This makes the signal dependent on the sequence of events rather than on one indicator crossing another.
Methodology
The trend engine uses a fast EMA and a slow EMA calculated from the selected price source.
When the fast EMA is above the slow EMA, the regime is bullish. When it is below the slow EMA, the regime is bearish.
The script also measures the percentage distance between the two EMAs:
Spread % = abs(Fast EMA - Slow EMA) / Close x 100
This value is normalized and used primarily to control the visual strength of the EMA cloud rather than to create an independent trading signal.
Trend age is tracked as the number of bars since the EMA regime last changed. A configurable minimum trend age prevents an immediate EMA flip from being treated as an established trend.
Retest Detection
Once a bullish regime is active, the script monitors for price interaction with the EMA cloud. For bearish regimes, the same process is applied in the opposite direction.
Depending on the selected setting, a retest can be recognized using either:
* A wick entering the EMA cloud.
* A candle close entering the EMA cloud.
Once the cloud is touched, a pullback state becomes active.
The script then tracks the most extreme price reached during that active pullback.
For bullish retests:
Pullback depth = Cloud top - Pullback low
For bearish retests:
Pullback depth = Pullback high - Cloud bottom
This allows the depth of the retracement to be compared with current volatility.
ATR Validation
The pullback-depth filter uses ATR as the volatility reference.
A bullish retest must satisfy:
Pullback depth >= ATR x Minimum Depth
A bearish retest uses the corresponding distance from the lower cloud boundary.
Because the threshold is expressed in ATR units, the filter adapts to the current volatility of the instrument instead of relying on a fixed price distance.
Volume Validation
When enabled, the retest candle is compared with a moving average of volume.
Volume confirmation requires:
Current volume >= Average volume x Volume multiplier
This filter is optional and can be disabled when volume data is unsuitable for the instrument.
Signal Workflow
1. Calculate the fast and slow EMAs.
2. Establish the bullish or bearish EMA regime.
3. Reset the signal lock when the EMA regime changes.
4. Count how many bars the current regime has remained active.
5. Ignore retests until the minimum trend-age requirement is satisfied.
6. Detect price interaction with the EMA cloud.
7. Activate a pullback state.
8. Track the deepest price reached during that pullback.
9. Compare pullback depth with the ATR-based minimum.
10. Optionally verify above-average volume.
11. Require price to close back through the appropriate cloud boundary.
12. Generate the retest signal.
13. Lock further signals until the EMA regime changes.
The one-signal-per-trend lock is an important part of the workflow. It prevents repeated cloud interactions during the same EMA regime from continuously producing identical signals.
Signal Strength
When enabled, the script classifies the retest using a simple three-point strength model.
One point is added when the trend has persisted for at least twice the minimum trend-age requirement.
One point is added when current volume reaches 1.5 times the average volume.
One point is added when the measured pullback depth reaches twice the configured minimum ATR depth.
A score of two or more is displayed as a stronger retest classification.
This score is a classification of the conditions present at the retest; it is not a probability or performance estimate.
Why This Indicator Is Different
A conventional EMA indicator normally answers one question: which EMA is above the other?
A basic pullback indicator may add a moving-average touch condition.
This script instead treats the retest as a sequence with persistent state:
EMA regime -> trend age -> cloud interaction -> pullback tracking -> ATR depth validation -> volume validation -> recovery through the cloud -> signal lock.
The distinction is therefore not the use of EMAs, ATR or volume individually. Those are standard analytical tools. The main contribution is the way they are used as sequential validation layers around a tracked pullback state.
The script also prevents multiple signals from the same trend regime by maintaining a signal-fired state until the EMA direction changes.
Inputs
EMA Cloud Settings
* Fast EMA Length
* Slow EMA Length
* Price Source
* EMA Line Width
* Candle coloring
* Cloud opacity and visual options
* ATR Length
Retest Settings
* Minimum Trend Age
* Wick-based or close-based cloud interaction
* Buy/Sell signal visibility
* Volume confirmation
* Volume moving-average length
* Volume multiplier
* Minimum pullback depth in ATR
* Signal-strength display
Risk and Target Settings
The script also provides configurable risk-reward reference levels where enabled, including target multipliers and a selectable stop-loss basis.
Alerts
The indicator provides alert functionality for the retest conditions according to the enabled alert settings.
Alerts should be interpreted as notifications that the defined sequence has completed, not as guarantees of future price movement.
Practical Usage
The indicator is intended primarily for trend-continuation analysis.
For bullish conditions, users can focus on periods where the fast EMA remains above the slow EMA, the trend has established for the required number of bars, and price pulls back into the EMA cloud before recovering above it.
For bearish conditions, the inverse process applies.
The ATR depth filter can be increased when shallow pullbacks generate excessive signals. The volume filter can be enabled when volume data provides useful participation information.
Signals should preferably be evaluated in the context of the broader market structure, timeframe and current volatility rather than treated as automatic entries.
Limitations
EMA-based regimes are lagging by construction and can change frequently during sideways markets.
A cloud interaction does not guarantee continuation. Ranging conditions can produce repeated pullbacks and failed retests.
ATR normalization adjusts the depth requirement to volatility but does not eliminate market noise.
Volume confirmation depends on the quality and meaning of the volume data available for the instrument.
The signal-strength score is a rule-based classification, not a statistical probability of success.
Trend age and pullback depth depend on historical bars and the selected settings, so results can vary substantially between instruments and timeframes.
Signals should be evaluated after bar close and should not be interpreted as guaranteed future price direction.
Notes
This indicator is an analytical framework for identifying structured EMA-cloud retests. It is not a trading strategy with guaranteed performance and should not be treated as financial advice.
The EMA, ATR and volume calculations used by the script are standard technical-analysis concepts. The intended distinction is the state-based workflow that combines them to qualify a single retest within an established trend regime.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Build your trading tools with AI : algotim.com
All content provided by AlgoTim (algo_aakash) is for informational and educational purposes only. Trading involves risk, and past performance does not guarantee future results.
All content provided by AlgoTim (algo_aakash) is for informational and educational purposes only. Trading involves risk, and past performance does not guarantee future results.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Build your trading tools with AI : algotim.com
All content provided by AlgoTim (algo_aakash) is for informational and educational purposes only. Trading involves risk, and past performance does not guarantee future results.
All content provided by AlgoTim (algo_aakash) is for informational and educational purposes only. Trading involves risk, and past performance does not guarantee future results.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.